From 653c210e02075750674d3e23c2371e493133f63c Mon Sep 17 00:00:00 2001
From: "Pavel N. Krivitsky"
Date: Mon, 4 Nov 2024 19:38:02 +1100
Subject: [PATCH] Attempted to address clang-asan's complaint about calling
callback network 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.
---
inst/include/ergm_MHproposal.h | 8 +++++++-
inst/include/ergm_changestat.h | 8 +++++++-
inst/include/ergm_dyadgen.h | 4 ++--
inst/include/ergm_stubs.c | 18 +++++++++---------
inst/include/ergm_wtMHproposal.h | 8 +++++++-
inst/include/ergm_wtchangestat.h | 8 +++++++-
src/ergm_dyadgen.c | 8 ++++++--
7 files changed, 45 insertions(+), 17 deletions(-)
diff --git a/inst/include/ergm_MHproposal.h b/inst/include/ergm_MHproposal.h
index 20bdba633..6710fabb8 100644
--- a/inst/include/ergm_MHproposal.h
+++ b/inst/include/ergm_MHproposal.h
@@ -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)
diff --git a/inst/include/ergm_changestat.h b/inst/include/ergm_changestat.h
index 3e8f3607f..603bd8672 100644
--- a/inst/include/ergm_changestat.h
+++ b/inst/include/ergm_changestat.h
@@ -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)
diff --git a/inst/include/ergm_dyadgen.h b/inst/include/ergm_dyadgen.h
index 3e50a4c6b..7d2f7dc36 100644
--- a/inst/include/ergm_dyadgen.h
+++ b/inst/include/ergm_dyadgen.h
@@ -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 *payload, Network *nwp, Rboolean edgestate);
+void WtDyadGenUpdate(Vertex tail, Vertex head, double weight, void *payload, WtNetwork *nwp, double edgestate);
static inline void DyadGenRandDyad(Vertex *tail, Vertex *head, DyadGen *gen){
switch(gen->type){
diff --git a/inst/include/ergm_stubs.c b/inst/include/ergm_stubs.c
index ed63fd9e4..a4f646aa7 100644
--- a/inst/include/ergm_stubs.c
+++ b/inst/include/ergm_stubs.c
@@ -67,15 +67,15 @@ static void (*fun)(DyadGen *) = NULL;
if(fun==NULL) fun = (void (*)(DyadGen *)) R_FindSymbol("DyadGenDestroy", "ergm", NULL);
fun(gen);
}
-void DyadGenUpdate(Vertex tail, Vertex head, DyadGen *gen, Network *nwp, Rboolean edgestate){
-static void (*fun)(Vertex,Vertex,DyadGen *,Network *,Rboolean) = NULL;
-if(fun==NULL) fun = (void (*)(Vertex,Vertex,DyadGen *,Network *,Rboolean)) R_FindSymbol("DyadGenUpdate", "ergm", NULL);
-fun(tail,head,gen,nwp,edgestate);
-}
-void WtDyadGenUpdate(Vertex tail, Vertex head, double weight, DyadGen *gen, WtNetwork *nwp, double edgestate){
-static void (*fun)(Vertex,Vertex,double,DyadGen *,WtNetwork *,double) = NULL;
-if(fun==NULL) fun = (void (*)(Vertex,Vertex,double,DyadGen *,WtNetwork *,double)) R_FindSymbol("WtDyadGenUpdate", "ergm", NULL);
-fun(tail,head,weight,gen,nwp,edgestate);
+void DyadGenUpdate(Vertex tail, Vertex head, void *payload, Network *nwp, Rboolean edgestate){
+static void (*fun)(Vertex,Vertex,void *,Network *,Rboolean) = NULL;
+if(fun==NULL) fun = (void (*)(Vertex,Vertex,void *,Network *,Rboolean)) R_FindSymbol("DyadGenUpdate", "ergm", NULL);
+fun(tail,head,payload,nwp,edgestate);
+}
+void WtDyadGenUpdate(Vertex tail, Vertex head, double weight, void *payload, WtNetwork *nwp, double edgestate){
+static void (*fun)(Vertex,Vertex,double,void *,WtNetwork *,double) = NULL;
+if(fun==NULL) fun = (void (*)(Vertex,Vertex,double,void *,WtNetwork *,double)) R_FindSymbol("WtDyadGenUpdate", "ergm", NULL);
+fun(tail,head,weight,payload,nwp,edgestate);
}
#define STUBFILE
diff --git a/inst/include/ergm_wtMHproposal.h b/inst/include/ergm_wtMHproposal.h
index 604e83809..5e40ca40d 100644
--- a/inst/include/ergm_wtMHproposal.h
+++ b/inst/include/ergm_wtMHproposal.h
@@ -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)
diff --git a/inst/include/ergm_wtchangestat.h b/inst/include/ergm_wtchangestat.h
index 85c4d71e9..e4d8158e5 100644
--- a/inst/include/ergm_wtchangestat.h
+++ b/inst/include/ergm_wtchangestat.h
@@ -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)
diff --git a/src/ergm_dyadgen.c b/src/ergm_dyadgen.c
index 1b873079f..744069321 100644
--- a/src/ergm_dyadgen.c
+++ b/src/ergm_dyadgen.c
@@ -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){
@@ -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){