diff --git a/src/global_perl.h b/src/global_perl.h index 563d4ac..5cef801 100644 --- a/src/global_perl.h +++ b/src/global_perl.h @@ -22,9 +22,12 @@ #include #include -// hv_stores(ssn_hv, "id", newSVpv(acct->id, 0)); -// TODO use sv_usepvn_flags soon -#define hvstores_str(hv, key, val) if ((val)) { hv_stores((hv), key, newSVpvn((val), strlen(val))); } +// Note: val MUST be a pointer to a value, and must end with a \0 (hence SvSETMAGIC) +#define hvstores_str(hv, key, val) if (val) { \ + SV* tmpsv = newSV(0); \ + sv_usepvn_flags(tmpsv, val, strlen(val), SvSETMAGIC); \ + hv_stores((hv), key, tmpsv); \ + } #define hvstores_int(hv, key, val) hv_stores((hv), key, newSViv((val))) #define hvstores_ref(hv, key, val) if (1) { \ SV* tmp = (SV*)(val); \ diff --git a/src/main.c b/src/main.c index 1103115..003b619 100644 --- a/src/main.c +++ b/src/main.c @@ -16,8 +16,6 @@ * along with this program. If not, see . */ -#include -#include #include "global_perl.h" #include #include @@ -251,10 +249,10 @@ int main(int argc, char **argv, char **env) init_template_files(aTHX); - // Setup mstdnt hooks + // Setup mstdnt hooks to use Perl functions struct mstdnt_hooks hooks = { .malloc = safemalloc, - // Not sure how this differs from Safefree? + // Not sure how this differs from Safefree? That's undefined... (but used elsewhere in the code just fine) .free = safefree, .calloc = safecalloc, .realloc = saferealloc,