Skip to content

Commit

Permalink
remove void* casts (#4)
Browse files Browse the repository at this point in the history
Co-authored-by: Dave Berkeley <via@rotwang.co.uk>
  • Loading branch information
DaveBerkeley and Dave Berkeley committed Sep 27, 2021
1 parent 0cdd860 commit 60509fa
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
6 changes: 3 additions & 3 deletions example/tb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ int main(int argc, char **argv, char **env) {
"gpio.SW14",
"gpio.SW15",
};
int num_inputs = 16;
int num_inputs = sizeof(inputs) / sizeof(inputs[0]);

int *input_vals = (int *)calloc(16, sizeof(int));
int *input_vals = (int *)calloc(num_inputs, sizeof(int));

vidbo_init(&vidbo_context, 8081);

vidbo_register_inputs((void *)inputs, num_inputs);
vidbo_register_inputs(inputs, num_inputs);

Verilated::commandArgs(argc, argv);

Expand Down
29 changes: 14 additions & 15 deletions src/vidbo.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ struct Node {
struct Node* next;
};

struct Node *head = NULL;
static struct Node *head = NULL;

struct msg {
void *payload; /* is malloc'd */
Expand All @@ -31,12 +31,12 @@ struct per_vhost_data__minimal {
struct msg amsg; /* the one pending message... */
};

int connected = 0;
int pending = 0;
int cts = 1;
char json_buf[1024];
const char * const json_template = "{\"%s\" : {\"%s\" : %d}}";
int *input_vals;
static int connected = 0;
static int pending = 0;
static int cts = 1;
static char json_buf[1024];
static const char * const json_template = "{\"%s\" : {\"%s\" : %d}}";
static int *input_vals;

static void __minimal_destroy_message(void *_msg) {
struct msg *msg = (struct msg *)_msg;
Expand Down Expand Up @@ -94,18 +94,19 @@ static signed char lejp_cb(struct lejp_ctx *ctx, char reason) {
}


void *input_paths;
int input_count;
static vidbo_input *input_paths;
static size_t input_count;

void vidbo_register_inputs(void * inputs, int count) {
void vidbo_register_inputs(vidbo_input * inputs, size_t count) {
input_vals = (int *)calloc(count, sizeof(int));
input_paths = inputs;
input_count = count;
}

static void parse_json(uint8_t *buf, int len) {
static void parse_json(uint8_t *buf, size_t len) {
len = len; // UNUSED
struct lejp_ctx lejp_ctx;
lejp_construct(&lejp_ctx, lejp_cb, NULL, (const char * const *)input_paths, input_count);
lejp_construct(&lejp_ctx, lejp_cb, NULL, input_paths, (unsigned char) input_count);
int m = lejp_parse(&lejp_ctx, (uint8_t *)buf, 1024);
if (m < 0 && m != LEJP_CONTINUE) {
lwsl_err("parse failed %d\n", m);
Expand All @@ -124,11 +125,9 @@ static int ws_cb(struct lws *wsi, enum lws_callback_reasons reason,

int m;
unsigned long cur_time;
struct Node *temp = NULL, *next;
struct Node *temp = NULL;
struct Node *gpio_head = NULL;
struct Node *gpio_cur = NULL;
struct Node *serial_head = NULL;
struct Node *serial_cur = NULL;

int chars_written = 0;
switch (reason) {
Expand Down
6 changes: 5 additions & 1 deletion src/vidbo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <libwebsockets.h>

typedef const char * const vidbo_input;

typedef struct {
struct lws_context *context;
struct lws_protocols *protocols;
Expand All @@ -8,5 +10,7 @@ typedef struct {
int vidbo_init(vidbo_context_t * context, uint16_t port);
int vidbo_send(vidbo_context_t *context, unsigned long time, char const *group, char const *item, int val);
int vidbo_recv(vidbo_context_t *context, int *inputs);
void vidbo_register_inputs(void * inputs, int count);
void vidbo_register_inputs(vidbo_input * inputs, size_t count);
void vidbo_destroy(vidbo_context_t *context);


0 comments on commit 60509fa

Please sign in to comment.