chunk_id stringlengths 36 36 | source stringclasses 35
values | source_url stringlengths 0 290 | upstream_license stringclasses 1
value | document_id stringlengths 36 36 | chunk_index int64 0 324k | retrieved_at stringclasses 2
values | chunker_version stringclasses 4
values | content_hash stringlengths 15 64 | content stringlengths 50 44.7k | namespace stringclasses 9
values | source_name stringclasses 35
values | raw_text stringlengths 50 44.7k | cleaned_text stringlengths 50 44.7k | tags stringclasses 49
values | collection_name stringclasses 11
values |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
5599cdee-a01a-4cce-b91b-598dc8cee535 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 813 | supabase-export-v2 | 01f176028a668031 | Standard guarantees). Maybe some day a sufficiently portable automatic garbage collector will be available for C. Until then, we'll have to live with reference counts.
While Python uses the traditional reference counting implementation, it also
offers a cycle detector that works to detect reference cycles. This allows
... | trusted_official_docs | CPython Docs | Standard guarantees). Maybe some day a sufficiently portable automatic garbage collector will be available for C. Until then, we'll have to live with reference counts.
While Python uses the traditional reference counting implementation, it also
offers a cycle detector that works to detect reference cycles. This allows
... | Standard guarantees). Maybe some day a sufficiently portable automatic garbage collector will be available for C. Until then, we'll have to live with reference counts.
While Python uses the traditional reference counting implementation, it also
offers a cycle detector that works to detect reference cycles. This allows
... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
568e5be3-8b5e-4279-8d8e-0a12313f0454 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 715 | supabase-export-v2 | 03400b4d9579fba0 | static PyModuleDef_Slot spam_module_slots[] = { {Py_mod_exec, spam_module_exec}, {0, NULL} };
static struct PyModuleDef spam_module = {
.m_base = PyModuleDef_HEAD_INIT,
.m_name = "spam",
.m_size = 0, // non-negative
.m_slots = spam_module_slots,
}; | trusted_official_docs | CPython Docs | static PyModuleDef_Slot spam_module_slots[] = { {Py_mod_exec, spam_module_exec}, {0, NULL} };
static struct PyModuleDef spam_module = {
.m_base = PyModuleDef_HEAD_INIT,
.m_name = "spam",
.m_size = 0, // non-negative
.m_slots = spam_module_slots,
}; | static PyModuleDef_Slot spam_module_slots[] = { {Py_mod_exec, spam_module_exec}, {0, NULL} };
static struct PyModuleDef spam_module = {
.m_base = PyModuleDef_HEAD_INIT,
.m_name = "spam",
.m_size = 0, // non-negative
.m_slots = spam_module_slots,
}; | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
58a01323-1c47-4337-a227-54ef29a63135 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 868 | supabase-export-v2 | e2456bf11528886d | takes care of importing the module and retrieving its C API pointers; client modules only have to call this macro before accessing the C API.
The exporting module is a modification of the :mod:`!spam` module from the
:ref:`tutorial <first-extension-module>`. The function :func:`!spam.system` does not call
the C library... | trusted_official_docs | CPython Docs | takes care of importing the module and retrieving its C API pointers; client modules only have to call this macro before accessing the C API.
The exporting module is a modification of the :mod:`!spam` module from the
:ref:`tutorial <first-extension-module>`. The function :func:`!spam.system` does not call
the C library... | takes care of importing the module and retrieving its C API pointers; client modules only have to call this macro before accessing the C API.
The exporting module is a modification of the :mod:`!spam` module from the
:ref:`tutorial <first-extension-module>`. The function :func:`!spam.system` does not call
the C library... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
58ebf926-2986-4160-9992-6872aea5ce0a | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 821 | supabase-export-v2 | a62e0d88332f5848 | where in seemingly correct code a borrowed reference can be used after the owner from which it was borrowed has in fact disposed of it.
A borrowed reference can be changed into an owned reference by calling
:c:func:`Py_INCREF`. This does not affect the status of the owner from which the
reference was borrowed --- it cr... | trusted_official_docs | CPython Docs | where in seemingly correct code a borrowed reference can be used after the owner from which it was borrowed has in fact disposed of it.
A borrowed reference can be changed into an owned reference by calling
:c:func:`Py_INCREF`. This does not affect the status of the owner from which the
reference was borrowed --- it cr... | where in seemingly correct code a borrowed reference can be used after the owner from which it was borrowed has in fact disposed of it.
A borrowed reference can be changed into an owned reference by calling
:c:func:`Py_INCREF`. This does not affect the status of the owner from which the
reference was borrowed --- it cr... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5aa108ad-ba31-44b9-b9fb-fa13dce70ed5 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 729 | supabase-export-v2 | 1e5732f69caff8b8 | the :file:`Modules/` subdirectory, but then you must first rebuild :file:`Makefile` there by running ':program:`make` Makefile'. (This is necessary each time you change the :file:`Setup` file.)
If your module requires additional libraries to link with, these can be listed
on the line in the configuration file as well, ... | trusted_official_docs | CPython Docs | the :file:`Modules/` subdirectory, but then you must first rebuild :file:`Makefile` there by running ':program:`make` Makefile'. (This is necessary each time you change the :file:`Setup` file.)
If your module requires additional libraries to link with, these can be listed
on the line in the configuration file as well, ... | the :file:`Modules/` subdirectory, but then you must first rebuild :file:`Makefile` there by running ':program:`make` Makefile'. (This is necessary each time you change the :file:`Setup` file.)
If your module requires additional libraries to link with, these can be listed
on the line in the configuration file as well, ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5af4ccfe-2533-462d-a605-655ff1b2d703 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 750 | supabase-export-v2 | 3764b51bad0de280 | before the error check! Also note that strictly speaking this code is not complete: :c:func:`Py_BuildValue` may run out of memory, and this should be checked.
You may also call a function with keyword arguments by using
:c:func:`PyObject_Call`, which supports arguments and keyword arguments. As in
the above example, we... | trusted_official_docs | CPython Docs | before the error check! Also note that strictly speaking this code is not complete: :c:func:`Py_BuildValue` may run out of memory, and this should be checked.
You may also call a function with keyword arguments by using
:c:func:`PyObject_Call`, which supports arguments and keyword arguments. As in
the above example, we... | before the error check! Also note that strictly speaking this code is not complete: :c:func:`Py_BuildValue` may run out of memory, and this should be checked.
You may also call a function with keyword arguments by using
:c:func:`PyObject_Call`, which supports arguments and keyword arguments. As in
the above example, we... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5c397c1d-f8f7-4cbb-813b-05b33453a665 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 761 | supabase-export-v2 | 7898ec3d07e30123 | const char *command; if (!PyArg_ParseTuple(args, "s", &command)) { return NULL; }
If an error is detected in the argument list, :c:func:`!PyArg_ParseTuple`
returns ``NULL`` (the error indicator for functions returning object pointers);
your function may return ``NULL``, relying on the exception set by
:c:func:`PyArg_Pa... | trusted_official_docs | CPython Docs | const char *command; if (!PyArg_ParseTuple(args, "s", &command)) { return NULL; }
If an error is detected in the argument list, :c:func:`!PyArg_ParseTuple`
returns ``NULL`` (the error indicator for functions returning object pointers);
your function may return ``NULL``, relying on the exception set by
:c:func:`PyArg_Pa... | const char *command; if (!PyArg_ParseTuple(args, "s", &command)) { return NULL; }
If an error is detected in the argument list, :c:func:`!PyArg_ParseTuple`
returns ``NULL`` (the error indicator for functions returning object pointers);
your function may return ``NULL``, relying on the exception set by
:c:func:`PyArg_Pa... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5c64653c-9f27-4dc8-b98d-9fe6e44e8624 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 744 | supabase-export-v2 | 3581dbaa6753f43b | its arguments. In the example a new tuple was created to serve as the argument list, which is :c:func:`Py_DECREF`\ -ed immediately after the :c:func:`PyObject_CallObject` call.
The return value of :c:func:`PyObject_CallObject` is "new": either it is a brand
new object, or it is an existing object whose reference count ... | trusted_official_docs | CPython Docs | its arguments. In the example a new tuple was created to serve as the argument list, which is :c:func:`Py_DECREF`\ -ed immediately after the :c:func:`PyObject_CallObject` call.
The return value of :c:func:`PyObject_CallObject` is "new": either it is a brand
new object, or it is an existing object whose reference count ... | its arguments. In the example a new tuple was created to serve as the argument list, which is :c:func:`Py_DECREF`\ -ed immediately after the :c:func:`PyObject_CallObject` call.
The return value of :c:func:`PyObject_CallObject` is "new": either it is a brand
new object, or it is an existing object whose reference count ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5dbcce83-66f4-478b-b83e-cc24307f83ea | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 825 | supabase-export-v2 | db8e2a9030f76e99 | is passed into or out of a function, it is part of the function's interface specification whether ownership is transferred with the reference or not.
Most functions that return a reference to an object pass on ownership with the
reference. In particular, all functions whose function it is to create a new
object, such a... | trusted_official_docs | CPython Docs | is passed into or out of a function, it is part of the function's interface specification whether ownership is transferred with the reference or not.
Most functions that return a reference to an object pass on ownership with the
reference. In particular, all functions whose function it is to create a new
object, such a... | is passed into or out of a function, it is part of the function's interface specification whether ownership is transferred with the reference or not.
Most functions that return a reference to an object pass on ownership with the
reference. In particular, all functions whose function it is to create a new
object, such a... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
61353a82-538f-4888-b9e9-7c507e1ea378 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 763 | supabase-export-v2 | e4106933d52b0e96 | passed to the call: if you make mistakes there, your code will probably crash or at least overwrite random bits in memory. So be careful!
Note that any Python object references which are provided to the caller are
*borrowed* references; do not decrement their reference count! | trusted_official_docs | CPython Docs | passed to the call: if you make mistakes there, your code will probably crash or at least overwrite random bits in memory. So be careful!
Note that any Python object references which are provided to the caller are
*borrowed* references; do not decrement their reference count! | passed to the call: if you make mistakes there, your code will probably crash or at least overwrite random bits in memory. So be careful!
Note that any Python object references which are provided to the caller are
*borrowed* references; do not decrement their reference count! | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
66fa6624-0749-4821-b882-fae56fa13d58 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 885 | supabase-export-v2 | fce73d10dd0a6f09 | Note that ``PySpam_API`` is declared ``static``; otherwise the pointer array would disappear when :c:func:`!PyInit_spam` terminates!
The bulk of the work is in the header file :file:`spammodule.h`, which looks
like this:: | trusted_official_docs | CPython Docs | Note that ``PySpam_API`` is declared ``static``; otherwise the pointer array would disappear when :c:func:`!PyInit_spam` terminates!
The bulk of the work is in the header file :file:`spammodule.h`, which looks
like this:: | Note that ``PySpam_API`` is declared ``static``; otherwise the pointer array would disappear when :c:func:`!PyInit_spam` terminates!
The bulk of the work is in the header file :file:`spammodule.h`, which looks
like this:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6790778c-025c-4507-ba89-d6b2a35bb3e5 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 837 | supabase-export-v2 | 02f503e3a4ad22f7 | first borrows a reference to ``list[0]``, then replaces ``list[1]`` with the value ``0``, and finally prints the borrowed reference. Looks harmless, right? But it's not!
Let's follow the control flow into :c:func:`PyList_SetItem`. The list owns
references to all its items, so when item 1 is replaced, it has to dispose ... | trusted_official_docs | CPython Docs | first borrows a reference to ``list[0]``, then replaces ``list[1]`` with the value ``0``, and finally prints the borrowed reference. Looks harmless, right? But it's not!
Let's follow the control flow into :c:func:`PyList_SetItem`. The list owns
references to all its items, so when item 1 is replaced, it has to dispose ... | first borrows a reference to ``list[0]``, then replaces ``list[1]`` with the value ``0``, and finally prints the borrowed reference. Looks harmless, right? But it's not!
Let's follow the control flow into :c:func:`PyList_SetItem`. The list owns
references to all its items, so when item 1 is replaced, it has to dispose ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
67922cab-9ab4-48b1-a056-c7849e343d75 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 797 | supabase-export-v2 | efb784becc7d350a | Py_RETURN_NONE; }
static PyMethodDef keywdarg_methods[] = {
/* The cast of the function is necessary since PyCFunction values
* only take two PyObject* parameters, and keywdarg_parrot() takes
* three. */
{"parrot", (PyCFunction)(void(*)(void))keywdarg_parrot, METH_VARARGS | METH_KEYWORDS,
"Print a lovely skit to s... | trusted_official_docs | CPython Docs | Py_RETURN_NONE; }
static PyMethodDef keywdarg_methods[] = {
/* The cast of the function is necessary since PyCFunction values
* only take two PyObject* parameters, and keywdarg_parrot() takes
* three. */
{"parrot", (PyCFunction)(void(*)(void))keywdarg_parrot, METH_VARARGS | METH_KEYWORDS,
"Print a lovely skit to s... | Py_RETURN_NONE; }
static PyMethodDef keywdarg_methods[] = {
/* The cast of the function is necessary since PyCFunction values
* only take two PyObject* parameters, and keywdarg_parrot() takes
* three. */
{"parrot", (PyCFunction)(void(*)(void))keywdarg_parrot, METH_VARARGS | METH_KEYWORDS,
"Print a lovely skit to s... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
67c5ac44-8c85-4242-b301-da63524118fd | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 737 | supabase-export-v2 | 1b417dfd0ae120bb | static PyObject * my_set_callback(PyObject *dummy, PyObject *args) { PyObject *result = NULL; PyObject *temp;
if (PyArg_ParseTuple(args, "O:set_callback", &temp)) {
if (!PyCallable_Check(temp)) {
PyErr_SetString(PyExc_TypeError, "parameter must be callable");
return NULL;
}
Py_XINCREF(temp); /* Add a reference to ... | trusted_official_docs | CPython Docs | static PyObject * my_set_callback(PyObject *dummy, PyObject *args) { PyObject *result = NULL; PyObject *temp;
if (PyArg_ParseTuple(args, "O:set_callback", &temp)) {
if (!PyCallable_Check(temp)) {
PyErr_SetString(PyExc_TypeError, "parameter must be callable");
return NULL;
}
Py_XINCREF(temp); /* Add a reference to ... | static PyObject * my_set_callback(PyObject *dummy, PyObject *args) { PyObject *result = NULL; PyObject *temp;
if (PyArg_ParseTuple(args, "O:set_callback", &temp)) {
if (!PyCallable_Check(temp)) {
PyErr_SetString(PyExc_TypeError, "parameter must be callable");
return NULL;
}
Py_XINCREF(temp); /* Add a reference to ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
692e6f4c-75f4-412b-a730-c8fc15a7d232 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 895 | supabase-export-v2 | 432dfcea769e2a24 | #define PySpam_System \ (*(PySpam_System_RETURN (*)PySpam_System_PROTO) PySpam_API[PySpam_System_NUM])
/* Return -1 on error, 0 on success. * PyCapsule_Import will set an exception if there's an error. */
static int
import_spam(void)
{
PySpam_API = (void **)PyCapsule_Import("spam._C_API", 0);
return (PySpam_API !=... | trusted_official_docs | CPython Docs | #define PySpam_System \ (*(PySpam_System_RETURN (*)PySpam_System_PROTO) PySpam_API[PySpam_System_NUM])
/* Return -1 on error, 0 on success. * PyCapsule_Import will set an exception if there's an error. */
static int
import_spam(void)
{
PySpam_API = (void **)PyCapsule_Import("spam._C_API", 0);
return (PySpam_API !=... | #define PySpam_System \ (*(PySpam_System_RETURN (*)PySpam_System_PROTO) PySpam_API[PySpam_System_NUM])
/* Return -1 on error, 0 on success. * PyCapsule_Import will set an exception if there's an error. */
static int
import_spam(void)
{
PySpam_API = (void **)PyCapsule_Import("spam._C_API", 0);
return (PySpam_API !=... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
693afba9-74bd-4947-9859-ad5d64d86659 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 838 | supabase-export-v2 | 5d68d68e0ad81b24 | deallocation, :c:member:`~PyTypeObject.tp_dealloc` calls :c:member:`~PyTypeObject.tp_finalize`, which is mapped to the :meth:`!__del__` method for class instances (see :pep:`442`). This entire sequence happens synchronously within the :c:func:`PyList_SetItem` call.
Since it is written in Python, the :meth:`!__del__` me... | trusted_official_docs | CPython Docs | deallocation, :c:member:`~PyTypeObject.tp_dealloc` calls :c:member:`~PyTypeObject.tp_finalize`, which is mapped to the :meth:`!__del__` method for class instances (see :pep:`442`). This entire sequence happens synchronously within the :c:func:`PyList_SetItem` call.
Since it is written in Python, the :meth:`!__del__` me... | deallocation, :c:member:`~PyTypeObject.tp_dealloc` calls :c:member:`~PyTypeObject.tp_finalize`, which is mapped to the :meth:`!__del__` method for class instances (see :pep:`442`). This entire sequence happens synchronously within the :c:func:`PyList_SetItem` call.
Since it is written in Python, the :meth:`!__del__` me... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6b6ba22d-869d-4da3-b46e-52dacebc1b72 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 869 | supabase-export-v2 | c2b2b01b3f1fa3f6 | of course do something more complicated in reality (such as adding "spam" to every command). This function :c:func:`!PySpam_System` is also exported to other extension modules.
The function :c:func:`!PySpam_System` is a plain C function, declared
``static`` like everything else:: | trusted_official_docs | CPython Docs | of course do something more complicated in reality (such as adding "spam" to every command). This function :c:func:`!PySpam_System` is also exported to other extension modules.
The function :c:func:`!PySpam_System` is a plain C function, declared
``static`` like everything else:: | of course do something more complicated in reality (such as adding "spam" to every command). This function :c:func:`!PySpam_System` is also exported to other extension modules.
The function :c:func:`!PySpam_System` is a plain C function, declared
``static`` like everything else:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6bb4df96-1fe3-4e2d-a8f1-563eddb52c37 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 824 | supabase-export-v2 | 835c0e2f903c7f7c | Ownership Rules ---------------
Whenever an object reference is passed into or out of a function, it is part of
the function's interface specification whether ownership is transferred with the
reference or not. | trusted_official_docs | CPython Docs | Ownership Rules ---------------
Whenever an object reference is passed into or out of a function, it is part of
the function's interface specification whether ownership is transferred with the
reference or not. | Ownership Rules ---------------
Whenever an object reference is passed into or out of a function, it is part of
the function's interface specification whether ownership is transferred with the
reference or not. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6c4aee27-0779-48a7-9494-dbffa50acb8f | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 900 | supabase-export-v2 | 33599d41e5fc7d50 | static int client_module_exec(PyObject *m) { if (import_spam() < 0) { return -1; } /* additional initialization can happen here */ return 0; }
The main disadvantage of this approach is that the file :file:`spammodule.h` is
rather complicated. However, the basic structure is the same for each function
that is exported, ... | trusted_official_docs | CPython Docs | static int client_module_exec(PyObject *m) { if (import_spam() < 0) { return -1; } /* additional initialization can happen here */ return 0; }
The main disadvantage of this approach is that the file :file:`spammodule.h` is
rather complicated. However, the basic structure is the same for each function
that is exported, ... | static int client_module_exec(PyObject *m) { if (import_spam() < 0) { return -1; } /* additional initialization can happen here */ return 0; }
The main disadvantage of this approach is that the file :file:`spammodule.h` is
rather complicated. However, the basic structure is the same for each function
that is exported, ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6da37a04-bd29-4558-a3ca-61dc44a2c8c8 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 697 | supabase-export-v2 | cbc2c55c2ed879ab | :c:func:`PyErr_SetObject`, which takes two object arguments, the exception and its associated value. You don't need to :c:func:`Py_INCREF` the objects passed to any of these functions.
You can test non-destructively whether an exception has been set with
:c:func:`PyErr_Occurred`. This returns the current exception obje... | trusted_official_docs | CPython Docs | :c:func:`PyErr_SetObject`, which takes two object arguments, the exception and its associated value. You don't need to :c:func:`Py_INCREF` the objects passed to any of these functions.
You can test non-destructively whether an exception has been set with
:c:func:`PyErr_Occurred`. This returns the current exception obje... | :c:func:`PyErr_SetObject`, which takes two object arguments, the exception and its associated value. You don't need to :c:func:`Py_INCREF` the objects passed to any of these functions.
You can test non-destructively whether an exception has been set with
:c:func:`PyErr_Occurred`. This returns the current exception obje... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6e19e3fa-cdcf-44c5-90d8-fa4a5a08aa8b | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 827 | supabase-export-v2 | d7a4ca7e4f4b0f2e | however, since a few common routines are exceptions: :c:func:`PyTuple_GetItem`, :c:func:`PyList_GetItem`, :c:func:`PyDict_GetItem`, and :c:func:`PyDict_GetItemString` all return references that you borrow from the tuple, list or dictionary.
The function :c:func:`PyImport_AddModule` also returns a borrowed reference, ev... | trusted_official_docs | CPython Docs | however, since a few common routines are exceptions: :c:func:`PyTuple_GetItem`, :c:func:`PyList_GetItem`, :c:func:`PyDict_GetItem`, and :c:func:`PyDict_GetItemString` all return references that you borrow from the tuple, list or dictionary.
The function :c:func:`PyImport_AddModule` also returns a borrowed reference, ev... | however, since a few common routines are exceptions: :c:func:`PyTuple_GetItem`, :c:func:`PyList_GetItem`, :c:func:`PyDict_GetItem`, and :c:func:`PyDict_GetItemString` all return references that you borrow from the tuple, list or dictionary.
The function :c:func:`PyImport_AddModule` also returns a borrowed reference, ev... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
7370a18f-e561-4c29-9235-db1d1a4b7b2c | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 844 | supabase-export-v2 | 76eaa28c3a6a8f55 | let other threads use the processor while waiting for the I/O to complete. Obviously, the following function has the same problem as the previous one::
void
bug(PyObject *list)
{
PyObject *item = PyList_GetItem(list, 0);
Py_BEGIN_ALLOW_THREADS
...some blocking I/O call... Py_END_ALLOW_THREADS
PyObject_Print(item,... | trusted_official_docs | CPython Docs | let other threads use the processor while waiting for the I/O to complete. Obviously, the following function has the same problem as the previous one::
void
bug(PyObject *list)
{
PyObject *item = PyList_GetItem(list, 0);
Py_BEGIN_ALLOW_THREADS
...some blocking I/O call... Py_END_ALLOW_THREADS
PyObject_Print(item,... | let other threads use the processor while waiting for the I/O to complete. Obviously, the following function has the same problem as the previous one::
void
bug(PyObject *list)
{
PyObject *item = PyList_GetItem(list, 0);
Py_BEGIN_ALLOW_THREADS
...some blocking I/O call... Py_END_ALLOW_THREADS
PyObject_Print(item,... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
75821bc2-7ab2-4c3d-8ab3-d83f75378d79 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 693 | supabase-export-v2 | f5a28dc5c0b7efcb | Errors and Exceptions =====================
An important convention throughout the Python interpreter is the following: when
a function fails, it should set an exception condition and return an error value
(usually ``-1`` or a ``NULL`` pointer). Exception information is stored in
three members of the interpreter's thre... | trusted_official_docs | CPython Docs | Errors and Exceptions =====================
An important convention throughout the Python interpreter is the following: when
a function fails, it should set an exception condition and return an error value
(usually ``-1`` or a ``NULL`` pointer). Exception information is stored in
three members of the interpreter's thre... | Errors and Exceptions =====================
An important convention throughout the Python interpreter is the following: when
a function fails, it should set an exception condition and return an error value
(usually ``-1`` or a ``NULL`` pointer). Exception information is stored in
three members of the interpreter's thre... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
765ebdcb-7321-41e2-b131-d6467867f1eb | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 899 | supabase-export-v2 | 3c9079856326d0b1 | must do in order to have access to the function :c:func:`!PySpam_System` is to call the function (or rather macro) :c:func:`!import_spam` in its :c:data:`mod_exec <Py_mod_exec>` function::
static int
client_module_exec(PyObject *m)
{
if (import_spam() < 0) {
return -1;
}
/* additional initialization can happen he... | trusted_official_docs | CPython Docs | must do in order to have access to the function :c:func:`!PySpam_System` is to call the function (or rather macro) :c:func:`!import_spam` in its :c:data:`mod_exec <Py_mod_exec>` function::
static int
client_module_exec(PyObject *m)
{
if (import_spam() < 0) {
return -1;
}
/* additional initialization can happen he... | must do in order to have access to the function :c:func:`!PySpam_System` is to call the function (or rather macro) :c:func:`!import_spam` in its :c:data:`mod_exec <Py_mod_exec>` function::
static int
client_module_exec(PyObject *m)
{
if (import_spam() < 0) {
return -1;
}
/* additional initialization can happen he... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
7d343e7e-7702-4fde-928f-723003ea9cfd | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 830 | supabase-export-v2 | c4183858fbc27595 | function returns. Only when such a borrowed reference must be stored or passed on, it must be turned into an owned reference by calling :c:func:`Py_INCREF`.
The object reference returned from a C function that is called from Python must
be an owned reference --- ownership is transferred from the function to its
caller. | trusted_official_docs | CPython Docs | function returns. Only when such a borrowed reference must be stored or passed on, it must be turned into an owned reference by calling :c:func:`Py_INCREF`.
The object reference returned from a C function that is called from Python must
be an owned reference --- ownership is transferred from the function to its
caller. | function returns. Only when such a borrowed reference must be stored or passed on, it must be turned into an owned reference by calling :c:func:`Py_INCREF`.
The object reference returned from a C function that is called from Python must
be an owned reference --- ownership is transferred from the function to its
caller. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
7eb15737-220c-454d-96c9-7d474619422e | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 849 | supabase-export-v2 | caf08f2e64fc5694 | The macros :c:func:`Py_INCREF` and :c:func:`Py_DECREF` do not check for ``NULL`` pointers --- however, their variants :c:func:`Py_XINCREF` and :c:func:`Py_XDECREF` do.
The macros for checking for a particular object type (``Pytype_Check()``) don't
check for ``NULL`` pointers --- again, there is much code that calls sev... | trusted_official_docs | CPython Docs | The macros :c:func:`Py_INCREF` and :c:func:`Py_DECREF` do not check for ``NULL`` pointers --- however, their variants :c:func:`Py_XINCREF` and :c:func:`Py_XDECREF` do.
The macros for checking for a particular object type (``Pytype_Check()``) don't
check for ``NULL`` pointers --- again, there is much code that calls sev... | The macros :c:func:`Py_INCREF` and :c:func:`Py_DECREF` do not check for ``NULL`` pointers --- however, their variants :c:func:`Py_XINCREF` and :c:func:`Py_XDECREF` do.
The macros for checking for a particular object type (``Pytype_Check()``) don't
check for ``NULL`` pointers --- again, there is much code that calls sev... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
820ccfd3-b09f-4fba-9cef-39323414040c | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 782 | supabase-export-v2 | a8244e34a40104e0 | <keyword argument>`, use the :c:data:`METH_KEYWORDS` flag in combination with :c:data:`METH_VARARGS`. (:c:data:`!METH_KEYWORDS` can also be used with other flags; see its documentation for the allowed combinations.)
In this case, the C function should accept a third ``PyObject *`` parameter
which will be a dictionary o... | trusted_official_docs | CPython Docs | <keyword argument>`, use the :c:data:`METH_KEYWORDS` flag in combination with :c:data:`METH_VARARGS`. (:c:data:`!METH_KEYWORDS` can also be used with other flags; see its documentation for the allowed combinations.)
In this case, the C function should accept a third ``PyObject *`` parameter
which will be a dictionary o... | <keyword argument>`, use the :c:data:`METH_KEYWORDS` flag in combination with :c:data:`METH_VARARGS`. (:c:data:`!METH_KEYWORDS` can also be used with other flags; see its documentation for the allowed combinations.)
In this case, the C function should accept a third ``PyObject *`` parameter
which will be a dictionary o... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8e7ced38-8fcc-413b-88d1-15512f247fbe | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 803 | supabase-export-v2 | 4cb1d1a75d52eeac | function, not output) must not be pointers, just values. It returns a new Python object, suitable for returning from a C function called from Python.
One difference with :c:func:`PyArg_ParseTuple`: while the latter requires its
first argument to be a tuple (since Python argument lists are always represented
as tuples i... | trusted_official_docs | CPython Docs | function, not output) must not be pointers, just values. It returns a new Python object, suitable for returning from a C function called from Python.
One difference with :c:func:`PyArg_ParseTuple`: while the latter requires its
first argument to be a tuple (since Python argument lists are always represented
as tuples i... | function, not output) must not be pointers, just values. It returns a new Python object, suitable for returning from a C function called from Python.
One difference with :c:func:`PyArg_ParseTuple`: while the latter requires its
first argument to be a tuple (since Python argument lists are always represented
as tuples i... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
91aa9c45-2961-45a1-847e-c60a35aa1969 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 836 | supabase-export-v2 | c64329412687fd40 | PyList_SetItem(list, 1, PyLong_FromLong(0L)); PyObject_Print(item, stdout, 0); /* BUG! */ }
This function first borrows a reference to ``list[0]``, then replaces
``list[1]`` with the value ``0``, and finally prints the borrowed reference. Looks harmless, right? But it's not! | trusted_official_docs | CPython Docs | PyList_SetItem(list, 1, PyLong_FromLong(0L)); PyObject_Print(item, stdout, 0); /* BUG! */ }
This function first borrows a reference to ``list[0]``, then replaces
``list[1]`` with the value ``0``, and finally prints the borrowed reference. Looks harmless, right? But it's not! | PyList_SetItem(list, 1, PyLong_FromLong(0L)); PyObject_Print(item, stdout, 0); /* BUG! */ }
This function first borrows a reference to ``list[0]``, then replaces
``list[1]`` with the value ``0``, and finally prints the borrowed reference. Looks harmless, right? But it's not! | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9224fdf1-0aed-40ea-9d9a-6f4580102fa5 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 802 | supabase-export-v2 | 65cbfb75966e4eaf | PyObject *Py_BuildValue(const char *format, ...);
It recognizes a set of format units similar to the ones recognized by
:c:func:`PyArg_ParseTuple`, but the arguments (which are input to the function,
not output) must not be pointers, just values. It returns a new Python object,
suitable for returning from a C function ... | trusted_official_docs | CPython Docs | PyObject *Py_BuildValue(const char *format, ...);
It recognizes a set of format units similar to the ones recognized by
:c:func:`PyArg_ParseTuple`, but the arguments (which are input to the function,
not output) must not be pointers, just values. It returns a new Python object,
suitable for returning from a C function ... | PyObject *Py_BuildValue(const char *format, ...);
It recognizes a set of format units similar to the ones recognized by
:c:func:`PyArg_ParseTuple`, but the arguments (which are input to the function,
not output) must not be pointers, just values. It returns a new Python object,
suitable for returning from a C function ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
93246357-a026-4a5b-a62b-5b020d5dcd51 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 712 | supabase-export-v2 | 6cf97af4e1b666e3 | static PyObject *SpamError = NULL;
static int
spam_module_exec(PyObject *m)
{
if (SpamError != NULL) {
PyErr_SetString(PyExc_ImportError,
"cannot initialize spam module more than once");
return -1;
}
SpamError = PyErr_NewException("spam.error", NULL, NULL);
if (PyModule_AddObjectRef(m, "SpamError", SpamError) ... | trusted_official_docs | CPython Docs | static PyObject *SpamError = NULL;
static int
spam_module_exec(PyObject *m)
{
if (SpamError != NULL) {
PyErr_SetString(PyExc_ImportError,
"cannot initialize spam module more than once");
return -1;
}
SpamError = PyErr_NewException("spam.error", NULL, NULL);
if (PyModule_AddObjectRef(m, "SpamError", SpamError) ... | static PyObject *SpamError = NULL;
static int
spam_module_exec(PyObject *m)
{
if (SpamError != NULL) {
PyErr_SetString(PyExc_ImportError,
"cannot initialize spam module more than once");
return -1;
}
SpamError = PyErr_NewException("spam.error", NULL, NULL);
if (PyModule_AddObjectRef(m, "SpamError", SpamError) ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
93c9f702-3c77-4e58-884c-dcd86cf0bb51 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 792 | supabase-export-v2 | d908f503ce3df3ed | #define PY_SSIZE_T_CLEAN #include <Python.h>
static PyObject *
keywdarg_parrot(PyObject *self, PyObject *args, PyObject *keywds)
{
int voltage;
const char *state = "a stiff";
const char *action = "voom";
const char *type = "Norwegian Blue"; | trusted_official_docs | CPython Docs | #define PY_SSIZE_T_CLEAN #include <Python.h>
static PyObject *
keywdarg_parrot(PyObject *self, PyObject *args, PyObject *keywds)
{
int voltage;
const char *state = "a stiff";
const char *action = "voom";
const char *type = "Norwegian Blue"; | #define PY_SSIZE_T_CLEAN #include <Python.h>
static PyObject *
keywdarg_parrot(PyObject *self, PyObject *args, PyObject *keywds)
{
int voltage;
const char *state = "a stiff";
const char *action = "voom";
const char *type = "Norwegian Blue"; | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
94a4ad31-3145-400a-bb4f-df2e8e05cc5e | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 832 | supabase-export-v2 | e874d38185b7c365 | Thin Ice --------
There are a few situations where seemingly harmless use of a borrowed reference
can lead to problems. These all have to do with implicit invocations of the
interpreter, which can cause the owner of a reference to dispose of it. | trusted_official_docs | CPython Docs | Thin Ice --------
There are a few situations where seemingly harmless use of a borrowed reference
can lead to problems. These all have to do with implicit invocations of the
interpreter, which can cause the owner of a reference to dispose of it. | Thin Ice --------
There are a few situations where seemingly harmless use of a borrowed reference
can lead to problems. These all have to do with implicit invocations of the
interpreter, which can cause the owner of a reference to dispose of it. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
94b6c7a7-b078-4485-9ff0-1c988ded7468 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 839 | supabase-export-v2 | c2111251af53ff06 | effect of ``del list[0]``, and assuming this was the last reference to that object, it would free the memory associated with it, thereby invalidating ``item``.
The solution, once you know the source of the problem, is easy: temporarily
increment the reference count. The correct version of the function reads:: | trusted_official_docs | CPython Docs | effect of ``del list[0]``, and assuming this was the last reference to that object, it would free the memory associated with it, thereby invalidating ``item``.
The solution, once you know the source of the problem, is easy: temporarily
increment the reference count. The correct version of the function reads:: | effect of ``del list[0]``, and assuming this was the last reference to that object, it would free the memory associated with it, thereby invalidating ``item``.
The solution, once you know the source of the problem, is easy: temporarily
increment the reference count. The correct version of the function reads:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
95b7723a-6c90-4330-b59b-939e695052de | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 858 | supabase-export-v2 | cd38fe0be540055d | Providing a C API for an Extension Module =========================================
Many extension modules just provide new functions and types to be used from
Python, but sometimes the code in an extension module can be useful for other
extension modules. For example, an extension module could implement a type
"collec... | trusted_official_docs | CPython Docs | Providing a C API for an Extension Module =========================================
Many extension modules just provide new functions and types to be used from
Python, but sometimes the code in an extension module can be useful for other
extension modules. For example, an extension module could implement a type
"collec... | Providing a C API for an Extension Module =========================================
Many extension modules just provide new functions and types to be used from
Python, but sometimes the code in an extension module can be useful for other
extension modules. For example, an extension module could implement a type
"collec... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
99231479-8fbd-4e16-a4f9-15b944581355 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 848 | supabase-export-v2 | c3f76b04d827bd0b | at the "source:" when a pointer that may be ``NULL`` is received, for example, from :c:func:`malloc` or from a function that may raise an exception.
The macros :c:func:`Py_INCREF` and :c:func:`Py_DECREF` do not check for ``NULL``
pointers --- however, their variants :c:func:`Py_XINCREF` and :c:func:`Py_XDECREF`
do. | trusted_official_docs | CPython Docs | at the "source:" when a pointer that may be ``NULL`` is received, for example, from :c:func:`malloc` or from a function that may raise an exception.
The macros :c:func:`Py_INCREF` and :c:func:`Py_DECREF` do not check for ``NULL``
pointers --- however, their variants :c:func:`Py_XINCREF` and :c:func:`Py_XDECREF`
do. | at the "source:" when a pointer that may be ``NULL`` is received, for example, from :c:func:`malloc` or from a function that may raise an exception.
The macros :c:func:`Py_INCREF` and :c:func:`Py_DECREF` do not check for ``NULL``
pointers --- however, their variants :c:func:`Py_XINCREF` and :c:func:`Py_XDECREF`
do. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9abeac93-ef1c-40b7-bdd3-4dd16260358d | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 746 | supabase-export-v2 | 4ec8623eafcbcc08 | the calling Python code can handle the exception. If this is not possible or desirable, the exception should be cleared by calling :c:func:`PyErr_Clear`. For example::
if (result == NULL)
return NULL; /* Pass error back */
...use result... Py_DECREF(result); | trusted_official_docs | CPython Docs | the calling Python code can handle the exception. If this is not possible or desirable, the exception should be cleared by calling :c:func:`PyErr_Clear`. For example::
if (result == NULL)
return NULL; /* Pass error back */
...use result... Py_DECREF(result); | the calling Python code can handle the exception. If this is not possible or desirable, the exception should be cleared by calling :c:func:`PyErr_Clear`. For example::
if (result == NULL)
return NULL; /* Pass error back */
...use result... Py_DECREF(result); | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9e69c10e-9cda-454c-8812-722d7849bba8 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 756 | supabase-export-v2 | 0297ad47063d0ccf | you want more, you can use :c:data:`METH_VARARGS` instead. With this flag, the C function will receive a :py:class:`tuple` of arguments instead of a single object.
For unpacking the tuple, CPython provides the :c:func:`PyArg_ParseTuple`
function, declared as follows:: | trusted_official_docs | CPython Docs | you want more, you can use :c:data:`METH_VARARGS` instead. With this flag, the C function will receive a :py:class:`tuple` of arguments instead of a single object.
For unpacking the tuple, CPython provides the :c:func:`PyArg_ParseTuple`
function, declared as follows:: | you want more, you can use :c:data:`METH_VARARGS` instead. With this flag, the C function will receive a :py:class:`tuple` of arguments instead of a single object.
For unpacking the tuple, CPython provides the :c:func:`PyArg_ParseTuple`
function, declared as follows:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9f7e6559-effe-4de0-a72b-5fce5bb5968f | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 705 | supabase-export-v2 | f6ebf7a9c96faaf3 | function usually raises :c:data:`PyExc_TypeError`. If you have an argument whose value must be in a particular range or must satisfy other conditions, :c:data:`PyExc_ValueError` is appropriate.
You can also define a new exception that is unique to your module. The simplest way to do this is to declare a static global o... | trusted_official_docs | CPython Docs | function usually raises :c:data:`PyExc_TypeError`. If you have an argument whose value must be in a particular range or must satisfy other conditions, :c:data:`PyExc_ValueError` is appropriate.
You can also define a new exception that is unique to your module. The simplest way to do this is to declare a static global o... | function usually raises :c:data:`PyExc_TypeError`. If you have an argument whose value must be in a particular range or must satisfy other conditions, :c:data:`PyExc_ValueError` is appropriate.
You can also define a new exception that is unique to your module. The simplest way to do this is to declare a static global o... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a1a74f01-22cf-4700-96b7-04966f6c844e | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 723 | supabase-export-v2 | 251195c33e3b17b4 | static PyObject * spam_system(PyObject *self, PyObject *args) { const char *command; int sts;
if (!PyArg_ParseTuple(args, "s", &command))
return NULL;
sts = system(command);
if (sts < 0) {
PyErr_SetString(SpamError, "System command failed");
return NULL;
}
return PyLong_FromLong(sts);
} | trusted_official_docs | CPython Docs | static PyObject * spam_system(PyObject *self, PyObject *args) { const char *command; int sts;
if (!PyArg_ParseTuple(args, "s", &command))
return NULL;
sts = system(command);
if (sts < 0) {
PyErr_SetString(SpamError, "System command failed");
return NULL;
}
return PyLong_FromLong(sts);
} | static PyObject * spam_system(PyObject *self, PyObject *args) { const char *command; int sts;
if (!PyArg_ParseTuple(args, "s", &command))
return NULL;
sts = system(command);
if (sts < 0) {
PyErr_SetString(SpamError, "System command failed");
return NULL;
}
return PyLong_FromLong(sts);
} | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a309ffbd-1ed1-4569-8cb3-6f8de397b4d2 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 741 | supabase-export-v2 | 7050b5cc4a6e2c2c | .. index:: single: PyObject_CallObject (C function)
Later, when it is time to call the function, you call the C function
:c:func:`PyObject_CallObject`. This function has two arguments, both pointers to
arbitrary Python objects: the Python function, and the argument list. The
argument list must always be a tuple object,... | trusted_official_docs | CPython Docs | .. index:: single: PyObject_CallObject (C function)
Later, when it is time to call the function, you call the C function
:c:func:`PyObject_CallObject`. This function has two arguments, both pointers to
arbitrary Python objects: the Python function, and the argument list. The
argument list must always be a tuple object,... | .. index:: single: PyObject_CallObject (C function)
Later, when it is time to call the function, you call the C function
:c:func:`PyObject_CallObject`. This function has two arguments, both pointers to
arbitrary Python objects: the Python function, and the argument list. The
argument list must always be a tuple object,... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a792dc4e-1733-45ae-8f49-0ad22b663411 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 834 | supabase-export-v2 | 717174c67232a37b | first and most important case to know about is using :c:func:`Py_DECREF` on an unrelated object while borrowing a reference to a list item. For instance::
void
bug(PyObject *list)
{
PyObject *item = PyList_GetItem(list, 0); | trusted_official_docs | CPython Docs | first and most important case to know about is using :c:func:`Py_DECREF` on an unrelated object while borrowing a reference to a list item. For instance::
void
bug(PyObject *list)
{
PyObject *item = PyList_GetItem(list, 0); | first and most important case to know about is using :c:func:`Py_DECREF` on an unrelated object while borrowing a reference to a list item. For instance::
void
bug(PyObject *list)
{
PyObject *item = PyList_GetItem(list, 0); | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
aa4633e9-8e35-4bd0-955e-96091c429db9 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 859 | supabase-export-v2 | ac8f0834d7e5f1e7 | extension modules to create and manipulate lists, this new collection type should have a set of C functions for direct manipulation from other extension modules.
At first sight this seems easy: just write the functions (without declaring them
``static``, of course), provide an appropriate header file, and document
the ... | trusted_official_docs | CPython Docs | extension modules to create and manipulate lists, this new collection type should have a set of C functions for direct manipulation from other extension modules.
At first sight this seems easy: just write the functions (without declaring them
``static``, of course), provide an appropriate header file, and document
the ... | extension modules to create and manipulate lists, this new collection type should have a set of C functions for direct manipulation from other extension modules.
At first sight this seems easy: just write the functions (without declaring them
``static``, of course), provide an appropriate header file, and document
the ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
acabcc31-96b3-4718-aa67-e3b5a94bdd5b | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 732 | supabase-export-v2 | 4b760906d6a8a2bc | Calling Python Functions from C ===============================
The tutorial concentrated on making C functions callable from Python. The
reverse is also useful: calling Python functions from C. This is especially the
case for libraries that support so-called "callback" functions. If a C
interface makes use of callback... | trusted_official_docs | CPython Docs | Calling Python Functions from C ===============================
The tutorial concentrated on making C functions callable from Python. The
reverse is also useful: calling Python functions from C. This is especially the
case for libraries that support so-called "callback" functions. If a C
interface makes use of callback... | Calling Python Functions from C ===============================
The tutorial concentrated on making C functions callable from Python. The
reverse is also useful: calling Python functions from C. This is especially the
case for libraries that support so-called "callback" functions. If a C
interface makes use of callback... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ae0802b0-8272-4261-a644-2dfd47cc1b4d | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 740 | supabase-export-v2 | 96994b80118b2f35 | safe in the presence of ``NULL`` pointers (but note that *temp* will not be ``NULL`` in this context). More info on them in section :ref:`refcounts`.
.. index:: single: PyObject_CallObject (C function) | trusted_official_docs | CPython Docs | safe in the presence of ``NULL`` pointers (but note that *temp* will not be ``NULL`` in this context). More info on them in section :ref:`refcounts`.
.. index:: single: PyObject_CallObject (C function) | safe in the presence of ``NULL`` pointers (but note that *temp* will not be ``NULL`` in this context). More info on them in section :ref:`refcounts`.
.. index:: single: PyObject_CallObject (C function) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b0b7a1c9-c995-471a-875a-e205a0373da1 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 847 | supabase-export-v2 | 052d91df835bca0b | function --- if each function were to test for ``NULL``, there would be a lot of redundant tests and the code would run more slowly.
It is better to test for ``NULL`` only at the "source:" when a pointer that may be
``NULL`` is received, for example, from :c:func:`malloc` or from a function that
may raise an exception. | trusted_official_docs | CPython Docs | function --- if each function were to test for ``NULL``, there would be a lot of redundant tests and the code would run more slowly.
It is better to test for ``NULL`` only at the "source:" when a pointer that may be
``NULL`` is received, for example, from :c:func:`malloc` or from a function that
may raise an exception. | function --- if each function were to test for ``NULL``, there would be a lot of redundant tests and the code would run more slowly.
It is better to test for ``NULL`` only at the "source:" when a pointer that may be
``NULL`` is received, for example, from :c:func:`malloc` or from a function that
may raise an exception. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b1c59250-dee1-4632-b56d-20b2221a60fb | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 898 | supabase-export-v2 | 140067c9d91a32d3 | #endif /* !defined(Py_SPAMMODULE_H) */
All that a client module must do in order to have access to the function
:c:func:`!PySpam_System` is to call the function (or rather macro)
:c:func:`!import_spam` in its :c:data:`mod_exec <Py_mod_exec>` function:: | trusted_official_docs | CPython Docs | #endif /* !defined(Py_SPAMMODULE_H) */
All that a client module must do in order to have access to the function
:c:func:`!PySpam_System` is to call the function (or rather macro)
:c:func:`!import_spam` in its :c:data:`mod_exec <Py_mod_exec>` function:: | #endif /* !defined(Py_SPAMMODULE_H) */
All that a client module must do in order to have access to the function
:c:func:`!PySpam_System` is to call the function (or rather macro)
:c:func:`!import_spam` in its :c:data:`mod_exec <Py_mod_exec>` function:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b46ef12b-19a4-4f4e-b182-d3ae8f9c47cd | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 833 | supabase-export-v2 | 8e8351f7a73fa7e0 | to problems. These all have to do with implicit invocations of the interpreter, which can cause the owner of a reference to dispose of it.
The first and most important case to know about is using :c:func:`Py_DECREF` on
an unrelated object while borrowing a reference to a list item. For instance:: | trusted_official_docs | CPython Docs | to problems. These all have to do with implicit invocations of the interpreter, which can cause the owner of a reference to dispose of it.
The first and most important case to know about is using :c:func:`Py_DECREF` on
an unrelated object while borrowing a reference to a list item. For instance:: | to problems. These all have to do with implicit invocations of the interpreter, which can cause the owner of a reference to dispose of it.
The first and most important case to know about is using :c:func:`Py_DECREF` on
an unrelated object while borrowing a reference to a list item. For instance:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b8288a37-e54a-45d7-b798-a96601e7a302 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 717 | supabase-export-v2 | 9fb99292000510da | PyMODINIT_FUNC PyInit_spam(void) { return PyModuleDef_Init(&spam_module); }
Note that the Python name for the exception object is :exc:`!spam.error`. The
:c:func:`PyErr_NewException` function may create a class with the base class
being :exc:`Exception` (unless another class is passed in instead of ``NULL``),
described... | trusted_official_docs | CPython Docs | PyMODINIT_FUNC PyInit_spam(void) { return PyModuleDef_Init(&spam_module); }
Note that the Python name for the exception object is :exc:`!spam.error`. The
:c:func:`PyErr_NewException` function may create a class with the base class
being :exc:`Exception` (unless another class is passed in instead of ``NULL``),
described... | PyMODINIT_FUNC PyInit_spam(void) { return PyModuleDef_Init(&spam_module); }
Note that the Python name for the exception object is :exc:`!spam.error`. The
:c:func:`PyErr_NewException` function may create a class with the base class
being :exc:`Exception` (unless another class is passed in instead of ``NULL``),
described... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b8d98254-4e49-41ed-8dfb-09da2dce5ba1 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 720 | supabase-export-v2 | 14e44b726cc87fc5 | down, the global :c:data:`!SpamError` variable will not be garbage-collected. It will "leak". We did, however, ensure that this will happen at most once per process.
We discuss the use of :c:macro:`PyMODINIT_FUNC` as a function return type later in this
sample. | trusted_official_docs | CPython Docs | down, the global :c:data:`!SpamError` variable will not be garbage-collected. It will "leak". We did, however, ensure that this will happen at most once per process.
We discuss the use of :c:macro:`PyMODINIT_FUNC` as a function return type later in this
sample. | down, the global :c:data:`!SpamError` variable will not be garbage-collected. It will "leak". We did, however, ensure that this will happen at most once per process.
We discuss the use of :c:macro:`PyMODINIT_FUNC` as a function return type later in this
sample. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
bb90eb7d-55ad-46b7-8f79-60769d2b8887 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 842 | supabase-export-v2 | 50151e7c00abf7f6 | Py_INCREF(item); PyList_SetItem(list, 1, PyLong_FromLong(0L)); PyObject_Print(item, stdout, 0); Py_DECREF(item); }
This is a true story. An older version of Python contained variants of this bug
and someone spent a considerable amount of time in a C debugger to figure out
why his :meth:`!__del__` methods would fail... | trusted_official_docs | CPython Docs | Py_INCREF(item); PyList_SetItem(list, 1, PyLong_FromLong(0L)); PyObject_Print(item, stdout, 0); Py_DECREF(item); }
This is a true story. An older version of Python contained variants of this bug
and someone spent a considerable amount of time in a C debugger to figure out
why his :meth:`!__del__` methods would fail... | Py_INCREF(item); PyList_SetItem(list, 1, PyLong_FromLong(0L)); PyObject_Print(item, stdout, 0); Py_DECREF(item); }
This is a true story. An older version of Python contained variants of this bug
and someone spent a considerable amount of time in a C debugger to figure out
why his :meth:`!__del__` methods would fail... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c10b9c74-ae7b-4848-b0ae-4ea8a1125a37 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 738 | supabase-export-v2 | 617f81cb966cbbb4 | previous callback */ my_callback = temp; /* Remember new callback */ /* Boilerplate to return "None" */ Py_INCREF(Py_None); result = Py_None; } return result; }
This function must be registered with the interpreter using the
:c:macro:`METH_VARARGS` flag in :c:type:`PyMethodDef.ml_flags`. The
:c:func:`PyArg_ParseTuple` ... | trusted_official_docs | CPython Docs | previous callback */ my_callback = temp; /* Remember new callback */ /* Boilerplate to return "None" */ Py_INCREF(Py_None); result = Py_None; } return result; }
This function must be registered with the interpreter using the
:c:macro:`METH_VARARGS` flag in :c:type:`PyMethodDef.ml_flags`. The
:c:func:`PyArg_ParseTuple` ... | previous callback */ my_callback = temp; /* Remember new callback */ /* Boilerplate to return "None" */ Py_INCREF(Py_None); result = Py_None; } return result; }
This function must be registered with the interpreter using the
:c:macro:`METH_VARARGS` flag in :c:type:`PyMethodDef.ml_flags`. The
:c:func:`PyArg_ParseTuple` ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c17b4edf-5fd3-46a0-94c3-cdc4237250fa | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 695 | supabase-export-v2 | ff1655d0dbf499dd | The Python API defines a number of functions to set various types of exceptions.
The most common one is :c:func:`PyErr_SetString`. Its arguments are an exception
object and a C string. The exception object is usually a predefined object like
:c:data:`PyExc_ZeroDivisionError`. The C string indicates the cause of the err... | trusted_official_docs | CPython Docs | The Python API defines a number of functions to set various types of exceptions.
The most common one is :c:func:`PyErr_SetString`. Its arguments are an exception
object and a C string. The exception object is usually a predefined object like
:c:data:`PyExc_ZeroDivisionError`. The C string indicates the cause of the err... | The Python API defines a number of functions to set various types of exceptions.
The most common one is :c:func:`PyErr_SetString`. Its arguments are an exception
object and a C string. The exception object is usually a predefined object like
:c:data:`PyExc_ZeroDivisionError`. The C string indicates the cause of the err... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c627c257-c578-4685-be59-4ba3bef01e5d | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 776 | supabase-export-v2 | 72bdbb3346d7def4 | ::
{
int left, top, right, bottom, h, v;
ok = PyArg_ParseTuple(args, "((ii)(ii))(ii)",
&left, &top, &right, &bottom, &h, &v);
/* A rectangle and a point */
/* Possible Python call:
f(((0, 0), (400, 300)), (10, 10)) */
} | trusted_official_docs | CPython Docs | ::
{
int left, top, right, bottom, h, v;
ok = PyArg_ParseTuple(args, "((ii)(ii))(ii)",
&left, &top, &right, &bottom, &h, &v);
/* A rectangle and a point */
/* Possible Python call:
f(((0, 0), (400, 300)), (10, 10)) */
} | ::
{
int left, top, right, bottom, h, v;
ok = PyArg_ParseTuple(args, "((ii)(ii))(ii)",
&left, &top, &right, &bottom, &h, &v);
/* A rectangle and a point */
/* Possible Python call:
f(((0, 0), (400, 300)), (10, 10)) */
} | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c7403917-c325-4dce-94c0-9ec8edb3521b | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 820 | supabase-export-v2 | c549c44fb6ea872d | which it was borrowed. Using a borrowed reference after the owner has disposed of it risks using freed memory and should be avoided completely [#dont-check-refcount]_.
The advantage of borrowing over owning a reference is that you don't need to
take care of disposing of the reference on all possible paths through the c... | trusted_official_docs | CPython Docs | which it was borrowed. Using a borrowed reference after the owner has disposed of it risks using freed memory and should be avoided completely [#dont-check-refcount]_.
The advantage of borrowing over owning a reference is that you don't need to
take care of disposing of the reference on all possible paths through the c... | which it was borrowed. Using a borrowed reference after the owner has disposed of it risks using freed memory and should be avoided completely [#dont-check-refcount]_.
The advantage of borrowing over owning a reference is that you don't need to
take care of disposing of the reference on all possible paths through the c... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c7df0831-ee64-4f93-a427-a40c83555ae9 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 759 | supabase-export-v2 | 8263af70270015b3 | explained in :ref:`arg-parsing` in the Python/C API Reference Manual. The remaining arguments must be addresses of variables whose type is determined by the format string.
For example, to receive a single Python :py:class:`str` object and turn it
into a C buffer, you would use ``"s"`` as the format string:: | trusted_official_docs | CPython Docs | explained in :ref:`arg-parsing` in the Python/C API Reference Manual. The remaining arguments must be addresses of variables whose type is determined by the format string.
For example, to receive a single Python :py:class:`str` object and turn it
into a C buffer, you would use ``"s"`` as the format string:: | explained in :ref:`arg-parsing` in the Python/C API Reference Manual. The remaining arguments must be addresses of variables whose type is determined by the format string.
For example, to receive a single Python :py:class:`str` object and turn it
into a C buffer, you would use ``"s"`` as the format string:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c81cb020-4ee8-4c44-9d6e-384456a348a2 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 864 | supabase-export-v2 | 324f62ee96b7244d | to specify a name. Properly named Capsules provide a degree of runtime type-safety; there is no feasible way to tell one unnamed Capsule from another.
In particular, Capsules used to expose C APIs should be given a name following
this convention:: | trusted_official_docs | CPython Docs | to specify a name. Properly named Capsules provide a degree of runtime type-safety; there is no feasible way to tell one unnamed Capsule from another.
In particular, Capsules used to expose C APIs should be given a name following
this convention:: | to specify a name. Properly named Capsules provide a degree of runtime type-safety; there is no feasible way to tell one unnamed Capsule from another.
In particular, Capsules used to expose C APIs should be given a name following
this convention:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c9851762-eeec-4cd9-94dd-e8b807e8a86e | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 862 | supabase-export-v2 | 92cc87db25c5bda6 | extension module's namespace. Other extension modules can then import this module, retrieve the value of this name, and then retrieve the pointer from the Capsule.
There are many ways in which Capsules can be used to export the C API of an
extension module. Each function could get its own Capsule, or all C API pointers... | trusted_official_docs | CPython Docs | extension module's namespace. Other extension modules can then import this module, retrieve the value of this name, and then retrieve the pointer from the Capsule.
There are many ways in which Capsules can be used to export the C API of an
extension module. Each function could get its own Capsule, or all C API pointers... | extension module's namespace. Other extension modules can then import this module, retrieve the value of this name, and then retrieve the pointer from the Capsule.
There are many ways in which Capsules can be used to export the C API of an
extension module. Each function could get its own Capsule, or all C API pointers... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
cbe0454d-1d71-4e20-b5b6-66759afb9450 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 783 | supabase-export-v2 | 9725abd001500d6a | function should accept a third ``PyObject *`` parameter which will be a dictionary of keywords. Use :c:func:`PyArg_ParseTupleAndKeywords` to parse the arguments to such a function.
.. index:: single: PyArg_ParseTupleAndKeywords (C function) | trusted_official_docs | CPython Docs | function should accept a third ``PyObject *`` parameter which will be a dictionary of keywords. Use :c:func:`PyArg_ParseTupleAndKeywords` to parse the arguments to such a function.
.. index:: single: PyArg_ParseTupleAndKeywords (C function) | function should accept a third ``PyObject *`` parameter which will be a dictionary of keywords. Use :c:func:`PyArg_ParseTupleAndKeywords` to parse the arguments to such a function.
.. index:: single: PyArg_ParseTupleAndKeywords (C function) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
cc5850db-d34e-4872-970b-8702d43ec03c | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 696 | supabase-export-v2 | ea9bfa6468b090b7 | C string indicates the cause of the error and is converted to a Python string object and stored as the "associated value" of the exception.
Another useful function is :c:func:`PyErr_SetFromErrno`, which only takes an
exception argument and constructs the associated value by inspection of the
global variable :c:data:`er... | trusted_official_docs | CPython Docs | C string indicates the cause of the error and is converted to a Python string object and stored as the "associated value" of the exception.
Another useful function is :c:func:`PyErr_SetFromErrno`, which only takes an
exception argument and constructs the associated value by inspection of the
global variable :c:data:`er... | C string indicates the cause of the error and is converted to a Python string object and stored as the "associated value" of the exception.
Another useful function is :c:func:`PyErr_SetFromErrno`, which only takes an
exception argument and constructs the associated value by inspection of the
global variable :c:data:`er... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
cc6de854-bdfa-48a3-8ba9-0fc719e537e8 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 701 | supabase-export-v2 | 96b7231350cb3580 | pass the error on to the interpreter but wants to handle it completely by itself (possibly by trying something else, or pretending nothing went wrong).
Every failing :c:func:`malloc` call must be turned into an exception --- the
direct caller of :c:func:`malloc` (or :c:func:`realloc`) must call
:c:func:`PyErr_NoMemory`... | trusted_official_docs | CPython Docs | pass the error on to the interpreter but wants to handle it completely by itself (possibly by trying something else, or pretending nothing went wrong).
Every failing :c:func:`malloc` call must be turned into an exception --- the
direct caller of :c:func:`malloc` (or :c:func:`realloc`) must call
:c:func:`PyErr_NoMemory`... | pass the error on to the interpreter but wants to handle it completely by itself (possibly by trying something else, or pretending nothing went wrong).
Every failing :c:func:`malloc` call must be turned into an exception --- the
direct caller of :c:func:`malloc` (or :c:func:`realloc`) must call
:c:func:`PyErr_NoMemory`... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ce370b64-75c4-4821-bf89-1dc2d9800660 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 905 | supabase-export-v2 | 8c9b8221d34c1949 | is at least 1 **does not work** --- the reference count itself could be in freed memory and may thus be reused for another object!
.. [#old-calling-convention] These guarantees don't hold when you use the
"old" style calling convention ---
this is still found in much existing code. | trusted_official_docs | CPython Docs | is at least 1 **does not work** --- the reference count itself could be in freed memory and may thus be reused for another object!
.. [#old-calling-convention] These guarantees don't hold when you use the
"old" style calling convention ---
this is still found in much existing code. | is at least 1 **does not work** --- the reference count itself could be in freed memory and may thus be reused for another object!
.. [#old-calling-convention] These guarantees don't hold when you use the
"old" style calling convention ---
this is still found in much existing code. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
cf89ed1a-6ebb-4750-9cfa-f7104be11750 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 747 | supabase-export-v2 | 1de7c3c515cdf825 | if (result == NULL) return NULL; /* Pass error back */ ...use result... Py_DECREF(result);
Depending on the desired interface to the Python callback function, you may also
have to provide an argument list to :c:func:`PyObject_CallObject`. In some cases
the argument list is also provided by the Python program, through t... | trusted_official_docs | CPython Docs | if (result == NULL) return NULL; /* Pass error back */ ...use result... Py_DECREF(result);
Depending on the desired interface to the Python callback function, you may also
have to provide an argument list to :c:func:`PyObject_CallObject`. In some cases
the argument list is also provided by the Python program, through t... | if (result == NULL) return NULL; /* Pass error back */ ...use result... Py_DECREF(result);
Depending on the desired interface to the Python callback function, you may also
have to provide an argument list to :c:func:`PyObject_CallObject`. In some cases
the argument list is also provided by the Python program, through t... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
cfc839cb-3672-4ebf-955a-d8a3c8735ff2 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 748 | supabase-export-v2 | e6f078fd660d13a2 | way to do this is to call :c:func:`Py_BuildValue`. For example, if you want to pass an integral event code, you might use the following code::
PyObject *arglist;
... arglist = Py_BuildValue("(l)", eventcode);
result = PyObject_CallObject(my_callback, arglist);
Py_DECREF(arglist);
if (result == NULL)
return NULL; /... | trusted_official_docs | CPython Docs | way to do this is to call :c:func:`Py_BuildValue`. For example, if you want to pass an integral event code, you might use the following code::
PyObject *arglist;
... arglist = Py_BuildValue("(l)", eventcode);
result = PyObject_CallObject(my_callback, arglist);
Py_DECREF(arglist);
if (result == NULL)
return NULL; /... | way to do this is to call :c:func:`Py_BuildValue`. For example, if you want to pass an integral event code, you might use the following code::
PyObject *arglist;
... arglist = Py_BuildValue("(l)", eventcode);
result = PyObject_CallObject(my_callback, arglist);
Py_DECREF(arglist);
if (result == NULL)
return NULL; /... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d01ea932-2243-4610-885d-f518dfd13e86 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 739 | supabase-export-v2 | 40c339e8f4342b34 | This function must be registered with the interpreter using the :c:macro:`METH_VARARGS` flag in :c:type:`PyMethodDef.ml_flags`. The :c:func:`PyArg_ParseTuple` function and its arguments are documented in section :ref:`parsetuple`.
The macros :c:func:`Py_XINCREF` and :c:func:`Py_XDECREF` increment/decrement the
referenc... | trusted_official_docs | CPython Docs | This function must be registered with the interpreter using the :c:macro:`METH_VARARGS` flag in :c:type:`PyMethodDef.ml_flags`. The :c:func:`PyArg_ParseTuple` function and its arguments are documented in section :ref:`parsetuple`.
The macros :c:func:`Py_XINCREF` and :c:func:`Py_XDECREF` increment/decrement the
referenc... | This function must be registered with the interpreter using the :c:macro:`METH_VARARGS` flag in :c:type:`PyMethodDef.ml_flags`. The :c:func:`PyArg_ParseTuple` function and its arguments are documented in section :ref:`parsetuple`.
The macros :c:func:`Py_XINCREF` and :c:func:`Py_XDECREF` increment/decrement the
referenc... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d22ae3f8-43df-4713-ac85-6e5267ca2a88 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 879 | supabase-export-v2 | ae8d8a01c035afd6 | included in the exporting module, not a client module. Finally, the module's :c:data:`mod_exec <Py_mod_exec>` function must take care of initializing the C API pointer array::
static int
spam_module_exec(PyObject *m)
{
static void *PySpam_API[PySpam_API_pointers];
PyObject *c_api_object; | trusted_official_docs | CPython Docs | included in the exporting module, not a client module. Finally, the module's :c:data:`mod_exec <Py_mod_exec>` function must take care of initializing the C API pointer array::
static int
spam_module_exec(PyObject *m)
{
static void *PySpam_API[PySpam_API_pointers];
PyObject *c_api_object; | included in the exporting module, not a client module. Finally, the module's :c:data:`mod_exec <Py_mod_exec>` function must take care of initializing the C API pointer array::
static int
spam_module_exec(PyObject *m)
{
static void *PySpam_API[PySpam_API_pointers];
PyObject *c_api_object; | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d6229b56-9f12-4877-8c2b-858554dd2b48 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 855 | supabase-export-v2 | e4bb6114c3bfe9fb | Writing Extensions in C++ =========================
It is possible to write extension modules in C++. Some restrictions apply. If
the main program (the Python interpreter) is compiled and linked by the C
compiler, global or static objects with constructors cannot be used. This is
not a problem if the main program is li... | trusted_official_docs | CPython Docs | Writing Extensions in C++ =========================
It is possible to write extension modules in C++. Some restrictions apply. If
the main program (the Python interpreter) is compiled and linked by the C
compiler, global or static objects with constructors cannot be used. This is
not a problem if the main program is li... | Writing Extensions in C++ =========================
It is possible to write extension modules in C++. Some restrictions apply. If
the main program (the Python interpreter) is compiled and linked by the C
compiler, global or static objects with constructors cannot be used. This is
not a problem if the main program is li... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d668e7e5-446c-4791-9e96-ef825b9858e9 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 795 | supabase-export-v2 | 1856a96604d5c5c6 | if (!PyArg_ParseTupleAndKeywords(args, keywds, "i|sss", kwlist, &voltage, &state, &action, &type)) return NULL;
printf("-- This parrot wouldn't %s if you put %i Volts through it.\n",
action, voltage);
printf("-- Lovely plumage, the %s -- It's %s!\n", type, state); | trusted_official_docs | CPython Docs | if (!PyArg_ParseTupleAndKeywords(args, keywds, "i|sss", kwlist, &voltage, &state, &action, &type)) return NULL;
printf("-- This parrot wouldn't %s if you put %i Volts through it.\n",
action, voltage);
printf("-- Lovely plumage, the %s -- It's %s!\n", type, state); | if (!PyArg_ParseTupleAndKeywords(args, keywds, "i|sss", kwlist, &voltage, &state, &action, &type)) return NULL;
printf("-- This parrot wouldn't %s if you put %i Volts through it.\n",
action, voltage);
printf("-- Lovely plumage, the %s -- It's %s!\n", type, state); | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d7e69f55-ae59-4e24-afb7-482af411c408 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 817 | supabase-export-v2 | aebf7c3a3c7b4e4b | Reference Counting in Python ----------------------------
There are two macros, ``Py_INCREF(x)`` and ``Py_DECREF(x)``, which handle the
incrementing and decrementing of the reference count. :c:func:`Py_DECREF` also
frees the object when the count reaches zero. For flexibility, it doesn't call
:c:func:`free` directly --... | trusted_official_docs | CPython Docs | Reference Counting in Python ----------------------------
There are two macros, ``Py_INCREF(x)`` and ``Py_DECREF(x)``, which handle the
incrementing and decrementing of the reference count. :c:func:`Py_DECREF` also
frees the object when the count reaches zero. For flexibility, it doesn't call
:c:func:`free` directly --... | Reference Counting in Python ----------------------------
There are two macros, ``Py_INCREF(x)`` and ``Py_DECREF(x)``, which handle the
incrementing and decrementing of the reference count. :c:func:`Py_DECREF` also
frees the object when the count reaches zero. For flexibility, it doesn't call
:c:func:`free` directly --... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
daac03b2-610c-49d3-9a0f-67745c842b64 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 861 | supabase-export-v2 | a4f2d69578a94dea | clashes with other extension modules. And it means that symbols that *should* be accessible from other extension modules must be exported in a different way.
Python provides a special mechanism to pass C-level information (pointers) from
one extension module to another one: Capsules. A Capsule is a Python data type
whi... | trusted_official_docs | CPython Docs | clashes with other extension modules. And it means that symbols that *should* be accessible from other extension modules must be exported in a different way.
Python provides a special mechanism to pass C-level information (pointers) from
one extension module to another one: Capsules. A Capsule is a Python data type
whi... | clashes with other extension modules. And it means that symbols that *should* be accessible from other extension modules must be exported in a different way.
Python provides a special mechanism to pass C-level information (pointers) from
one extension module to another one: Capsules. A Capsule is a Python data type
whi... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
daf3ef32-9e74-43de-b30d-4636156110ad | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 734 | supabase-export-v2 | 93c7524ab75e9389 | as input --- if you're interested, have a look at the implementation of the :option:`-c` command line option in :file:`Modules/main.c` from the Python source code.)
Calling a Python function is easy. First, the Python program must somehow pass
you the Python function object. You should provide a function (or some other... | trusted_official_docs | CPython Docs | as input --- if you're interested, have a look at the implementation of the :option:`-c` command line option in :file:`Modules/main.c` from the Python source code.)
Calling a Python function is easy. First, the Python program must somehow pass
you the Python function object. You should provide a function (or some other... | as input --- if you're interested, have a look at the implementation of the :option:`-c` command line option in :file:`Modules/main.c` from the Python source code.)
Calling a Python function is easy. First, the Python program must somehow pass
you the Python function object. You should provide a function (or some other... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
dd84b464-8e87-411a-a433-9bf386aa920a | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 786 | supabase-export-v2 | ab8be1f5dd685076 | int PyArg_ParseTupleAndKeywords(PyObject *arg, PyObject *kwdict, const char *format, char * const *kwlist, ...);
The *arg* and *format* parameters are identical to those of the
:c:func:`PyArg_ParseTuple` function. The *kwdict* parameter is the dictionary of
keywords received as the third parameter from the Python runti... | trusted_official_docs | CPython Docs | int PyArg_ParseTupleAndKeywords(PyObject *arg, PyObject *kwdict, const char *format, char * const *kwlist, ...);
The *arg* and *format* parameters are identical to those of the
:c:func:`PyArg_ParseTuple` function. The *kwdict* parameter is the dictionary of
keywords received as the third parameter from the Python runti... | int PyArg_ParseTupleAndKeywords(PyObject *arg, PyObject *kwdict, const char *format, char * const *kwlist, ...);
The *arg* and *format* parameters are identical to those of the
:c:func:`PyArg_ParseTuple` function. The *kwdict* parameter is the dictionary of
keywords received as the third parameter from the Python runti... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
e1df0e24-1d83-4161-b2a7-5c33b7c5894a | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 774 | supabase-export-v2 | eda764a9cf2d4cae | ::
{
const char *file;
const char *mode = "r";
int bufsize = 0;
ok = PyArg_ParseTuple(args, "s|si", &file, &mode, &bufsize);
/* A string, and optionally another string and an integer */
/* Possible Python calls:
f('spam')
f('spam', 'w')
f('spam', 'wb', 100000) */
} | trusted_official_docs | CPython Docs | ::
{
const char *file;
const char *mode = "r";
int bufsize = 0;
ok = PyArg_ParseTuple(args, "s|si", &file, &mode, &bufsize);
/* A string, and optionally another string and an integer */
/* Possible Python calls:
f('spam')
f('spam', 'w')
f('spam', 'wb', 100000) */
} | ::
{
const char *file;
const char *mode = "r";
int bufsize = 0;
ok = PyArg_ParseTuple(args, "s|si", &file, &mode, &bufsize);
/* A string, and optionally another string and an integer */
/* Possible Python calls:
f('spam')
f('spam', 'w')
f('spam', 'wb', 100000) */
} | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
e21f7b8f-408a-4de6-aaf1-0446086de7be | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 828 | supabase-export-v2 | 2a9ac75b1552b6c6 | reference, even though it may actually create the object it returns: this is possible because an owned reference to the object is stored in ``sys.modules``.
When you pass an object reference into another function, in general, the
function borrows the reference from you --- if it needs to store it, it will use
:c:func:`... | trusted_official_docs | CPython Docs | reference, even though it may actually create the object it returns: this is possible because an owned reference to the object is stored in ``sys.modules``.
When you pass an object reference into another function, in general, the
function borrows the reference from you --- if it needs to store it, it will use
:c:func:`... | reference, even though it may actually create the object it returns: this is possible because an owned reference to the object is stored in ``sys.modules``.
When you pass an object reference into another function, in general, the
function borrows the reference from you --- if it needs to store it, it will use
:c:func:`... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
e2df86d1-1772-47f0-8781-7026bfe1432e | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 762 | supabase-export-v2 | af002dd438351b81 | argument list, :c:func:`!PyArg_ParseTuple` returns ``NULL`` (the error indicator for functions returning object pointers); your function may return ``NULL``, relying on the exception set by :c:func:`PyArg_ParseTuple`.
Note that while :c:func:`PyArg_ParseTuple` checks that the Python arguments have
the required types, i... | trusted_official_docs | CPython Docs | argument list, :c:func:`!PyArg_ParseTuple` returns ``NULL`` (the error indicator for functions returning object pointers); your function may return ``NULL``, relying on the exception set by :c:func:`PyArg_ParseTuple`.
Note that while :c:func:`PyArg_ParseTuple` checks that the Python arguments have
the required types, i... | argument list, :c:func:`!PyArg_ParseTuple` returns ``NULL`` (the error indicator for functions returning object pointers); your function may return ``NULL``, relying on the exception set by :c:func:`PyArg_ParseTuple`.
Note that while :c:func:`PyArg_ParseTuple` checks that the Python arguments have
the required types, i... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
e3564d8c-2367-4c56-b84d-0d2f98dbc168 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 726 | supabase-export-v2 | 1451bcf26b93162d | Embedding an extension ======================
If you want to make your module a permanent
part of the Python interpreter, you will have to change the configuration setup
and rebuild the interpreter. On Unix, place
your file (:file:`spammodule.c` for example) in the :file:`Modules/` directory
of an unpacked source distr... | trusted_official_docs | CPython Docs | Embedding an extension ======================
If you want to make your module a permanent
part of the Python interpreter, you will have to change the configuration setup
and rebuild the interpreter. On Unix, place
your file (:file:`spammodule.c` for example) in the :file:`Modules/` directory
of an unpacked source distr... | Embedding an extension ======================
If you want to make your module a permanent
part of the Python interpreter, you will have to change the configuration setup
and rebuild the interpreter. On Unix, place
your file (:file:`spammodule.c` for example) in the :file:`Modules/` directory
of an unpacked source distr... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
e6f0a74b-fce6-4797-a07c-ad7c7dfa83cd | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 846 | supabase-export-v2 | d249cdbbff5d26e4 | NULL Pointers -------------
In general, functions that take object references as arguments do not expect you
to pass them ``NULL`` pointers, and will dump core (or cause later core dumps) if
you do so. Functions that return object references generally return ``NULL`` only
to indicate that an exception occurred. The rea... | trusted_official_docs | CPython Docs | NULL Pointers -------------
In general, functions that take object references as arguments do not expect you
to pass them ``NULL`` pointers, and will dump core (or cause later core dumps) if
you do so. Functions that return object references generally return ``NULL`` only
to indicate that an exception occurred. The rea... | NULL Pointers -------------
In general, functions that take object references as arguments do not expect you
to pass them ``NULL`` pointers, and will dump core (or cause later core dumps) if
you do so. Functions that return object references generally return ``NULL`` only
to indicate that an exception occurred. The rea... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
e7335ec2-177d-4214-9eef-78f8bc16eac6 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 850 | supabase-export-v2 | 81ced602a850dead | in a row to test an object against various different expected types, and this would generate redundant tests. There are no variants with ``NULL`` checking.
The C function calling mechanism guarantees that the argument list passed to C
functions (``args`` in the examples) is never ``NULL`` --- in fact it guarantees
that... | trusted_official_docs | CPython Docs | in a row to test an object against various different expected types, and this would generate redundant tests. There are no variants with ``NULL`` checking.
The C function calling mechanism guarantees that the argument list passed to C
functions (``args`` in the examples) is never ``NULL`` --- in fact it guarantees
that... | in a row to test an object against various different expected types, and this would generate redundant tests. There are no variants with ``NULL`` checking.
The C function calling mechanism guarantees that the argument list passed to C
functions (``args`` in the examples) is never ``NULL`` --- in fact it guarantees
that... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
e7982232-6fb2-4aa7-b274-b307611d4638 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 809 | supabase-export-v2 | d8806c8521f38c91 | :c:func:`free`. In C++, the operators ``new`` and ``delete`` are used with essentially the same meaning and we'll restrict the following discussion to the C case.
Every block of memory allocated with :c:func:`malloc` should eventually be
returned to the pool of available memory by exactly one call to :c:func:`free`. It... | trusted_official_docs | CPython Docs | :c:func:`free`. In C++, the operators ``new`` and ``delete`` are used with essentially the same meaning and we'll restrict the following discussion to the C case.
Every block of memory allocated with :c:func:`malloc` should eventually be
returned to the pool of available memory by exactly one call to :c:func:`free`. It... | :c:func:`free`. In C++, the operators ``new`` and ``delete`` are used with essentially the same meaning and we'll restrict the following discussion to the C case.
Every block of memory allocated with :c:func:`malloc` should eventually be
returned to the pool of available memory by exactly one call to :c:func:`free`. It... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
eb8e5584-f25f-48f3-a6b0-73e9ae09cdc3 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 818 | supabase-export-v2 | e7abc4334219ab31 | call through a function pointer in the object's :dfn:`type object`. For this purpose (and others), every object also contains a pointer to its type object.
The big question now remains: when to use ``Py_INCREF(x)`` and ``Py_DECREF(x)``? Let's first introduce some terms. Nobody "owns" an object; however, you can
:dfn:`o... | trusted_official_docs | CPython Docs | call through a function pointer in the object's :dfn:`type object`. For this purpose (and others), every object also contains a pointer to its type object.
The big question now remains: when to use ``Py_INCREF(x)`` and ``Py_DECREF(x)``? Let's first introduce some terms. Nobody "owns" an object; however, you can
:dfn:`o... | call through a function pointer in the object's :dfn:`type object`. For this purpose (and others), every object also contains a pointer to its type object.
The big question now remains: when to use ``Py_INCREF(x)`` and ``Py_DECREF(x)``? Let's first introduce some terms. Nobody "owns" an object; however, you can
:dfn:`o... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
f39c9283-bddc-4010-855f-879855d3a35c | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 811 | supabase-export-v2 | da2fbe34e710eefd | the leaking function frequently. Therefore, it's important to prevent leaks from happening by having a coding convention or strategy that minimizes this kind of errors.
Since Python makes heavy use of :c:func:`malloc` and :c:func:`free`, it needs a
strategy to avoid memory leaks as well as the use of freed memory. The ... | trusted_official_docs | CPython Docs | the leaking function frequently. Therefore, it's important to prevent leaks from happening by having a coding convention or strategy that minimizes this kind of errors.
Since Python makes heavy use of :c:func:`malloc` and :c:func:`free`, it needs a
strategy to avoid memory leaks as well as the use of freed memory. The ... | the leaking function frequently. Therefore, it's important to prevent leaks from happening by having a coding convention or strategy that minimizes this kind of errors.
Since Python makes heavy use of :c:func:`malloc` and :c:func:`free`, it needs a
strategy to avoid memory leaks as well as the use of freed memory. The ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
f7ce1730-b071-4094-9bc1-443e2265b6d8 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 745 | supabase-export-v2 | 12bed64afb683953 | you want to save it in a global variable, you should somehow :c:func:`Py_DECREF` the result, even (especially!) if you are not interested in its value.
Before you do this, however, it is important to check that the return value
isn't ``NULL``. If it is, the Python function terminated by raising an exception. If the C c... | trusted_official_docs | CPython Docs | you want to save it in a global variable, you should somehow :c:func:`Py_DECREF` the result, even (especially!) if you are not interested in its value.
Before you do this, however, it is important to check that the return value
isn't ``NULL``. If it is, the Python function terminated by raising an exception. If the C c... | you want to save it in a global variable, you should somehow :c:func:`Py_DECREF` the result, even (especially!) if you are not interested in its value.
Before you do this, however, it is important to check that the return value
isn't ``NULL``. If it is, the Python function terminated by raising an exception. If the C c... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
f9ca7468-a48b-4e26-b006-961f7bc71114 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 806 | supabase-export-v2 | c50d361c5c334c93 | .. code-block:: none
Py_BuildValue("") None
Py_BuildValue("i", 123) 123
Py_BuildValue("iii", 123, 456, 789) (123, 456, 789)
Py_BuildValue("s", "hello") 'hello'
Py_BuildValue("y", "hello") b'hello'
Py_BuildValue("ss", "hello", "world") ('hello', 'world')
Py_BuildValue("s#", "hello", 4) 'hell'
Py_BuildValue("y#", ... | trusted_official_docs | CPython Docs | .. code-block:: none
Py_BuildValue("") None
Py_BuildValue("i", 123) 123
Py_BuildValue("iii", 123, 456, 789) (123, 456, 789)
Py_BuildValue("s", "hello") 'hello'
Py_BuildValue("y", "hello") b'hello'
Py_BuildValue("ss", "hello", "world") ('hello', 'world')
Py_BuildValue("s#", "hello", 4) 'hell'
Py_BuildValue("y#", ... | .. code-block:: none
Py_BuildValue("") None
Py_BuildValue("i", 123) 123
Py_BuildValue("iii", 123, 456, 789) (123, 456, 789)
Py_BuildValue("s", "hello") 'hello'
Py_BuildValue("y", "hello") b'hello'
Py_BuildValue("ss", "hello", "world") ('hello', 'world')
Py_BuildValue("s#", "hello", 4) 'hell'
Py_BuildValue("y#", ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
fa3c22a9-8dbe-421b-b753-97bf02da2d4c | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 819 | supabase-export-v2 | 04dccc0cd9da783b | to dispose of an owned reference: pass it on, store it, or call :c:func:`Py_DECREF`. Forgetting to dispose of an owned reference creates a memory leak.
It is also possible to :dfn:`borrow` [#borrow]_ a reference to an object. The
borrower of a reference should not call :c:func:`Py_DECREF`. The borrower must
not hold on... | trusted_official_docs | CPython Docs | to dispose of an owned reference: pass it on, store it, or call :c:func:`Py_DECREF`. Forgetting to dispose of an owned reference creates a memory leak.
It is also possible to :dfn:`borrow` [#borrow]_ a reference to an object. The
borrower of a reference should not call :c:func:`Py_DECREF`. The borrower must
not hold on... | to dispose of an owned reference: pass it on, store it, or call :c:func:`Py_DECREF`. Forgetting to dispose of an owned reference creates a memory leak.
It is also possible to :dfn:`borrow` [#borrow]_ a reference to an object. The
borrower of a reference should not call :c:func:`Py_DECREF`. The borrower must
not hold on... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
fab57aa8-ecec-43d0-bbf8-b3059098fed9 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 743 | supabase-export-v2 | 74f37ee4d063c844 | PyObject *arglist; PyObject *result; ... arg = 123; ... /* Time to call the callback */ arglist = Py_BuildValue("(i)", arg); result = PyObject_CallObject(my_callback, arglist); Py_DECREF(arglist);
:c:func:`PyObject_CallObject` returns a Python object pointer: this is the return
value of the Python function. :c:func:`Py... | trusted_official_docs | CPython Docs | PyObject *arglist; PyObject *result; ... arg = 123; ... /* Time to call the callback */ arglist = Py_BuildValue("(i)", arg); result = PyObject_CallObject(my_callback, arglist); Py_DECREF(arglist);
:c:func:`PyObject_CallObject` returns a Python object pointer: this is the return
value of the Python function. :c:func:`Py... | PyObject *arglist; PyObject *result; ... arg = 123; ... /* Time to call the callback */ arglist = Py_BuildValue("(i)", arg); result = PyObject_CallObject(my_callback, arglist); Py_DECREF(arglist);
:c:func:`PyObject_CallObject` returns a Python object pointer: this is the return
value of the Python function. :c:func:`Py... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
fd501178-02c7-4181-bdd5-e6c9ea1bd7a2 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 814 | supabase-export-v2 | 602c296afde8712c | any objects in a reference cycle, or referenced from the objects in the cycle, even though there are no further references to the cycle itself.
The cycle detector is able to detect garbage cycles and can reclaim them. The :mod:`gc` module exposes a way to run the detector (the
:func:`~gc.collect` function), as well as ... | trusted_official_docs | CPython Docs | any objects in a reference cycle, or referenced from the objects in the cycle, even though there are no further references to the cycle itself.
The cycle detector is able to detect garbage cycles and can reclaim them. The :mod:`gc` module exposes a way to run the detector (the
:func:`~gc.collect` function), as well as ... | any objects in a reference cycle, or referenced from the objects in the cycle, even though there are no further references to the cycle itself.
The cycle detector is able to detect garbage cycles and can reclaim them. The :mod:`gc` module exposes a way to run the detector (the
:func:`~gc.collect` function), as well as ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
fda0b857-29d7-42ad-bd45-ff88c78949ad | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 804 | supabase-export-v2 | ce2f6b94775dee81 | returns whatever object is described by that format unit. To force it to return a tuple of size 0 or one, parenthesize the format string.
Examples (to the left the call, to the right the resulting Python value): | trusted_official_docs | CPython Docs | returns whatever object is described by that format unit. To force it to return a tuple of size 0 or one, parenthesize the format string.
Examples (to the left the call, to the right the resulting Python value): | returns whatever object is described by that format unit. To force it to return a tuple of size 0 or one, parenthesize the format string.
Examples (to the left the call, to the right the resulting Python value): | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ff21eed0-b5e0-4f8f-b865-8d8eac9fc734 | CPython Docs | file://datasets/cpython/Doc/extending/extending.rst | unknown | 5300cab5-221b-4121-9962-d6b5f617402a | 710 | supabase-export-v2 | c98739f80dbb9243 | Since :c:data:`!SpamError` is a global variable, it will be overwritten every time the module is reinitialized, when the :c:data:`Py_mod_exec` function is called.
For now, let's avoid the issue: we will block repeated initialization by raising an
:py:exc:`ImportError`:: | trusted_official_docs | CPython Docs | Since :c:data:`!SpamError` is a global variable, it will be overwritten every time the module is reinitialized, when the :c:data:`Py_mod_exec` function is called.
For now, let's avoid the issue: we will block repeated initialization by raising an
:py:exc:`ImportError`:: | Since :c:data:`!SpamError` is a global variable, it will be overwritten every time the module is reinitialized, when the :c:data:`Py_mod_exec` function is called.
For now, let's avoid the issue: we will block repeated initialization by raising an
:py:exc:`ImportError`:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
006ce061-f92d-4f39-9e4c-e9511ff91388 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 913 | supabase-export-v2 | 485611a04f985c42 | what Python's C API is like. It will not teach you important concepts, like error handling and reference counting, which are covered in later chapters.
We will assume that you use a Unix-like system (including macOS and
Linux), or Windows. On other systems, you might need to adjust some details -- for example,
a system... | trusted_official_docs | CPython Docs | what Python's C API is like. It will not teach you important concepts, like error handling and reference counting, which are covered in later chapters.
We will assume that you use a Unix-like system (including macOS and
Linux), or Windows. On other systems, you might need to adjust some details -- for example,
a system... | what Python's C API is like. It will not teach you important concepts, like error handling and reference counting, which are covered in later chapters.
We will assume that you use a Unix-like system (including macOS and
Linux), or Windows. On other systems, you might need to adjust some details -- for example,
a system... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
02b3cbcb-6ea5-4e20-850b-59fffabb79f6 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 912 | supabase-export-v2 | aaaabef10e1c55d3 | several concepts that a C beginner would not be expected to know, like ``static`` functions or linkage declarations, understanding these is not necessary for success.
We will focus on giving you a "feel" of what Python's C API is like. It will not teach you important concepts, like error handling
and reference counting... | trusted_official_docs | CPython Docs | several concepts that a C beginner would not be expected to know, like ``static`` functions or linkage declarations, understanding these is not necessary for success.
We will focus on giving you a "feel" of what Python's C API is like. It will not teach you important concepts, like error handling
and reference counting... | several concepts that a C beginner would not be expected to know, like ``static`` functions or linkage declarations, understanding these is not necessary for success.
We will focus on giving you a "feel" of what Python's C API is like. It will not teach you important concepts, like error handling
and reference counting... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
045a5a4b-f919-4941-bc86-d54c788a3e8b | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 966 | supabase-export-v2 | 5a28c30ca8addbc6 | :c:macro:`PyMODEXPORT_FUNC` macro declares the function's return type, and adds any special linkage declarations needed to make the function visible and usable when CPython loads it.
After the prototype, add the function itself. For now, make it return ``NULL``: | trusted_official_docs | CPython Docs | :c:macro:`PyMODEXPORT_FUNC` macro declares the function's return type, and adds any special linkage declarations needed to make the function visible and usable when CPython loads it.
After the prototype, add the function itself. For now, make it return ``NULL``: | :c:macro:`PyMODEXPORT_FUNC` macro declares the function's return type, and adds any special linkage declarations needed to make the function visible and usable when CPython loads it.
After the prototype, add the function itself. For now, make it return ``NULL``: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
06765803-0422-49c6-b21f-47049c7d4fc3 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 928 | supabase-export-v2 | b862de0aadbfbcbb | system command ``whoami`` prints out your username. It's useful in tutorials like this one because it has the same name on both Unix and Windows.
Start with the headers
====================== | trusted_official_docs | CPython Docs | system command ``whoami`` prints out your username. It's useful in tutorials like this one because it has the same name on both Unix and Windows.
Start with the headers
====================== | system command ``whoami`` prints out your username. It's useful in tutorials like this one because it has the same name on both Unix and Windows.
Start with the headers
====================== | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
1b00d7f7-9f70-4282-a80f-d9b4b7d2aa1e | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 979 | supabase-export-v2 | cbbc208205204d73 | macro and the :c:data:`Py_mod_abi` slot are a bit of boilerplate that helps prevent extensions compiled for a different version of Python from crashing the interpreter.
For both :c:data:`Py_mod_name` and :c:data:`Py_mod_doc`, the values are C
strings -- that is, NUL-terminated, UTF-8 encoded byte arrays. | trusted_official_docs | CPython Docs | macro and the :c:data:`Py_mod_abi` slot are a bit of boilerplate that helps prevent extensions compiled for a different version of Python from crashing the interpreter.
For both :c:data:`Py_mod_name` and :c:data:`Py_mod_doc`, the values are C
strings -- that is, NUL-terminated, UTF-8 encoded byte arrays. | macro and the :c:data:`Py_mod_abi` slot are a bit of boilerplate that helps prevent extensions compiled for a different version of Python from crashing the interpreter.
For both :c:data:`Py_mod_name` and :c:data:`Py_mod_doc`, the values are C
strings -- that is, NUL-terminated, UTF-8 encoded byte arrays. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
1ecfdb6f-b57c-4271-80ec-809dd9862f13 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 929 | supabase-export-v2 | 7aea093252aebd16 | Start with the headers ======================
Begin by creating a directory for this tutorial, and switching to it
on the command line. Then, create a file named :file:`spammodule.c` in your directory. [#why-spammodule]_ | trusted_official_docs | CPython Docs | Start with the headers ======================
Begin by creating a directory for this tutorial, and switching to it
on the command line. Then, create a file named :file:`spammodule.c` in your directory. [#why-spammodule]_ | Start with the headers ======================
Begin by creating a directory for this tutorial, and switching to it
on the command line. Then, create a file named :file:`spammodule.c` in your directory. [#why-spammodule]_ | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
20e1587d-dba1-4068-9598-778b21c0c1b4 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 909 | supabase-export-v2 | c8f094cdd0b77f22 | This tutorial will take you through creating a simple Python extension module written in C or C++.
We will use the low-level Python C API directly. For easier ways to create extension modules, see
the :ref:`recommended third party tools <c-api-tools>`. | trusted_official_docs | CPython Docs | This tutorial will take you through creating a simple Python extension module written in C or C++.
We will use the low-level Python C API directly. For easier ways to create extension modules, see
the :ref:`recommended third party tools <c-api-tools>`. | This tutorial will take you through creating a simple Python extension module written in C or C++.
We will use the low-level Python C API directly. For easier ways to create extension modules, see
the :ref:`recommended third party tools <c-api-tools>`. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
25e0e5f1-3e5d-4ffb-b04e-374a75b9f826 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 1,027 | supabase-export-v2 | 1be22cb36180f7b1 | Finally, let's handle the function argument.
Our C function, :c:func:`!spam_system`, takes two arguments. The first one, ``PyObject *self``, will be set to the ``spam`` module
object. This isn't useful in our case, so we'll ignore it. | trusted_official_docs | CPython Docs | Finally, let's handle the function argument.
Our C function, :c:func:`!spam_system`, takes two arguments. The first one, ``PyObject *self``, will be set to the ``spam`` module
object. This isn't useful in our case, so we'll ignore it. | Finally, let's handle the function argument.
Our C function, :c:func:`!spam_system`, takes two arguments. The first one, ``PyObject *self``, will be set to the ``spam`` module
object. This isn't useful in our case, so we'll ignore it. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
28fd9ff2-6d31-402c-8609-d4f90ed7a265 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 996 | supabase-export-v2 | 82fbfb44167a37ed | static PyObject * spam_system(PyObject *self, PyObject *arg) { Py_RETURN_NONE; }
For now, we ignore the arguments, and use the :c:macro:`Py_RETURN_NONE`
macro, which expands to a ``return`` statement that properly returns
a Python :py:data:`None` object. | trusted_official_docs | CPython Docs | static PyObject * spam_system(PyObject *self, PyObject *arg) { Py_RETURN_NONE; }
For now, we ignore the arguments, and use the :c:macro:`Py_RETURN_NONE`
macro, which expands to a ``return`` statement that properly returns
a Python :py:data:`None` object. | static PyObject * spam_system(PyObject *self, PyObject *arg) { Py_RETURN_NONE; }
For now, we ignore the arguments, and use the :c:macro:`Py_RETURN_NONE`
macro, which expands to a ``return`` statement that properly returns
a Python :py:data:`None` object. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2acdd1fa-e7a5-4bd8-87a8-39731f3e6971 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 1,016 | supabase-export-v2 | 6ec9bf8cd123e85c | Returning an integer ====================
Now, let's take a look at the return value. Instead of ``None``, we'll want ``spam.system`` to return a number -- that is,
a Python :py:type:`int` object. Eventually this will be the exit code of a system command,
but let's start with a fixed value, say, ``3``. | trusted_official_docs | CPython Docs | Returning an integer ====================
Now, let's take a look at the return value. Instead of ``None``, we'll want ``spam.system`` to return a number -- that is,
a Python :py:type:`int` object. Eventually this will be the exit code of a system command,
but let's start with a fixed value, say, ``3``. | Returning an integer ====================
Now, let's take a look at the return value. Instead of ``None``, we'll want ``spam.system`` to return a number -- that is,
a Python :py:type:`int` object. Eventually this will be the exit code of a system command,
but let's start with a fixed value, say, ``3``. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2b03fe16-5069-4eca-9bd5-6b57ee3c573e | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 965 | supabase-export-v2 | 3af9a7022425bed5 | prototype is not strictly necessary, but some modern compilers emit warnings without it. It's generally better to add the prototype than to disable the warning.
The :c:macro:`PyMODEXPORT_FUNC` macro declares the function's
return type, and adds any special linkage declarations needed
to make the function visible and us... | trusted_official_docs | CPython Docs | prototype is not strictly necessary, but some modern compilers emit warnings without it. It's generally better to add the prototype than to disable the warning.
The :c:macro:`PyMODEXPORT_FUNC` macro declares the function's
return type, and adds any special linkage declarations needed
to make the function visible and us... | prototype is not strictly necessary, but some modern compilers emit warnings without it. It's generally better to add the prototype than to disable the warning.
The :c:macro:`PyMODEXPORT_FUNC` macro declares the function's
return type, and adds any special linkage declarations needed
to make the function visible and us... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
31d5b284-0336-4bd5-a5df-1dcc46c5e758 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 956 | supabase-export-v2 | c7cb92dac947c264 | .. _meson-python: https://mesonbuild.com/meson-python/ .. _virtual environment: https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/#create-and-use-virtual-environments
Note that you will need to run this command again every time you change your
extension. Unlike Python, C has an... | trusted_official_docs | CPython Docs | .. _meson-python: https://mesonbuild.com/meson-python/ .. _virtual environment: https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/#create-and-use-virtual-environments
Note that you will need to run this command again every time you change your
extension. Unlike Python, C has an... | .. _meson-python: https://mesonbuild.com/meson-python/ .. _virtual environment: https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/#create-and-use-virtual-environments
Note that you will need to run this command again every time you change your
extension. Unlike Python, C has an... | python, official-docs, cpython, P0 | Local_Trusted_Corpus |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.