Ignore:
Timestamp:
Mar 19, 2014, 11:11:30 AM (11 years ago)
Author:
dmik
Message:

python: Update vendor to 2.7.6.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/vendor/current/Modules/resource.c

    r2 r388  
    3030
    3131static PyStructSequence_Field struct_rusage_fields[] = {
    32         {"ru_utime",    "user time used"},
    33         {"ru_stime",    "system time used"},
    34         {"ru_maxrss",   "max. resident set size"},
    35         {"ru_ixrss",    "shared memory size"},
    36         {"ru_idrss",    "unshared data size"},
    37         {"ru_isrss",    "unshared stack size"},
    38         {"ru_minflt",   "page faults not requiring I/O"},
    39         {"ru_majflt",   "page faults requiring I/O"},
    40         {"ru_nswap",    "number of swap outs"},
    41         {"ru_inblock",  "block input operations"},
    42         {"ru_oublock",  "block output operations"},
    43         {"ru_msgsnd",   "IPC messages sent"},
    44         {"ru_msgrcv",   "IPC messages received"},
    45         {"ru_nsignals", "signals received"},
    46         {"ru_nvcsw",    "voluntary context switches"},
    47         {"ru_nivcsw",   "involuntary context switches"},
    48         {0}
     32    {"ru_utime",        "user time used"},
     33    {"ru_stime",        "system time used"},
     34    {"ru_maxrss",       "max. resident set size"},
     35    {"ru_ixrss",        "shared memory size"},
     36    {"ru_idrss",        "unshared data size"},
     37    {"ru_isrss",        "unshared stack size"},
     38    {"ru_minflt",       "page faults not requiring I/O"},
     39    {"ru_majflt",       "page faults requiring I/O"},
     40    {"ru_nswap",        "number of swap outs"},
     41    {"ru_inblock",      "block input operations"},
     42    {"ru_oublock",      "block output operations"},
     43    {"ru_msgsnd",       "IPC messages sent"},
     44    {"ru_msgrcv",       "IPC messages received"},
     45    {"ru_nsignals",     "signals received"},
     46    {"ru_nvcsw",        "voluntary context switches"},
     47    {"ru_nivcsw",       "involuntary context switches"},
     48    {0}
    4949};
    5050
    5151static PyStructSequence_Desc struct_rusage_desc = {
    52         "resource.struct_rusage",       /* name */
    53         struct_rusage__doc__,   /* doc */
    54         struct_rusage_fields,   /* fields */
    55         16      /* n_in_sequence */
     52    "resource.struct_rusage",           /* name */
     53    struct_rusage__doc__,       /* doc */
     54    struct_rusage_fields,       /* fields */
     55    16          /* n_in_sequence */
    5656};
    5757
     
    6262resource_getrusage(PyObject *self, PyObject *args)
    6363{
    64         int who;
    65         struct rusage ru;
    66         PyObject *result;
    67 
    68         if (!PyArg_ParseTuple(args, "i:getrusage", &who))
    69                 return NULL;
    70 
    71         if (getrusage(who, &ru) == -1) {
    72                 if (errno == EINVAL) {
    73                         PyErr_SetString(PyExc_ValueError,
    74                                         "invalid who parameter");
    75                         return NULL;
    76                 }
    77                 PyErr_SetFromErrno(ResourceError);
    78                 return NULL;
    79         }
    80 
    81         result = PyStructSequence_New(&StructRUsageType);
    82         if (!result)
    83                 return NULL;
    84 
    85         PyStructSequence_SET_ITEM(result, 0,
    86                         PyFloat_FromDouble(doubletime(ru.ru_utime)));
    87         PyStructSequence_SET_ITEM(result, 1,
    88                         PyFloat_FromDouble(doubletime(ru.ru_stime)));
    89         PyStructSequence_SET_ITEM(result, 2, PyInt_FromLong(ru.ru_maxrss));
    90         PyStructSequence_SET_ITEM(result, 3, PyInt_FromLong(ru.ru_ixrss));
    91         PyStructSequence_SET_ITEM(result, 4, PyInt_FromLong(ru.ru_idrss));
    92         PyStructSequence_SET_ITEM(result, 5, PyInt_FromLong(ru.ru_isrss));
    93         PyStructSequence_SET_ITEM(result, 6, PyInt_FromLong(ru.ru_minflt));
    94         PyStructSequence_SET_ITEM(result, 7, PyInt_FromLong(ru.ru_majflt));
    95         PyStructSequence_SET_ITEM(result, 8, PyInt_FromLong(ru.ru_nswap));
    96         PyStructSequence_SET_ITEM(result, 9, PyInt_FromLong(ru.ru_inblock));
    97         PyStructSequence_SET_ITEM(result, 10, PyInt_FromLong(ru.ru_oublock));
    98         PyStructSequence_SET_ITEM(result, 11, PyInt_FromLong(ru.ru_msgsnd));
    99         PyStructSequence_SET_ITEM(result, 12, PyInt_FromLong(ru.ru_msgrcv));
    100         PyStructSequence_SET_ITEM(result, 13, PyInt_FromLong(ru.ru_nsignals));
    101         PyStructSequence_SET_ITEM(result, 14, PyInt_FromLong(ru.ru_nvcsw));
    102         PyStructSequence_SET_ITEM(result, 15, PyInt_FromLong(ru.ru_nivcsw));
    103 
    104         if (PyErr_Occurred()) {
    105                 Py_DECREF(result);
    106                 return NULL;
    107         }
    108 
    109         return result;
     64    int who;
     65    struct rusage ru;
     66    PyObject *result;
     67
     68    if (!PyArg_ParseTuple(args, "i:getrusage", &who))
     69        return NULL;
     70
     71    if (getrusage(who, &ru) == -1) {
     72        if (errno == EINVAL) {
     73            PyErr_SetString(PyExc_ValueError,
     74                            "invalid who parameter");
     75            return NULL;
     76        }
     77        PyErr_SetFromErrno(ResourceError);
     78        return NULL;
     79    }
     80
     81    result = PyStructSequence_New(&StructRUsageType);
     82    if (!result)
     83        return NULL;
     84
     85    PyStructSequence_SET_ITEM(result, 0,
     86                    PyFloat_FromDouble(doubletime(ru.ru_utime)));
     87    PyStructSequence_SET_ITEM(result, 1,
     88                    PyFloat_FromDouble(doubletime(ru.ru_stime)));
     89    PyStructSequence_SET_ITEM(result, 2, PyInt_FromLong(ru.ru_maxrss));
     90    PyStructSequence_SET_ITEM(result, 3, PyInt_FromLong(ru.ru_ixrss));
     91    PyStructSequence_SET_ITEM(result, 4, PyInt_FromLong(ru.ru_idrss));
     92    PyStructSequence_SET_ITEM(result, 5, PyInt_FromLong(ru.ru_isrss));
     93    PyStructSequence_SET_ITEM(result, 6, PyInt_FromLong(ru.ru_minflt));
     94    PyStructSequence_SET_ITEM(result, 7, PyInt_FromLong(ru.ru_majflt));
     95    PyStructSequence_SET_ITEM(result, 8, PyInt_FromLong(ru.ru_nswap));
     96    PyStructSequence_SET_ITEM(result, 9, PyInt_FromLong(ru.ru_inblock));
     97    PyStructSequence_SET_ITEM(result, 10, PyInt_FromLong(ru.ru_oublock));
     98    PyStructSequence_SET_ITEM(result, 11, PyInt_FromLong(ru.ru_msgsnd));
     99    PyStructSequence_SET_ITEM(result, 12, PyInt_FromLong(ru.ru_msgrcv));
     100    PyStructSequence_SET_ITEM(result, 13, PyInt_FromLong(ru.ru_nsignals));
     101    PyStructSequence_SET_ITEM(result, 14, PyInt_FromLong(ru.ru_nvcsw));
     102    PyStructSequence_SET_ITEM(result, 15, PyInt_FromLong(ru.ru_nivcsw));
     103
     104    if (PyErr_Occurred()) {
     105        Py_DECREF(result);
     106        return NULL;
     107    }
     108
     109    return result;
    110110}
    111111
     
    114114resource_getrlimit(PyObject *self, PyObject *args)
    115115{
    116         struct rlimit rl;
    117         int resource;
    118 
    119         if (!PyArg_ParseTuple(args, "i:getrlimit", &resource))
    120                 return NULL;
    121 
    122         if (resource < 0 || resource >= RLIM_NLIMITS) {
    123                 PyErr_SetString(PyExc_ValueError,
    124                                 "invalid resource specified");
    125                 return NULL;
    126         }
    127 
    128         if (getrlimit(resource, &rl) == -1) {
    129                 PyErr_SetFromErrno(ResourceError);
    130                 return NULL;
    131         }
     116    struct rlimit rl;
     117    int resource;
     118
     119    if (!PyArg_ParseTuple(args, "i:getrlimit", &resource))
     120        return NULL;
     121
     122    if (resource < 0 || resource >= RLIM_NLIMITS) {
     123        PyErr_SetString(PyExc_ValueError,
     124                        "invalid resource specified");
     125        return NULL;
     126    }
     127
     128    if (getrlimit(resource, &rl) == -1) {
     129        PyErr_SetFromErrno(ResourceError);
     130        return NULL;
     131    }
    132132
    133133#if defined(HAVE_LONG_LONG)
    134         if (sizeof(rl.rlim_cur) > sizeof(long)) {
    135                 return Py_BuildValue("LL",
    136                                      (PY_LONG_LONG) rl.rlim_cur,
    137                                      (PY_LONG_LONG) rl.rlim_max);
    138         }
    139 #endif
    140         return Py_BuildValue("ll", (long) rl.rlim_cur, (long) rl.rlim_max);
     134    if (sizeof(rl.rlim_cur) > sizeof(long)) {
     135        return Py_BuildValue("LL",
     136                             (PY_LONG_LONG) rl.rlim_cur,
     137                             (PY_LONG_LONG) rl.rlim_max);
     138    }
     139#endif
     140    return Py_BuildValue("ll", (long) rl.rlim_cur, (long) rl.rlim_max);
    141141}
    142142
     
    144144resource_setrlimit(PyObject *self, PyObject *args)
    145145{
    146         struct rlimit rl;
    147         int resource;
    148         PyObject *curobj, *maxobj;
    149 
    150         if (!PyArg_ParseTuple(args, "i(OO):setrlimit",
    151                               &resource, &curobj, &maxobj))
    152                 return NULL;
    153 
    154         if (resource < 0 || resource >= RLIM_NLIMITS) {
    155                 PyErr_SetString(PyExc_ValueError,
    156                                 "invalid resource specified");
    157                 return NULL;
    158         }
     146    struct rlimit rl;
     147    int resource;
     148    PyObject *limits, *curobj, *maxobj;
     149
     150    if (!PyArg_ParseTuple(args, "iO:setrlimit", &resource, &limits))
     151        return NULL;
     152
     153    if (resource < 0 || resource >= RLIM_NLIMITS) {
     154        PyErr_SetString(PyExc_ValueError,
     155                        "invalid resource specified");
     156        return NULL;
     157    }
     158
     159    limits = PySequence_Tuple(limits);
     160    if (!limits)
     161        /* Here limits is a borrowed reference */
     162        return NULL;
     163
     164    if (PyTuple_GET_SIZE(limits) != 2) {
     165        PyErr_SetString(PyExc_ValueError,
     166                        "expected a tuple of 2 integers");
     167        goto error;
     168    }
     169    curobj = PyTuple_GET_ITEM(limits, 0);
     170    maxobj = PyTuple_GET_ITEM(limits, 1);
    159171
    160172#if !defined(HAVE_LARGEFILE_SUPPORT)
    161         rl.rlim_cur = PyInt_AsLong(curobj);
    162         if (rl.rlim_cur == (rlim_t)-1 && PyErr_Occurred())
    163             return NULL;
    164         rl.rlim_max = PyInt_AsLong(maxobj);
    165         if (rl.rlim_max == (rlim_t)-1 && PyErr_Occurred())
    166             return NULL;
     173    rl.rlim_cur = PyInt_AsLong(curobj);
     174    if (rl.rlim_cur == (rlim_t)-1 && PyErr_Occurred())
     175        goto error;
     176    rl.rlim_max = PyInt_AsLong(maxobj);
     177    if (rl.rlim_max == (rlim_t)-1 && PyErr_Occurred())
     178        goto error;
    167179#else
    168         /* The limits are probably bigger than a long */
    169         rl.rlim_cur = PyLong_Check(curobj) ?
    170                 PyLong_AsLongLong(curobj) : PyInt_AsLong(curobj);
    171         if (rl.rlim_cur == (rlim_t)-1 && PyErr_Occurred())
    172             return NULL;
    173         rl.rlim_max = PyLong_Check(maxobj) ?
    174                 PyLong_AsLongLong(maxobj) : PyInt_AsLong(maxobj);
    175         if (rl.rlim_max == (rlim_t)-1 && PyErr_Occurred())
    176             return NULL;
    177 #endif
    178 
    179         rl.rlim_cur = rl.rlim_cur & RLIM_INFINITY;
    180         rl.rlim_max = rl.rlim_max & RLIM_INFINITY;
    181         if (setrlimit(resource, &rl) == -1) {
    182                 if (errno == EINVAL)
    183                         PyErr_SetString(PyExc_ValueError,
    184                                         "current limit exceeds maximum limit");
    185                 else if (errno == EPERM)
    186                         PyErr_SetString(PyExc_ValueError,
    187                                         "not allowed to raise maximum limit");
    188                 else
    189                         PyErr_SetFromErrno(ResourceError);
    190                 return NULL;
    191         }
    192         Py_INCREF(Py_None);
    193         return Py_None;
     180    /* The limits are probably bigger than a long */
     181    rl.rlim_cur = PyLong_Check(curobj) ?
     182        PyLong_AsLongLong(curobj) : PyInt_AsLong(curobj);
     183    if (rl.rlim_cur == (rlim_t)-1 && PyErr_Occurred())
     184        goto error;
     185    rl.rlim_max = PyLong_Check(maxobj) ?
     186        PyLong_AsLongLong(maxobj) : PyInt_AsLong(maxobj);
     187    if (rl.rlim_max == (rlim_t)-1 && PyErr_Occurred())
     188        goto error;
     189#endif
     190
     191    rl.rlim_cur = rl.rlim_cur & RLIM_INFINITY;
     192    rl.rlim_max = rl.rlim_max & RLIM_INFINITY;
     193    if (setrlimit(resource, &rl) == -1) {
     194        if (errno == EINVAL)
     195            PyErr_SetString(PyExc_ValueError,
     196                            "current limit exceeds maximum limit");
     197        else if (errno == EPERM)
     198            PyErr_SetString(PyExc_ValueError,
     199                            "not allowed to raise maximum limit");
     200        else
     201            PyErr_SetFromErrno(ResourceError);
     202        goto error;
     203    }
     204    Py_DECREF(limits);
     205    Py_INCREF(Py_None);
     206    return Py_None;
     207
     208  error:
     209    Py_DECREF(limits);
     210    return NULL;
    194211}
    195212
     
    197214resource_getpagesize(PyObject *self, PyObject *unused)
    198215{
    199         long pagesize = 0;
     216    long pagesize = 0;
    200217#if defined(HAVE_GETPAGESIZE)
    201         pagesize = getpagesize();
     218    pagesize = getpagesize();
    202219#elif defined(HAVE_SYSCONF)
    203220#if defined(_SC_PAGE_SIZE)
    204         pagesize = sysconf(_SC_PAGE_SIZE);
     221    pagesize = sysconf(_SC_PAGE_SIZE);
    205222#else
    206         /* Irix 5.3 has _SC_PAGESIZE, but not _SC_PAGE_SIZE */
    207         pagesize = sysconf(_SC_PAGESIZE);
    208 #endif
    209 #endif
    210         return Py_BuildValue("i", pagesize);
     223    /* Irix 5.3 has _SC_PAGESIZE, but not _SC_PAGE_SIZE */
     224    pagesize = sysconf(_SC_PAGESIZE);
     225#endif
     226#endif
     227    return Py_BuildValue("i", pagesize);
    211228
    212229}
     
    216233static struct PyMethodDef
    217234resource_methods[] = {
    218         {"getrusage",    resource_getrusage,   METH_VARARGS},
    219         {"getrlimit",    resource_getrlimit,   METH_VARARGS},
    220         {"setrlimit",    resource_setrlimit,   METH_VARARGS},
    221         {"getpagesize",  resource_getpagesize, METH_NOARGS},
    222         {NULL, NULL}                         /* sentinel */
     235    {"getrusage",    resource_getrusage,   METH_VARARGS},
     236    {"getrlimit",    resource_getrlimit,   METH_VARARGS},
     237    {"setrlimit",    resource_setrlimit,   METH_VARARGS},
     238    {"getpagesize",  resource_getpagesize, METH_NOARGS},
     239    {NULL, NULL}                             /* sentinel */
    223240};
    224241
     
    229246initresource(void)
    230247{
    231         PyObject *m, *v;
    232 
    233         /* Create the module and add the functions */
    234         m = Py_InitModule("resource", resource_methods);
    235         if (m == NULL)
    236                 return;
    237 
    238         /* Add some symbolic constants to the module */
    239         if (ResourceError == NULL) {
    240                 ResourceError = PyErr_NewException("resource.error",
    241                                                    NULL, NULL);
    242         }
    243         Py_INCREF(ResourceError);
    244         PyModule_AddObject(m, "error", ResourceError);
    245         if (!initialized)
    246                 PyStructSequence_InitType(&StructRUsageType,
    247                                           &struct_rusage_desc);
    248         Py_INCREF(&StructRUsageType);
    249         PyModule_AddObject(m, "struct_rusage",
    250                            (PyObject*) &StructRUsageType);
    251 
    252         /* insert constants */
     248    PyObject *m, *v;
     249
     250    /* Create the module and add the functions */
     251    m = Py_InitModule("resource", resource_methods);
     252    if (m == NULL)
     253        return;
     254
     255    /* Add some symbolic constants to the module */
     256    if (ResourceError == NULL) {
     257        ResourceError = PyErr_NewException("resource.error",
     258                                           NULL, NULL);
     259    }
     260    Py_INCREF(ResourceError);
     261    PyModule_AddObject(m, "error", ResourceError);
     262    if (!initialized)
     263        PyStructSequence_InitType(&StructRUsageType,
     264                                  &struct_rusage_desc);
     265    Py_INCREF(&StructRUsageType);
     266    PyModule_AddObject(m, "struct_rusage",
     267                       (PyObject*) &StructRUsageType);
     268
     269    /* insert constants */
    253270#ifdef RLIMIT_CPU
    254         PyModule_AddIntConstant(m, "RLIMIT_CPU", RLIMIT_CPU);
     271    PyModule_AddIntConstant(m, "RLIMIT_CPU", RLIMIT_CPU);
    255272#endif
    256273
    257274#ifdef RLIMIT_FSIZE
    258         PyModule_AddIntConstant(m, "RLIMIT_FSIZE", RLIMIT_FSIZE);
     275    PyModule_AddIntConstant(m, "RLIMIT_FSIZE", RLIMIT_FSIZE);
    259276#endif
    260277
    261278#ifdef RLIMIT_DATA
    262         PyModule_AddIntConstant(m, "RLIMIT_DATA", RLIMIT_DATA);
     279    PyModule_AddIntConstant(m, "RLIMIT_DATA", RLIMIT_DATA);
    263280#endif
    264281
    265282#ifdef RLIMIT_STACK
    266         PyModule_AddIntConstant(m, "RLIMIT_STACK", RLIMIT_STACK);
     283    PyModule_AddIntConstant(m, "RLIMIT_STACK", RLIMIT_STACK);
    267284#endif
    268285
    269286#ifdef RLIMIT_CORE
    270         PyModule_AddIntConstant(m, "RLIMIT_CORE", RLIMIT_CORE);
     287    PyModule_AddIntConstant(m, "RLIMIT_CORE", RLIMIT_CORE);
    271288#endif
    272289
    273290#ifdef RLIMIT_NOFILE
    274         PyModule_AddIntConstant(m, "RLIMIT_NOFILE", RLIMIT_NOFILE);
     291    PyModule_AddIntConstant(m, "RLIMIT_NOFILE", RLIMIT_NOFILE);
    275292#endif
    276293
    277294#ifdef RLIMIT_OFILE
    278         PyModule_AddIntConstant(m, "RLIMIT_OFILE", RLIMIT_OFILE);
     295    PyModule_AddIntConstant(m, "RLIMIT_OFILE", RLIMIT_OFILE);
    279296#endif
    280297
    281298#ifdef RLIMIT_VMEM
    282         PyModule_AddIntConstant(m, "RLIMIT_VMEM", RLIMIT_VMEM);
     299    PyModule_AddIntConstant(m, "RLIMIT_VMEM", RLIMIT_VMEM);
    283300#endif
    284301
    285302#ifdef RLIMIT_AS
    286         PyModule_AddIntConstant(m, "RLIMIT_AS", RLIMIT_AS);
     303    PyModule_AddIntConstant(m, "RLIMIT_AS", RLIMIT_AS);
    287304#endif
    288305
    289306#ifdef RLIMIT_RSS
    290         PyModule_AddIntConstant(m, "RLIMIT_RSS", RLIMIT_RSS);
     307    PyModule_AddIntConstant(m, "RLIMIT_RSS", RLIMIT_RSS);
    291308#endif
    292309
    293310#ifdef RLIMIT_NPROC
    294         PyModule_AddIntConstant(m, "RLIMIT_NPROC", RLIMIT_NPROC);
     311    PyModule_AddIntConstant(m, "RLIMIT_NPROC", RLIMIT_NPROC);
    295312#endif
    296313
    297314#ifdef RLIMIT_MEMLOCK
    298         PyModule_AddIntConstant(m, "RLIMIT_MEMLOCK", RLIMIT_MEMLOCK);
     315    PyModule_AddIntConstant(m, "RLIMIT_MEMLOCK", RLIMIT_MEMLOCK);
    299316#endif
    300317
    301318#ifdef RLIMIT_SBSIZE
    302         PyModule_AddIntConstant(m, "RLIMIT_SBSIZE", RLIMIT_SBSIZE);
     319    PyModule_AddIntConstant(m, "RLIMIT_SBSIZE", RLIMIT_SBSIZE);
    303320#endif
    304321
    305322#ifdef RUSAGE_SELF
    306         PyModule_AddIntConstant(m, "RUSAGE_SELF", RUSAGE_SELF);
     323    PyModule_AddIntConstant(m, "RUSAGE_SELF", RUSAGE_SELF);
    307324#endif
    308325
    309326#ifdef RUSAGE_CHILDREN
    310         PyModule_AddIntConstant(m, "RUSAGE_CHILDREN", RUSAGE_CHILDREN);
     327    PyModule_AddIntConstant(m, "RUSAGE_CHILDREN", RUSAGE_CHILDREN);
    311328#endif
    312329
    313330#ifdef RUSAGE_BOTH
    314         PyModule_AddIntConstant(m, "RUSAGE_BOTH", RUSAGE_BOTH);
     331    PyModule_AddIntConstant(m, "RUSAGE_BOTH", RUSAGE_BOTH);
    315332#endif
    316333
    317334#if defined(HAVE_LONG_LONG)
    318         if (sizeof(RLIM_INFINITY) > sizeof(long)) {
    319                 v = PyLong_FromLongLong((PY_LONG_LONG) RLIM_INFINITY);
    320         } else
    321 #endif
    322         {
    323                 v = PyInt_FromLong((long) RLIM_INFINITY);
    324         }
    325         if (v) {
    326                 PyModule_AddObject(m, "RLIM_INFINITY", v);
    327         }
    328         initialized = 1;
    329 }
     335    if (sizeof(RLIM_INFINITY) > sizeof(long)) {
     336        v = PyLong_FromLongLong((PY_LONG_LONG) RLIM_INFINITY);
     337    } else
     338#endif
     339    {
     340        v = PyInt_FromLong((long) RLIM_INFINITY);
     341    }
     342    if (v) {
     343        PyModule_AddObject(m, "RLIM_INFINITY", v);
     344    }
     345    initialized = 1;
     346}
Note: See TracChangeset for help on using the changeset viewer.