| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,6 +29,21 @@ Latest version of the header file: | |||
| 29 | 29 | Python 3.15 | |
| 30 | 30 | ----------- | |
| 31 | 31 | ||
| 32 | + .. c:function:: PyBytesWriter* PyBytesWriter_Create(Py_ssize_t size) | ||
| 33 | + .. c:function:: void* PyBytesWriter_GetData(PyBytesWriter *writer) | ||
| 34 | + .. c:function:: Py_ssize_t PyBytesWriter_GetSize(PyBytesWriter *writer) | ||
| 35 | + .. c:function:: PyObject* PyBytesWriter_FinishWithSize(PyBytesWriter *writer, Py_ssize_t size) | ||
| 36 | + .. c:function:: PyObject* PyBytesWriter_Finish(PyBytesWriter *writer) | ||
| 37 | + .. c:function:: PyObject* PyBytesWriter_FinishWithPointer(PyBytesWriter *writer, void *buf) | ||
| 38 | + .. c:function:: void PyBytesWriter_Discard(PyBytesWriter *writer) | ||
| 39 | + .. c:function:: int PyBytesWriter_Resize(PyBytesWriter *writer, Py_ssize_t size) | ||
| 40 | + .. c:function:: int PyBytesWriter_Grow(PyBytesWriter *writer, Py_ssize_t size) | ||
| 41 | + .. c:function:: void* PyBytesWriter_GrowAndUpdatePointer(PyBytesWriter *writer, Py_ssize_t size, void *buf) | ||
| 42 | + .. c:function:: int PyBytesWriter_WriteBytes(PyBytesWriter *writer, const void *bytes, Py_ssize_t size) | ||
| 43 | + .. c:function:: int PyBytesWriter_Format(PyBytesWriter *writer, const char *format, ...) | ||
| 44 | + | ||
| 45 | + See `PyBytesWriter documentation <https://docs.python.org/dev/c-api/bytes.html#pybyteswriter>`__. | ||
| 46 | + | ||
| 32 | 47 | .. c:function:: PyObject* PySys_GetAttr(const char *name) | |
| 33 | 48 | ||
| 34 | 49 | See `PySys_GetAttr() documentation <https://docs.python.org/dev/c-api/sys.html#c.PySys_GetAttr>`__. | |
@@ -45,20 +60,9 @@ Python 3.15 | |||
| 45 | 60 | ||
| 46 | 61 | See `PySys_GetOptionalAttrString() documentation <https://docs.python.org/dev/c-api/sys.html#c.PySys_GetOptionalAttrString>`__. | |
| 47 | 62 | ||
| 48 | - .. c:function:: PyBytesWriter* PyBytesWriter_Create(Py_ssize_t size) | ||
| 49 | - .. c:function:: void* PyBytesWriter_GetData(PyBytesWriter *writer) | ||
| 50 | - .. c:function:: Py_ssize_t PyBytesWriter_GetSize(PyBytesWriter *writer) | ||
| 51 | - .. c:function:: PyObject* PyBytesWriter_FinishWithSize(PyBytesWriter *writer, Py_ssize_t size) | ||
| 52 | - .. c:function:: PyObject* PyBytesWriter_Finish(PyBytesWriter *writer) | ||
| 53 | - .. c:function:: PyObject* PyBytesWriter_FinishWithPointer(PyBytesWriter *writer, void *buf) | ||
| 54 | - .. c:function:: void PyBytesWriter_Discard(PyBytesWriter *writer) | ||
| 55 | - .. c:function:: int PyBytesWriter_Resize(PyBytesWriter *writer, Py_ssize_t size) | ||
| 56 | - .. c:function:: int PyBytesWriter_Grow(PyBytesWriter *writer, Py_ssize_t size) | ||
| 57 | - .. c:function:: void* PyBytesWriter_GrowAndUpdatePointer(PyBytesWriter *writer, Py_ssize_t size, void *buf) | ||
| 58 | - .. c:function:: int PyBytesWriter_WriteBytes(PyBytesWriter *writer, const void *bytes, Py_ssize_t size) | ||
| 59 | - .. c:function:: int PyBytesWriter_Format(PyBytesWriter *writer, const char *format, ...) | ||
| 63 | + .. c:function:: PyObject* PyTuple_FromArray(PyObject *const *array, Py_ssize_t size) | ||
| 60 | 64 | ||
| 61 | - See `PyBytesWriter documentation <https://docs.python.org/dev/c-api/bytes.html#pybyteswriter>`__. | ||
| 65 | + See `PyTuple_FromArray() documentation <https://docs.python.org/dev/c-api/tuple.html#c.PyTuple_FromArray>`__. | ||
| 62 | 66 | ||
| 63 | 67 | ||
| 64 | 68 | Python 3.14 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,8 @@ | |||
| 1 | 1 | Changelog | |
| 2 | 2 | ========= | |
| 3 | 3 | ||
| 4 | - * 2025-11-18: Add PEP 782 functions: | ||
| 4 | + * 2025-10-14: Add ``PyTuple_FromArray()`` function. | ||
| 5 | + * 2025-09-18: Add PEP 782 functions: | ||
| 5 | 6 | ||
| 6 | 7 | * ``PyBytesWriter_Create()`` | |
| 7 | 8 | * ``PyBytesWriter_Discard()`` | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2553,6 +2553,23 @@ PyBytesWriter_Format(PyBytesWriter *writer, const char *format, ...) | |||
| 2553 | 2553 | #endif // PY_VERSION_HEX < 0x030F00A1 | |
| 2554 | 2554 | ||
| 2555 | 2555 | ||
| 2556 | + #if PY_VERSION_HEX < 0x030F00A1 | ||
| 2557 | + static inline PyObject* | ||
| 2558 | + PyTuple_FromArray(PyObject *const *array, Py_ssize_t size) | ||
| 2559 | + { | ||
| 2560 | + PyObject *tuple = PyTuple_New(size); | ||
| 2561 | + if (tuple == NULL) { | ||
| 2562 | + return NULL; | ||
| 2563 | + } | ||
| 2564 | + for (Py_ssize_t i=0; i < size; i++) { | ||
| 2565 | + PyObject *item = array[i]; | ||
| 2566 | + PyTuple_SET_ITEM(tuple, i, Py_NewRef(item)); | ||
| 2567 | + } | ||
| 2568 | + return tuple; | ||
| 2569 | + } | ||
| 2570 | + #endif | ||
| 2571 | + | ||
| 2572 | + | ||
| 2556 | 2573 | #ifdef __cplusplus | |
| 2557 | 2574 | } | |
| 2558 | 2575 | #endif | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2392,6 +2392,54 @@ test_byteswriter(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args)) | |||
| 2392 | 2392 | } | |
| 2393 | 2393 | ||
| 2394 | 2394 | ||
| 2395 | + static PyObject* | ||
| 2396 | + test_tuple_fromarray(void) | ||
| 2397 | + { | ||
| 2398 | + PyObject* array[] = { | ||
| 2399 | + PyLong_FromLong(1), | ||
| 2400 | + PyLong_FromLong(2), | ||
| 2401 | + PyLong_FromLong(3) | ||
| 2402 | + }; | ||
| 2403 | + PyObject *tuple = PyTuple_FromArray(array, 3); | ||
| 2404 | + if (tuple == NULL) { | ||
| 2405 | + goto error; | ||
| 2406 | + } | ||
| 2407 | + | ||
| 2408 | + assert(PyTuple_GET_SIZE(tuple) == 3); | ||
| 2409 | + assert(PyTuple_GET_ITEM(tuple, 0) == array[0]); | ||
| 2410 | + assert(PyTuple_GET_ITEM(tuple, 1) == array[1]); | ||
| 2411 | + assert(PyTuple_GET_ITEM(tuple, 2) == array[2]); | ||
| 2412 | + | ||
| 2413 | + Py_DECREF(tuple); | ||
| 2414 | + Py_DECREF(array[0]); | ||
| 2415 | + Py_DECREF(array[1]); | ||
| 2416 | + Py_DECREF(array[2]); | ||
| 2417 | + | ||
| 2418 | + // Test PyTuple_FromArray(NULL, 0) | ||
| 2419 | + tuple = PyTuple_FromArray(NULL, 0); | ||
| 2420 | + if (tuple == NULL) { | ||
| 2421 | + return NULL; | ||
| 2422 | + } | ||
| 2423 | + assert(PyTuple_GET_SIZE(tuple) == 0); | ||
| 2424 | + Py_DECREF(tuple); | ||
| 2425 | + | ||
| 2426 | + Py_RETURN_NONE; | ||
| 2427 | + | ||
| 2428 | + error: | ||
| 2429 | + Py_DECREF(array[0]); | ||
| 2430 | + Py_DECREF(array[1]); | ||
| 2431 | + Py_DECREF(array[2]); | ||
| 2432 | + return NULL; | ||
| 2433 | + } | ||
| 2434 | + | ||
| 2435 | + | ||
| 2436 | + static PyObject* | ||
| 2437 | + test_tuple(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args)) | ||
| 2438 | + { | ||
| 2439 | + return test_tuple_fromarray(); | ||
| 2440 | + } | ||
| 2441 | + | ||
| 2442 | + | ||
| 2395 | 2443 | static struct PyMethodDef methods[] = { | |
| 2396 | 2444 | {"test_object", test_object, METH_NOARGS, _Py_NULL}, | |
| 2397 | 2445 | {"test_py_is", test_py_is, METH_NOARGS, _Py_NULL}, | |
@@ -2446,6 +2494,7 @@ static struct PyMethodDef methods[] = { | |||
| 2446 | 2494 | {"test_sys", test_sys, METH_NOARGS, _Py_NULL}, | |
| 2447 | 2495 | {"test_uniquely_referenced", test_uniquely_referenced, METH_NOARGS, _Py_NULL}, | |
| 2448 | 2496 | {"test_byteswriter", test_byteswriter, METH_NOARGS, _Py_NULL}, | |
| 2497 | + {"test_tuple", test_tuple, METH_NOARGS, _Py_NULL}, | ||
| 2449 | 2498 | {_Py_NULL, _Py_NULL, 0, _Py_NULL} | |
| 2450 | 2499 | }; | |
| 2451 | 2500 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments