Skip to content

Commit 96a8fb7

Browse files
committed
Cleanup patches from Greg Stein:
* in import.c, #ifdef out references to dynamic loading based on HAVE_DYNAMIC_LOADING * clean out the platform-specific crud from importdl.c. [ maybe fold this function into import.c and drop the importdl.c file? Greg.] * change GetDynLoadFunc's "funcname" parameter to "shortname". change "name" to "fqname" for clarification. * each GetDynLoadFunc now creates its own funcname value. WARNING: as I mentioned previously, we may run into an issue with a missing "_" on some platforms. Testing will show this pretty quickly, however. * move pathname munging into dynload_shlib.c
1 parent 6a90b5e commit 96a8fb7

File tree

11 files changed

+64
-75
lines changed

11 files changed

+64
-75
lines changed

Python/dynload_aix.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ aix_loaderror(pathname)
202202
}
203203

204204

205-
dl_funcptr _PyImport_GetDynLoadFunc(const char *name, const char *funcname,
205+
dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
206206
const char *pathname, FILE *fp)
207207
{
208208
dl_funcptr p;

Python/dynload_beos.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,14 @@ static void beos_add_dyn( char *name, image_id id )
185185

186186

187187

188-
dl_funcptr _PyImport_GetDynLoadFunc(const char *name, const char *funcname,
188+
dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
189189
const char *pathname, FILE *fp)
190190
{
191191
dl_funcptr p;
192192
image_id the_id;
193193
status_t retval;
194194
char fullpath[PATH_MAX];
195+
char funcname[258];
195196

196197
if( Py_VerboseFlag ) {
197198
printf( "load_add_on( %s )\n", pathname );
@@ -236,6 +237,7 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *name, const char *funcname,
236237
return NULL;
237238
}
238239

240+
sprintf(funcname, "init%.200s", shortname);
239241
if( Py_VerboseFlag ) {
240242
printf( "get_image_symbol( %s )\n", funcname );
241243
}
@@ -274,7 +276,7 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *name, const char *funcname,
274276
/* Save the module name and image ID for later so we can clean up
275277
* gracefully.
276278
*/
277-
beos_add_dyn( name, the_id );
279+
beos_add_dyn( fqname, the_id );
278280

279281
return p;
280282
}

Python/dynload_dl.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@ const struct filedescr _PyImport_DynLoadFiletab[] = {
4646
};
4747

4848

49-
dl_funcptr _PyImport_GetDynLoadFunc(const char *name, const char *funcname,
49+
dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
5050
const char *pathname, FILE *fp)
5151
{
52+
char funcname[258];
53+
54+
sprintf(funcname, "init%.200s", shortname);
5255
return dl_loadmod(Py_GetProgramName(), pathname, funcname);
5356
}

Python/dynload_hpux.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,25 @@ PERFORMANCE OF THIS SOFTWARE.
3737
#include "Python.h"
3838
#include "importdl.h"
3939

40+
#if defined(__hp9000s300)
41+
#define FUNCNAME_PATTERN "_init%.200s"
42+
#else
43+
#define FUNCNAME_PATTERN "init%.200s"
44+
#endif
4045

4146
const struct filedescr _PyImport_DynLoadFiletab[] = {
4247
{".sl", "rb", C_EXTENSION},
4348
{"module.sl", "rb", C_EXTENSION},
4449
{0, 0}
4550
};
4651

47-
dl_funcptr _PyImport_GetDynLoadFunc(const char *name, const char *funcname,
52+
dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
4853
const char *pathname, FILE *fp)
4954
{
5055
dl_funcptr p;
5156
shl_t lib;
5257
int flags;
58+
char funcname[258];
5359

5460
flags = BIND_FIRST | BIND_DEFERRED;
5561
if (Py_VerboseFlag) {
@@ -67,6 +73,7 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *name, const char *funcname,
6773
PyErr_SetString(PyExc_ImportError, buf);
6874
return NULL;
6975
}
76+
sprintf(funcname, FUNCNAME_PATTERN, shortname);
7077
if (Py_VerboseFlag)
7178
printf("shl_findsym %s\n", funcname);
7279
shl_findsym(&lib, funcname, TYPE_UNDEFINED, (void *) &p);

Python/dynload_mac.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,11 @@ const struct filedescr _PyImport_DynLoadFiletab[] = {
5959
};
6060

6161

62-
dl_funcptr _PyImport_GetDynLoadFunc(const char *name, const char *funcname,
62+
dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
6363
const char *pathname, FILE *fp)
6464
{
6565
dl_funcptr p;
66+
char funcname[258];
6667

6768
/*
6869
** Dynamic loading of CFM shared libraries on the Mac. The
@@ -121,6 +122,7 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *name, const char *funcname,
121122
return NULL;
122123
}
123124
/* Locate the address of the correct init function */
125+
sprintf(funcname, "init%.200s", shortname);
124126
err = FindSymbol(connID, Pstring(funcname), &symAddr, &class);
125127
if ( err ) {
126128
sprintf(buf, "%s: %.200s",

Python/dynload_next.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,13 @@ const struct filedescr _PyImport_DynLoadFiletab[] = {
6868
{0, 0}
6969
};
7070

71-
dl_funcptr _PyImport_GetDynLoadFunc(const char *name, const char *funcname,
71+
dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
7272
const char *pathname, FILE *fp)
7373
{
7474
dl_funcptr p = NULL;
75+
char funcname[258];
76+
77+
sprintf(funcname, "_init%.200s", shortname);
7578

7679
#ifdef USE_RLD
7780
{

Python/dynload_os2.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@ const struct filedescr _PyImport_DynLoadFiletab[] = {
4545
{0, 0}
4646
};
4747

48-
dl_funcptr _PyImport_GetDynLoadFunc(const char *name, const char *funcname,
48+
dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
4949
const char *pathname, FILE *fp)
5050
{
5151
dl_funcptr p;
5252
APIRET rc;
5353
HMODULE hDLL;
5454
char failreason[256];
55+
char funcname[258];
5556

5657
rc = DosLoadModule(failreason,
5758
sizeof(failreason),
@@ -67,6 +68,7 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *name, const char *funcname,
6768
return NULL;
6869
}
6970

71+
sprintf(funcname, "init%.200s", shortname);
7072
rc = DosQueryProcAddr(hDLL, 0L, funcname, &p);
7173
if (rc != NO_ERROR)
7274
p = NULL; /* Signify Failure to Acquire Entrypoint */

Python/dynload_shlib.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,22 @@ static struct {
6565
static int nhandles = 0;
6666

6767

68-
dl_funcptr _PyImport_GetDynLoadFunc(const char *name, const char *funcname,
68+
dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
6969
const char *pathname, FILE *fp)
7070
{
7171
dl_funcptr p;
7272
void *handle;
73+
char funcname[258];
74+
char pathbuf[260];
75+
76+
if (strchr(pathname, '/') == NULL) {
77+
/* Prefix bare filename with "./" */
78+
sprintf(pathbuf, "./%-.255s", pathname);
79+
pathname = pathbuf;
80+
}
81+
82+
/* ### should there be a leading underscore for some platforms? */
83+
sprintf(funcname, "init%.200s", shortname);
7384

7485
if (fp != NULL) {
7586
int i;

Python/dynload_win.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,13 @@ const struct filedescr _PyImport_DynLoadFiletab[] = {
4949
};
5050

5151

52-
dl_funcptr _PyImport_GetDynLoadFunc(const char *name, const char *funcname,
52+
dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
5353
const char *pathname, FILE *fp)
5454
{
5555
dl_funcptr p;
56+
char funcname[258];
57+
58+
sprintf(funcname, "init%.200s", shortname);
5659

5760
#ifdef MS_WIN32
5861
{

Python/import.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,9 +1234,11 @@ load_module(name, fp, buf, type)
12341234
m = load_compiled_module(name, buf, fp);
12351235
break;
12361236

1237+
#ifdef HAVE_DYNAMIC_LOADING
12371238
case C_EXTENSION:
12381239
m = _PyImport_LoadDynamicModule(name, buf, fp);
12391240
break;
1241+
#endif
12401242

12411243
#ifdef macintosh
12421244
case PY_RESOURCE:
@@ -2158,6 +2160,8 @@ imp_load_compiled(self, args)
21582160
return m;
21592161
}
21602162

2163+
#ifdef HAVE_DYNAMIC_LOADING
2164+
21612165
static PyObject *
21622166
imp_load_dynamic(self, args)
21632167
PyObject *self;
@@ -2180,6 +2184,8 @@ imp_load_dynamic(self, args)
21802184
return m;
21812185
}
21822186

2187+
#endif /* HAVE_DYNAMIC_LOADING */
2188+
21832189
static PyObject *
21842190
imp_load_source(self, args)
21852191
PyObject *self;
@@ -2330,7 +2336,9 @@ static PyMethodDef imp_methods[] = {
23302336
{"is_builtin", imp_is_builtin, 1},
23312337
{"is_frozen", imp_is_frozen, 1},
23322338
{"load_compiled", imp_load_compiled, 1},
2339+
#ifdef HAVE_DYNAMIC_LOADING
23332340
{"load_dynamic", imp_load_dynamic, 1},
2341+
#endif
23342342
{"load_package", imp_load_package, 1},
23352343
#ifdef macintosh
23362344
{"load_resource", imp_load_resource, 1},

0 commit comments

Comments
 (0)