[asperl] integrate mainline changes
[p5sagit/p5-mst-13.2.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
30 #include "dlutils.c"    /* for SaveError() etc */
31
32 static AV *dl_resolve_using = Nullav;
33
34
35 static void
36 dl_private_init()
37 {
38     (void)dl_generic_private_init();
39     dl_resolve_using = perl_get_av("DynaLoader::dl_resolve_using", 0x4);
40 }
41
42 MODULE = DynaLoader     PACKAGE = DynaLoader
43
44 BOOT:
45     (void)dl_private_init();
46
47
48 void *
49 dl_load_file(filename, flags=0)
50     char *      filename
51     int         flags
52     PREINIT:
53     shl_t obj = NULL;
54     int i, max, bind_type;
55     CODE:
56     DLDEBUG(1,PerlIO_printf(PerlIO_stderr(), "dl_load_file(%s,%x):\n", filename,flags));
57     if (flags & 0x01)
58         warn("Can't make loaded symbols global on this platform while loading %s",filename);
59     if (dl_nonlazy) {
60       bind_type = BIND_IMMEDIATE|BIND_VERBOSE;
61     } else {
62       bind_type = BIND_DEFERRED;
63       /* For certain libraries, like DCE, deferred binding often causes run
64        * time problems.  Adding BIND_NONFATAL to BIND_IMMEDIATE still allows
65        * unresolved references in situations like this.  */
66       /* bind_type = BIND_IMMEDIATE|BIND_NONFATAL; */
67     }
68 #ifdef DEBUGGING
69     if (dl_debug)
70         bind_type |= BIND_VERBOSE;
71 #endif /* DEBUGGING */
72
73     max = AvFILL(dl_resolve_using);
74     for (i = 0; i <= max; i++) {
75         char *sym = SvPVX(*av_fetch(dl_resolve_using, i, 0));
76         DLDEBUG(1,PerlIO_printf(PerlIO_stderr(), "dl_load_file(%s) (dependent)\n", sym));
77         obj = shl_load(sym, bind_type | BIND_NOSTART, 0L);
78         if (obj == NULL) {
79             goto end;
80         }
81     }
82
83     DLDEBUG(1,PerlIO_printf(PerlIO_stderr(), "dl_load_file(%s): ", filename));
84     obj = shl_load(filename, bind_type | BIND_NOSTART, 0L);
85
86     DLDEBUG(2,PerlIO_printf(PerlIO_stderr(), " libref=%x\n", obj));
87 end:
88     ST(0) = sv_newmortal() ;
89     if (obj == NULL)
90         SaveError("%s",Strerror(errno));
91     else
92         sv_setiv( ST(0), (IV)obj);
93
94
95 void *
96 dl_find_symbol(libhandle, symbolname)
97     void *      libhandle
98     char *      symbolname
99     CODE:
100     shl_t obj = (shl_t) libhandle;
101     void *symaddr = NULL;
102     int status;
103 #ifdef __hp9000s300
104     symbolname = form("_%s", symbolname);
105 #endif
106     DLDEBUG(2, PerlIO_printf(PerlIO_stderr(),
107                              "dl_find_symbol(handle=%lx, symbol=%s)\n",
108                              (unsigned long) libhandle, symbolname));
109
110     ST(0) = sv_newmortal() ;
111     errno = 0;
112
113     status = shl_findsym(&obj, symbolname, TYPE_PROCEDURE, &symaddr);
114     DLDEBUG(2,PerlIO_printf(PerlIO_stderr(), "  symbolref(PROCEDURE) = %x\n", symaddr));
115
116     if (status == -1 && errno == 0) {   /* try TYPE_DATA instead */
117         status = shl_findsym(&obj, symbolname, TYPE_DATA, &symaddr);
118         DLDEBUG(2,PerlIO_printf(PerlIO_stderr(), "  symbolref(DATA) = %x\n", symaddr));
119     }
120
121     if (status == -1) {
122         SaveError("%s",(errno) ? Strerror(errno) : "Symbol not found") ;
123     } else {
124         sv_setiv( ST(0), (IV)symaddr);
125     }
126
127
128 void
129 dl_undef_symbols()
130     PPCODE:
131
132
133
134 # These functions should not need changing on any platform:
135
136 void
137 dl_install_xsub(perl_name, symref, filename="$Package")
138     char *      perl_name
139     void *      symref 
140     char *      filename
141     CODE:
142     DLDEBUG(2,PerlIO_printf(PerlIO_stderr(), "dl_install_xsub(name=%s, symref=%x)\n",
143             perl_name, symref));
144     ST(0)=sv_2mortal(newRV((SV*)newXS(perl_name, (void(*)())symref, filename)));
145
146
147 char *
148 dl_error()
149     CODE:
150     RETVAL = LastError ;
151     OUTPUT:
152     RETVAL
153
154 # end.