Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Python/dynload_shlib.c

    r10 r391  
    2828#endif
    2929
    30 #if ((defined(__OpenBSD__) || defined(__NetBSD__)) && !defined(__ELF__)) \
    31     || (defined(__OS2__) && defined(__KLIBC__))
     30#if ((defined(__OpenBSD__) || defined(__NetBSD__)) && !defined(__ELF__)) || defined(PYOS_OS2)
    3231#define LEAD_UNDERSCORE "_"
    3332#else
     
    3837const struct filedescr _PyImport_DynLoadFiletab[] = {
    3938#ifdef __CYGWIN__
    40         {".dll", "rb", C_EXTENSION},
    41         {"module.dll", "rb", C_EXTENSION},
     39    {".dll", "rb", C_EXTENSION},
     40    {"module.dll", "rb", C_EXTENSION},
    4241#else
    43 #if (defined(PYOS_OS2) && defined(PYCC_GCC)) || (defined(__OS2__) && defined(__KLIBC__))
    44         {".pyd", "rb", C_EXTENSION},
    45         {".dll", "rb", C_EXTENSION},
     42#if defined(PYOS_OS2) && defined(PYCC_GCC)
     43    {".pyd", "rb", C_EXTENSION},
     44    {".dll", "rb", C_EXTENSION},
    4645#else
    4746#ifdef __VMS
    48         {".exe", "rb", C_EXTENSION},
    49         {".EXE", "rb", C_EXTENSION},
    50         {"module.exe", "rb", C_EXTENSION},
    51         {"MODULE.EXE", "rb", C_EXTENSION},
     47    {".exe", "rb", C_EXTENSION},
     48    {".EXE", "rb", C_EXTENSION},
     49    {"module.exe", "rb", C_EXTENSION},
     50    {"MODULE.EXE", "rb", C_EXTENSION},
    5251#else
    53         {".so", "rb", C_EXTENSION},
    54         {"module.so", "rb", C_EXTENSION},
     52    {".so", "rb", C_EXTENSION},
     53    {"module.so", "rb", C_EXTENSION},
    5554#endif
    5655#endif
    5756#endif
    58         {0, 0}
     57    {0, 0}
    5958};
    6059
    6160static struct {
    62         dev_t dev;
     61    dev_t dev;
    6362#ifdef __VMS
    64         ino_t ino[3];
     63    ino_t ino[3];
    6564#else
    66         ino_t ino;
     65    ino_t ino;
    6766#endif
    68         void *handle;
     67    void *handle;
    6968} handles[128];
    7069static int nhandles = 0;
     
    7271
    7372dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
    74                                     const char *pathname, FILE *fp)
     73                                    const char *pathname, FILE *fp)
    7574{
    76         dl_funcptr p;
    77         void *handle;
    78         char funcname[258];
    79         char pathbuf[260];
    80         int dlopenflags=0;
     75    dl_funcptr p;
     76    void *handle;
     77    char funcname[258];
     78    char pathbuf[260];
     79    int dlopenflags=0;
    8180
    82         if (strchr(pathname, '/') == NULL) {
    83                 /* Prefix bare filename with "./" */
    84                 PyOS_snprintf(pathbuf, sizeof(pathbuf), "./%-.255s", pathname);
    85                 pathname = pathbuf;
    86         }
     81    if (strchr(pathname, '/') == NULL) {
     82        /* Prefix bare filename with "./" */
     83        PyOS_snprintf(pathbuf, sizeof(pathbuf), "./%-.255s", pathname);
     84        pathname = pathbuf;
     85    }
    8786
    88         PyOS_snprintf(funcname, sizeof(funcname),
    89                       LEAD_UNDERSCORE "init%.200s", shortname);
     87    PyOS_snprintf(funcname, sizeof(funcname),
     88                  LEAD_UNDERSCORE "init%.200s", shortname);
    9089
    91         if (fp != NULL) {
    92                 int i;
    93                 struct stat statb;
    94                 fstat(fileno(fp), &statb);
    95                 for (i = 0; i < nhandles; i++) {
    96                         if (statb.st_dev == handles[i].dev &&
    97                             statb.st_ino == handles[i].ino) {
    98                                 p = (dl_funcptr) dlsym(handles[i].handle,
    99                                                        funcname);
    100                                 return p;
    101                         }
    102                 }
    103                 if (nhandles < 128) {
    104                         handles[nhandles].dev = statb.st_dev;
     90    if (fp != NULL) {
     91        int i;
     92        struct stat statb;
     93        fstat(fileno(fp), &statb);
     94        for (i = 0; i < nhandles; i++) {
     95            if (statb.st_dev == handles[i].dev &&
     96                statb.st_ino == handles[i].ino) {
     97                p = (dl_funcptr) dlsym(handles[i].handle,
     98                                       funcname);
     99                return p;
     100            }
     101        }
     102        if (nhandles < 128) {
     103            handles[nhandles].dev = statb.st_dev;
    105104#ifdef __VMS
    106                         handles[nhandles].ino[0] = statb.st_ino[0];
    107                         handles[nhandles].ino[1] = statb.st_ino[1];
    108                         handles[nhandles].ino[2] = statb.st_ino[2];
     105            handles[nhandles].ino[0] = statb.st_ino[0];
     106            handles[nhandles].ino[1] = statb.st_ino[1];
     107            handles[nhandles].ino[2] = statb.st_ino[2];
    109108#else
    110                         handles[nhandles].ino = statb.st_ino;
     109            handles[nhandles].ino = statb.st_ino;
    111110#endif
    112                 }
    113         }
     111        }
     112    }
    114113
    115114#if !(defined(PYOS_OS2) && defined(PYCC_GCC))
    116         dlopenflags = PyThreadState_GET()->interp->dlopenflags;
     115    dlopenflags = PyThreadState_GET()->interp->dlopenflags;
    117116#endif
    118117
    119         if (Py_VerboseFlag)
    120                 PySys_WriteStderr("dlopen(\"%s\", %x);\n", pathname,
    121                                   dlopenflags);
     118    if (Py_VerboseFlag)
     119        PySys_WriteStderr("dlopen(\"%s\", %x);\n", pathname,
     120                          dlopenflags);
    122121
    123122#ifdef __VMS
    124         /* VMS currently don't allow a pathname, use a logical name instead */
    125         /* Concatenate 'python_module_' and shortname */
    126         /* so "import vms.bar" will use the logical python_module_bar */
    127         /* As C module use only one name space this is probably not a */
    128         /* important limitation */
    129         PyOS_snprintf(pathbuf, sizeof(pathbuf), "python_module_%-.200s",
    130                       shortname);
    131         pathname = pathbuf;
     123    /* VMS currently don't allow a pathname, use a logical name instead */
     124    /* Concatenate 'python_module_' and shortname */
     125    /* so "import vms.bar" will use the logical python_module_bar */
     126    /* As C module use only one name space this is probably not a */
     127    /* important limitation */
     128    PyOS_snprintf(pathbuf, sizeof(pathbuf), "python_module_%-.200s",
     129                  shortname);
     130    pathname = pathbuf;
    132131#endif
    133132
    134133#if (defined(PYOS_OS2) && defined(PYCC_GCC))
    135         // resolve unixroot
    136         if (_realrealpath( pathname, pathbuf, sizeof(pathbuf))!=0)
    137                 pathname = pathbuf;
     134    // resolve unixroot
     135    if (_realrealpath( pathname, pathbuf, sizeof(pathbuf))!=0)
     136        pathname = pathbuf;
    138137#endif
    139138
    140         handle = dlopen(pathname, dlopenflags);
     139    handle = dlopen(pathname, dlopenflags);
    141140
    142         if (handle == NULL) {
    143                 const char *error = dlerror();
    144                 if (error == NULL)
    145                         error = "unknown dlopen() error";
    146                 PyErr_SetString(PyExc_ImportError, error);
    147                 return NULL;
    148         }
    149         if (fp != NULL && nhandles < 128)
    150                 handles[nhandles++].handle = handle;
    151         p = (dl_funcptr) dlsym(handle, funcname);
    152         return p;
     141    if (handle == NULL) {
     142        const char *error = dlerror();
     143        if (error == NULL)
     144            error = "unknown dlopen() error";
     145        PyErr_SetString(PyExc_ImportError, error);
     146        return NULL;
     147    }
     148    if (fp != NULL && nhandles < 128)
     149        handles[nhandles++].handle = handle;
     150    p = (dl_funcptr) dlsym(handle, funcname);
     151    return p;
    153152}
Note: See TracChangeset for help on using the changeset viewer.