Skip to content

Commit

Permalink
Remove csp_malloc completely
Browse files Browse the repository at this point in the history
Only rdp and rtable still uses malloc internally
and kiss and zmqhub also does
  • Loading branch information
johandc committed Sep 12, 2021
1 parent bd15417 commit a24701e
Show file tree
Hide file tree
Showing 34 changed files with 48 additions and 334 deletions.
13 changes: 1 addition & 12 deletions examples/csp_arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include <csp/arch/csp_thread.h>
#include <csp/arch/csp_clock.h>
#include <csp/arch/csp_time.h>
#include <csp/arch/csp_malloc.h>
#include <csp/arch/csp_queue.h>
#include <csp/arch/csp_semaphore.h>

Expand Down Expand Up @@ -82,17 +81,7 @@ int main(int argc, char * argv[]) {
csp_assert(csp_get_s() >= (sec1 + 1));
csp_assert(csp_get_s_isr() >= (sec2 + 1));

// malloc
uint32_t * ptr = csp_malloc(sizeof(*ptr));
csp_assert(ptr != NULL);
ptr[0] = 10;
csp_free(ptr);
ptr = csp_calloc(1, sizeof(*ptr));
csp_assert(ptr != NULL);
csp_assert(*ptr == 0);
ptr[0] = 20;
csp_free(ptr);


// check thread actually executed
csp_assert(thread_executed != false);

Expand Down
60 changes: 0 additions & 60 deletions include/csp/arch/csp_malloc.h

This file was deleted.

24 changes: 5 additions & 19 deletions include/csp/csp.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ enum csp_dedup_types {

/**
CSP configuration.
@see csp_init()
*/
typedef struct csp_conf_s {
uint8_t version; /**< Protocol version to use (either 1 or 2) */
Expand All @@ -65,26 +64,13 @@ typedef struct csp_conf_s {
uint8_t dedup; /**< Enable CSP deduplication. 0 = off, 1 = always on, 2 = only on forwarded packets, */
} csp_conf_t;

/**
Get default CSP configuration.
*/
static inline void csp_conf_get_defaults(csp_conf_t * conf) {
conf->version = 2;
conf->address = 1;
conf->hostname = "hostname";
conf->model = "model";
conf->revision = "revision";
conf->conn_dfl_so = CSP_O_NONE;
conf->dedup = CSP_DEDUP_OFF;
}
extern csp_conf_t csp_conf;

/**
Initialize CSP.
This will configure/allocate basic structures.
@param[in] conf configuration. A shallow copy will be done of the provided configuration, i.e. only copy references to strings/structers.
@return #CSP_ERR_NONE on success, otherwise an error code.
*/
int csp_init(const csp_conf_t * conf);
* Initialize CSP.
* This will configure basic structures.
*/
void csp_init(void);

/**
Free allocated resorces in CSP.
Expand Down
4 changes: 2 additions & 2 deletions include/csp/csp_sfp.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static inline int csp_sfp_send(csp_conn_t * conn, const void * data, unsigned in
This is the counterpart to the csp_sfp_send() and csp_sfp_send_own_memcpy().
@param[in] conn established connection for receiving SFP packets.
@param[out] dataout received data on success. Allocated with csp_malloc(), so should be freed with csp_free(). The pointer will be NULL on failure.
@param[out] dataout received data on success. Allocated with malloc(), so should be freed with free(). The pointer will be NULL on failure.
@param[out] datasize size of received data.
@param[in] timeout timeout in ms to wait for csp_read()
@param[in] first_packet First packet of a SFP transfer. Use NULL to receive first packet on the connection.
Expand All @@ -96,7 +96,7 @@ int csp_sfp_recv_fp(csp_conn_t * conn, void ** dataout, int * datasize, uint32_t
This is the counterpart to the csp_sfp_send() and csp_sfp_send_own_memcpy().
@param[in] conn established connection for receiving SFP packets.
@param[out] dataout received data on success. Allocated with csp_malloc(), so should be freed with csp_free(). The pointer will be NULL on failure.
@param[out] dataout received data on success. Allocated with malloc(), so should be freed with free(). The pointer will be NULL on failure.
@param[out] datasize size of received data.
@param[in] timeout timeout in ms to wait for csp_read()
@return #CSP_ERR_NONE on success, otherwise an error.
Expand Down
42 changes: 0 additions & 42 deletions src/arch/freertos/csp_malloc.c

This file was deleted.

1 change: 0 additions & 1 deletion src/arch/freertos/meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
csp_sources += files([
'csp_malloc.c',
'csp_queue.c',
'csp_semaphore.c',
'csp_system.c',
Expand Down
22 changes: 0 additions & 22 deletions src/arch/macosx/csp_malloc.c

This file was deleted.

36 changes: 0 additions & 36 deletions src/arch/posix/csp_malloc.c

This file was deleted.

1 change: 0 additions & 1 deletion src/arch/posix/meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
csp_sources += files([
'csp_malloc.c',
'csp_queue.c',
'csp_semaphore.c',
'csp_system.c',
Expand Down
16 changes: 8 additions & 8 deletions src/arch/posix/pthread_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ Inspired by c-pthread-queue by Matthew Dickinson

#include <errno.h>
#include <string.h>
#include <malloc.h>

#include <csp/csp.h>
#include <csp/arch/csp_malloc.h>

static inline int get_deadline(struct timespec *ts, uint32_t timeout_ms)
{
Expand Down Expand Up @@ -74,23 +74,23 @@ static inline int init_cond_clock_monotonic(pthread_cond_t * cond)

pthread_queue_t * pthread_queue_create(int length, size_t item_size) {

pthread_queue_t * q = csp_malloc(sizeof(pthread_queue_t));
pthread_queue_t * q = malloc(sizeof(pthread_queue_t));

if (q != NULL) {
q->buffer = csp_malloc(length*item_size);
q->buffer = malloc(length*item_size);
if (q->buffer != NULL) {
q->size = length;
q->item_size = item_size;
q->items = 0;
q->in = 0;
q->out = 0;
if (pthread_mutex_init(&(q->mutex), NULL) || init_cond_clock_monotonic(&(q->cond_full)) || init_cond_clock_monotonic(&(q->cond_empty))) {
csp_free(q->buffer);
csp_free(q);
free(q->buffer);
free(q);
q = NULL;
}
} else {
csp_free(q);
free(q);
q = NULL;
}
}
Expand All @@ -104,8 +104,8 @@ void pthread_queue_delete(pthread_queue_t * q) {
if (q == NULL)
return;

csp_free(q->buffer);
csp_free(q);
free(q->buffer);
free(q);

return;

Expand Down
35 changes: 0 additions & 35 deletions src/arch/windows/csp_malloc.c

This file was deleted.

5 changes: 0 additions & 5 deletions src/csp_bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,9 @@ License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include <csp/csp.h>

#include <csp/csp_interface.h>
#include <csp/interfaces/csp_if_zmqhub.h>
#include <csp/arch/csp_thread.h>
#include "csp_qfifo.h"
#include "csp_io.h"
#include "csp_promisc.h"

typedef struct {
csp_iface_t* iface;
Expand Down
4 changes: 1 addition & 3 deletions src/csp_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

#include <csp/csp_buffer.h>

#include <csp/csp_debug.h>
#include <csp/arch/csp_queue.h>
#include <csp/arch/csp_malloc.h>
#include "csp_init.h"
#include <csp/csp_debug.h>

#ifndef CSP_BUFFER_ALIGN
#define CSP_BUFFER_ALIGN (sizeof(int *))
Expand Down
2 changes: 0 additions & 2 deletions src/csp_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include <stdlib.h>
#include <stdio.h>

#include <csp/csp.h>
#include <csp/arch/csp_queue.h>
#include <csp/arch/csp_semaphore.h>
#include <csp/arch/csp_time.h>
#include <csp/csp_id.h>
#include <csp_autoconfig.h>
#include "csp_init.h"
#include "transport/csp_transport.h"

/* Connection pool */
Expand Down
1 change: 0 additions & 1 deletion src/csp_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include <avr/pgmspace.h>
#endif

#include <csp/csp.h>
#include <csp/arch/csp_clock.h>
#include <csp/arch/csp_system.h>

Expand Down
Loading

0 comments on commit a24701e

Please sign in to comment.