* files when the interpreter exits
*/
-#define MY_CXT_KEY "DynaLoader_guts"
+#ifndef START_MY_CXT /* Some IDEs try compiling this standalone. */
+# include "EXTERN.h"
+# include "perl.h"
+# include "XSUB.h"
+#endif
+
+#ifndef XS_VERSION
+# define XS_VERSION "0"
+#endif
+#define MY_CXT_KEY "DynaLoader::_guts" XS_VERSION
typedef struct {
- char * x_dl_last_error; /* pointer to allocated memory for
+ SV* x_dl_last_error; /* pointer to allocated memory for
last error message */
int x_dl_nonlazy; /* flag for immediate rather than lazy
linking (spots unresolved symbol) */
#endif
} my_cxt_t;
-/* XXX most of this is boilerplate code that should abstracted further into
- * macros and exposed via XSUB.h */
-
-#if defined(USE_ITHREADS)
-
-#define dMY_CXT_SV \
- SV *my_cxt_sv = *hv_fetch(PL_modglobal, MY_CXT_KEY, \
- sizeof(MY_CXT_KEY)-1, TRUE)
-
-/* we allocate my_cxt in a Perl SV so that it will be released when
- * the interpreter goes away */
-#define dMY_CXT_INIT \
- dMY_CXT_SV; \
- /* newSV() allocates one more than needed */ \
- my_cxt_t *my_cxt = (my_cxt_t*)SvPVX(newSV(sizeof(my_cxt_t)-1)); \
- Zero(my_cxt, 1, my_cxt_t); \
- sv_setuv(my_cxt_sv, (UV)my_cxt);
+START_MY_CXT
-#define dMY_CXT \
- dMY_CXT_SV; \
- my_cxt_t *my_cxt = (my_cxt_t*)SvUV(my_cxt_sv)
-
-#define dl_last_error (my_cxt->x_dl_last_error)
-#define dl_nonlazy (my_cxt->x_dl_nonlazy)
+#define dl_last_error (SvPVX(MY_CXT.x_dl_last_error))
+#define dl_nonlazy (MY_CXT.x_dl_nonlazy)
#ifdef DL_LOADONCEONLY
-#define dl_loaded_files (my_cxt->x_dl_loaded_files)
+#define dl_loaded_files (MY_CXT.x_dl_loaded_files)
#endif
#ifdef DL_CXT_EXTRA
-#define dl_cxtx (my_cxt->x_dl_cxtx)
+#define dl_cxtx (MY_CXT.x_dl_cxtx)
#endif
#ifdef DEBUGGING
-#define dl_debug (my_cxt->x_dl_debug)
+#define dl_debug (MY_CXT.x_dl_debug)
#endif
-#else /* USE_ITHREADS */
-
-static my_cxt_t my_cxt;
-
-#define dMY_CXT_SV dNOOP
-#define dMY_CXT_INIT dNOOP
-#define dMY_CXT dNOOP
-
-#define dl_last_error (my_cxt.x_dl_last_error)
-#define dl_nonlazy (my_cxt.x_dl_nonlazy)
-#ifdef DL_LOADONCEONLY
-#define dl_loaded_files (my_cxt.x_dl_loaded_files)
-#endif
-#ifdef DL_CXT_EXTRA
-#define dl_cxtx (my_cxt.x_dl_cxtx)
-#endif
-#ifdef DEBUGGING
-#define dl_debug (my_cxt.x_dl_debug)
-#endif
-
-#endif /* !defined(USE_ITHREADS) */
-
-
#ifdef DEBUGGING
#define DLDEBUG(level,code) \
STMT_START { \
dl_generic_private_init(pTHX) /* called by dl_*.xs dl_private_init() */
{
char *perl_dl_nonlazy;
- dMY_CXT_INIT;
+ MY_CXT_INIT;
- dl_last_error = NULL;
+ MY_CXT.x_dl_last_error = newSVpvn("", 0);
dl_nonlazy = 0;
#ifdef DL_LOADONCEONLY
dl_loaded_files = Nullhv;
}
+#ifndef SYMBIAN
/* SaveError() takes printf style args and saves the result in dl_last_error */
static void
-SaveError(pTHX_ char* pat, ...)
+SaveError(pTHX_ const char* pat, ...)
{
dMY_CXT;
va_list args;
SV *msv;
- char *message;
+ const char *message;
STRLEN len;
/* This code is based on croak/warn, see mess() in util.c */
message = SvPV(msv,len);
len++; /* include terminating null char */
- /* Allocate some memory for the error message */
- if (dl_last_error)
- dl_last_error = (char*)saferealloc(dl_last_error, len);
- else
- dl_last_error = (char*)safemalloc(len);
-
/* Copy message into dl_last_error (including terminating null char) */
- strncpy(dl_last_error, message, len) ;
+ sv_setpvn(MY_CXT.x_dl_last_error, message, len) ;
DLDEBUG(2,PerlIO_printf(Perl_debug_log, "DynaLoader: stored error msg '%s'\n",dl_last_error));
}
+#endif