Mercurial > cpython-lru_cache-weakref
annotate Python/dynload_next.c @ 68233:e849d484029f 2.1
Close 2.1 branch.
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Sat, 05 Mar 2011 14:54:46 +0100 |
| parents | 9746219813f9 |
| children | 379fc66f4c96 |
| rev | line source |
|---|---|
|
11599
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 /* Support for dynamic loading of extension modules */ |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
3 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
4 #include "Python.h" |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
5 #include "importdl.h" |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
6 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
7 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
8 #ifdef WITH_DYLD |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
10 #define USE_DYLD |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
12 #include <mach-o/dyld.h> |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
13 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
14 #else /* WITH_DYLD */ |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
15 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
16 #define USE_RLD |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
17 /* Define this to 1 if you want be able to load ObjC modules as well: |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
18 it switches between two different way of loading modules on the NeXT, |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
19 one that directly interfaces with the dynamic loader (rld_load(), which |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
20 does not correctly load ObjC object files), and another that uses the |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
21 ObjC runtime (objc_loadModules()) to do the job. |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
22 You'll have to add ``-ObjC'' to the compiler flags if you set this to 1. |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
23 */ |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
24 #define HANDLE_OBJC_MODULES 1 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
25 #if HANDLE_OBJC_MODULES |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
26 #include <objc/Object.h> |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
27 #include <objc/objc-load.h> |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
28 #endif |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
29 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
30 #include <mach-o/rld.h> |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
31 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
32 #endif /* WITH_DYLD */ |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
33 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
34 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
35 const struct filedescr _PyImport_DynLoadFiletab[] = { |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
36 {".so", "rb", C_EXTENSION}, |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
37 {"module.so", "rb", C_EXTENSION}, |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
38 {0, 0} |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
39 }; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
40 |
|
11618
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11599
diff
changeset
|
41 dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname, |
|
11599
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
42 const char *pathname, FILE *fp) |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
43 { |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
44 dl_funcptr p = NULL; |
|
11618
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11599
diff
changeset
|
45 char funcname[258]; |
|
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11599
diff
changeset
|
46 |
|
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11599
diff
changeset
|
47 sprintf(funcname, "_init%.200s", shortname); |
|
11599
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
48 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
49 #ifdef USE_RLD |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
50 { |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
51 NXStream *errorStream; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
52 struct mach_header *new_header; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
53 const char *filenames[2]; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
54 long ret; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
55 unsigned long ptr; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
56 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
57 errorStream = NXOpenMemory(NULL, 0, NX_WRITEONLY); |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
58 filenames[0] = pathname; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
59 filenames[1] = NULL; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
60 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
61 #if HANDLE_OBJC_MODULES |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
62 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
63 /* The following very bogus line of code ensures that |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
64 objc_msgSend, etc are linked into the binary. Without |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
65 it, dynamic loading of a module that includes objective-c |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
66 method calls will fail with "undefined symbol _objc_msgSend()". |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
67 This remains true even in the presence of the -ObjC flag |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
68 to the compiler |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
69 */ |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
70 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
71 [Object name]; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
72 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
73 /* objc_loadModules() dynamically loads the object files |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
74 indicated by the paths in filenames. If there are any |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
75 errors generated during loading -- typically due to the |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
76 inability to find particular symbols -- an error message |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
77 will be written to errorStream. |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
78 It returns 0 if the module is successfully loaded, 1 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
79 otherwise. |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
80 */ |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
81 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
82 ret = !objc_loadModules(filenames, errorStream, |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
83 NULL, &new_header, NULL); |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
84 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
85 #else /* !HANDLE_OBJC_MODULES */ |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
86 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
87 ret = rld_load(errorStream, &new_header, |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
88 filenames, NULL); |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
89 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
90 #endif /* HANDLE_OBJC_MODULES */ |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
91 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
92 /* extract the error messages for the exception */ |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
93 if(!ret) { |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
94 char *streamBuf; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
95 int len, maxLen; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
96 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
97 NXPutc(errorStream, (char)0); |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
98 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
99 NXGetMemoryBuffer(errorStream, |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
100 &streamBuf, &len, &maxLen); |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
101 PyErr_SetString(PyExc_ImportError, streamBuf); |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
102 } |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
103 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
104 if(ret && rld_lookup(errorStream, funcname, &ptr)) |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
105 p = (dl_funcptr) ptr; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
106 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
107 NXCloseMemory(errorStream, NX_FREEBUFFER); |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
108 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
109 if(!ret) |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
110 return NULL; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
111 } |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
112 #endif /* USE_RLD */ |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
113 #ifdef USE_DYLD |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
114 /* This is also NeXT-specific. However, frameworks (the new style |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
115 of shared library) and rld() can't be used in the same program; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
116 instead, you have to use dyld, which is mostly unimplemented. */ |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
117 { |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
118 NSObjectFileImageReturnCode rc; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
119 NSObjectFileImage image; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
120 NSModule newModule; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
121 NSSymbol theSym; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
122 const char *errString; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
123 |
|
21031
9746219813f9
backport of 2.8 by jack:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
14375
diff
changeset
|
124 if (NSIsSymbolNameDefined(funcname)) { |
|
9746219813f9
backport of 2.8 by jack:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
14375
diff
changeset
|
125 theSym = NSLookupAndBindSymbol(funcname); |
|
9746219813f9
backport of 2.8 by jack:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
14375
diff
changeset
|
126 p = (dl_funcptr)NSAddressOfSymbol(theSym); |
|
9746219813f9
backport of 2.8 by jack:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
14375
diff
changeset
|
127 return p; |
|
9746219813f9
backport of 2.8 by jack:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
14375
diff
changeset
|
128 } |
|
11599
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
129 rc = NSCreateObjectFileImageFromFile(pathname, &image); |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
130 switch(rc) { |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
131 default: |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
132 case NSObjectFileImageFailure: |
|
21031
9746219813f9
backport of 2.8 by jack:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
14375
diff
changeset
|
133 case NSObjectFileImageFormat: |
|
11599
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
134 /* for these a message is printed on stderr by dyld */ |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
135 errString = "Can't create object file image"; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
136 break; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
137 case NSObjectFileImageSuccess: |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
138 errString = NULL; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
139 break; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
140 case NSObjectFileImageInappropriateFile: |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
141 errString = "Inappropriate file type for dynamic loading"; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
142 break; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
143 case NSObjectFileImageArch: |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
144 errString = "Wrong CPU type in object file"; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
145 break; |
|
21031
9746219813f9
backport of 2.8 by jack:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
14375
diff
changeset
|
146 case NSObjectFileImageAccess: |
|
11599
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
147 errString = "Can't read object file (no access)"; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
148 break; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
149 } |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
150 if (errString == NULL) { |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
151 newModule = NSLinkModule(image, pathname, TRUE); |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
152 if (!newModule) |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
153 errString = "Failure linking new module"; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
154 } |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
155 if (errString != NULL) { |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
156 PyErr_SetString(PyExc_ImportError, errString); |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
157 return NULL; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
158 } |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
159 if (!NSIsSymbolNameDefined(funcname)) { |
|
13620
5b727ab37092
Spelling fixes supplied by Rob W. W. Hooft. All these are fixes in either
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
160 /* UnlinkModule() isn't implemented in current versions, but calling it does no harm */ |
|
11599
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
161 NSUnLinkModule(newModule, FALSE); |
|
12320
5de0b939fe61
Skip Montanaro: add string precisions to calls to PyErr_Format
Guido van Rossum <guido@python.org>
parents:
11618
diff
changeset
|
162 PyErr_Format(PyExc_ImportError, |
|
5de0b939fe61
Skip Montanaro: add string precisions to calls to PyErr_Format
Guido van Rossum <guido@python.org>
parents:
11618
diff
changeset
|
163 "Loaded module does not contain symbol %.200s", |
|
5de0b939fe61
Skip Montanaro: add string precisions to calls to PyErr_Format
Guido van Rossum <guido@python.org>
parents:
11618
diff
changeset
|
164 funcname); |
|
11599
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
165 return NULL; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
166 } |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
167 theSym = NSLookupAndBindSymbol(funcname); |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
168 p = (dl_funcptr)NSAddressOfSymbol(theSym); |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
169 } |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
170 #endif /* USE_DYLD */ |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
171 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
172 return p; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
173 } |
