-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
At compile time, packages linking to 'ergm' will now store the C API …
…version numbers of the 'ergm' installation they were built against in global variables built_ERGM_API_MAJOR and built_ERGM_API_MINOR; model and proposal initialization code will then check whether the linking package was compiled under a wrong version and issue a warning.
- Loading branch information
Showing
7 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include "ergm_Rutil.h" | ||
#include "ergm_constants.h" | ||
#include "ergm_kvec.h" | ||
#include "ergm_khash.h" | ||
|
||
unsigned int built_ERGM_API_MAJOR = ERGM_API_MAJOR; | ||
unsigned int built_ERGM_API_MINOR = ERGM_API_MINOR; | ||
|
||
static kvec_t(khint_t) build_version_warned = kv_blank; | ||
|
||
void warn_API_version(const char *sn){ | ||
|
||
/* Here, we are saving the hash of the library name rather than the | ||
name itself, since keeping track of strings allocated from the | ||
heap is a hassle, and we don't want to assume that sn will always | ||
be around. Chances of collision are negligible. */ | ||
khint_t snhash = kh_str_hash_func(sn); | ||
unsigned int i = 0; | ||
while(i < kv_size(build_version_warned) && kv_A(build_version_warned, i) != snhash) i++; | ||
if(i < kv_size(build_version_warned)) return; | ||
|
||
kv_push(khint_t, build_version_warned, snhash); | ||
|
||
void *bv = R_FindSymbol("built_ERGM_API_MAJOR",sn,NULL); | ||
unsigned int bv_major = bv ? *(unsigned int *)bv : 0; | ||
if(bv_major){ | ||
unsigned int bv_minor = *(unsigned int *)R_FindSymbol("built_ERGM_API_MINOR",sn,NULL); | ||
if(bv_major != ERGM_API_MAJOR || bv_minor != ERGM_API_MINOR) | ||
warningcall_immediate(R_NilValue, "Package '%s' was compiled against 'ergm' with C API version\n %d.%d, but it is being loaded by 'ergm' with C API version %d.%d. Inconsistent\n versions may result in malfunctions ranging from incorrect results to R\n crashing. Please rebuild the package against the current 'ergm' version.", | ||
sn, bv_major, bv_minor, ERGM_API_MAJOR, ERGM_API_MINOR); | ||
}else | ||
warningcall_immediate(R_NilValue, "Package '%s' was compiled against an older version of 'ergm'\n that did not store '%s''s C API version information. Inconsistent\n versions may cause malfunctions ranging from incorrect results to R\n crashing. Please rebuild the package against the current 'ergm' version.", | ||
sn, sn); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters