Skip to content

Commit

Permalink
Attempted to address clang-asan's complaint about calling callback ne…
Browse files Browse the repository at this point in the history
…twork change callback functions from incorrect function type by redefining *U_CHANGESTAT_FN() and *MH_U_FN() to construct a wrapper function with the correct signature and defining the implementing function with munged name as static inline.
  • Loading branch information
krivit committed Nov 4, 2024
1 parent 1856fd4 commit eccf171
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 8 deletions.
8 changes: 7 additions & 1 deletion inst/include/ergm_MHproposal.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,13 @@ void MHProposalDestroy(MHProposal *MHp, Network *nwp);
#define Mhead (MHp->togglehead)

#define MH_I_FN(a) void a (MHProposal *MHp, Network *nwp)
#define MH_U_FN(a) void a (Vertex tail, Vertex head, MHProposal *MHp, Network *nwp, Rboolean edgestate)
#define MH_U_FN(a)\
static inline void _ ## a ## __implementation_ (Vertex tail, Vertex head, MHProposal *MHp, Network *nwp, Rboolean edgestate); \
void a (Vertex tail, Vertex head, void *MHp, Network *nwp, Rboolean edgestate){ \
_ ## a ## __implementation_(tail, head, (MHProposal *) MHp, nwp, edgestate); \
} \
static inline void _ ## a ## __implementation_ (Vertex tail, Vertex head, MHProposal *MHp, Network *nwp, Rboolean edgestate)

#define MH_P_FN(a) void a (MHProposal *MHp, Network *nwp)
#define MH_F_FN(a) void a (MHProposal *MHp, Network *nwp)
#define MH_X_FN(a) void a (unsigned int type, void *data, MHProposal* MHp, Network* nwp)
Expand Down
8 changes: 7 additions & 1 deletion inst/include/ergm_changestat.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,13 @@ typedef struct ModelTermstruct {
#define C_CHANGESTAT_FN(a) void a (Vertex tail, Vertex head, ModelTerm *mtp, Network *nwp, Rboolean edgestate)
#define D_CHANGESTAT_FN(a) void a (Edge ntoggles, Vertex *tails, Vertex *heads, ModelTerm *mtp, Network *nwp)
#define I_CHANGESTAT_FN(a) void a (ModelTerm *mtp, Network *nwp)
#define U_CHANGESTAT_FN(a) void a (Vertex tail, Vertex head, ModelTerm *mtp, Network *nwp, Rboolean edgestate)
#define U_CHANGESTAT_FN(a) \
static inline void _ ## a ## __implementation_ (Vertex tail, Vertex head, ModelTerm *mtp, Network *nwp, Rboolean edgestate); \
void a (Vertex tail, Vertex head, void *mtp, Network *nwp, Rboolean edgestate){ \
_ ## a ## __implementation_ (tail, head, (ModelTerm *) mtp, nwp, edgestate); \
} \
static inline void _ ## a ## __implementation_ (Vertex tail, Vertex head, ModelTerm *mtp, Network *nwp, Rboolean edgestate)

#define F_CHANGESTAT_FN(a) void a (ModelTerm *mtp, Network *nwp)
#define S_CHANGESTAT_FN(a) void a (ModelTerm *mtp, Network *nwp)
#define W_CHANGESTAT_FN(a) SEXP a (ModelTerm *mtp, Network *nwp)
Expand Down
4 changes: 2 additions & 2 deletions inst/include/ergm_dyadgen.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ DyadGen *DyadGenInitialize(DyadGenType type, void *dyads, void *track_nwp);
DyadGen *DyadGenInitializeR(SEXP pR, void *any_nwp, Rboolean el);
void DyadGenDestroy(DyadGen *gen);

void DyadGenUpdate(Vertex tail, Vertex head, DyadGen *gen, Network *nwp, Rboolean edgestate);
void WtDyadGenUpdate(Vertex tail, Vertex head, double weight, DyadGen *gen, WtNetwork *nwp, double edgestate);
void DyadGenUpdate(Vertex tail, Vertex head, void *gen, Network *nwp, Rboolean edgestate);
void WtDyadGenUpdate(Vertex tail, Vertex head, double weight, void *gen, WtNetwork *nwp, double edgestate);

static inline void DyadGenRandDyad(Vertex *tail, Vertex *head, DyadGen *gen){
switch(gen->type){
Expand Down
8 changes: 7 additions & 1 deletion inst/include/ergm_wtMHproposal.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,13 @@ void WtMHProposalDestroy(WtMHProposal *MH, WtNetwork *nwp);
#define Mweight (MHp->toggleweight)

#define WtMH_I_FN(a) void (a) (WtMHProposal *MHp, WtNetwork *nwp)
#define WtMH_U_FN(a) void (a) (Vertex tail, Vertex head, double weight, WtMHProposal *MHp, WtNetwork *nwp, double edgestate)
#define WtMH_U_FN(a) \
static inline void _ ## a ## __implementation_ (Vertex tail, Vertex head, double weight, WtMHProposal *MHp, WtNetwork *nwp, double edgestate); \
void a (Vertex tail, Vertex head, double weight, void *MHp, WtNetwork *nwp, double edgestate){ \
_ ## a ## __implementation_(tail, head, weight, (WtMHProposal *) MHp, nwp, edgestate); \
} \
static inline void _ ## a ## __implementation_ (Vertex tail, Vertex head, double weight, WtMHProposal *MHp, WtNetwork *nwp, double edgestate)

#define WtMH_P_FN(a) void (a) (WtMHProposal *MHp, WtNetwork *nwp)
#define WtMH_F_FN(a) void (a) (WtMHProposal *MHp, WtNetwork *nwp)
#define WtMH_X_FN(a) void (a) (unsigned int type, void *data, WtMHProposal* MHp, WtNetwork* nwp)
Expand Down
8 changes: 7 additions & 1 deletion inst/include/ergm_wtchangestat.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,13 @@ typedef struct WtModelTermstruct {
#define WtC_CHANGESTAT_FN(a) void (a) (Vertex tail, Vertex head, double weight, WtModelTerm *mtp, WtNetwork *nwp, double edgestate)
#define WtD_CHANGESTAT_FN(a) void (a) (Edge ntoggles, Vertex *tails, Vertex *heads, double *weights, WtModelTerm *mtp, WtNetwork *nwp)
#define WtI_CHANGESTAT_FN(a) void (a) (WtModelTerm *mtp, WtNetwork *nwp)
#define WtU_CHANGESTAT_FN(a) void (a) (Vertex tail, Vertex head, double weight, WtModelTerm *mtp, WtNetwork *nwp, double edgestate)
#define WtU_CHANGESTAT_FN(a) \
static inline void _ ## a ## __implementation_ (Vertex tail, Vertex head, double weight, WtModelTerm *mtp, WtNetwork *nwp, double edgestate); \
void a (Vertex tail, Vertex head, double weight, void *mtp, WtNetwork *nwp, double edgestate){ \
_ ## a ## __implementation_ (tail, head, weight, (WtModelTerm *) mtp, nwp, edgestate); \
} \
static inline void _ ## a ## __implementation_ (Vertex tail, Vertex head, double weight, WtModelTerm *mtp, WtNetwork *nwp, double edgestate)

#define WtF_CHANGESTAT_FN(a) void (a) (WtModelTerm *mtp, WtNetwork *nwp)
#define WtS_CHANGESTAT_FN(a) void (a) (WtModelTerm *mtp, WtNetwork *nwp)
#define WtW_CHANGESTAT_FN(a) SEXP (a) (WtModelTerm *mtp, WtNetwork *nwp)
Expand Down
8 changes: 6 additions & 2 deletions src/ergm_dyadgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ void DyadGenDestroy(DyadGen *gen){
}


void DyadGenUpdate(Vertex tail, Vertex head, DyadGen *gen, Network *nwp, Rboolean edgestate){
void DyadGenUpdate(Vertex tail, Vertex head, void *payload, Network *nwp, Rboolean edgestate){
DyadGen *gen = (DyadGen *) payload;

if(gen->sleeping) return;

switch(gen->intertype){
Expand All @@ -193,7 +195,9 @@ void DyadGenUpdate(Vertex tail, Vertex head, DyadGen *gen, Network *nwp, Rboolea
}


void WtDyadGenUpdate(Vertex tail, Vertex head, double weight, DyadGen *gen, WtNetwork *nwp, double edgestate){
void WtDyadGenUpdate(Vertex tail, Vertex head, double weight, void *payload, WtNetwork *nwp, double edgestate){
DyadGen *gen = (DyadGen *) payload;

if(gen->sleeping) return;

switch(gen->intertype){
Expand Down

0 comments on commit eccf171

Please sign in to comment.