This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix bug in DynaLoader, which has been passing a filename in dynamic
[perl5.git] / ext / DynaLoader / dl_hpux.xs
CommitLineData
a0d0e21e
LW
1/*
2 * Author: Jeff Okamoto (okamoto@corp.hp.com)
75f92628 3 * Version: 2.1, 1995/1/25
a0d0e21e
LW
4 */
5
b13ecc09
CP
6/* o Added BIND_VERBOSE to dl_nonlazy condition to add names of missing
7 * symbols to stderr message on fatal error.
8 *
9 * o Added BIND_NONFATAL comment to default condition.
10 *
11 * Chuck Phillips (cdp@fc.hp.com)
12 * Version: 2.2, 1997/5/4 */
13
a0d0e21e
LW
14#ifdef __hp9000s300
15#define magic hpux_magic
16#define MAGIC HPUX_MAGIC
17#endif
18
19#include <dl.h>
20#ifdef __hp9000s300
21#undef magic
22#undef MAGIC
23#endif
24
25#include "EXTERN.h"
26#include "perl.h"
27#include "XSUB.h"
28
cdc73a10
JH
29typedef struct {
30 AV * x_resolve_using;
31} my_cxtx_t; /* this *must* be named my_cxtx_t */
a0d0e21e 32
cdc73a10 33#define DL_CXT_EXTRA /* ask for dl_cxtx to be defined in dlutils.c */
a0d0e21e
LW
34#include "dlutils.c" /* for SaveError() etc */
35
cdc73a10 36#define dl_resolve_using (dl_cxtx.x_resolve_using)
a0d0e21e
LW
37
38static void
cea2e8a9 39dl_private_init(pTHX)
a0d0e21e 40{
cea2e8a9 41 (void)dl_generic_private_init(aTHX);
cdc73a10
JH
42 {
43 dMY_CXT;
44 dl_resolve_using = get_av("DynaLoader::dl_resolve_using", GV_ADDMULTI);
45 }
a0d0e21e
LW
46}
47
48MODULE = DynaLoader PACKAGE = DynaLoader
49
50BOOT:
cea2e8a9 51 (void)dl_private_init(aTHX);
a0d0e21e
LW
52
53
54void *
ff7f3c60
NIS
55dl_load_file(filename, flags=0)
56 char * filename
57 int flags
58 PREINIT:
a0d0e21e 59 shl_t obj = NULL;
8e07c86e 60 int i, max, bind_type;
cdc73a10 61 dMY_CXT;
c6a08c25 62 CODE:
bf49b057 63 DLDEBUG(1,PerlIO_printf(Perl_debug_log, "dl_load_file(%s,%x):\n", filename,flags));
ff7f3c60 64 if (flags & 0x01)
cea2e8a9 65 Perl_warn(aTHX_ "Can't make loaded symbols global on this platform while loading %s",filename);
b13ecc09
CP
66 if (dl_nonlazy) {
67 bind_type = BIND_IMMEDIATE|BIND_VERBOSE;
68 } else {
69 bind_type = BIND_DEFERRED;
70 /* For certain libraries, like DCE, deferred binding often causes run
71 * time problems. Adding BIND_NONFATAL to BIND_IMMEDIATE still allows
72 * unresolved references in situations like this. */
73 /* bind_type = BIND_IMMEDIATE|BIND_NONFATAL; */
74 }
491527d0
GS
75 /* BIND_NOSTART removed from bind_type because it causes the shared library's */
76 /* initialisers not to be run. This causes problems with all of the static objects */
77 /* in the library. */
d43d69ec
JO
78#ifdef DEBUGGING
79 if (dl_debug)
80 bind_type |= BIND_VERBOSE;
81#endif /* DEBUGGING */
8e07c86e
AD
82
83 max = AvFILL(dl_resolve_using);
84 for (i = 0; i <= max; i++) {
85 char *sym = SvPVX(*av_fetch(dl_resolve_using, i, 0));
bf49b057 86 DLDEBUG(1,PerlIO_printf(Perl_debug_log, "dl_load_file(%s) (dependent)\n", sym));
491527d0 87 obj = shl_load(sym, bind_type, 0L);
8e07c86e
AD
88 if (obj == NULL) {
89 goto end;
75f92628
AD
90 }
91 }
92
bf49b057 93 DLDEBUG(1,PerlIO_printf(Perl_debug_log, "dl_load_file(%s): ", filename));
491527d0 94 obj = shl_load(filename, bind_type, 0L);
75f92628 95
bf49b057 96 DLDEBUG(2,PerlIO_printf(Perl_debug_log, " libref=%x\n", obj));
75f92628 97end:
a0d0e21e
LW
98 ST(0) = sv_newmortal() ;
99 if (obj == NULL)
cea2e8a9 100 SaveError(aTHX_ "%s",Strerror(errno));
a0d0e21e 101 else
3175b8cd 102 sv_setiv( ST(0), PTR2IV(obj) );
a0d0e21e
LW
103
104
4b1aa53e
NW
105int
106dl_unload_file(libref)
107 void * libref
108 CODE:
109 DLDEBUG(1,PerlIO_printf(Perl_debug_log, "dl_unload_file(%lx):\n", PTR2ul(libref)));
110 RETVAL = (shl_unload(libref) == 0 ? 1 : 0);
111 if (!RETVAL)
112 SaveError(aTHX_ "%s", Strerror(errno));
113 DLDEBUG(2,PerlIO_printf(Perl_debug_log, " retval = %d\n", RETVAL));
114 OUTPUT:
115 RETVAL
116
117
a0d0e21e
LW
118void *
119dl_find_symbol(libhandle, symbolname)
120 void * libhandle
121 char * symbolname
122 CODE:
123 shl_t obj = (shl_t) libhandle;
124 void *symaddr = NULL;
125 int status;
126#ifdef __hp9000s300
7a3f2258 127 symbolname = Perl_form_nocontext("_%s", symbolname);
a0d0e21e 128#endif
bf49b057 129 DLDEBUG(2, PerlIO_printf(Perl_debug_log,
46fc3d4c
PP
130 "dl_find_symbol(handle=%lx, symbol=%s)\n",
131 (unsigned long) libhandle, symbolname));
132
8e07c86e
AD
133 ST(0) = sv_newmortal() ;
134 errno = 0;
135
a0d0e21e 136 status = shl_findsym(&obj, symbolname, TYPE_PROCEDURE, &symaddr);
bf49b057 137 DLDEBUG(2,PerlIO_printf(Perl_debug_log, " symbolref(PROCEDURE) = %x\n", symaddr));
8e07c86e
AD
138
139 if (status == -1 && errno == 0) { /* try TYPE_DATA instead */
140 status = shl_findsym(&obj, symbolname, TYPE_DATA, &symaddr);
bf49b057 141 DLDEBUG(2,PerlIO_printf(Perl_debug_log, " symbolref(DATA) = %x\n", symaddr));
8e07c86e
AD
142 }
143
75f92628 144 if (status == -1) {
cea2e8a9 145 SaveError(aTHX_ "%s",(errno) ? Strerror(errno) : "Symbol not found") ;
75f92628 146 } else {
3175b8cd 147 sv_setiv( ST(0), PTR2IV(symaddr) );
75f92628 148 }
a0d0e21e
LW
149
150
8e07c86e 151void
a0d0e21e
LW
152dl_undef_symbols()
153 PPCODE:
154
155
156
157# These functions should not need changing on any platform:
158
159void
160dl_install_xsub(perl_name, symref, filename="$Package")
161 char * perl_name
162 void * symref
163 char * filename
164 CODE:
bf49b057 165 DLDEBUG(2,PerlIO_printf(Perl_debug_log, "dl_install_xsub(name=%s, symref=%x)\n",
a0d0e21e 166 perl_name, symref));
77004dee
NC
167 ST(0) = sv_2mortal(newRV((SV*)newXS_flags(perl_name,
168 (void(*)(pTHX_ CV *))symref,
169 filename, NULL,
170 XS_DYNAMIC_FILENAME)));
a0d0e21e
LW
171
172char *
173dl_error()
174 CODE:
cdc73a10
JH
175 dMY_CXT;
176 RETVAL = dl_last_error ;
a0d0e21e
LW
177 OUTPUT:
178 RETVAL
179
180# end.