| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e6911a4 commit ba85d69
18 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -209,6 +209,11 @@ PyAPI_FUNC(long) PyOS_strtol(const char *, char **, int); | |||
| 209 | 209 | PyAPI_FUNC(PyObject *) _PyLong_GCD(PyObject *, PyObject *); | |
| 210 | 210 | #endif /* !Py_LIMITED_API */ | |
| 211 | 211 | ||
| 212 | + #ifndef Py_LIMITED_API | ||
| 213 | + PyAPI_DATA(PyObject *) _PyLong_Zero; | ||
| 214 | + PyAPI_DATA(PyObject *) _PyLong_One; | ||
| 215 | + #endif | ||
| 216 | + | ||
| 212 | 217 | #ifdef __cplusplus | |
| 213 | 218 | } | |
| 214 | 219 | #endif | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2267,8 +2267,6 @@ _count_elements(PyObject *self, PyObject *args) | |||
| 2267 | 2267 | PyObject *it, *iterable, *mapping, *oldval; | |
| 2268 | 2268 | PyObject *newval = NULL; | |
| 2269 | 2269 | PyObject *key = NULL; | |
| 2270 | - PyObject *zero = NULL; | ||
| 2271 | - PyObject *one = NULL; | ||
| 2272 | 2270 | PyObject *bound_get = NULL; | |
| 2273 | 2271 | PyObject *mapping_get; | |
| 2274 | 2272 | PyObject *dict_get; | |
@@ -2282,10 +2280,6 @@ _count_elements(PyObject *self, PyObject *args) | |||
| 2282 | 2280 | if (it == NULL) | |
| 2283 | 2281 | return NULL; | |
| 2284 | 2282 | ||
| 2285 | - one = PyLong_FromLong(1); | ||
| 2286 | - if (one == NULL) | ||
| 2287 | - goto done; | ||
| 2288 | - | ||
| 2289 | 2283 | /* Only take the fast path when get() and __setitem__() | |
| 2290 | 2284 | * have not been overridden. | |
| 2291 | 2285 | */ | |
@@ -2325,10 +2319,10 @@ _count_elements(PyObject *self, PyObject *args) | |||
| 2325 | 2319 | if (oldval == NULL) { | |
| 2326 | 2320 | if (PyErr_Occurred()) | |
| 2327 | 2321 | goto done; | |
| 2328 | - if (_PyDict_SetItem_KnownHash(mapping, key, one, hash) < 0) | ||
| 2322 | + if (_PyDict_SetItem_KnownHash(mapping, key, _PyLong_One, hash) < 0) | ||
| 2329 | 2323 | goto done; | |
| 2330 | 2324 | } else { | |
| 2331 | - newval = PyNumber_Add(oldval, one); | ||
| 2325 | + newval = PyNumber_Add(oldval, _PyLong_One); | ||
| 2332 | 2326 | if (newval == NULL) | |
| 2333 | 2327 | goto done; | |
| 2334 | 2328 | if (_PyDict_SetItem_KnownHash(mapping, key, newval, hash) < 0) | |
@@ -2342,18 +2336,14 @@ _count_elements(PyObject *self, PyObject *args) | |||
| 2342 | 2336 | if (bound_get == NULL) | |
| 2343 | 2337 | goto done; | |
| 2344 | 2338 | ||
| 2345 | - zero = PyLong_FromLong(0); | ||
| 2346 | - if (zero == NULL) | ||
| 2347 | - goto done; | ||
| 2348 | - | ||
| 2349 | 2339 | while (1) { | |
| 2350 | 2340 | key = PyIter_Next(it); | |
| 2351 | 2341 | if (key == NULL) | |
| 2352 | 2342 | break; | |
| 2353 | - oldval = PyObject_CallFunctionObjArgs(bound_get, key, zero, NULL); | ||
| 2343 | + oldval = PyObject_CallFunctionObjArgs(bound_get, key, _PyLong_Zero, NULL); | ||
| 2354 | 2344 | if (oldval == NULL) | |
| 2355 | 2345 | break; | |
| 2356 | - newval = PyNumber_Add(oldval, one); | ||
| 2346 | + newval = PyNumber_Add(oldval, _PyLong_One); | ||
| 2357 | 2347 | Py_DECREF(oldval); | |
| 2358 | 2348 | if (newval == NULL) | |
| 2359 | 2349 | break; | |
@@ -2369,8 +2359,6 @@ _count_elements(PyObject *self, PyObject *args) | |||
| 2369 | 2359 | Py_XDECREF(key); | |
| 2370 | 2360 | Py_XDECREF(newval); | |
| 2371 | 2361 | Py_XDECREF(bound_get); | |
| 2372 | - Py_XDECREF(zero); | ||
| 2373 | - Py_XDECREF(one); | ||
| 2374 | 2362 | if (PyErr_Occurred()) | |
| 2375 | 2363 | return NULL; | |
| 2376 | 2364 | Py_RETURN_NONE; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3606,12 +3606,9 @@ _build_callargs(PyCFuncPtrObject *self, PyObject *argtypes, | |||
| 3606 | 3606 | case PARAMFLAG_FIN | PARAMFLAG_FLCID: | |
| 3607 | 3607 | /* ['in', 'lcid'] parameter. Always taken from defval, | |
| 3608 | 3608 | if given, else the integer 0. */ | |
| 3609 | - if (defval == NULL) { | ||
| 3610 | - defval = PyLong_FromLong(0); | ||
| 3611 | - if (defval == NULL) | ||
| 3612 | - goto error; | ||
| 3613 | - } else | ||
| 3614 | - Py_INCREF(defval); | ||
| 3609 | + if (defval == NULL) | ||
| 3610 | + defval = _PyLong_Zero; | ||
| 3611 | + Py_INCREF(defval); | ||
| 3615 | 3612 | PyTuple_SET_ITEM(callargs, i, defval); | |
| 3616 | 3613 | break; | |
| 3617 | 3614 | case (PARAMFLAG_FIN | PARAMFLAG_FOUT): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1481,7 +1481,6 @@ cmperror(PyObject *a, PyObject *b) | |||
| 1481 | 1481 | */ | |
| 1482 | 1482 | ||
| 1483 | 1483 | /* Conversion factors. */ | |
| 1484 | - static PyObject *one = NULL; /* 1 */ | ||
| 1485 | 1484 | static PyObject *us_per_ms = NULL; /* 1000 */ | |
| 1486 | 1485 | static PyObject *us_per_second = NULL; /* 1000000 */ | |
| 1487 | 1486 | static PyObject *us_per_minute = NULL; /* 1e6 * 60 as Python int */ | |
@@ -2201,7 +2200,7 @@ delta_new(PyTypeObject *type, PyObject *args, PyObject *kw) | |||
| 2201 | 2200 | goto Done | |
| 2202 | 2201 | ||
| 2203 | 2202 | if (us) { | |
| 2204 | - y = accum("microseconds", x, us, one, &leftover_us); | ||
| 2203 | + y = accum("microseconds", x, us, _PyLong_One, &leftover_us); | ||
| 2205 | 2204 | CLEANUP; | |
| 2206 | 2205 | } | |
| 2207 | 2206 | if (ms) { | |
@@ -2241,7 +2240,7 @@ delta_new(PyTypeObject *type, PyObject *args, PyObject *kw) | |||
| 2241 | 2240 | * is odd. Note that x is odd when it's last bit is 1. The | |
| 2242 | 2241 | * code below uses bitwise and operation to check the last | |
| 2243 | 2242 | * bit. */ | |
| 2244 | - temp = PyNumber_And(x, one); /* temp <- x & 1 */ | ||
| 2243 | + temp = PyNumber_And(x, _PyLong_One); /* temp <- x & 1 */ | ||
| 2245 | 2244 | if (temp == NULL) { | |
| 2246 | 2245 | Py_DECREF(x); | |
| 2247 | 2246 | goto Done; | |
@@ -5839,12 +5838,11 @@ PyInit__datetime(void) | |||
| 5839 | 5838 | Py_BUILD_ASSERT(DI100Y == 25 * DI4Y - 1); | |
| 5840 | 5839 | assert(DI100Y == days_before_year(100+1)); | |
| 5841 | 5840 | ||
| 5842 | - one = PyLong_FromLong(1); | ||
| 5843 | 5841 | us_per_ms = PyLong_FromLong(1000); | |
| 5844 | 5842 | us_per_second = PyLong_FromLong(1000000); | |
| 5845 | 5843 | us_per_minute = PyLong_FromLong(60000000); | |
| 5846 | 5844 | seconds_per_day = PyLong_FromLong(24 * 3600); | |
| 5847 | - if (one == NULL || us_per_ms == NULL || us_per_second == NULL || | ||
| 5845 | + if (us_per_ms == NULL || us_per_second == NULL || | ||
| 5848 | 5846 | us_per_minute == NULL || seconds_per_day == NULL) | |
| 5849 | 5847 | return NULL; | |
| 5850 | 5848 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -529,15 +529,8 @@ keyobject_richcompare(PyObject *ko, PyObject *other, int op) | |||
| 529 | 529 | PyObject *y; | |
| 530 | 530 | PyObject *compare; | |
| 531 | 531 | PyObject *answer; | |
| 532 | - static PyObject *zero; | ||
| 533 | 532 | PyObject* stack[2]; | |
| 534 | 533 | ||
| 535 | - if (zero == NULL) { | ||
| 536 | - zero = PyLong_FromLong(0); | ||
| 537 | - if (!zero) | ||
| 538 | - return NULL; | ||
| 539 | - } | ||
| 540 | - | ||
| 541 | 534 | if (Py_TYPE(other) != &keyobject_type){ | |
| 542 | 535 | PyErr_Format(PyExc_TypeError, "other argument must be K instance"); | |
| 543 | 536 | return NULL; | |
@@ -561,7 +554,7 @@ keyobject_richcompare(PyObject *ko, PyObject *other, int op) | |||
| 561 | 554 | return NULL; | |
| 562 | 555 | } | |
| 563 | 556 | ||
| 564 | - answer = PyObject_RichCompare(res, zero, op); | ||
| 557 | + answer = PyObject_RichCompare(res, _PyLong_Zero, op); | ||
| 565 | 558 | Py_DECREF(res); | |
| 566 | 559 | return answer; | |
| 567 | 560 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -53,7 +53,6 @@ PyObject *_PyIO_str_write; | |||
| 53 | 53 | ||
| 54 | 54 | PyObject *_PyIO_empty_str; | |
| 55 | 55 | PyObject *_PyIO_empty_bytes; | |
| 56 | - PyObject *_PyIO_zero; | ||
| 57 | 56 | ||
| 58 | 57 | PyDoc_STRVAR(module_doc, | |
| 59 | 58 | "The io module provides the Python interfaces to stream handling. The\n" | |
@@ -790,9 +789,6 @@ PyInit__io(void) | |||
| 790 | 789 | if (!_PyIO_empty_bytes && | |
| 791 | 790 | !(_PyIO_empty_bytes = PyBytes_FromStringAndSize(NULL, 0))) | |
| 792 | 791 | goto fail; | |
| 793 | - if (!_PyIO_zero && | ||
| 794 | - !(_PyIO_zero = PyLong_FromLong(0L))) | ||
| 795 | - goto fail; | ||
| 796 | 792 | ||
| 797 | 793 | state->initialized = 1; | |
| 798 | 794 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -183,6 +183,5 @@ extern PyObject *_PyIO_str_write; | |||
| 183 | 183 | ||
| 184 | 184 | extern PyObject *_PyIO_empty_str; | |
| 185 | 185 | extern PyObject *_PyIO_empty_bytes; | |
| 186 | - extern PyObject *_PyIO_zero; | ||
| 187 | 186 | ||
| 188 | 187 | extern PyTypeObject _PyBytesIOBuffer_Type; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1078,7 +1078,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer, | |||
| 1078 | 1078 | if (cookieObj == NULL) | |
| 1079 | 1079 | goto error; | |
| 1080 | 1080 | ||
| 1081 | - cmp = PyObject_RichCompareBool(cookieObj, _PyIO_zero, Py_EQ); | ||
| 1081 | + cmp = PyObject_RichCompareBool(cookieObj, _PyLong_Zero, Py_EQ); | ||
| 1082 | 1082 | Py_DECREF(cookieObj); | |
| 1083 | 1083 | if (cmp < 0) { | |
| 1084 | 1084 | goto error; | |
@@ -1087,7 +1087,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer, | |||
| 1087 | 1087 | if (cmp == 0) { | |
| 1088 | 1088 | self->encoding_start_of_stream = 0; | |
| 1089 | 1089 | res = PyObject_CallMethodObjArgs(self->encoder, _PyIO_str_setstate, | |
| 1090 | - _PyIO_zero, NULL); | ||
| 1090 | + _PyLong_Zero, NULL); | ||
| 1091 | 1091 | if (res == NULL) | |
| 1092 | 1092 | goto error; | |
| 1093 | 1093 | Py_DECREF(res); | |
@@ -2030,7 +2030,7 @@ _textiowrapper_encoder_reset(textio *self, int start_of_stream) | |||
| 2030 | 2030 | } | |
| 2031 | 2031 | else { | |
| 2032 | 2032 | res = PyObject_CallMethodObjArgs(self->encoder, _PyIO_str_setstate, | |
| 2033 | - _PyIO_zero, NULL); | ||
| 2033 | + _PyLong_Zero, NULL); | ||
| 2034 | 2034 | self->encoding_start_of_stream = 0; | |
| 2035 | 2035 | } | |
| 2036 | 2036 | if (res == NULL) | |
@@ -2075,7 +2075,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence) | |||
| 2075 | 2075 | ||
| 2076 | 2076 | if (whence == 1) { | |
| 2077 | 2077 | /* seek relative to current position */ | |
| 2078 | - cmp = PyObject_RichCompareBool(cookieObj, _PyIO_zero, Py_EQ); | ||
| 2078 | + cmp = PyObject_RichCompareBool(cookieObj, _PyLong_Zero, Py_EQ); | ||
| 2079 | 2079 | if (cmp < 0) | |
| 2080 | 2080 | goto fail; | |
| 2081 | 2081 | ||
@@ -2094,7 +2094,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence) | |||
| 2094 | 2094 | } | |
| 2095 | 2095 | else if (whence == 2) { | |
| 2096 | 2096 | /* seek relative to end of file */ | |
| 2097 | - cmp = PyObject_RichCompareBool(cookieObj, _PyIO_zero, Py_EQ); | ||
| 2097 | + cmp = PyObject_RichCompareBool(cookieObj, _PyLong_Zero, Py_EQ); | ||
| 2098 | 2098 | if (cmp < 0) | |
| 2099 | 2099 | goto fail; | |
| 2100 | 2100 | ||
@@ -2123,7 +2123,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence) | |||
| 2123 | 2123 | goto fail; | |
| 2124 | 2124 | if (self->encoder) { | |
| 2125 | 2125 | /* If seek() == 0, we are at the start of stream, otherwise not */ | |
| 2126 | - cmp = PyObject_RichCompareBool(res, _PyIO_zero, Py_EQ); | ||
| 2126 | + cmp = PyObject_RichCompareBool(res, _PyLong_Zero, Py_EQ); | ||
| 2127 | 2127 | if (cmp < 0 || _textiowrapper_encoder_reset(self, cmp)) { | |
| 2128 | 2128 | Py_DECREF(res); | |
| 2129 | 2129 | goto fail; | |
@@ -2137,7 +2137,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence) | |||
| 2137 | 2137 | goto fail; | |
| 2138 | 2138 | } | |
| 2139 | 2139 | ||
| 2140 | - cmp = PyObject_RichCompareBool(cookieObj, _PyIO_zero, Py_LT); | ||
| 2140 | + cmp = PyObject_RichCompareBool(cookieObj, _PyLong_Zero, Py_LT); | ||
| 2141 | 2141 | if (cmp < 0) | |
| 2142 | 2142 | goto fail; | |
| 2143 | 2143 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2041,7 +2041,7 @@ match_group(MatchObject* self, PyObject* args) | |||
| 2041 | 2041 | ||
| 2042 | 2042 | switch (size) { | |
| 2043 | 2043 | case 0: | |
| 2044 | - result = match_getslice(self, Py_False, Py_None); | ||
| 2044 | + result = match_getslice(self, _PyLong_Zero, Py_None); | ||
| 2045 | 2045 | break; | |
| 2046 | 2046 | case 1: | |
| 2047 | 2047 | result = match_getslice(self, PyTuple_GET_ITEM(args, 0), Py_None); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3965,24 +3965,16 @@ count_new(PyTypeObject *type, PyObject *args, PyObject *kwds) | |||
| 3965 | 3965 | fast_mode = 0; | |
| 3966 | 3966 | } | |
| 3967 | 3967 | } | |
| 3968 | - Py_INCREF(long_cnt); | ||
| 3969 | 3968 | } else { | |
| 3970 | 3969 | cnt = 0; | |
| 3971 | - long_cnt = PyLong_FromLong(0); | ||
| 3972 | - if (long_cnt == NULL) { | ||
| 3973 | - return NULL; | ||
| 3974 | - } | ||
| 3970 | + long_cnt = _PyLong_Zero; | ||
| 3975 | 3971 | } | |
| 3972 | + Py_INCREF(long_cnt); | ||
| 3976 | 3973 | ||
| 3977 | 3974 | /* If not specified, step defaults to 1 */ | |
| 3978 | - if (long_step == NULL) { | ||
| 3979 | - long_step = PyLong_FromLong(1); | ||
| 3980 | - if (long_step == NULL) { | ||
| 3981 | - Py_DECREF(long_cnt); | ||
| 3982 | - return NULL; | ||
| 3983 | - } | ||
| 3984 | - } else | ||
| 3985 | - Py_INCREF(long_step); | ||
| 3975 | + if (long_step == NULL) | ||
| 3976 | + long_step = _PyLong_One; | ||
| 3977 | + Py_INCREF(long_step); | ||
| 3986 | 3978 | ||
| 3987 | 3979 | assert(long_cnt != NULL && long_step != NULL); | |
| 3988 | 3980 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments