Changeset 10 for python/trunk/Modules


Ignore:
Timestamp:
Sep 3, 2010, 5:33:06 PM (15 years ago)
Author:
Yuri Dario
Message:

python: merged offline changes.

Location:
python/trunk/Modules
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • python/trunk/Modules/Setup.dist

    r2 r10  
    113113# setup.py script in the root of the Python source tree.
    114114
    115 posix posixmodule.c             # posix (UNIX) system calls
     115os2 posixmodule.c               # posix (UNIX) system calls
    116116errno errnomodule.c             # posix (UNIX) errno values
    117117pwd pwdmodule.c                 # this is needed to find out the user's home dir
  • python/trunk/Modules/_hotshot.c

    r2 r10  
    16051605
    16061606
     1607#ifdef __OS2__
     1608PyMODINIT_FUNC
     1609#else
    16071610void
     1611#endif
    16081612init_hotshot(void)
    16091613{
  • python/trunk/Modules/_multiprocessing/multiprocessing.c

    r2 r10  
    8787#else /* !MS_WINDOWS */
    8888
    89 #if HAVE_FD_TRANSFER
     89#if defined(HAVE_FD_TRANSFER)
    9090
    9191/* Functions for transferring file descriptors between processes.
  • python/trunk/Modules/_multiprocessing/multiprocessing.h

    r2 r10  
    2828#  include <sys/uio.h>
    2929#  include <arpa/inet.h>             /* htonl() and ntohl() */
     30#ifndef __EMX__
    3031#  if HAVE_SEM_OPEN
    3132#    include <semaphore.h>
    3233     typedef sem_t *SEM_HANDLE;
    3334#  endif
     35#else
     36#  define SEM_HANDLE HANDLE
     37#endif
    3438#  define HANDLE int
    3539#  define SOCKET int
  • python/trunk/Modules/cjkcodecs/cjkcodecs.h

    r2 r10  
    387387#endif
    388388
     389#ifdef __OS2__
     390#define I_AM_A_MODULE_FOR(loc)                                          \
     391        PyMODINIT_FUNC                                                          \
     392        init_codecs_##loc(void)                                         \
     393        {                                                               \
     394                PyObject *m = Py_InitModule("_codecs_" #loc, __methods);\
     395                if (m != NULL)                                          \
     396                        (void)register_maps(m);                         \
     397        }
     398#else   
    389399#define I_AM_A_MODULE_FOR(loc)                                          \
    390400        void                                                            \
     
    395405                        (void)register_maps(m);                         \
    396406        }
    397 
    398 #endif
     407#endif
     408
     409#endif
  • python/trunk/Modules/fcntlmodule.c

    r2 r10  
    316316            return NULL;
    317317
    318 #if defined(PYOS_OS2) && defined(PYCC_GCC)
     318#if defined(PYOS_OS2) && defined(PYCC_GCC) && !defined(__KLIBC__)
    319319        PyErr_SetString(PyExc_NotImplementedError,
    320320                        "lockf not supported on OS/2 (EMX)");
     
    374374        Py_INCREF(Py_None);
    375375        return Py_None;
    376 #endif  /* defined(PYOS_OS2) && defined(PYCC_GCC) */
     376#endif  /* defined(PYOS_OS2) && defined(PYCC_GCC) && !defined(__KLIBC__)*/
    377377}
    378378
  • python/trunk/Modules/getpath.c

    r2 r10  
    117117#endif
    118118
     119#ifndef __EMX__
    119120#ifndef PYTHONPATH
    120121#define PYTHONPATH PREFIX "/lib/python" VERSION ":" \
    121122              EXEC_PREFIX "/lib/python" VERSION "/lib-dynload"
     123#endif
     124#else
     125//#define PYTHONPATH    "./Lib;./Lib/plat-" PLATFORM \
     126//                      ";./Lib/lib-dynload;./Lib/site-packages"
     127// force unixroot
     128#define PYTHONPATH PREFIX "/lib/python" VERSION ";" \
     129              EXEC_PREFIX "/lib/python" VERSION "/lib-" PLATFORM ";" \
     130              EXEC_PREFIX "/lib/python" VERSION "/site-packages" ";" \
     131              EXEC_PREFIX "/lib/python" VERSION "/lib-dynload" ";" \
     132/* now local (for building) */ \
     133              "./lib" ";" \
     134              "./lib/plat-" PLATFORM ";" \
     135              "./lib/site-packages" ";" \
     136              "./lib/lib-dynload"
    122137#endif
    123138
     
    136151{
    137152    size_t i = strlen(dir);
    138     while (i > 0 && dir[i] != SEP)
     153    while (i > 0 && !IS_SEP(dir[i]))
    139154        --i;
    140155    dir[i] = '\0';
     
    209224{
    210225    size_t n, k;
    211     if (stuff[0] == SEP)
     226    if (IS_ABSPATH(stuff))
    212227        n = 0;
    213228    else {
    214229        n = strlen(buffer);
    215         if (n > 0 && buffer[n-1] != SEP && n < MAXPATHLEN)
     230        if (n > 0 && !IS_SEP(buffer[n-1]) && n < MAXPATHLEN)
    216231            buffer[n++] = SEP;
    217232    }
     
    230245copy_absolute(char *path, char *p)
    231246{
    232     if (p[0] == SEP)
     247    if (IS_ABSPATH(p)) {
    233248        strcpy(path, p);
     249#ifdef ALTSEP
     250        p = path;
     251        while ((p = strchr(p, ALTSEP)))
     252            *p++ = SEP;
     253#endif
     254    }
    234255    else {
    235256        getcwd(path, MAXPATHLEN);
    236         if (p[0] == '.' && p[1] == SEP)
     257        if (p[0] == '.' && IS_SEP(p[1]))
    237258            p += 2;
    238259        joinpath(path, p);
     
    246267    char buffer[MAXPATHLEN + 1];
    247268
    248     if (path[0] == SEP)
     269    if (IS_ABSPATH(path)) {
     270#ifdef ALTSEP
     271        while ((path = strchr(path, ALTSEP)))
     272            *path++ = SEP;
     273#endif
    249274        return;
     275    }
    250276    copy_absolute(buffer, path);
    251277    strcpy(path, buffer);
     
    399425         * $PATH isn't exported, you lose.
    400426         */
    401         if (strchr(prog, SEP))
     427        if (HAS_ANYSEP(prog))
    402428                strncpy(progpath, prog, MAXPATHLEN);
    403429#ifdef __APPLE__
     
    442468        else
    443469                progpath[0] = '\0';
    444         if (progpath[0] != SEP)
     470#ifndef ALTSEP
     471        if (!IS_ABSPATH(progpath))
     472#endif
    445473                absolutize(progpath);
    446474        strncpy(argv0_path, progpath, MAXPATHLEN);
     
    488516            /* It's not null terminated! */
    489517            tmpbuffer[linklen] = '\0';
    490             if (tmpbuffer[0] == SEP)
     518            if (IS_ABSPATH(tmpbuffer))
    491519                /* tmpbuffer should never be longer than MAXPATHLEN,
    492520                   but extra check does not hurt */
     
    553581
    554582    while (1) {
    555         char *delim = strchr(defpath, DELIM);
    556 
    557         if (defpath[0] != SEP)
     583        char *delim = strchr(defpath, ':'); /* bird: hardcoded DELIM in default path. */
     584
     585        if (!IS_ABSPATH(defpath))
    558586            /* Paths are relative to prefix */
    559587            bufsz += prefixsz;
     
    598626        defpath = pythonpath;
    599627        while (1) {
    600             char *delim = strchr(defpath, DELIM);
    601 
    602             if (defpath[0] != SEP) {
     628            char *delim = strchr(defpath, ':'); /* bird: hardcoded DELIM in default path. */
     629
     630            if (!IS_ABSPATH(defpath)) {
    603631                strcat(buf, prefix);
    604632                strcat(buf, separator);
     
    606634
    607635            if (delim) {
    608                 size_t len = delim - defpath + 1;
     636                size_t len = delim - defpath;
    609637                size_t end = strlen(buf) + len;
    610638                strncat(buf, defpath, len);
    611                 *(buf + end) = '\0';
     639                *(buf + end) = DELIM;   /* bird: correct the DELIM char. */
     640                *(buf + end + 1) = '\0';
    612641            }
    613642            else {
  • python/trunk/Modules/posixmodule.c

    r2 r10  
    3434#    include <unixio.h>
    3535#endif /* defined(__VMS) */
     36
     37#if defined(__KLIBC__)
     38#include <sys/socket.h>
     39#endif
    3640
    3741#ifdef __cplusplus
     
    132136#define fsync _commit
    133137#else
    134 #if defined(PYOS_OS2) && defined(PYCC_GCC) || defined(__VMS)
     138#if (defined(PYOS_OS2) && defined(PYCC_GCC) && !defined(__KLIBC__)) || defined(__VMS)
    135139/* Everything needed is defined in PC/os2emx/pyconfig.h or vms/pyconfig.h */
    136140#else                   /* all other compilers */
     
    428432            Py_DECREF(v);
    429433        }
     434#ifdef LIBPATHSTRICT
     435        buffer[0] = buffer[1] = buffer[2] = buffer[3] = '\0';
     436        rc = DosQueryExtLIBPATH(buffer, LIBPATHSTRICT);
     437        if (rc == NO_ERROR) { /* (not a typo, envname is NOT 'LIBPATH_STRICT') */
     438            PyObject *v = PyString_FromString(buffer);
     439                    PyDict_SetItemString(d, "LIBPATHSTRICT", v);
     440            Py_DECREF(v);
     441        }
     442#endif
    430443    }
    431444#endif
     
    16501663#ifdef MS_WINDOWS
    16511664        return win32_1str(args, "chdir", "s:chdir", win32_chdir, "U:chdir", win32_wchdir);
    1652 #elif defined(PYOS_OS2) && defined(PYCC_GCC)
    1653         return posix_1str(args, "et:chdir", _chdir2);
    16541665#elif defined(__VMS)
    16551666        return posix_1str(args, "et:chdir", (int (*)(const char *))chdir);
     
    19871998                        break;
    19881999                }
    1989 #if defined(PYOS_OS2) && defined(PYCC_GCC)
    1990                 res = _getcwd2(tmpbuf, bufsize);
    1991 #else
    19922000                res = getcwd(tmpbuf, bufsize);
    1993 #endif
    19942001
    19952002                if (res == NULL) {
     
    20512058
    20522059        Py_BEGIN_ALLOW_THREADS
    2053 #if defined(PYOS_OS2) && defined(PYCC_GCC)
    2054         res = _getcwd2(buf, sizeof buf);
    2055 #else
    20562060        res = getcwd(buf, sizeof buf);
    2057 #endif
    20582061        Py_END_ALLOW_THREADS
    20592062        if (res == NULL)
     
    22452248        return d;
    22462249
    2247 #elif defined(PYOS_OS2)
     2250#elif defined(PYOS_OS2_00) // YD os2 api does not support path rewriting
    22482251
    22492252#ifndef MAX_PATH
     
    31173120#if defined(PYOS_OS2)
    31183121        /* Omit Pseudo-Env Vars that Would Confuse Programs if Passed On */
    3119         if (stricmp(k, "BEGINLIBPATH") != 0 && stricmp(k, "ENDLIBPATH") != 0) {
     3122        if (stricmp(k, "BEGINLIBPATH") != 0 && stricmp(k, "ENDLIBPATH") != 0
     3123         && stricmp(k, "LIBPATHSTRICT") != 0) {
    31203124#endif
    31213125                len = PyString_Size(key) + PyString_Size(val) + 2;
     
    42164220        char *mode = "r";
    42174221        int bufsize = -1;
     4222        int unset_emxshell = 0;
    42184223        FILE *fp;
    42194224        PyObject *f;
    42204225        if (!PyArg_ParseTuple(args, "s|si:popen", &name, &mode, &bufsize))
    42214226                return NULL;
     4227        /* a little hack for making sure commands.getstatusoutput works
     4228         * (ASSUMES that COMSPEC isn't a posix shell.) */
     4229        if (name[0] == '{' && !getenv("EMXSHELL")) {
     4230                char path[512];
     4231                _searchenv("sh.exe", "PATH", path);
     4232                if (!path[0])
     4233                        _searchenv("ash.exe", "PATH", path);
     4234                if (!path[0])
     4235                        _searchenv("bash.exe", "PATH", path);
     4236                if (path[0])
     4237                        unset_emxshell = setenv("EMXSHELL", path, 0) == 0;
     4238        }
    42224239        Py_BEGIN_ALLOW_THREADS
    42234240        fp = popen(name, mode);
    42244241        Py_END_ALLOW_THREADS
     4242        if (unset_emxshell)
     4243                unsetenv("EMXSHELL");
    42254244        if (fp == NULL)
    42264245                return posix_error();
     
    43724391        FILE *p_s[3];
    43734392        int file_count, i, pipe_err;
    4374         pid_t pipe_pid;
     4393        pid_t pipe_pid = -1;
    43754394        char *shell, *sh_name, *opt, *rd_mode, *wr_mode;
    43764395        PyObject *f, *p_f[3];
     
    43914410        if ((shell = getenv("EMXSHELL")) == NULL)
    43924411                if ((shell = getenv("COMSPEC")) == NULL)
     4412                        if ((shell = getenv("SHELL")) == NULL)
     4413                                if ((shell = getenv("OS2_SHELL")) == NULL)
    43934414                {
    43944415                        errno = ENOENT;
     
    44294450        i = pipe_err = 0;
    44304451        while ((pipe_err == 0) && (i < file_count))
     4452#ifndef __KLIBC__
    44314453                pipe_err = pipe((int *)&p_fd[i++]);
     4454#else
     4455                pipe_err = socketpair(AF_UNIX, SOCK_STREAM,0,(int *)&p_fd[i++]);
     4456#endif
    44324457        if (pipe_err < 0)
    44334458        {
     
    65906615posix_pipe(PyObject *self, PyObject *noargs)
    65916616{
    6592 #if defined(PYOS_OS2)
     6617#if defined(PYOS_OS2) && !defined(__KLIBC__)
    65936618    HFILE read, write;
    65946619    APIRET rc;
     
    66066631        int res;
    66076632        Py_BEGIN_ALLOW_THREADS
     6633#ifndef __KLIBC__
    66086634        res = pipe(fds);
     6635#else
     6636        res = socketpair(AF_UNIX, SOCK_STREAM,0, fds);
     6637#endif
    66096638        Py_END_ALLOW_THREADS
    66106639        if (res != 0)
     
    67966825        if (rc != NO_ERROR)
    67976826            return os2_error(rc);
     6827#ifdef LIBPATHSTRICT
     6828    } else if (stricmp(s1, "LIBPATHSTRICT") == 0) {
     6829        APIRET rc;
     6830
     6831        rc = DosSetExtLIBPATH(s2, LIBPATHSTRICT);
     6832        if (rc != NO_ERROR)
     6833            return os2_error(rc);
     6834#endif
    67986835    } else {
    6799 #endif
     6836#endif /* OS2 */
    68006837
    68016838        /* XXX This can leak memory -- not easy to fix :-( */
     
    84298466}
    84308467#endif
     8468
     8469#ifdef __EMX__
     8470/* Use openssl random routine */
     8471#include <openssl/rand.h>
     8472PyDoc_STRVAR(os2_urandom__doc__,
     8473"urandom(n) -> str\n\n\
     8474Return a string of n random bytes suitable for cryptographic use.");
     8475
     8476static PyObject*
     8477os2_urandom(PyObject *self, PyObject *args)
     8478{
     8479        int howMany;
     8480        PyObject* result;
     8481
     8482        /* Read arguments */
     8483        if (! PyArg_ParseTuple(args, "i:urandom", &howMany))
     8484                return NULL;
     8485        if (howMany < 0)
     8486                return PyErr_Format(PyExc_ValueError,
     8487                                    "negative argument not allowed");
     8488
     8489        /* Allocate bytes */
     8490        result = PyString_FromStringAndSize(NULL, howMany);
     8491        if (result != NULL) {
     8492                /* Get random data */
     8493                if (RAND_pseudo_bytes((unsigned char*)
     8494                                      PyString_AS_STRING(result),
     8495                                      howMany) < 0) {
     8496                        Py_DECREF(result);
     8497                        return PyErr_Format(PyExc_ValueError,
     8498                                            "RAND_pseudo_bytes");
     8499                }
     8500        }
     8501        return result;
     8502}
     8503#endif
     8504
    84318505
    84328506static PyMethodDef posix_methods[] = {
     
    87408814        {"urandom", vms_urandom, METH_VARARGS, vms_urandom__doc__},
    87418815 #endif
     8816 #ifdef __EMX__
     8817        {"urandom", os2_urandom, METH_VARARGS, os2_urandom__doc__},
     8818 #endif
    87428819        {NULL,          NULL}            /* Sentinel */
    87438820};
     
    87568833    APIRET    rc;
    87578834    ULONG     values[QSV_MAX+1];
    8758     PyObject *v;
    87598835    char     *ver, tmp[50];
    87608836
     
    87858861    default:
    87868862        PyOS_snprintf(tmp, sizeof(tmp),
    8787                       "%d-%d", values[QSV_VERSION_MAJOR],
     8863                      "%ld-%ld", values[QSV_VERSION_MAJOR],
    87888864                      values[QSV_VERSION_MINOR]);
    87898865        ver = &tmp[0];
  • python/trunk/Modules/resource.c

    r2 r10  
    6969                return NULL;
    7070
     71#ifndef __OS2__
    7172        if (getrusage(who, &ru) == -1) {
    7273                if (errno == EINVAL) {
     
    7879                return NULL;
    7980        }
    80 
     81#endif
    8182        result = PyStructSequence_New(&StructRUsageType);
    8283        if (!result)
Note: See TracChangeset for help on using the changeset viewer.