This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Integrate change #12626 from maintperl;
[perl5.git] / ext / DynaLoader / dl_hpux.xs
1 /*
2  * Author: Jeff Okamoto (okamoto@corp.hp.com)
3  * Version: 2.1, 1995/1/25
4  */
5
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
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
29 typedef struct {
30     AV *        x_resolve_using;
31 } my_cxtx_t;            /* this *must* be named my_cxtx_t */
32
33 #define DL_CXT_EXTRA    /* ask for dl_cxtx to be defined in dlutils.c */
34 #include "dlutils.c"    /* for SaveError() etc */
35
36 #define dl_resolve_using        (dl_cxtx.x_resolve_using)
37
38 static void
39 dl_private_init(pTHX)
40 {
41     (void)dl_generic_private_init(aTHX);
42     {
43         dMY_CXT;
44         dl_resolve_using = get_av("DynaLoader::dl_resolve_using", GV_ADDMULTI);
45     }
46 }
47
48 MODULE = DynaLoader     PACKAGE = DynaLoader
49
50 BOOT:
51     (void)dl_private_init(aTHX);
52
53
54 void *
55 dl_load_file(filename, flags=0)
56     char *      filename
57     int         flags
58     PREINIT:
59     shl_t obj = NULL;
60     int i, max, bind_type;
61     CODE:
62     dMY_CXT;
63     DLDEBUG(1,PerlIO_printf(Perl_debug_log, "dl_load_file(%s,%x):\n", filename,flags));
64     if (flags & 0x01)
65         Perl_warn(aTHX_ "Can't make loaded symbols global on this platform while loading %s",filename);
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     }
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.     */
78 #ifdef DEBUGGING
79     if (dl_debug)
80         bind_type |= BIND_VERBOSE;
81 #endif /* DEBUGGING */
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));
86         DLDEBUG(1,PerlIO_printf(Perl_debug_log, "dl_load_file(%s) (dependent)\n", sym));
87         obj = shl_load(sym, bind_type, 0L);
88         if (obj == NULL) {
89             goto end;
90         }
91     }
92
93     DLDEBUG(1,PerlIO_printf(Perl_debug_log, "dl_load_file(%s): ", filename));
94     obj = shl_load(filename, bind_type, 0L);
95
96     DLDEBUG(2,PerlIO_printf(Perl_debug_log, " libref=%x\n", obj));
97 end:
98     ST(0) = sv_newmortal() ;
99     if (obj == NULL)
100         SaveError(aTHX_ "%s",Strerror(errno));
101     else
102         sv_setiv( ST(0), PTR2IV(obj) );
103
104
105 void *
106 dl_find_symbol(libhandle, symbolname)
107     void *      libhandle
108     char *      symbolname
109     CODE:
110     shl_t obj = (shl_t) libhandle;
111     void *symaddr = NULL;
112     int status;
113 #ifdef __hp9000s300
114     symbolname = Perl_form_nocontext("_%s", symbolname);
115 #endif
116     DLDEBUG(2, PerlIO_printf(Perl_debug_log,
117                              "dl_find_symbol(handle=%lx, symbol=%s)\n",
118                              (unsigned long) libhandle, symbolname));
119
120     ST(0) = sv_newmortal() ;
121     errno = 0;
122
123     status = shl_findsym(&obj, symbolname, TYPE_PROCEDURE, &symaddr);
124     DLDEBUG(2,PerlIO_printf(Perl_debug_log, "  symbolref(PROCEDURE) = %x\n", symaddr));
125
126     if (status == -1 && errno == 0) {   /* try TYPE_DATA instead */
127         status = shl_findsym(&obj, symbolname, TYPE_DATA, &symaddr);
128         DLDEBUG(2,PerlIO_printf(Perl_debug_log, "  symbolref(DATA) = %x\n", symaddr));
129     }
130
131     if (status == -1) {
132         SaveError(aTHX_ "%s",(errno) ? Strerror(errno) : "Symbol not found") ;
133     } else {
134         sv_setiv( ST(0), PTR2IV(symaddr) );
135     }
136
137
138 void
139 dl_undef_symbols()
140     PPCODE:
141
142
143
144 # These functions should not need changing on any platform:
145
146 void
147 dl_install_xsub(perl_name, symref, filename="$Package")
148     char *      perl_name
149     void *      symref 
150     char *      filename
151     CODE:
152     DLDEBUG(2,PerlIO_printf(Perl_debug_log, "dl_install_xsub(name=%s, symref=%x)\n",
153             perl_name, symref));
154     ST(0) = sv_2mortal(newRV((SV*)newXS(perl_name,
155                                         (void(*)(pTHX_ CV *))symref,
156                                         filename)));
157
158
159 char *
160 dl_error()
161     CODE:
162     dMY_CXT;
163     RETVAL = dl_last_error ;
164     OUTPUT:
165     RETVAL
166
167 # end.