annotate Python/dynload_aix.c @ 76451:ea46ebba8a0f

Issue #13959: Re-implement imp.source_from_cache() in Lib/imp.py.
author Brett Cannon <brett@python.org>
date Sat, 21 Apr 2012 18:52:52 -0400
parents 56aa4cda11a8
children 257cbd2fac38
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
28383
f99cf9bfbbaf Include Python.h first which defines _XOPEN_SOURCE
Neal Norwitz <nnorwitz@gmail.com>
parents: 26911
diff changeset
4 #include "Python.h"
f99cf9bfbbaf Include Python.h first which defines _XOPEN_SOURCE
Neal Norwitz <nnorwitz@gmail.com>
parents: 26911
diff changeset
5 #include "importdl.h"
f99cf9bfbbaf Include Python.h first which defines _XOPEN_SOURCE
Neal Norwitz <nnorwitz@gmail.com>
parents: 26911
diff changeset
6
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
7 #include <ctype.h> /* for isdigit() */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
8 #include <errno.h> /* for global errno */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
9 #include <string.h> /* for strerror() */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
10 #include <stdlib.h> /* for malloc(), free() */
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 #include <sys/ldr.h>
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
12
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 #ifdef AIX_GENUINE_CPLUSPLUS
68018
34ae316318ef Merged revisions 88430,88438,88440 via svnmerge from
Georg Brandl <georg@python.org>
parents: 61463
diff changeset
15 #include <load.h>
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 #define aix_load loadAndInit
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 #else
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 #define aix_load load
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 #endif
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
20
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
21
13663
29da35543833 ANSIfy as many declarations as possible.
Thomas Wouters <thomas@python.org>
parents: 13658
diff changeset
22 extern char *Py_GetProgramName(void);
11599
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 typedef struct Module {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
25 struct Module *next;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
26 void *entry;
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 } Module, *ModulePtr;
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
28
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 const struct filedescr _PyImport_DynLoadFiletab[] = {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
30 {".so", "rb", C_EXTENSION},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
31 {0, 0}
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 };
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 static int
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
35 aix_getoldmodules(void **modlistptr)
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
37 register ModulePtr modptr, prevmodptr;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
38 register struct ld_info *ldiptr;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
39 register char *ldibuf;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
40 register int errflag, bufsize = 1024;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
41 register unsigned int offset;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
42 char *progname = Py_GetProgramName();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
43
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
44 /*
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
45 -- Get the list of loaded modules into ld_info structures.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
46 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
47 if ((ldibuf = malloc(bufsize)) == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
48 PyErr_SetString(PyExc_ImportError, strerror(errno));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
49 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
50 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
51 while ((errflag = loadquery(L_GETINFO, ldibuf, bufsize)) == -1
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
52 && errno == ENOMEM) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
53 free(ldibuf);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
54 bufsize += 1024;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
55 if ((ldibuf = malloc(bufsize)) == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
56 PyErr_SetString(PyExc_ImportError, strerror(errno));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
57 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
58 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
59 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
60 if (errflag == -1) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
61 PyErr_SetString(PyExc_ImportError, strerror(errno));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
62 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
63 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
64 /*
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
65 -- Make the modules list from the ld_info structures.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
66 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
67 ldiptr = (struct ld_info *)ldibuf;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
68 prevmodptr = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
69 do {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
70 if (strstr(progname, ldiptr->ldinfo_filename) == NULL &&
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
71 strstr(ldiptr->ldinfo_filename, "python") == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
72 /*
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
73 -- Extract only the modules belonging to the main
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
74 -- executable + those containing "python" as a
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
75 -- substring (like the "python[version]" binary or
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
76 -- "libpython[version].a" in case it's a shared lib).
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
77 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
78 offset = (unsigned int)ldiptr->ldinfo_next;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
79 ldiptr = (struct ld_info *)((char*)ldiptr + offset);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
80 continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
81 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
82 if ((modptr = (ModulePtr)malloc(sizeof(Module))) == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
83 PyErr_SetString(PyExc_ImportError, strerror(errno));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
84 while (*modlistptr) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
85 modptr = (ModulePtr)*modlistptr;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
86 *modlistptr = (void *)modptr->next;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
87 free(modptr);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
88 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
89 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
90 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
91 modptr->entry = ldiptr->ldinfo_dataorg;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
92 modptr->next = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
93 if (prevmodptr == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
94 *modlistptr = (void *)modptr;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
95 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
96 prevmodptr->next = modptr;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
97 prevmodptr = modptr;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
98 offset = (unsigned int)ldiptr->ldinfo_next;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
99 ldiptr = (struct ld_info *)((char*)ldiptr + offset);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
100 } while (offset);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
101 free(ldibuf);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
102 return 0;
11599
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
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
105
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
106 static void
14392
63d824679b28 Fix the char* vs. const char* mismatch for the argument of aix_loaderror()
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 14375
diff changeset
107 aix_loaderror(const char *pathname)
11599
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
110 char *message[1024], errbuf[1024];
76436
56aa4cda11a8 Issue #14599: Support ImportError.path on AIX and HPUX when loading
Brett Cannon <brett@python.org>
parents: 75059
diff changeset
111 PyObject *pathname_ob = NULL;
56aa4cda11a8 Issue #14599: Support ImportError.path on AIX and HPUX when loading
Brett Cannon <brett@python.org>
parents: 75059
diff changeset
112 PyObject *errbuf_ob = NULL;
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
113 register int i,j;
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
114
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
115 struct errtab {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
116 int errNo;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
117 char *errstr;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
118 } load_errtab[] = {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
119 {L_ERROR_TOOMANY, "too many errors, rest skipped."},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
120 {L_ERROR_NOLIB, "can't load library:"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
121 {L_ERROR_UNDEF, "can't find symbol in library:"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
122 {L_ERROR_RLDBAD,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
123 "RLD index out of range or bad relocation type:"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
124 {L_ERROR_FORMAT, "not a valid, executable xcoff file:"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
125 {L_ERROR_MEMBER,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
126 "file not an archive or does not contain requested member:"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
127 {L_ERROR_TYPE, "symbol table mismatch:"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
128 {L_ERROR_ALIGN, "text alignment in file is wrong."},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
129 {L_ERROR_SYSTEM, "System error:"},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
130 {L_ERROR_ERRNO, NULL}
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
131 };
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
132
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
133 #define ERRBUF_APPEND(s) strncat(errbuf, s, sizeof(errbuf)-strlen(errbuf)-1)
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
134
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
135 PyOS_snprintf(errbuf, sizeof(errbuf), "from module %.200s ", pathname);
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
136
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
137 if (!loadquery(L_GETMESSAGES, &message[0], sizeof(message))) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
138 ERRBUF_APPEND(strerror(errno));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
139 ERRBUF_APPEND("\n");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
140 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
141 for(i = 0; message[i] && *message[i]; i++) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
142 int nerr = atoi(message[i]);
72510
b534b56379cb Use the new Py_ARRAY_LENGTH macro
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68108
diff changeset
143 for (j=0; j < Py_ARRAY_LENGTH(load_errtab); j++) {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
144 if (nerr == load_errtab[j].errNo && load_errtab[j].errstr)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
145 ERRBUF_APPEND(load_errtab[j].errstr);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
146 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
147 while (isdigit(Py_CHARMASK(*message[i]))) message[i]++ ;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
148 ERRBUF_APPEND(message[i]);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
149 ERRBUF_APPEND("\n");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
150 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
151 errbuf[strlen(errbuf)-1] = '\0'; /* trim off last newline */
76436
56aa4cda11a8 Issue #14599: Support ImportError.path on AIX and HPUX when loading
Brett Cannon <brett@python.org>
parents: 75059
diff changeset
152 pathname_ob = PyUnicode_FromString(pathname);
56aa4cda11a8 Issue #14599: Support ImportError.path on AIX and HPUX when loading
Brett Cannon <brett@python.org>
parents: 75059
diff changeset
153 errbuf_ob = PyUnicode_FromString(errbuf);
56aa4cda11a8 Issue #14599: Support ImportError.path on AIX and HPUX when loading
Brett Cannon <brett@python.org>
parents: 75059
diff changeset
154 PyErr_SetImportError(errbuf_ob, NULL, pathname);
56aa4cda11a8 Issue #14599: Support ImportError.path on AIX and HPUX when loading
Brett Cannon <brett@python.org>
parents: 75059
diff changeset
155 Py_DECREF(pathname_ob);
56aa4cda11a8 Issue #14599: Support ImportError.path on AIX and HPUX when loading
Brett Cannon <brett@python.org>
parents: 75059
diff changeset
156 Py_DECREF(errbuf_ob);
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
157 return;
11599
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
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
160
68108
0874698b1201 Issue #3080: Remove unused argument of _PyImport_GetDynLoadFunc()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68018
diff changeset
161 dl_funcptr _PyImport_GetDynLoadFunc(const char *shortname,
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
162 const char *pathname, FILE *fp)
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
163 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
164 dl_funcptr p;
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
165
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
166 /*
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
167 -- Invoke load() with L_NOAUTODEFER leaving the imported symbols
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
168 -- of the shared module unresolved. Thus we have to resolve them
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
169 -- explicitly with loadbind. The new module is loaded, then we
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
170 -- resolve its symbols using the list of already loaded modules
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
171 -- (only those that belong to the python executable). Get these
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
172 -- with loadquery(L_GETINFO).
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
173 */
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
174
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
175 static void *staticmodlistptr = NULL;
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
176
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
177 if (!staticmodlistptr)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
178 if (aix_getoldmodules(&staticmodlistptr) == -1)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
179 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
180 p = (dl_funcptr) aix_load((char *)pathname, L_NOAUTODEFER, 0);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
181 if (p == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
182 aix_loaderror(pathname);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
183 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
184 }
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
185
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 36090
diff changeset
186 return p;
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
187 }