annotate Python/importdl.c @ 3930:52c19ee83a6b legacy-trunk

Guido's 1.4b2 fixes: Py_GetProgramName, Py_GetPrefix and Py_GetExecPrefix.
author Jack Jansen <jack.jansen@cwi.nl>
date Fri, 02 Aug 1996 15:16:16 +0000
parents ac1d5abfd78e
children efb3a5a2cdea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 /***********************************************************
2062
d0d0a69b5ca3 Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents: 2052
diff changeset
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
d0d0a69b5ca3 Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents: 2052
diff changeset
3 The Netherlands.
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
4
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 All Rights Reserved
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
6
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 Permission to use, copy, modify, and distribute this software and its
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 documentation for any purpose and without fee is hereby granted,
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 provided that the above copyright notice appear in all copies and that
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 both that copyright notice and this permission notice appear in
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 supporting documentation, and that the names of Stichting Mathematisch
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 Centrum or CWI not be used in advertising or publicity pertaining to
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 distribution of the software without specific, written prior permission.
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
14
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
22
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 ******************************************************************/
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
24
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 /* Support for dynamic loading of extension modules */
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 /* If no dynamic linking is supported, this file still generates some code! */
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
27
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 #include "allobjects.h"
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 #include "osdefs.h"
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 #include "importdl.h"
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
31
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 /* Explanation of some of the the various #defines used by dynamic linking...
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
33
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 symbol -- defined for:
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
35
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 DYNAMIC_LINK -- any kind of dynamic linking
2733
dc64df7f1ad6 re-enabled NeXT dynamic linking (#ifdef NeXT)
Guido van Rossum <guido@python.org>
parents: 2729
diff changeset
37 USE_RLD -- NeXT dynamic linking
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 USE_DL -- Jack's dl for IRIX 4 or GNU dld with emulation for Jack's dl
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 USE_SHLIB -- SunOS or IRIX 5 (SVR4?) shared libraries
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 _AIX -- AIX style dynamic linking
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 NT -- NT style dynamic linking (using DLLs)
3591
1c18f90636fb removed verbose decl; added win3.1 dynamic linking.
Guido van Rossum <guido@python.org>
parents: 3491
diff changeset
42 WIN16_DL -- Windows 16-bit dynamic linking (using DLLs)
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 _DL_FUNCPTR_DEFINED -- if the typedef dl_funcptr has been defined
2729
5af6db1f6c0c Mac dynloading is now enabled by USE_MAC_DYNAMIC_LOADING.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2724
diff changeset
44 USE_MAC_DYNAMIC_LOADING -- Mac CFM shared libraries
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 SHORT_EXT -- short extension for dynamic module, e.g. ".so"
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 LONG_EXT -- long extension, e.g. "module.so"
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 hpux -- HP-UX Dynamic Linking - defined by the compiler
2199
f4671b681ab9 added changes for NetBSD dynamic linking; removed shared linking for NeXT
Guido van Rossum <guido@python.org>
parents: 2094
diff changeset
48 __NetBSD__ -- NetBSD shared libraries (not quite SVR4 compatible)
3420
013bbe4ef943 __FreeBSD__ shared libraries
Guido van Rossum <guido@python.org>
parents: 3327
diff changeset
49 __FreeBSD__ -- FreeBSD shared libraries
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
50
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 (The other WITH_* symbols are used only once, to set the
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 appropriate symbols.)
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 */
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
54
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 /* Configure dynamic linking */
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
56
3327
49f7a4a1f0f6 __hpux -> hpux equivalence
Guido van Rossum <guido@python.org>
parents: 3224
diff changeset
57 #ifdef __hpux
49f7a4a1f0f6 __hpux -> hpux equivalence
Guido van Rossum <guido@python.org>
parents: 3224
diff changeset
58 #define hpux
49f7a4a1f0f6 __hpux -> hpux equivalence
Guido van Rossum <guido@python.org>
parents: 3224
diff changeset
59 #endif
49f7a4a1f0f6 __hpux -> hpux equivalence
Guido van Rossum <guido@python.org>
parents: 3224
diff changeset
60
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 #ifdef hpux
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 #define DYNAMIC_LINK
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 #include <errno.h>
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 typedef void (*dl_funcptr)();
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 #define _DL_FUNCPTR_DEFINED 1
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 #define SHORT_EXT ".sl"
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 #define LONG_EXT "module.sl"
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 #endif
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
69
3420
013bbe4ef943 __FreeBSD__ shared libraries
Guido van Rossum <guido@python.org>
parents: 3327
diff changeset
70 #if defined(__NetBSD__) || defined(__FreeBSD__)
2199
f4671b681ab9 added changes for NetBSD dynamic linking; removed shared linking for NeXT
Guido van Rossum <guido@python.org>
parents: 2094
diff changeset
71 #define DYNAMIC_LINK
f4671b681ab9 added changes for NetBSD dynamic linking; removed shared linking for NeXT
Guido van Rossum <guido@python.org>
parents: 2094
diff changeset
72 #define USE_SHLIB
f4671b681ab9 added changes for NetBSD dynamic linking; removed shared linking for NeXT
Guido van Rossum <guido@python.org>
parents: 2094
diff changeset
73
f4671b681ab9 added changes for NetBSD dynamic linking; removed shared linking for NeXT
Guido van Rossum <guido@python.org>
parents: 2094
diff changeset
74 #define dlerror() "error in dynamic linking"
f4671b681ab9 added changes for NetBSD dynamic linking; removed shared linking for NeXT
Guido van Rossum <guido@python.org>
parents: 2094
diff changeset
75 #endif
f4671b681ab9 added changes for NetBSD dynamic linking; removed shared linking for NeXT
Guido van Rossum <guido@python.org>
parents: 2094
diff changeset
76
2435
1e8aebab874a for BorlandC
Guido van Rossum <guido@python.org>
parents: 2420
diff changeset
77 #ifdef __WIN32__
1e8aebab874a for BorlandC
Guido van Rossum <guido@python.org>
parents: 2420
diff changeset
78 #define NT
1e8aebab874a for BorlandC
Guido van Rossum <guido@python.org>
parents: 2420
diff changeset
79 #endif
1e8aebab874a for BorlandC
Guido van Rossum <guido@python.org>
parents: 2420
diff changeset
80
3591
1c18f90636fb removed verbose decl; added win3.1 dynamic linking.
Guido van Rossum <guido@python.org>
parents: 3491
diff changeset
81 #ifdef MS_WIN16
1c18f90636fb removed verbose decl; added win3.1 dynamic linking.
Guido van Rossum <guido@python.org>
parents: 3491
diff changeset
82 #define WIN16_DL
1c18f90636fb removed verbose decl; added win3.1 dynamic linking.
Guido van Rossum <guido@python.org>
parents: 3491
diff changeset
83 #endif
1c18f90636fb removed verbose decl; added win3.1 dynamic linking.
Guido van Rossum <guido@python.org>
parents: 3491
diff changeset
84
1c18f90636fb removed verbose decl; added win3.1 dynamic linking.
Guido van Rossum <guido@python.org>
parents: 3491
diff changeset
85 #if defined(NT) || defined(WIN16_DL)
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
86 #define DYNAMIC_LINK
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 #include <windows.h>
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
88 typedef FARPROC dl_funcptr;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
89 #define _DL_FUNCPTR_DEFINED
2085
8921a2881fc7 NT dlls have .pyd extension instead of .dll
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
90 #define SHORT_EXT ".pyd"
3491
16a5f6048461 Under NT, change "long" sharedlib extension to ".dll". (Mark H.)
Guido van Rossum <guido@python.org>
parents: 3420
diff changeset
91 #define LONG_EXT ".dll"
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
92 #endif
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
93
2733
dc64df7f1ad6 re-enabled NeXT dynamic linking (#ifdef NeXT)
Guido van Rossum <guido@python.org>
parents: 2729
diff changeset
94 #ifdef NeXT
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
95 #define DYNAMIC_LINK
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
96 #define USE_RLD
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
97 #endif
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
98
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
99 #ifdef WITH_SGI_DL
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
100 #define DYNAMIC_LINK
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
101 #define USE_DL
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
102 #endif
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
103
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
104 #ifdef WITH_DL_DLD
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
105 #define DYNAMIC_LINK
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
106 #define USE_DL
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
107 #endif
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
108
2374
397478bca0c4 ported to 68K Mac; changed suffix to .slb
Guido van Rossum <guido@python.org>
parents: 2331
diff changeset
109 #ifdef __CFM68K__
2729
5af6db1f6c0c Mac dynloading is now enabled by USE_MAC_DYNAMIC_LOADING.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2724
diff changeset
110 #define USE_MAC_DYNAMIC_LOADING
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
111 #endif
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
112
2729
5af6db1f6c0c Mac dynloading is now enabled by USE_MAC_DYNAMIC_LOADING.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2724
diff changeset
113 #ifdef USE_MAC_DYNAMIC_LOADING
2331
242dd5ed3b08 Added code to import dynamic modules using mac CFM.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2199
diff changeset
114 #define DYNAMIC_LINK
2374
397478bca0c4 ported to 68K Mac; changed suffix to .slb
Guido van Rossum <guido@python.org>
parents: 2331
diff changeset
115 #define SHORT_EXT ".slb"
397478bca0c4 ported to 68K Mac; changed suffix to .slb
Guido van Rossum <guido@python.org>
parents: 2331
diff changeset
116 #define LONG_EXT "module.slb"
2331
242dd5ed3b08 Added code to import dynamic modules using mac CFM.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2199
diff changeset
117 #ifndef _DL_FUNCPTR_DEFINED
242dd5ed3b08 Added code to import dynamic modules using mac CFM.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2199
diff changeset
118 typedef void (*dl_funcptr)();
242dd5ed3b08 Added code to import dynamic modules using mac CFM.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2199
diff changeset
119 #endif
242dd5ed3b08 Added code to import dynamic modules using mac CFM.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2199
diff changeset
120 #endif
242dd5ed3b08 Added code to import dynamic modules using mac CFM.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2199
diff changeset
121
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 #if !defined(DYNAMIC_LINK) && defined(HAVE_DLFCN_H) && defined(HAVE_DLOPEN)
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
123 #define DYNAMIC_LINK
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
124 #define USE_SHLIB
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 #endif
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
126
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
127 #ifdef _AIX
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
128 #define DYNAMIC_LINK
3907
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
129 #define SHORT_EXT ".so"
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
130 #define LONG_EXT "module.so"
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
131 #include <sys/ldr.h>
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
132 typedef void (*dl_funcptr)();
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
133 #define _DL_FUNCPTR_DEFINED
3907
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
134 static int aix_getoldmodules(void **);
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
135 static int aix_bindnewmodule(void *, void *);
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
136 static void aix_loaderror(char *);
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
137 #endif
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
138
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
139 #ifdef DYNAMIC_LINK
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
140
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
141 #ifdef USE_SHLIB
2724
6a9ecb05c679 Check if we've already loaded a dynamic module under a different name.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2435
diff changeset
142 #include <sys/types.h>
6a9ecb05c679 Check if we've already loaded a dynamic module under a different name.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2435
diff changeset
143 #include <sys/stat.h>
3420
013bbe4ef943 __FreeBSD__ shared libraries
Guido van Rossum <guido@python.org>
parents: 3327
diff changeset
144 #if defined(__NetBSD__) || defined(__FreeBSD__)
2199
f4671b681ab9 added changes for NetBSD dynamic linking; removed shared linking for NeXT
Guido van Rossum <guido@python.org>
parents: 2094
diff changeset
145 #include <nlist.h>
f4671b681ab9 added changes for NetBSD dynamic linking; removed shared linking for NeXT
Guido van Rossum <guido@python.org>
parents: 2094
diff changeset
146 #include <link.h>
f4671b681ab9 added changes for NetBSD dynamic linking; removed shared linking for NeXT
Guido van Rossum <guido@python.org>
parents: 2094
diff changeset
147 #else
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
148 #include <dlfcn.h>
2199
f4671b681ab9 added changes for NetBSD dynamic linking; removed shared linking for NeXT
Guido van Rossum <guido@python.org>
parents: 2094
diff changeset
149 #endif
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
150 #ifndef _DL_FUNCPTR_DEFINED
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
151 typedef void (*dl_funcptr)();
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
152 #endif
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
153 #ifndef RTLD_LAZY
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
154 #define RTLD_LAZY 1
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
155 #endif
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
156 #define SHORT_EXT ".so"
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
157 #define LONG_EXT "module.so"
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
158 #endif /* USE_SHLIB */
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
159
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
160 #if defined(USE_DL) || defined(hpux)
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
161 #include "dl.h"
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
162 #endif
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
163
2729
5af6db1f6c0c Mac dynloading is now enabled by USE_MAC_DYNAMIC_LOADING.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2724
diff changeset
164 #ifdef USE_MAC_DYNAMIC_LOADING
3224
2fb398ab3e6a Added missing include for <Aliases.h>
Jack Jansen <jack.jansen@cwi.nl>
parents: 2843
diff changeset
165 #include <Aliases.h>
2331
242dd5ed3b08 Added code to import dynamic modules using mac CFM.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2199
diff changeset
166 #include <CodeFragments.h>
2793
b8937e74fdf5 Porting to CW CFM68K
Jack Jansen <jack.jansen@cwi.nl>
parents: 2733
diff changeset
167 #ifdef SYMANTEC__CFM68K__ /* Really just an older version of Universal Headers */
2374
397478bca0c4 ported to 68K Mac; changed suffix to .slb
Guido van Rossum <guido@python.org>
parents: 2331
diff changeset
168 #define CFragConnectionID ConnectionID
397478bca0c4 ported to 68K Mac; changed suffix to .slb
Guido van Rossum <guido@python.org>
parents: 2331
diff changeset
169 #define kLoadCFrag 0x01
397478bca0c4 ported to 68K Mac; changed suffix to .slb
Guido van Rossum <guido@python.org>
parents: 2331
diff changeset
170 #endif
2331
242dd5ed3b08 Added code to import dynamic modules using mac CFM.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2199
diff changeset
171 #include <Files.h>
242dd5ed3b08 Added code to import dynamic modules using mac CFM.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2199
diff changeset
172 #include "macdefs.h"
242dd5ed3b08 Added code to import dynamic modules using mac CFM.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2199
diff changeset
173 #include "macglue.h"
242dd5ed3b08 Added code to import dynamic modules using mac CFM.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2199
diff changeset
174 #endif
242dd5ed3b08 Added code to import dynamic modules using mac CFM.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2199
diff changeset
175
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
176 #ifdef USE_RLD
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
177 #include <mach-o/rld.h>
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
178 #define FUNCNAME_PATTERN "_init%.200s"
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
179 #ifndef _DL_FUNCPTR_DEFINED
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
180 typedef void (*dl_funcptr)();
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
181 #endif
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
182 #endif /* USE_RLD */
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
183
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
184 extern char *getprogramname();
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
185
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
186 #ifndef FUNCNAME_PATTERN
3420
013bbe4ef943 __FreeBSD__ shared libraries
Guido van Rossum <guido@python.org>
parents: 3327
diff changeset
187 #if defined(__hp9000s300) || defined(__NetBSD__) || defined(__FreeBSD__) || defined(__BORLANDC__)
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
188 #define FUNCNAME_PATTERN "_init%.200s"
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
189 #else
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
190 #define FUNCNAME_PATTERN "init%.200s"
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
191 #endif
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
192 #endif
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
193
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
194 #if !defined(SHORT_EXT) && !defined(LONG_EXT)
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
195 #define SHORT_EXT ".o"
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
196 #define LONG_EXT "module.o"
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
197 #endif /* !SHORT_EXT && !LONG_EXT */
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
198
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
199 #endif /* DYNAMIC_LINK */
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
200
2374
397478bca0c4 ported to 68K Mac; changed suffix to .slb
Guido van Rossum <guido@python.org>
parents: 2331
diff changeset
201 /* Max length of module suffix searched for -- accommodates "module.slb" */
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
202 #ifndef MAXSUFFIXSIZE
2331
242dd5ed3b08 Added code to import dynamic modules using mac CFM.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2199
diff changeset
203 #define MAXSUFFIXSIZE 12
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
204 #endif
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
205
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
206 /* Pass it on to import.c */
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
207 int import_maxsuffixsize = MAXSUFFIXSIZE;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
208
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
209 struct filedescr import_filetab[] = {
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
210 #ifdef SHORT_EXT
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
211 {SHORT_EXT, "rb", C_EXTENSION},
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
212 #endif /* !SHORT_EXT */
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
213 #ifdef LONG_EXT
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
214 {LONG_EXT, "rb", C_EXTENSION},
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
215 #endif /* !LONG_EXT */
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
216 {".py", "r", PY_SOURCE},
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
217 {".pyc", "rb", PY_COMPILED},
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
218 {0, 0}
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
219 };
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
220
3898
94c6bf6fd7f4 If NO_DYNAMIC_LINK is defined, load_dynamic_module() will always fail.
Guido van Rossum <guido@python.org>
parents: 3732
diff changeset
221 #ifdef NO_DYNAMIC_LINK
94c6bf6fd7f4 If NO_DYNAMIC_LINK is defined, load_dynamic_module() will always fail.
Guido van Rossum <guido@python.org>
parents: 3732
diff changeset
222 #undef DYNAMIC_LINK
94c6bf6fd7f4 If NO_DYNAMIC_LINK is defined, load_dynamic_module() will always fail.
Guido van Rossum <guido@python.org>
parents: 3732
diff changeset
223 #endif
94c6bf6fd7f4 If NO_DYNAMIC_LINK is defined, load_dynamic_module() will always fail.
Guido van Rossum <guido@python.org>
parents: 3732
diff changeset
224
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
225 object *
2724
6a9ecb05c679 Check if we've already loaded a dynamic module under a different name.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2435
diff changeset
226 load_dynamic_module(name, pathname, fp)
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
227 char *name;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
228 char *pathname;
2724
6a9ecb05c679 Check if we've already loaded a dynamic module under a different name.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2435
diff changeset
229 FILE *fp;
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
230 {
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
231 #ifndef DYNAMIC_LINK
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
232 err_setstr(ImportError, "dynamically linked modules not supported");
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
233 return NULL;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
234 #else
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
235 object *m;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
236 char funcname[258];
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
237 dl_funcptr p = NULL;
2724
6a9ecb05c679 Check if we've already loaded a dynamic module under a different name.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2435
diff changeset
238 #ifdef USE_SHLIB
6a9ecb05c679 Check if we've already loaded a dynamic module under a different name.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2435
diff changeset
239 static struct {
6a9ecb05c679 Check if we've already loaded a dynamic module under a different name.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2435
diff changeset
240 dev_t dev;
6a9ecb05c679 Check if we've already loaded a dynamic module under a different name.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2435
diff changeset
241 ino_t ino;
6a9ecb05c679 Check if we've already loaded a dynamic module under a different name.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2435
diff changeset
242 void *handle;
6a9ecb05c679 Check if we've already loaded a dynamic module under a different name.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2435
diff changeset
243 } handles[128];
6a9ecb05c679 Check if we've already loaded a dynamic module under a different name.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2435
diff changeset
244 static int nhandles = 0;
6a9ecb05c679 Check if we've already loaded a dynamic module under a different name.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2435
diff changeset
245 #endif
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
246 sprintf(funcname, FUNCNAME_PATTERN, name);
2724
6a9ecb05c679 Check if we've already loaded a dynamic module under a different name.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2435
diff changeset
247 #ifdef USE_SHLIB
6a9ecb05c679 Check if we've already loaded a dynamic module under a different name.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2435
diff changeset
248 if (fp != NULL) {
6a9ecb05c679 Check if we've already loaded a dynamic module under a different name.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2435
diff changeset
249 int i;
6a9ecb05c679 Check if we've already loaded a dynamic module under a different name.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2435
diff changeset
250 struct stat statb;
6a9ecb05c679 Check if we've already loaded a dynamic module under a different name.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2435
diff changeset
251 fstat(fileno(fp), &statb);
6a9ecb05c679 Check if we've already loaded a dynamic module under a different name.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2435
diff changeset
252 for (i = 0; i < nhandles; i++) {
6a9ecb05c679 Check if we've already loaded a dynamic module under a different name.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2435
diff changeset
253 if (statb.st_dev == handles[i].dev &&
6a9ecb05c679 Check if we've already loaded a dynamic module under a different name.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2435
diff changeset
254 statb.st_ino == handles[i].ino) {
6a9ecb05c679 Check if we've already loaded a dynamic module under a different name.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2435
diff changeset
255 p = (dl_funcptr) dlsym(handles[i].handle,
6a9ecb05c679 Check if we've already loaded a dynamic module under a different name.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2435
diff changeset
256 funcname);
6a9ecb05c679 Check if we've already loaded a dynamic module under a different name.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2435
diff changeset
257 goto got_it;
6a9ecb05c679 Check if we've already loaded a dynamic module under a different name.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2435
diff changeset
258 }
6a9ecb05c679 Check if we've already loaded a dynamic module under a different name.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2435
diff changeset
259 }
6a9ecb05c679 Check if we've already loaded a dynamic module under a different name.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2435
diff changeset
260 if (nhandles < 128) {
6a9ecb05c679 Check if we've already loaded a dynamic module under a different name.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2435
diff changeset
261 handles[nhandles].dev = statb.st_dev;
6a9ecb05c679 Check if we've already loaded a dynamic module under a different name.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2435
diff changeset
262 handles[nhandles].ino = statb.st_ino;
6a9ecb05c679 Check if we've already loaded a dynamic module under a different name.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2435
diff changeset
263 }
6a9ecb05c679 Check if we've already loaded a dynamic module under a different name.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2435
diff changeset
264 }
6a9ecb05c679 Check if we've already loaded a dynamic module under a different name.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2435
diff changeset
265 #endif /* USE_SHLIB */
2729
5af6db1f6c0c Mac dynloading is now enabled by USE_MAC_DYNAMIC_LOADING.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2724
diff changeset
266 #ifdef USE_MAC_DYNAMIC_LOADING
5af6db1f6c0c Mac dynloading is now enabled by USE_MAC_DYNAMIC_LOADING.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2724
diff changeset
267 /*
5af6db1f6c0c Mac dynloading is now enabled by USE_MAC_DYNAMIC_LOADING.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2724
diff changeset
268 ** Dynamic loading of CFM shared libraries on the Mac.
5af6db1f6c0c Mac dynloading is now enabled by USE_MAC_DYNAMIC_LOADING.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2724
diff changeset
269 ** The code has become more convoluted than it was, because we want to be able
5af6db1f6c0c Mac dynloading is now enabled by USE_MAC_DYNAMIC_LOADING.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2724
diff changeset
270 ** to put multiple modules in a single file. For this reason, we have to determine
5af6db1f6c0c Mac dynloading is now enabled by USE_MAC_DYNAMIC_LOADING.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2724
diff changeset
271 ** the fragment name, and we cannot use the library entry point but we have to locate
5af6db1f6c0c Mac dynloading is now enabled by USE_MAC_DYNAMIC_LOADING.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2724
diff changeset
272 ** the correct init routine "by hand".
5af6db1f6c0c Mac dynloading is now enabled by USE_MAC_DYNAMIC_LOADING.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2724
diff changeset
273 */
2331
242dd5ed3b08 Added code to import dynamic modules using mac CFM.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2199
diff changeset
274 {
242dd5ed3b08 Added code to import dynamic modules using mac CFM.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2199
diff changeset
275 FSSpec libspec;
242dd5ed3b08 Added code to import dynamic modules using mac CFM.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2199
diff changeset
276 CFragConnectionID connID;
2374
397478bca0c4 ported to 68K Mac; changed suffix to .slb
Guido van Rossum <guido@python.org>
parents: 2331
diff changeset
277 Ptr mainAddr;
397478bca0c4 ported to 68K Mac; changed suffix to .slb
Guido van Rossum <guido@python.org>
parents: 2331
diff changeset
278 Str255 errMessage;
397478bca0c4 ported to 68K Mac; changed suffix to .slb
Guido van Rossum <guido@python.org>
parents: 2331
diff changeset
279 OSErr err;
2729
5af6db1f6c0c Mac dynloading is now enabled by USE_MAC_DYNAMIC_LOADING.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2724
diff changeset
280 Boolean isfolder, didsomething;
5af6db1f6c0c Mac dynloading is now enabled by USE_MAC_DYNAMIC_LOADING.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2724
diff changeset
281 char buf[512];
5af6db1f6c0c Mac dynloading is now enabled by USE_MAC_DYNAMIC_LOADING.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2724
diff changeset
282 Str63 fragname;
5af6db1f6c0c Mac dynloading is now enabled by USE_MAC_DYNAMIC_LOADING.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2724
diff changeset
283 Ptr symAddr;
5af6db1f6c0c Mac dynloading is now enabled by USE_MAC_DYNAMIC_LOADING.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2724
diff changeset
284 CFragSymbolClass class;
2331
242dd5ed3b08 Added code to import dynamic modules using mac CFM.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2199
diff changeset
285
2729
5af6db1f6c0c Mac dynloading is now enabled by USE_MAC_DYNAMIC_LOADING.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2724
diff changeset
286 /* First resolve any aliases to find the real file */
2331
242dd5ed3b08 Added code to import dynamic modules using mac CFM.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2199
diff changeset
287 (void)FSMakeFSSpec(0, 0, Pstring(pathname), &libspec);
2729
5af6db1f6c0c Mac dynloading is now enabled by USE_MAC_DYNAMIC_LOADING.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2724
diff changeset
288 err = ResolveAliasFile(&libspec, 1, &isfolder, &didsomething);
5af6db1f6c0c Mac dynloading is now enabled by USE_MAC_DYNAMIC_LOADING.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2724
diff changeset
289 if ( err ) {
5af6db1f6c0c Mac dynloading is now enabled by USE_MAC_DYNAMIC_LOADING.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2724
diff changeset
290 sprintf(buf, "%s: %s", pathname, PyMac_StrError(err));
5af6db1f6c0c Mac dynloading is now enabled by USE_MAC_DYNAMIC_LOADING.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2724
diff changeset
291 err_setstr(ImportError, buf);
5af6db1f6c0c Mac dynloading is now enabled by USE_MAC_DYNAMIC_LOADING.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2724
diff changeset
292 return NULL;
5af6db1f6c0c Mac dynloading is now enabled by USE_MAC_DYNAMIC_LOADING.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2724
diff changeset
293 }
5af6db1f6c0c Mac dynloading is now enabled by USE_MAC_DYNAMIC_LOADING.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2724
diff changeset
294 /* Next, determine the fragment name, by stripping '.slb' and 'module' */
5af6db1f6c0c Mac dynloading is now enabled by USE_MAC_DYNAMIC_LOADING.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2724
diff changeset
295 memcpy(fragname+1, libspec.name+1, libspec.name[0]);
5af6db1f6c0c Mac dynloading is now enabled by USE_MAC_DYNAMIC_LOADING.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2724
diff changeset
296 fragname[0] = libspec.name[0];
5af6db1f6c0c Mac dynloading is now enabled by USE_MAC_DYNAMIC_LOADING.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2724
diff changeset
297 if( strncmp((char *)(fragname+1+fragname[0]-4), ".slb", 4) == 0 )
5af6db1f6c0c Mac dynloading is now enabled by USE_MAC_DYNAMIC_LOADING.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2724
diff changeset
298 fragname[0] -= 4;
5af6db1f6c0c Mac dynloading is now enabled by USE_MAC_DYNAMIC_LOADING.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2724
diff changeset
299 if ( strncmp((char *)(fragname+1+fragname[0]-6), "module", 6) == 0 )
5af6db1f6c0c Mac dynloading is now enabled by USE_MAC_DYNAMIC_LOADING.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2724
diff changeset
300 fragname[0] -= 6;
5af6db1f6c0c Mac dynloading is now enabled by USE_MAC_DYNAMIC_LOADING.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2724
diff changeset
301 /* Load the fragment (or return the connID if it is already loaded */
5af6db1f6c0c Mac dynloading is now enabled by USE_MAC_DYNAMIC_LOADING.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2724
diff changeset
302 err = GetDiskFragment(&libspec, 0, 0, fragname,
2374
397478bca0c4 ported to 68K Mac; changed suffix to .slb
Guido van Rossum <guido@python.org>
parents: 2331
diff changeset
303 kLoadCFrag, &connID, &mainAddr,
397478bca0c4 ported to 68K Mac; changed suffix to .slb
Guido van Rossum <guido@python.org>
parents: 2331
diff changeset
304 errMessage);
2331
242dd5ed3b08 Added code to import dynamic modules using mac CFM.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2199
diff changeset
305 if ( err ) {
2420
6beef17871f9 change ifdefs and fix "%#s" format
Guido van Rossum <guido@python.org>
parents: 2374
diff changeset
306 sprintf(buf, "%.*s: %s", errMessage[0], errMessage+1, PyMac_StrError(err));
2331
242dd5ed3b08 Added code to import dynamic modules using mac CFM.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2199
diff changeset
307 err_setstr(ImportError, buf);
242dd5ed3b08 Added code to import dynamic modules using mac CFM.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2199
diff changeset
308 return NULL;
242dd5ed3b08 Added code to import dynamic modules using mac CFM.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2199
diff changeset
309 }
2729
5af6db1f6c0c Mac dynloading is now enabled by USE_MAC_DYNAMIC_LOADING.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2724
diff changeset
310 /* Locate the address of the correct init function */
5af6db1f6c0c Mac dynloading is now enabled by USE_MAC_DYNAMIC_LOADING.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2724
diff changeset
311 err = FindSymbol(connID, Pstring(funcname), &symAddr, &class);
5af6db1f6c0c Mac dynloading is now enabled by USE_MAC_DYNAMIC_LOADING.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2724
diff changeset
312 if ( err ) {
5af6db1f6c0c Mac dynloading is now enabled by USE_MAC_DYNAMIC_LOADING.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2724
diff changeset
313 sprintf(buf, "%s: %s", funcname, PyMac_StrError(err));
5af6db1f6c0c Mac dynloading is now enabled by USE_MAC_DYNAMIC_LOADING.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2724
diff changeset
314 err_setstr(ImportError, buf);
5af6db1f6c0c Mac dynloading is now enabled by USE_MAC_DYNAMIC_LOADING.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2724
diff changeset
315 return NULL;
5af6db1f6c0c Mac dynloading is now enabled by USE_MAC_DYNAMIC_LOADING.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2724
diff changeset
316 }
5af6db1f6c0c Mac dynloading is now enabled by USE_MAC_DYNAMIC_LOADING.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2724
diff changeset
317 p = (dl_funcptr)symAddr;
2331
242dd5ed3b08 Added code to import dynamic modules using mac CFM.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2199
diff changeset
318 }
2729
5af6db1f6c0c Mac dynloading is now enabled by USE_MAC_DYNAMIC_LOADING.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2724
diff changeset
319 #endif /* USE_MAC_DYNAMIC_LOADING */
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
320 #ifdef USE_SHLIB
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
321 {
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
322 #ifdef RTLD_NOW
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
323 /* RTLD_NOW: resolve externals now
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
324 (i.e. core dump now if some are missing) */
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
325 void *handle = dlopen(pathname, RTLD_NOW);
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
326 #else
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
327 void *handle;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
328 if (verbose)
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
329 printf("dlopen(\"%s\", %d);\n", pathname, RTLD_LAZY);
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
330 handle = dlopen(pathname, RTLD_LAZY);
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
331 #endif /* RTLD_NOW */
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
332 if (handle == NULL) {
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
333 err_setstr(ImportError, dlerror());
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
334 return NULL;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
335 }
2724
6a9ecb05c679 Check if we've already loaded a dynamic module under a different name.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2435
diff changeset
336 if (fp != NULL && nhandles < 128)
6a9ecb05c679 Check if we've already loaded a dynamic module under a different name.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2435
diff changeset
337 handles[nhandles++].handle = handle;
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
338 p = (dl_funcptr) dlsym(handle, funcname);
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
339 }
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
340 #endif /* USE_SHLIB */
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
341 #ifdef _AIX
3907
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
342 /*
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
343 -- Invoke load() with L_NOAUTODEFER leaving the imported symbols
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
344 -- of the shared module unresolved. Thus we have to resolve them
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
345 -- explicitely with loadbind. The new module is loaded, then we
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
346 -- resolve its symbols using the list of already loaded modules
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
347 -- (only those that belong to the python executable). Get these
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
348 -- with loadquery(L_GETINFO).
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
349 */
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
350 {
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
351 static void *staticmodlistptr = NULL;
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
352
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
353 if (!staticmodlistptr)
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
354 if (aix_getoldmodules(&staticmodlistptr) == -1)
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
355 return NULL;
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
356 p = (dl_funcptr) load(pathname, L_NOAUTODEFER, 0);
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
357 if (p == NULL) {
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
358 aix_loaderror(pathname);
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
359 return NULL;
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
360 }
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
361 if (aix_bindnewmodule((void *)p, staticmodlistptr) == -1) {
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
362 aix_loaderror(pathname);
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
363 return NULL;
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
364 }
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
365 }
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
366 #endif /* _AIX */
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
367 #ifdef NT
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
368 {
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
369 HINSTANCE hDLL;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
370 hDLL = LoadLibrary(pathname);
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
371 if (hDLL==NULL){
2843
8d92a3bb9c1f NT specific change for nicer error message (Mark H)
Guido van Rossum <guido@python.org>
parents: 2793
diff changeset
372 char errBuf[256];
8d92a3bb9c1f NT specific change for nicer error message (Mark H)
Guido van Rossum <guido@python.org>
parents: 2793
diff changeset
373 unsigned int errorCode;
8d92a3bb9c1f NT specific change for nicer error message (Mark H)
Guido van Rossum <guido@python.org>
parents: 2793
diff changeset
374
8d92a3bb9c1f NT specific change for nicer error message (Mark H)
Guido van Rossum <guido@python.org>
parents: 2793
diff changeset
375 /* Get an error string from Win32 error code */
8d92a3bb9c1f NT specific change for nicer error message (Mark H)
Guido van Rossum <guido@python.org>
parents: 2793
diff changeset
376 char theInfo[256]; /* Pointer to error text from system */
8d92a3bb9c1f NT specific change for nicer error message (Mark H)
Guido van Rossum <guido@python.org>
parents: 2793
diff changeset
377 int theLength; /* Length of error text */
8d92a3bb9c1f NT specific change for nicer error message (Mark H)
Guido van Rossum <guido@python.org>
parents: 2793
diff changeset
378
8d92a3bb9c1f NT specific change for nicer error message (Mark H)
Guido van Rossum <guido@python.org>
parents: 2793
diff changeset
379 errorCode = GetLastError();
8d92a3bb9c1f NT specific change for nicer error message (Mark H)
Guido van Rossum <guido@python.org>
parents: 2793
diff changeset
380
8d92a3bb9c1f NT specific change for nicer error message (Mark H)
Guido van Rossum <guido@python.org>
parents: 2793
diff changeset
381 theLength = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, /* flags */
8d92a3bb9c1f NT specific change for nicer error message (Mark H)
Guido van Rossum <guido@python.org>
parents: 2793
diff changeset
382 NULL, /* message source */
8d92a3bb9c1f NT specific change for nicer error message (Mark H)
Guido van Rossum <guido@python.org>
parents: 2793
diff changeset
383 errorCode, /* the message (error) ID */
8d92a3bb9c1f NT specific change for nicer error message (Mark H)
Guido van Rossum <guido@python.org>
parents: 2793
diff changeset
384 0, /* default language environment */
8d92a3bb9c1f NT specific change for nicer error message (Mark H)
Guido van Rossum <guido@python.org>
parents: 2793
diff changeset
385 (LPTSTR) theInfo, /* the buffer */
8d92a3bb9c1f NT specific change for nicer error message (Mark H)
Guido van Rossum <guido@python.org>
parents: 2793
diff changeset
386 sizeof(theInfo), /* the buffer size */
8d92a3bb9c1f NT specific change for nicer error message (Mark H)
Guido van Rossum <guido@python.org>
parents: 2793
diff changeset
387 NULL); /* no additional format args. */
8d92a3bb9c1f NT specific change for nicer error message (Mark H)
Guido van Rossum <guido@python.org>
parents: 2793
diff changeset
388
8d92a3bb9c1f NT specific change for nicer error message (Mark H)
Guido van Rossum <guido@python.org>
parents: 2793
diff changeset
389 /* Problem: could not get the error message. This should not happen if called correctly. */
8d92a3bb9c1f NT specific change for nicer error message (Mark H)
Guido van Rossum <guido@python.org>
parents: 2793
diff changeset
390 if (theLength == 0) {
8d92a3bb9c1f NT specific change for nicer error message (Mark H)
Guido van Rossum <guido@python.org>
parents: 2793
diff changeset
391 sprintf(errBuf, "DLL load failed with error code %d", errorCode);
8d92a3bb9c1f NT specific change for nicer error message (Mark H)
Guido van Rossum <guido@python.org>
parents: 2793
diff changeset
392 } else {
8d92a3bb9c1f NT specific change for nicer error message (Mark H)
Guido van Rossum <guido@python.org>
parents: 2793
diff changeset
393 int len;
8d92a3bb9c1f NT specific change for nicer error message (Mark H)
Guido van Rossum <guido@python.org>
parents: 2793
diff changeset
394 /* For some reason a \r\n is appended to the text */
8d92a3bb9c1f NT specific change for nicer error message (Mark H)
Guido van Rossum <guido@python.org>
parents: 2793
diff changeset
395 if (theLength >= 2 && theInfo[theLength-2] == '\r' && theInfo[theLength-1] == '\n') {
8d92a3bb9c1f NT specific change for nicer error message (Mark H)
Guido van Rossum <guido@python.org>
parents: 2793
diff changeset
396 theLength -= 2;
8d92a3bb9c1f NT specific change for nicer error message (Mark H)
Guido van Rossum <guido@python.org>
parents: 2793
diff changeset
397 theInfo[theLength] = '\0';
8d92a3bb9c1f NT specific change for nicer error message (Mark H)
Guido van Rossum <guido@python.org>
parents: 2793
diff changeset
398 }
8d92a3bb9c1f NT specific change for nicer error message (Mark H)
Guido van Rossum <guido@python.org>
parents: 2793
diff changeset
399 strcpy(errBuf, "DLL load failed: ");
8d92a3bb9c1f NT specific change for nicer error message (Mark H)
Guido van Rossum <guido@python.org>
parents: 2793
diff changeset
400 len = strlen(errBuf);
8d92a3bb9c1f NT specific change for nicer error message (Mark H)
Guido van Rossum <guido@python.org>
parents: 2793
diff changeset
401 strncpy(errBuf+len, theInfo, sizeof(errBuf)-len);
8d92a3bb9c1f NT specific change for nicer error message (Mark H)
Guido van Rossum <guido@python.org>
parents: 2793
diff changeset
402 errBuf[sizeof(errBuf)-1] = '\0';
8d92a3bb9c1f NT specific change for nicer error message (Mark H)
Guido van Rossum <guido@python.org>
parents: 2793
diff changeset
403 }
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
404 err_setstr(ImportError, errBuf);
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
405 return NULL;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
406 }
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
407 p = GetProcAddress(hDLL, funcname);
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
408 }
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
409 #endif /* NT */
3591
1c18f90636fb removed verbose decl; added win3.1 dynamic linking.
Guido van Rossum <guido@python.org>
parents: 3491
diff changeset
410 #ifdef WIN16_DL
1c18f90636fb removed verbose decl; added win3.1 dynamic linking.
Guido van Rossum <guido@python.org>
parents: 3491
diff changeset
411 {
1c18f90636fb removed verbose decl; added win3.1 dynamic linking.
Guido van Rossum <guido@python.org>
parents: 3491
diff changeset
412 HINSTANCE hDLL;
1c18f90636fb removed verbose decl; added win3.1 dynamic linking.
Guido van Rossum <guido@python.org>
parents: 3491
diff changeset
413 hDLL = LoadLibrary(pathname);
1c18f90636fb removed verbose decl; added win3.1 dynamic linking.
Guido van Rossum <guido@python.org>
parents: 3491
diff changeset
414 if (hDLL < HINSTANCE_ERROR){
1c18f90636fb removed verbose decl; added win3.1 dynamic linking.
Guido van Rossum <guido@python.org>
parents: 3491
diff changeset
415 char errBuf[256];
1c18f90636fb removed verbose decl; added win3.1 dynamic linking.
Guido van Rossum <guido@python.org>
parents: 3491
diff changeset
416 sprintf(errBuf, "DLL load failed with error code %d", hDLL);
1c18f90636fb removed verbose decl; added win3.1 dynamic linking.
Guido van Rossum <guido@python.org>
parents: 3491
diff changeset
417 err_setstr(ImportError, errBuf);
1c18f90636fb removed verbose decl; added win3.1 dynamic linking.
Guido van Rossum <guido@python.org>
parents: 3491
diff changeset
418 return NULL;
1c18f90636fb removed verbose decl; added win3.1 dynamic linking.
Guido van Rossum <guido@python.org>
parents: 3491
diff changeset
419 }
1c18f90636fb removed verbose decl; added win3.1 dynamic linking.
Guido van Rossum <guido@python.org>
parents: 3491
diff changeset
420 p = GetProcAddress(hDLL, funcname);
1c18f90636fb removed verbose decl; added win3.1 dynamic linking.
Guido van Rossum <guido@python.org>
parents: 3491
diff changeset
421 }
1c18f90636fb removed verbose decl; added win3.1 dynamic linking.
Guido van Rossum <guido@python.org>
parents: 3491
diff changeset
422 #endif /* WIN16_DL */
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
423 #ifdef USE_DL
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
424 p = dl_loadmod(getprogramname(), pathname, funcname);
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
425 #endif /* USE_DL */
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
426 #ifdef USE_RLD
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
427 {
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
428 NXStream *errorStream;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
429 struct mach_header *new_header;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
430 const char *filenames[2];
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
431 long ret;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
432 unsigned long ptr;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
433
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
434 errorStream = NXOpenMemory(NULL, 0, NX_WRITEONLY);
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
435 filenames[0] = pathname;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
436 filenames[1] = NULL;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
437 ret = rld_load(errorStream, &new_header,
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
438 filenames, NULL);
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
439
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
440 /* extract the error messages for the exception */
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
441 if(!ret) {
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
442 char *streamBuf;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
443 int len, maxLen;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
444
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
445 NXPutc(errorStream, (char)0);
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
446
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
447 NXGetMemoryBuffer(errorStream,
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
448 &streamBuf, &len, &maxLen);
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
449 err_setstr(ImportError, streamBuf);
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
450 }
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
451
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
452 if(ret && rld_lookup(errorStream, funcname, &ptr))
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
453 p = (dl_funcptr) ptr;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
454
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
455 NXCloseMemory(errorStream, NX_FREEBUFFER);
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
456
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
457 if(!ret)
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
458 return NULL;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
459 }
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
460 #endif /* USE_RLD */
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
461 #ifdef hpux
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
462 {
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
463 shl_t lib;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
464 int flags;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
465
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
466 flags = BIND_DEFERRED;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
467 if (verbose)
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
468 {
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
469 flags = BIND_IMMEDIATE | BIND_NONFATAL | BIND_VERBOSE;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
470 printf("shl_load %s\n",pathname);
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
471 }
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
472 lib = shl_load(pathname, flags, 0);
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
473 if (lib == NULL)
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
474 {
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
475 char buf[256];
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
476 if (verbose)
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
477 perror(pathname);
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
478 sprintf(buf, "Failed to load %.200s", pathname);
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
479 err_setstr(ImportError, buf);
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
480 return NULL;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
481 }
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
482 if (verbose)
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
483 printf("shl_findsym %s\n", funcname);
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
484 shl_findsym(&lib, funcname, TYPE_UNDEFINED, (void *) &p);
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
485 if (p == NULL && verbose)
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
486 perror(funcname);
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
487 }
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
488 #endif /* hpux */
2724
6a9ecb05c679 Check if we've already loaded a dynamic module under a different name.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2435
diff changeset
489 got_it:
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
490 if (p == NULL) {
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
491 err_setstr(ImportError,
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
492 "dynamic module does not define init function");
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
493 return NULL;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
494 }
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
495 (*p)();
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
496
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
497 m = dictlookup(import_modules, name);
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
498 if (m == NULL) {
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
499 if (err_occurred() == NULL)
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
500 err_setstr(SystemError,
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
501 "dynamic module not initialized properly");
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
502 return NULL;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
503 }
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
504 if (verbose)
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
505 fprintf(stderr,
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
506 "import %s # dynamically loaded from %s\n",
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
507 name, pathname);
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
508 INCREF(m);
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
509 return m;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
510 #endif /* DYNAMIC_LINK */
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
511 }
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
512
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
513
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
514 #ifdef _AIX
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
515
3907
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
516 #include <ctype.h> /* for isdigit() */
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
517 #include <errno.h> /* for global errno */
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
518 #include <string.h> /* for strerror() */
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
519 #include <stdlib.h> /* for malloc(), free() */
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
520
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
521 typedef struct Module {
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
522 struct Module *next;
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
523 void *entry;
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
524 } Module, *ModulePtr;
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
525
3907
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
526 static int
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
527 aix_getoldmodules(modlistptr)
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
528 void **modlistptr;
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
529 {
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
530 register ModulePtr modptr, prevmodptr;
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
531 register struct ld_info *ldiptr;
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
532 register char *ldibuf;
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
533 register int errflag, bufsize = 1024;
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
534 register unsigned int offset;
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
535
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
536 /*
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
537 -- Get the list of loaded modules into ld_info structures.
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
538 */
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
539 if ((ldibuf = malloc(bufsize)) == NULL) {
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
540 err_setstr(ImportError, strerror(errno));
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
541 return -1;
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
542 }
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
543 while ((errflag = loadquery(L_GETINFO, ldibuf, bufsize)) == -1
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
544 && errno == ENOMEM) {
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
545 free(ldibuf);
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
546 bufsize += 1024;
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
547 if ((ldibuf = malloc(bufsize)) == NULL) {
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
548 err_setstr(ImportError, strerror(errno));
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
549 return -1;
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
550 }
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
551 }
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
552 if (errflag == -1) {
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
553 err_setstr(ImportError, strerror(errno));
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
554 return -1;
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
555 }
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
556 /*
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
557 -- Make the modules list from the ld_info structures.
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
558 */
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
559 ldiptr = (struct ld_info *)ldibuf;
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
560 prevmodptr = NULL;
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
561 do {
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
562 if ((modptr = (ModulePtr)malloc(sizeof(Module))) == NULL) {
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
563 err_setstr(ImportError, strerror(errno));
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
564 while (*modlistptr) {
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
565 modptr = (ModulePtr)*modlistptr;
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
566 *modlistptr = (void *)modptr->next;
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
567 free(modptr);
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
568 }
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
569 return -1;
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
570 }
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
571 modptr->entry = ldiptr->ldinfo_dataorg;
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
572 modptr->next = NULL;
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
573 if (prevmodptr == NULL)
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
574 *modlistptr = (void *)modptr;
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
575 else
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
576 prevmodptr->next = modptr;
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
577 prevmodptr = modptr;
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
578 offset = (unsigned int)ldiptr->ldinfo_next;
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
579 ldiptr = (struct ld_info *)((unsigned int)ldiptr + offset);
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
580 } while (offset);
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
581 free(ldibuf);
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
582 return 0;
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
583 }
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
584
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
585 static int
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
586 aix_bindnewmodule(newmoduleptr, modlistptr)
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
587 void *newmoduleptr;
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
588 void *modlistptr;
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
589 {
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
590 register ModulePtr modptr;
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
591
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
592 /*
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
593 -- Bind the new module with the list of loaded modules.
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
594 */
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
595 for (modptr = (ModulePtr)modlistptr; modptr; modptr = modptr->next)
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
596 if (loadbind(0, modptr->entry, newmoduleptr) != 0)
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
597 return -1;
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
598 return 0;
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
599 }
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
600
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
601 static void
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
602 aix_loaderror(pathname)
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
603 char *pathname;
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
604 {
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
605
3732
523f49a1e42a Corrections to aix_loaderror(), by Manus Hand.
Guido van Rossum <guido@python.org>
parents: 3591
diff changeset
606 char *message[1024], errbuf[1024];
3907
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
607 register int i,j;
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
608
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
609 struct errtab {
3907
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
610 int errNo;
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
611 char *errstr;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
612 } load_errtab[] = {
2724
6a9ecb05c679 Check if we've already loaded a dynamic module under a different name.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2435
diff changeset
613 {L_ERROR_TOOMANY, "too many errors, rest skipped."},
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
614 {L_ERROR_NOLIB, "can't load library:"},
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
615 {L_ERROR_UNDEF, "can't find symbol in library:"},
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
616 {L_ERROR_RLDBAD,
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
617 "RLD index out of range or bad relocation type:"},
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
618 {L_ERROR_FORMAT, "not a valid, executable xcoff file:"},
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
619 {L_ERROR_MEMBER,
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
620 "file not an archive or does not contain requested member:"},
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
621 {L_ERROR_TYPE, "symbol table mismatch:"},
3732
523f49a1e42a Corrections to aix_loaderror(), by Manus Hand.
Guido van Rossum <guido@python.org>
parents: 3591
diff changeset
622 {L_ERROR_ALIGN, "text alignment in file is wrong."},
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
623 {L_ERROR_SYSTEM, "System error:"},
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
624 {L_ERROR_ERRNO, NULL}
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
625 };
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
626
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
627 #define LOAD_ERRTAB_LEN (sizeof(load_errtab)/sizeof(load_errtab[0]))
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
628 #define ERRBUF_APPEND(s) strncat(errbuf, s, sizeof(errbuf)-strlen(errbuf)-1)
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
629
3907
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
630 sprintf(errbuf, "from module %.200s ", pathname);
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
631
3907
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
632 if (!loadquery(L_GETMESSAGES, &message[0], sizeof(message))) {
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
633 ERRBUF_APPEND(strerror(errno));
3732
523f49a1e42a Corrections to aix_loaderror(), by Manus Hand.
Guido van Rossum <guido@python.org>
parents: 3591
diff changeset
634 ERRBUF_APPEND("\n");
523f49a1e42a Corrections to aix_loaderror(), by Manus Hand.
Guido van Rossum <guido@python.org>
parents: 3591
diff changeset
635 }
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
636 for(i = 0; message[i] && *message[i]; i++) {
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
637 int nerr = atoi(message[i]);
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
638 for (j=0; j<LOAD_ERRTAB_LEN ; j++) {
3907
ac1d5abfd78e Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents: 3898
diff changeset
639 if (nerr == load_errtab[j].errNo && load_errtab[j].errstr)
3732
523f49a1e42a Corrections to aix_loaderror(), by Manus Hand.
Guido van Rossum <guido@python.org>
parents: 3591
diff changeset
640 ERRBUF_APPEND(load_errtab[j].errstr);
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
641 }
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
642 while (isdigit(*message[i])) message[i]++ ;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
643 ERRBUF_APPEND(message[i]);
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
644 ERRBUF_APPEND("\n");
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
645 }
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
646 errbuf[strlen(errbuf)-1] = '\0'; /* trim off last newline */
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
647 err_setstr(ImportError, errbuf);
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
648 return;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
649 }
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
650
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff changeset
651 #endif /* _AIX */