Commit | Line | Data |
a0d0e21e |
1 | /* dlutils.c - handy functions and definitions for dl_*.xs files |
2 | * |
3 | * Currently this file is simply #included into dl_*.xs/.c files. |
4 | * It should really be split into a dlutils.h and dlutils.c |
5 | * |
6 | */ |
7 | |
8 | |
9 | /* pointer to allocated memory for last error message */ |
10 | static char *LastError = (char*)NULL; |
11 | |
8e07c86e |
12 | /* flag for immediate rather than lazy linking (spots unresolved symbol) */ |
13 | static int dl_nonlazy = 0; |
14 | |
15 | #ifdef DL_LOADONCEONLY |
16 | static HV *dl_loaded_files = Nullhv; /* only needed on a few systems */ |
17 | #endif |
a0d0e21e |
18 | |
19 | |
20 | #ifdef DEBUGGING |
8e07c86e |
21 | static int dl_debug = 0; /* value copied from $DynaLoader::dl_error */ |
22 | #define DLDEBUG(level,code) if (dl_debug>=level) { code; } |
a0d0e21e |
23 | #else |
24 | #define DLDEBUG(level,code) |
25 | #endif |
26 | |
27 | |
28 | static void |
0cb96387 |
29 | dl_generic_private_init(pTHXo) /* called by dl_*.xs dl_private_init() */ |
a0d0e21e |
30 | { |
8e07c86e |
31 | char *perl_dl_nonlazy; |
a0d0e21e |
32 | #ifdef DEBUGGING |
9426adcd |
33 | SV *sv = get_sv("DynaLoader::dl_debug", 0); |
34 | dl_debug = sv ? SvIV(sv) : 0; |
8e07c86e |
35 | #endif |
36 | if ( (perl_dl_nonlazy = getenv("PERL_DL_NONLAZY")) != NULL ) |
37 | dl_nonlazy = atoi(perl_dl_nonlazy); |
38 | if (dl_nonlazy) |
bf49b057 |
39 | DLDEBUG(1,PerlIO_printf(Perl_debug_log, "DynaLoader bind mode is 'non-lazy'\n")); |
8e07c86e |
40 | #ifdef DL_LOADONCEONLY |
41 | if (!dl_loaded_files) |
42 | dl_loaded_files = newHV(); /* provide cache for dl_*.xs if needed */ |
a0d0e21e |
43 | #endif |
44 | } |
45 | |
46 | |
47 | /* SaveError() takes printf style args and saves the result in LastError */ |
a0d0e21e |
48 | static void |
0cb96387 |
49 | SaveError(pTHXo_ char* pat, ...) |
a0d0e21e |
50 | { |
51 | va_list args; |
a6c40364 |
52 | SV *msv; |
a0d0e21e |
53 | char *message; |
a6c40364 |
54 | STRLEN len; |
a0d0e21e |
55 | |
8e07c86e |
56 | /* This code is based on croak/warn, see mess() in util.c */ |
a0d0e21e |
57 | |
a0d0e21e |
58 | va_start(args, pat); |
5a844595 |
59 | msv = vmess(pat, &args); |
a0d0e21e |
60 | va_end(args); |
61 | |
a6c40364 |
62 | message = SvPV(msv,len); |
63 | len++; /* include terminating null char */ |
a0d0e21e |
64 | |
65 | /* Allocate some memory for the error message */ |
66 | if (LastError) |
67 | LastError = (char*)saferealloc(LastError, len) ; |
68 | else |
2e5d53bf |
69 | LastError = (char *) safemalloc(len) ; |
a0d0e21e |
70 | |
71 | /* Copy message into LastError (including terminating null char) */ |
72 | strncpy(LastError, message, len) ; |
bf49b057 |
73 | DLDEBUG(2,PerlIO_printf(Perl_debug_log, "DynaLoader: stored error msg '%s'\n",LastError)); |
a0d0e21e |
74 | } |
75 | |