| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2799,7 +2799,7 @@ MODULE__SHA2_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_SHA2_HEADERS) $(LIBHACL_ | |||
| 2799 | 2799 | MODULE__SHA3_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_HEADERS) Modules/_hacl/Hacl_Hash_SHA3.h Modules/_hacl/Hacl_Hash_SHA3.c | |
| 2800 | 2800 | MODULE__SOCKET_DEPS=$(srcdir)/Modules/socketmodule.h $(srcdir)/Modules/addrinfo.h $(srcdir)/Modules/getaddrinfo.c $(srcdir)/Modules/getnameinfo.c | |
| 2801 | 2801 | MODULE__SSL_DEPS=$(srcdir)/Modules/_ssl.h $(srcdir)/Modules/_ssl/cert.c $(srcdir)/Modules/_ssl/debughelpers.c $(srcdir)/Modules/_ssl/misc.c $(srcdir)/Modules/_ssl_data.h $(srcdir)/Modules/_ssl_data_111.h $(srcdir)/Modules/_ssl_data_300.h $(srcdir)/Modules/socketmodule.h | |
| 2802 | - MODULE__TESTCAPI_DEPS=$(srcdir)/Modules/_testcapi/testcapi_long.h $(srcdir)/Modules/_testcapi/parts.h | ||
| 2802 | + MODULE__TESTCAPI_DEPS=$(srcdir)/Modules/_testcapi/testcapi_long.h $(srcdir)/Modules/_testcapi/parts.h $(srcdir)/Modules/_testcapi/util.h | ||
| 2803 | 2803 | MODULE__SQLITE3_DEPS=$(srcdir)/Modules/_sqlite/connection.h $(srcdir)/Modules/_sqlite/cursor.h $(srcdir)/Modules/_sqlite/microprotocols.h $(srcdir)/Modules/_sqlite/module.h $(srcdir)/Modules/_sqlite/prepare_protocol.h $(srcdir)/Modules/_sqlite/row.h $(srcdir)/Modules/_sqlite/util.h | |
| 2804 | 2804 | ||
| 2805 | 2805 | CODECS_COMMON_HEADERS=$(srcdir)/Modules/cjkcodecs/multibytecodec.h $(srcdir)/Modules/cjkcodecs/cjkcodecs.h | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,24 +1,7 @@ | |||
| 1 | 1 | #include <stddef.h> // ptrdiff_t | |
| 2 | 2 | ||
| 3 | 3 | #include "parts.h" | |
| 4 | - | ||
| 5 | - #define NULLABLE(x) do { if (x == Py_None) x = NULL; } while (0); | ||
| 6 | - | ||
| 7 | - #define RETURN_INT(value) do { \ | ||
| 8 | - int _ret = (value); \ | ||
| 9 | - if (_ret == -1) { \ | ||
| 10 | - return NULL; \ | ||
| 11 | - } \ | ||
| 12 | - return PyLong_FromLong(_ret); \ | ||
| 13 | - } while (0) | ||
| 14 | - | ||
| 15 | - #define RETURN_SIZE(value) do { \ | ||
| 16 | - Py_ssize_t _ret = (value); \ | ||
| 17 | - if (_ret == -1) { \ | ||
| 18 | - return NULL; \ | ||
| 19 | - } \ | ||
| 20 | - return PyLong_FromSsize_t(_ret); \ | ||
| 21 | - } while (0) | ||
| 4 | + #include "util.h" | ||
| 22 | 5 | ||
| 23 | 6 | ||
| 24 | 7 | static PyObject * | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,24 +1,7 @@ | |||
| 1 | 1 | #include <stddef.h> // ptrdiff_t | |
| 2 | 2 | ||
| 3 | 3 | #include "parts.h" | |
| 4 | - | ||
| 5 | - #define NULLABLE(x) do { if (x == Py_None) x = NULL; } while (0); | ||
| 6 | - | ||
| 7 | - #define RETURN_INT(value) do { \ | ||
| 8 | - int _ret = (value); \ | ||
| 9 | - if (_ret == -1) { \ | ||
| 10 | - return NULL; \ | ||
| 11 | - } \ | ||
| 12 | - return PyLong_FromLong(_ret); \ | ||
| 13 | - } while (0) | ||
| 14 | - | ||
| 15 | - #define RETURN_SIZE(value) do { \ | ||
| 16 | - Py_ssize_t _ret = (value); \ | ||
| 17 | - if (_ret == -1) { \ | ||
| 18 | - return NULL; \ | ||
| 19 | - } \ | ||
| 20 | - return PyLong_FromSsize_t(_ret); \ | ||
| 21 | - } while (0) | ||
| 4 | + #include "util.h" | ||
| 22 | 5 | ||
| 23 | 6 | ||
| 24 | 7 | static PyObject * | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,7 @@ | |||
| 1 | 1 | #include "parts.h" | |
| 2 | + #include "util.h" | ||
| 2 | 3 | #include "clinic/exceptions.c.h" | |
| 3 | 4 | ||
| 4 | - #define NULLABLE(x) do { if (x == Py_None) x = NULL; } while (0); | ||
| 5 | 5 | ||
| 6 | 6 | /*[clinic input] | |
| 7 | 7 | module _testcapi | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,7 @@ | |||
| 1 | 1 | #include <stddef.h> // ptrdiff_t | |
| 2 | 2 | ||
| 3 | 3 | #include "parts.h" | |
| 4 | + #include "util.h" | ||
| 4 | 5 | ||
| 5 | 6 | static struct PyModuleDef *_testcapimodule = NULL; // set at initialization | |
| 6 | 7 | ||
@@ -101,7 +102,6 @@ test_widechar(PyObject *self, PyObject *Py_UNUSED(ignored)) | |||
| 101 | 102 | Py_RETURN_NONE; | |
| 102 | 103 | } | |
| 103 | 104 | ||
| 104 | - #define NULLABLE(x) do { if (x == Py_None) x = NULL; } while (0); | ||
| 105 | 105 | ||
| 106 | 106 | static PyObject * | |
| 107 | 107 | unicode_copy(PyObject *unicode) | |
@@ -347,13 +347,8 @@ unicode_substring(PyObject *self, PyObject *args) | |||
| 347 | 347 | static PyObject * | |
| 348 | 348 | unicode_getlength(PyObject *self, PyObject *arg) | |
| 349 | 349 | { | |
| 350 | - Py_ssize_t result; | ||
| 351 | - | ||
| 352 | 350 | NULLABLE(arg); | |
| 353 | - result = PyUnicode_GetLength(arg); | ||
| 354 | - if (result == -1) | ||
| 355 | - return NULL; | ||
| 356 | - return PyLong_FromSsize_t(result); | ||
| 351 | + RETURN_SIZE(PyUnicode_GetLength(arg)); | ||
| 357 | 352 | } | |
| 358 | 353 | ||
| 359 | 354 | /* Test PyUnicode_ReadChar() */ | |
@@ -482,16 +477,12 @@ static PyObject * | |||
| 482 | 477 | unicode_aswidechar_null(PyObject *self, PyObject *args) | |
| 483 | 478 | { | |
| 484 | 479 | PyObject *unicode; | |
| 485 | - Py_ssize_t buflen, size; | ||
| 480 | + Py_ssize_t buflen; | ||
| 486 | 481 | ||
| 487 | 482 | if (!PyArg_ParseTuple(args, "On", &unicode, &buflen)) | |
| 488 | 483 | return NULL; | |
| 489 | 484 | NULLABLE(unicode); | |
| 490 | - size = PyUnicode_AsWideChar(unicode, NULL, buflen); | ||
| 491 | - if (size == -1) { | ||
| 492 | - return NULL; | ||
| 493 | - } | ||
| 494 | - return PyLong_FromSsize_t(size); | ||
| 485 | + RETURN_SIZE(PyUnicode_AsWideChar(unicode, NULL, buflen)); | ||
| 495 | 486 | } | |
| 496 | 487 | ||
| 497 | 488 | /* Test PyUnicode_AsWideCharString() */ | |
@@ -1293,17 +1284,13 @@ unicode_count(PyObject *self, PyObject *args) | |||
| 1293 | 1284 | PyObject *substr; | |
| 1294 | 1285 | Py_ssize_t start; | |
| 1295 | 1286 | Py_ssize_t end; | |
| 1296 | - Py_ssize_t result; | ||
| 1297 | 1287 | ||
| 1298 | 1288 | if (!PyArg_ParseTuple(args, "OOnn", &str, &substr, &start, &end)) | |
| 1299 | 1289 | return NULL; | |
| 1300 | 1290 | ||
| 1301 | 1291 | NULLABLE(str); | |
| 1302 | 1292 | NULLABLE(substr); | |
| 1303 | - result = PyUnicode_Count(str, substr, start, end); | ||
| 1304 | - if (result == -1) | ||
| 1305 | - return NULL; | ||
| 1306 | - return PyLong_FromSsize_t(result); | ||
| 1293 | + RETURN_SIZE(PyUnicode_Count(str, substr, start, end)); | ||
| 1307 | 1294 | } | |
| 1308 | 1295 | ||
| 1309 | 1296 | /* Test PyUnicode_Find() */ | |
@@ -1323,8 +1310,11 @@ unicode_find(PyObject *self, PyObject *args) | |||
| 1323 | 1310 | NULLABLE(str); | |
| 1324 | 1311 | NULLABLE(substr); | |
| 1325 | 1312 | result = PyUnicode_Find(str, substr, start, end, direction); | |
| 1326 | - if (result == -2) | ||
| 1313 | + if (result == -2) { | ||
| 1314 | + assert(PyErr_Occurred()); | ||
| 1327 | 1315 | return NULL; | |
| 1316 | + } | ||
| 1317 | + assert(!PyErr_Occurred()); | ||
| 1328 | 1318 | return PyLong_FromSsize_t(result); | |
| 1329 | 1319 | } | |
| 1330 | 1320 | ||
@@ -1337,17 +1327,13 @@ unicode_tailmatch(PyObject *self, PyObject *args) | |||
| 1337 | 1327 | Py_ssize_t start; | |
| 1338 | 1328 | Py_ssize_t end; | |
| 1339 | 1329 | int direction; | |
| 1340 | - Py_ssize_t result; | ||
| 1341 | 1330 | ||
| 1342 | 1331 | if (!PyArg_ParseTuple(args, "OOnni", &str, &substr, &start, &end, &direction)) | |
| 1343 | 1332 | return NULL; | |
| 1344 | 1333 | ||
| 1345 | 1334 | NULLABLE(str); | |
| 1346 | 1335 | NULLABLE(substr); | |
| 1347 | - result = PyUnicode_Tailmatch(str, substr, start, end, direction); | ||
| 1348 | - if (result == -1) | ||
| 1349 | - return NULL; | ||
| 1350 | - return PyLong_FromSsize_t(result); | ||
| 1336 | + RETURN_SIZE(PyUnicode_Tailmatch(str, substr, start, end, direction)); | ||
| 1351 | 1337 | } | |
| 1352 | 1338 | ||
| 1353 | 1339 | /* Test PyUnicode_FindChar() */ | |
@@ -1366,10 +1352,12 @@ unicode_findchar(PyObject *self, PyObject *args) | |||
| 1366 | 1352 | } | |
| 1367 | 1353 | NULLABLE(str); | |
| 1368 | 1354 | result = PyUnicode_FindChar(str, (Py_UCS4)ch, start, end, direction); | |
| 1369 | - if (result == -2) | ||
| 1355 | + if (result == -2) { | ||
| 1356 | + assert(PyErr_Occurred()); | ||
| 1370 | 1357 | return NULL; | |
| 1371 | - else | ||
| 1372 | - return PyLong_FromSsize_t(result); | ||
| 1358 | + } | ||
| 1359 | + assert(!PyErr_Occurred()); | ||
| 1360 | + return PyLong_FromSsize_t(result); | ||
| 1373 | 1361 | } | |
| 1374 | 1362 | ||
| 1375 | 1363 | /* Test PyUnicode_Replace() */ | |
@@ -1407,6 +1395,7 @@ unicode_compare(PyObject *self, PyObject *args) | |||
| 1407 | 1395 | if (result == -1 && PyErr_Occurred()) { | |
| 1408 | 1396 | return NULL; | |
| 1409 | 1397 | } | |
| 1398 | + assert(!PyErr_Occurred()); | ||
| 1410 | 1399 | return PyLong_FromLong(result); | |
| 1411 | 1400 | } | |
| 1412 | 1401 | ||
@@ -1467,32 +1456,21 @@ unicode_contains(PyObject *self, PyObject *args) | |||
| 1467 | 1456 | { | |
| 1468 | 1457 | PyObject *container; | |
| 1469 | 1458 | PyObject *element; | |
| 1470 | - int result; | ||
| 1471 | 1459 | ||
| 1472 | 1460 | if (!PyArg_ParseTuple(args, "OO", &container, &element)) | |
| 1473 | 1461 | return NULL; | |
| 1474 | 1462 | ||
| 1475 | 1463 | NULLABLE(container); | |
| 1476 | 1464 | NULLABLE(element); | |
| 1477 | - result = PyUnicode_Contains(container, element); | ||
| 1478 | - if (result == -1 && PyErr_Occurred()) { | ||
| 1479 | - return NULL; | ||
| 1480 | - } | ||
| 1481 | - return PyLong_FromLong(result); | ||
| 1465 | + RETURN_INT(PyUnicode_Contains(container, element)); | ||
| 1482 | 1466 | } | |
| 1483 | 1467 | ||
| 1484 | 1468 | /* Test PyUnicode_IsIdentifier() */ | |
| 1485 | 1469 | static PyObject * | |
| 1486 | 1470 | unicode_isidentifier(PyObject *self, PyObject *arg) | |
| 1487 | 1471 | { | |
| 1488 | - int result; | ||
| 1489 | - | ||
| 1490 | 1472 | NULLABLE(arg); | |
| 1491 | - result = PyUnicode_IsIdentifier(arg); | ||
| 1492 | - if (result == -1 && PyErr_Occurred()) { | ||
| 1493 | - return NULL; | ||
| 1494 | - } | ||
| 1495 | - return PyLong_FromLong(result); | ||
| 1473 | + RETURN_INT(PyUnicode_IsIdentifier(arg)); | ||
| 1496 | 1474 | } | |
| 1497 | 1475 | ||
| 1498 | 1476 | /* Test PyUnicode_CopyCharacters() */ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,25 @@ | |||
| 1 | + #define NULLABLE(x) do { \ | ||
| 2 | + if (x == Py_None) { \ | ||
| 3 | + x = NULL; \ | ||
| 4 | + } \ | ||
| 5 | + } while (0); | ||
| 6 | + | ||
| 7 | + #define RETURN_INT(value) do { \ | ||
| 8 | + int _ret = (value); \ | ||
| 9 | + if (_ret == -1) { \ | ||
| 10 | + assert(PyErr_Occurred()); \ | ||
| 11 | + return NULL; \ | ||
| 12 | + } \ | ||
| 13 | + assert(!PyErr_Occurred()); \ | ||
| 14 | + return PyLong_FromLong(_ret); \ | ||
| 15 | + } while (0) | ||
| 16 | + | ||
| 17 | + #define RETURN_SIZE(value) do { \ | ||
| 18 | + Py_ssize_t _ret = (value); \ | ||
| 19 | + if (_ret == -1) { \ | ||
| 20 | + assert(PyErr_Occurred()); \ | ||
| 21 | + return NULL; \ | ||
| 22 | + } \ | ||
| 23 | + assert(!PyErr_Occurred()); \ | ||
| 24 | + return PyLong_FromSsize_t(_ret); \ | ||
| 25 | + } while (0) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -43,16 +43,8 @@ | |||
| 43 | 43 | // Several parts of this module are broken out into files in _testcapi/. | |
| 44 | 44 | // Include definitions from there. | |
| 45 | 45 | #include "_testcapi/parts.h" | |
| 46 | + #include "_testcapi/util.h" | ||
| 46 | 47 | ||
| 47 | - #define NULLABLE(x) do { if (x == Py_None) x = NULL; } while (0); | ||
| 48 | - | ||
| 49 | - #define RETURN_INT(value) do { \ | ||
| 50 | - int _ret = (value); \ | ||
| 51 | - if (_ret == -1) { \ | ||
| 52 | - return NULL; \ | ||
| 53 | - } \ | ||
| 54 | - return PyLong_FromLong(_ret); \ | ||
| 55 | - } while (0) | ||
| 56 | 48 | ||
| 57 | 49 | // Forward declarations | |
| 58 | 50 | static struct PyModuleDef _testcapimodule; | |
@@ -1333,19 +1325,13 @@ static PyObject * | |||
| 1333 | 1325 | test_PyBuffer_SizeFromFormat(PyObject *self, PyObject *args) | |
| 1334 | 1326 | { | |
| 1335 | 1327 | const char *format; | |
| 1336 | - Py_ssize_t result; | ||
| 1337 | 1328 | ||
| 1338 | 1329 | if (!PyArg_ParseTuple(args, "s:test_PyBuffer_SizeFromFormat", | |
| 1339 | 1330 | &format)) { | |
| 1340 | 1331 | return NULL; | |
| 1341 | 1332 | } | |
| 1342 | 1333 | ||
| 1343 | - result = PyBuffer_SizeFromFormat(format); | ||
| 1344 | - if (result == -1) { | ||
| 1345 | - return NULL; | ||
| 1346 | - } | ||
| 1347 | - | ||
| 1348 | - return PyLong_FromSsize_t(result); | ||
| 1334 | + RETURN_SIZE(PyBuffer_SizeFromFormat(format)); | ||
| 1349 | 1335 | } | |
| 1350 | 1336 | ||
| 1351 | 1337 | /* Test that the fatal error from not having a current thread doesn't | |
| Back | FazBrowse Home | New Git URL |
0 commit comments