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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
326c4986-aac0-4de5-806d-0b60cb1997eb | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 921 | supabase-export-v2 | c5bc5f52807acab8 | runs the argument as a system command, and returns a result value as an integer. A manual page for :c:func:`system` might summarize it this way::
#include <stdlib.h>
int system(const char *command); | trusted_official_docs | CPython Docs | runs the argument as a system command, and returns a result value as an integer. A manual page for :c:func:`system` might summarize it this way::
#include <stdlib.h>
int system(const char *command); | runs the argument as a system command, and returns a result value as an integer. A manual page for :c:func:`system` might summarize it this way::
#include <stdlib.h>
int system(const char *command); | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
358f2f83-1af4-4e4d-84cc-23dcdccc4386 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 936 | supabase-export-v2 | 43879aa14318e82d | This will ensure that your build tool works, so that you can make and test incremental changes as you follow the rest of the text.
CPython itself does not come with a tool to build extension modules;
it is recommended to use a third-party project for this. In this tutorial, we'll use `meson-python`_. (If you want to us... | trusted_official_docs | CPython Docs | This will ensure that your build tool works, so that you can make and test incremental changes as you follow the rest of the text.
CPython itself does not come with a tool to build extension modules;
it is recommended to use a third-party project for this. In this tutorial, we'll use `meson-python`_. (If you want to us... | This will ensure that your build tool works, so that you can make and test incremental changes as you follow the rest of the text.
CPython itself does not come with a tool to build extension modules;
it is recommended to use a third-party project for this. In this tutorial, we'll use `meson-python`_. (If you want to us... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
37265d8d-adfd-4aaa-a644-72f2427ddb40 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 1,039 | supabase-export-v2 | f8fdae82bd656adb | { const char *command = PyUnicode_AsUTF8AndSize(arg); if (command == NULL) { return NULL; } int status = 3; PyObject *result = PyLong_FromLong(status); return result; }
To test that error handling works, compile again, restart Python so that
``import spam`` picks up the new version of your module, and try passing
a non... | trusted_official_docs | CPython Docs | { const char *command = PyUnicode_AsUTF8AndSize(arg); if (command == NULL) { return NULL; } int status = 3; PyObject *result = PyLong_FromLong(status); return result; }
To test that error handling works, compile again, restart Python so that
``import spam`` picks up the new version of your module, and try passing
a non... | { const char *command = PyUnicode_AsUTF8AndSize(arg); if (command == NULL) { return NULL; } int status = 3; PyObject *result = PyLong_FromLong(status); return result; }
To test that error handling works, compile again, restart Python so that
``import spam`` picks up the new version of your module, and try passing
a non... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3825d105-f57b-4a4d-8497-86f92e44215e | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 938 | supabase-export-v2 | 983627939df58370 | .. at the time of writing, meson-python has the least overhead for a simple extension using PyModExport. Change this if another tool makes things easier.
``meson-python`` requires defining a "project" using two extra files. | trusted_official_docs | CPython Docs | .. at the time of writing, meson-python has the least overhead for a simple extension using PyModExport. Change this if another tool makes things easier.
``meson-python`` requires defining a "project" using two extra files. | .. at the time of writing, meson-python has the least overhead for a simple extension using PyModExport. Change this if another tool makes things easier.
``meson-python`` requires defining a "project" using two extra files. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
386c4c7e-15af-4485-8344-44a54fa67cab | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 1,077 | supabase-export-v2 | ce79f44130724a7e | ``FromLong`` refers to the C ``long`` (or ``long int``) type. .. [#why-pyunicodeasutf8] Here, ``PyUnicode`` refers to the original name of the Python :py:class:`str` class: ``unicode``.
The ``AndSize`` part of the name refers to the fact that this function can
also retrieve the size of the buffer, using an output argu... | trusted_official_docs | CPython Docs | ``FromLong`` refers to the C ``long`` (or ``long int``) type. .. [#why-pyunicodeasutf8] Here, ``PyUnicode`` refers to the original name of the Python :py:class:`str` class: ``unicode``.
The ``AndSize`` part of the name refers to the fact that this function can
also retrieve the size of the buffer, using an output argu... | ``FromLong`` refers to the C ``long`` (or ``long int``) type. .. [#why-pyunicodeasutf8] Here, ``PyUnicode`` refers to the original name of the Python :py:class:`str` class: ``unicode``.
The ``AndSize`` part of the name refers to the fact that this function can
also retrieve the size of the buffer, using an output argu... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3bc53505-44b2-4520-be9a-d17640b66fa2 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 982 | supabase-export-v2 | 25a4985115150e48 | needs to access the export hook; all global variables and all other functions should generally be ``static``, so that they don't clash with other extensions.
Return this array from your export hook instead of ``NULL``: | trusted_official_docs | CPython Docs | needs to access the export hook; all global variables and all other functions should generally be ``static``, so that they don't clash with other extensions.
Return this array from your export hook instead of ``NULL``: | needs to access the export hook; all global variables and all other functions should generally be ``static``, so that they don't clash with other extensions.
Return this array from your export hook instead of ``NULL``: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3ccc3d81-4c0c-4c8c-b4a1-036afaeabd27 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 955 | supabase-export-v2 | 480af4b1d2e89691 | run ``python -m ensurepip``, preferably in a :ref:`virtual environment <venv-def>`. (Or, if you prefer another tool that can build and install ``pyproject.toml``-based projects, use that.)
.. _meson-python: https://mesonbuild.com/meson-python/
.. _virtual environment: https://packaging.python.org/en/latest/guides/insta... | trusted_official_docs | CPython Docs | run ``python -m ensurepip``, preferably in a :ref:`virtual environment <venv-def>`. (Or, if you prefer another tool that can build and install ``pyproject.toml``-based projects, use that.)
.. _meson-python: https://mesonbuild.com/meson-python/
.. _virtual environment: https://packaging.python.org/en/latest/guides/insta... | run ``python -m ensurepip``, preferably in a :ref:`virtual environment <venv-def>`. (Or, if you prefer another tool that can build and install ``pyproject.toml``-based projects, use that.)
.. _meson-python: https://mesonbuild.com/meson-python/
.. _virtual environment: https://packaging.python.org/en/latest/guides/insta... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
42b6a359-f051-44f4-a029-6e5e1b8d399c | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 961 | supabase-export-v2 | 18ce121795a144c7 | Module export hook ==================
The exception you got when you tried to import the module told you that Python
is looking for a "module export function", also known as a
:ref:`module export hook <extension-export-hook>`. Let's define one. | trusted_official_docs | CPython Docs | Module export hook ==================
The exception you got when you tried to import the module told you that Python
is looking for a "module export function", also known as a
:ref:`module export hook <extension-export-hook>`. Let's define one. | Module export hook ==================
The exception you got when you tried to import the module told you that Python
is looking for a "module export function", also known as a
:ref:`module export hook <extension-export-hook>`. Let's define one. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
470b37f6-8666-4a04-807a-950894d7232d | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 981 | supabase-export-v2 | 787cb6f33f688aa4 | Note the zero-filled sentinel entry at the end. If you forget it, you'll trigger undefined behavior.
The array is defined as ``static`` -- that is, not visible outside this ``.c`` file. This will be a common theme. CPython only needs to access the export hook; all global variables
and all other functions should general... | trusted_official_docs | CPython Docs | Note the zero-filled sentinel entry at the end. If you forget it, you'll trigger undefined behavior.
The array is defined as ``static`` -- that is, not visible outside this ``.c`` file. This will be a common theme. CPython only needs to access the export hook; all global variables
and all other functions should general... | Note the zero-filled sentinel entry at the end. If you forget it, you'll trigger undefined behavior.
The array is defined as ``static`` -- that is, not visible outside this ``.c`` file. This will be a common theme. CPython only needs to access the export hook; all global variables
and all other functions should general... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4c722e80-0d8d-47b7-b6f3-ae970c2cf37a | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 1,036 | supabase-export-v2 | 0402d8110c31a3cc | do this in general is left for later chapters of this documentation. For now, be assured that we are already handling errors from :c:func:`PyLong_FromLong` correctly.
For the :c:func:`PyUnicode_AsUTF8AndSize` call, the correct way to handle
errors is returning ``NULL`` from ``spam_system``. Add an ``if`` block for this... | trusted_official_docs | CPython Docs | do this in general is left for later chapters of this documentation. For now, be assured that we are already handling errors from :c:func:`PyLong_FromLong` correctly.
For the :c:func:`PyUnicode_AsUTF8AndSize` call, the correct way to handle
errors is returning ``NULL`` from ``spam_system``. Add an ``if`` block for this... | do this in general is left for later chapters of this documentation. For now, be assured that we are already handling errors from :c:func:`PyLong_FromLong` correctly.
For the :c:func:`PyUnicode_AsUTF8AndSize` call, the correct way to handle
errors is returning ``NULL`` from ``spam_system``. Add an ``if`` block for this... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4dbe7b6d-2811-4859-9bfd-445039acfad6 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 1,034 | supabase-export-v2 | cfeddfac4fe83ef4 | of bytes [#embedded-nul]_. This buffer is managed by the *arg* object, which means we don't need to free it, but we must follow some rules:
* We should only use the buffer inside the ``spam_system`` function. After ``spam_system`` returns, *arg* and the buffer it manages might be
garbage-collected. * We must not modif... | trusted_official_docs | CPython Docs | of bytes [#embedded-nul]_. This buffer is managed by the *arg* object, which means we don't need to free it, but we must follow some rules:
* We should only use the buffer inside the ``spam_system`` function. After ``spam_system`` returns, *arg* and the buffer it manages might be
garbage-collected. * We must not modif... | of bytes [#embedded-nul]_. This buffer is managed by the *arg* object, which means we don't need to free it, but we must follow some rules:
* We should only use the buffer inside the ``spam_system`` function. After ``spam_system`` returns, *arg* and the buffer it manages might be
garbage-collected. * We must not modif... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4e548a7f-16f8-4678-a261-7174b8eb24d9 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 910 | supabase-export-v2 | 3161c35e55964827 | 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>`.
The tutorial assumes basic knowledge about Python: you should be able to
define functions in Python code before starting to write them in C. See :ref:`tutorial-index`... | trusted_official_docs | CPython Docs | 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>`.
The tutorial assumes basic knowledge about Python: you should be able to
define functions in Python code before starting to write them in C. See :ref:`tutorial-index`... | 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>`.
The tutorial assumes basic knowledge about Python: you should be able to
define functions in Python code before starting to write them in C. See :ref:`tutorial-index`... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4fa37f2f-bb04-4ff9-a00d-77273b524fda | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 917 | supabase-export-v2 | 05aa2575d0876dea | .. note::
This tutorial uses APIs that were added in CPython 3.15. To create an extension that's compatible with earlier versions of CPython,
please follow an earlier version of this documentation. | trusted_official_docs | CPython Docs | .. note::
This tutorial uses APIs that were added in CPython 3.15. To create an extension that's compatible with earlier versions of CPython,
please follow an earlier version of this documentation. | .. note::
This tutorial uses APIs that were added in CPython 3.15. To create an extension that's compatible with earlier versions of CPython,
please follow an earlier version of this documentation. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
56433fa4-ff72-4b4f-a13d-1f758de41a6d | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 1,045 | supabase-export-v2 | d423bfe236286e56 | { const char *command = PyUnicode_AsUTF8AndSize(arg); if (command == NULL) { return NULL; } int status = system(command); PyObject *result = PyLong_FromLong(status); return result; }
Compile your module, restart Python, and test. This time, you should see your username -- the output of the ``whoami``
system command: | trusted_official_docs | CPython Docs | { const char *command = PyUnicode_AsUTF8AndSize(arg); if (command == NULL) { return NULL; } int status = system(command); PyObject *result = PyLong_FromLong(status); return result; }
Compile your module, restart Python, and test. This time, you should see your username -- the output of the ``whoami``
system command: | { const char *command = PyUnicode_AsUTF8AndSize(arg); if (command == NULL) { return NULL; } int status = system(command); PyObject *result = PyLong_FromLong(status); return result; }
Compile your module, restart Python, and test. This time, you should see your username -- the output of the ``whoami``
system command: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
56eacfe5-0648-4fb1-8912-49f19fdfd5b1 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 1,059 | supabase-export-v2 | 053daea167be04b5 | You should be able to follow this tutorial -- except the *Running your build tool* section itself -- with a build tool other than ``meson-python``.
The Python Packaging User Guide has a `list of recommended tools <https://packaging.python.org/en/latest/guides/tool-recommendations/#build-backends-for-extension-modules>`... | trusted_official_docs | CPython Docs | You should be able to follow this tutorial -- except the *Running your build tool* section itself -- with a build tool other than ``meson-python``.
The Python Packaging User Guide has a `list of recommended tools <https://packaging.python.org/en/latest/guides/tool-recommendations/#build-backends-for-extension-modules>`... | You should be able to follow this tutorial -- except the *Running your build tool* section itself -- with a build tool other than ``meson-python``.
The Python Packaging User Guide has a `list of recommended tools <https://packaging.python.org/en/latest/guides/tool-recommendations/#build-backends-for-extension-modules>`... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5a52908a-8c42-4ec7-af6c-8b6bb85c6267 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 1,007 | supabase-export-v2 | 3c3866430980e95d | .. literalinclude:: ../includes/capi-extension/spammodule-01.c :start-after: /// Module slot table :end-before: /// :emphasize-lines: 5
Recompile your extension again, and test it. Be sure to restart the Python interpreter, so that ``import spam`` picks
up the new version of the module. | trusted_official_docs | CPython Docs | .. literalinclude:: ../includes/capi-extension/spammodule-01.c :start-after: /// Module slot table :end-before: /// :emphasize-lines: 5
Recompile your extension again, and test it. Be sure to restart the Python interpreter, so that ``import spam`` picks
up the new version of the module. | .. literalinclude:: ../includes/capi-extension/spammodule-01.c :start-after: /// Module slot table :end-before: /// :emphasize-lines: 5
Recompile your extension again, and test it. Be sure to restart the Python interpreter, so that ``import spam`` picks
up the new version of the module. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5c0535b7-395d-4236-87bd-0de02c2bd2c7 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 1,002 | supabase-export-v2 | f553eb5f9ff1e2c2 | describing details like how Python arguments are passed to the C function. We'll use :c:data:`METH_O` here -- the flag that matches our ``spam_system`` function's signature.
Because modules typically create several functions, these definitions
need to be collected in an array, with a zero-filled sentinel at the end. Ad... | trusted_official_docs | CPython Docs | describing details like how Python arguments are passed to the C function. We'll use :c:data:`METH_O` here -- the flag that matches our ``spam_system`` function's signature.
Because modules typically create several functions, these definitions
need to be collected in an array, with a zero-filled sentinel at the end. Ad... | describing details like how Python arguments are passed to the C function. We'll use :c:data:`METH_O` here -- the flag that matches our ``spam_system`` function's signature.
Because modules typically create several functions, these definitions
need to be collected in an array, with a zero-filled sentinel at the end. Ad... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
618f359e-d481-40a2-b488-31feb472451c | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 1,044 | supabase-export-v2 | e947863232d5d587 | .. code-block:: c :emphasize-lines: 8
static PyObject *
spam_system(PyObject *self, PyObject *arg)
{
const char *command = PyUnicode_AsUTF8AndSize(arg);
if (command == NULL) {
return NULL;
}
int status = system(command);
PyObject *result = PyLong_FromLong(status);
return result;
} | trusted_official_docs | CPython Docs | .. code-block:: c :emphasize-lines: 8
static PyObject *
spam_system(PyObject *self, PyObject *arg)
{
const char *command = PyUnicode_AsUTF8AndSize(arg);
if (command == NULL) {
return NULL;
}
int status = system(command);
PyObject *result = PyLong_FromLong(status);
return result;
} | .. code-block:: c :emphasize-lines: 8
static PyObject *
spam_system(PyObject *self, PyObject *arg)
{
const char *command = PyUnicode_AsUTF8AndSize(arg);
if (command == NULL) {
return NULL;
}
int status = system(command);
PyObject *result = PyLong_FromLong(status);
return result;
} | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6c328329-38b4-42d7-83b2-e6346e109a09 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 1,028 | supabase-export-v2 | 7e723c4bddde240e | 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.
The other one, ``PyObject *arg``, will be set to the object that the user
passed from Python. We expect that it should be a Python string. In order to use the information in it... | trusted_official_docs | CPython Docs | 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.
The other one, ``PyObject *arg``, will be set to the object that the user
passed from Python. We expect that it should be a Python string. In order to use the information in it... | 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.
The other one, ``PyObject *arg``, will be set to the object that the user
passed from Python. We expect that it should be a Python string. In order to use the information in it... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6dfbd96b-fa36-4231-b926-45e14338b11c | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 1,042 | supabase-export-v2 | 42749cc7455ce591 | >>> import spam >>> spam.system(3) Traceback (most recent call last): ... TypeError: bad argument type for built-in operation
Now, all that is left is calling the C library function :c:func:`system` with
the ``char *`` buffer, and using its result instead of the ``3``: | trusted_official_docs | CPython Docs | >>> import spam >>> spam.system(3) Traceback (most recent call last): ... TypeError: bad argument type for built-in operation
Now, all that is left is calling the C library function :c:func:`system` with
the ``char *`` buffer, and using its result instead of the ``3``: | >>> import spam >>> spam.system(3) Traceback (most recent call last): ... TypeError: bad argument type for built-in operation
Now, all that is left is calling the C library function :c:func:`system` with
the ``char *`` buffer, and using its result instead of the ``3``: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6fc4442f-28fd-41e4-9d64-4903594f9735 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 1,065 | supabase-export-v2 | 6077cfdbb4fdef2c | CPython 3.14 and below. Current CPython does not need it, but some build tools may still assume that all extension modules need to define it.
If you use this workaround, you will get the exception
``SystemError: initialization of spam failed without raising an exception``
instead of
``ImportError: dynamic module does n... | trusted_official_docs | CPython Docs | CPython 3.14 and below. Current CPython does not need it, but some build tools may still assume that all extension modules need to define it.
If you use this workaround, you will get the exception
``SystemError: initialization of spam failed without raising an exception``
instead of
``ImportError: dynamic module does n... | CPython 3.14 and below. Current CPython does not need it, but some build tools may still assume that all extension modules need to define it.
If you use this workaround, you will get the exception
``SystemError: initialization of spam failed without raising an exception``
instead of
``ImportError: dynamic module does n... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6ff80ba3-28e0-4563-875f-b098b88e2129 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 914 | supabase-export-v2 | 230a178004bc877c | Unix-like system (including macOS and Linux), or Windows. On other systems, you might need to adjust some details -- for example, a system command name.
You need to have a suitable C compiler and Python development headers installed. On Linux, headers are often in a package like ``python3-dev``
or ``python3-devel``. | trusted_official_docs | CPython Docs | Unix-like system (including macOS and Linux), or Windows. On other systems, you might need to adjust some details -- for example, a system command name.
You need to have a suitable C compiler and Python development headers installed. On Linux, headers are often in a package like ``python3-dev``
or ``python3-devel``. | Unix-like system (including macOS and Linux), or Windows. On other systems, you might need to adjust some details -- for example, a system command name.
You need to have a suitable C compiler and Python development headers installed. On Linux, headers are often in a package like ``python3-dev``
or ``python3-devel``. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
71255539-927a-4f93-83d3-ed78451e8abc | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 937 | supabase-export-v2 | 5ca9f376647c4089 | it is recommended to use a third-party project for this. In this tutorial, we'll use `meson-python`_. (If you want to use another one, see :ref:`first-extension-other-tools`.)
.. at the time of writing, meson-python has the least overhead for a
simple extension using PyModExport. Change this if another tool makes thin... | trusted_official_docs | CPython Docs | it is recommended to use a third-party project for this. In this tutorial, we'll use `meson-python`_. (If you want to use another one, see :ref:`first-extension-other-tools`.)
.. at the time of writing, meson-python has the least overhead for a
simple extension using PyModExport. Change this if another tool makes thin... | it is recommended to use a third-party project for this. In this tutorial, we'll use `meson-python`_. (If you want to use another one, see :ref:`first-extension-other-tools`.)
.. at the time of writing, meson-python has the least overhead for a
simple extension using PyModExport. Change this if another tool makes thin... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
78692113-dc17-4179-9998-803d491bfccc | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 957 | supabase-export-v2 | 3fe1d5ee92e0141e | Note that you will need to run this command again every time you change your extension. Unlike Python, C has an explicit compilation step.
When your extension is compiled and installed, start Python and try to
import it. This should fail with the following exception: | trusted_official_docs | CPython Docs | Note that you will need to run this command again every time you change your extension. Unlike Python, C has an explicit compilation step.
When your extension is compiled and installed, start Python and try to
import it. This should fail with the following exception: | Note that you will need to run this command again every time you change your extension. Unlike Python, C has an explicit compilation step.
When your extension is compiled and installed, start Python and try to
import it. This should fail with the following exception: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
798e59e1-6c5c-48db-b441-8fa9d5da18cc | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 1,068 | supabase-export-v2 | cae54cface6920f8 | as it will take care of various details of your platform and Python installation, of naming the resulting extension, and, later, of distributing your work.
If you are building an extension for as *specific* system, or for yourself
only, you might instead want to run your compiler directly. The way to do this is system-... | trusted_official_docs | CPython Docs | as it will take care of various details of your platform and Python installation, of naming the resulting extension, and, later, of distributing your work.
If you are building an extension for as *specific* system, or for yourself
only, you might instead want to run your compiler directly. The way to do this is system-... | as it will take care of various details of your platform and Python installation, of naming the resulting extension, and, later, of distributing your work.
If you are building an extension for as *specific* system, or for yourself
only, you might instead want to run your compiler directly. The way to do this is system-... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
7aa097c8-b7e6-4cb6-bd18-3708054de4c5 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 1,018 | supabase-export-v2 | 8714e99961c1dff8 | The Python C API provides a function to create a Python :py:type:`int` object from a C ``int`` value: :c:func:`PyLong_FromLong`. [#why-pylongfromlong]_
To call it, replace the ``Py_RETURN_NONE`` with the following 3 lines: | trusted_official_docs | CPython Docs | The Python C API provides a function to create a Python :py:type:`int` object from a C ``int`` value: :c:func:`PyLong_FromLong`. [#why-pylongfromlong]_
To call it, replace the ``Py_RETURN_NONE`` with the following 3 lines: | The Python C API provides a function to create a Python :py:type:`int` object from a C ``int`` value: :c:func:`PyLong_FromLong`. [#why-pylongfromlong]_
To call it, replace the ``Py_RETURN_NONE`` with the following 3 lines: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
7e370f99-8fd3-44ed-adde-8ba172c4f6f0 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 935 | supabase-export-v2 | 9cd71277ec22bc75 | Running your build tool =======================
With only the includes in place, your extension won't do anything. Still, it's a good time to compile it and try to import it. This will ensure that your build tool works, so that you can make
and test incremental changes as you follow the rest of the text. | trusted_official_docs | CPython Docs | Running your build tool =======================
With only the includes in place, your extension won't do anything. Still, it's a good time to compile it and try to import it. This will ensure that your build tool works, so that you can make
and test incremental changes as you follow the rest of the text. | Running your build tool =======================
With only the includes in place, your extension won't do anything. Still, it's a good time to compile it and try to import it. This will ensure that your build tool works, so that you can make
and test incremental changes as you follow the rest of the text. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
7f66f51e-cc49-412d-b80b-736f3ee536c9 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 1,058 | supabase-export-v2 | 309a8204bdffb4f6 | Appendix: Other build tools ===========================
You should be able to follow this tutorial -- except the
*Running your build tool* section itself -- with a build tool other
than ``meson-python``. | trusted_official_docs | CPython Docs | Appendix: Other build tools ===========================
You should be able to follow this tutorial -- except the
*Running your build tool* section itself -- with a build tool other
than ``meson-python``. | Appendix: Other build tools ===========================
You should be able to follow this tutorial -- except the
*Running your build tool* section itself -- with a build tool other
than ``meson-python``. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
806413ef-258b-4146-9a0f-91eff09d3ea2 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 980 | supabase-export-v2 | 45b9cfecb124951a | 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.
Note the zero-filled sentinel entry at the end. If you forget it, you'll trigger undefined behavior. | trusted_official_docs | CPython Docs | 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.
Note the zero-filled sentinel entry at the end. If you forget it, you'll trigger undefined behavior. | 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.
Note the zero-filled sentinel entry at the end. If you forget it, you'll trigger undefined behavior. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
884049b7-d52b-4c91-9338-a8cab119c596 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 975 | supabase-export-v2 | 654e49f6f69015b7 | Rather than ``NULL``, the export hook should return the information needed to create a module. Let's start with the basics: the name and docstring.
The information should be defined in a ``static`` array of
:c:type:`PyModuleDef_Slot` entries, which are essentially key-value pairs. Define this array just before your exp... | trusted_official_docs | CPython Docs | Rather than ``NULL``, the export hook should return the information needed to create a module. Let's start with the basics: the name and docstring.
The information should be defined in a ``static`` array of
:c:type:`PyModuleDef_Slot` entries, which are essentially key-value pairs. Define this array just before your exp... | Rather than ``NULL``, the export hook should return the information needed to create a module. Let's start with the basics: the name and docstring.
The information should be defined in a ``static`` array of
:c:type:`PyModuleDef_Slot` entries, which are essentially key-value pairs. Define this array just before your exp... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
88f46846-0208-4679-a960-ba3fd7e7bb51 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 930 | supabase-export-v2 | 6aa48d268225caeb | 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]_
In this file, we'll include two headers: :file:`Python.h` to pull in
all declarations of the Python C API, and :file:`stdlib.h` for the
:c:func:`system... | trusted_official_docs | CPython Docs | 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]_
In this file, we'll include two headers: :file:`Python.h` to pull in
all declarations of the Python C API, and :file:`stdlib.h` for the
:c:func:`system... | 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]_
In this file, we'll include two headers: :file:`Python.h` to pull in
all declarations of the Python C API, and :file:`stdlib.h` for the
:c:func:`system... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
94753300-2b01-4ae6-badd-cfd350b273ea | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 1,070 | supabase-export-v2 | 68b3fb87faaa7c30 | Linux ^^^^^
On Linux, the Python development package may include a ``python3-config``
command that prints out the required compiler flags. If you use it, check that it corresponds to the CPython interpreter you'll use
to load the module. Then, start with the following command: | trusted_official_docs | CPython Docs | Linux ^^^^^
On Linux, the Python development package may include a ``python3-config``
command that prints out the required compiler flags. If you use it, check that it corresponds to the CPython interpreter you'll use
to load the module. Then, start with the following command: | Linux ^^^^^
On Linux, the Python development package may include a ``python3-config``
command that prints out the required compiler flags. If you use it, check that it corresponds to the CPython interpreter you'll use
to load the module. Then, start with the following command: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
94edef34-0f00-44b6-a059-0122aa5292cf | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 962 | supabase-export-v2 | 15adcc012e5512c7 | import the module told you that Python is looking for a "module export function", also known as a :ref:`module export hook <extension-export-hook>`. Let's define one.
First, add a prototype below the ``#include`` lines: | trusted_official_docs | CPython Docs | import the module told you that Python is looking for a "module export function", also known as a :ref:`module export hook <extension-export-hook>`. Let's define one.
First, add a prototype below the ``#include`` lines: | import the module told you that Python is looking for a "module export function", also known as a :ref:`module export hook <extension-export-hook>`. Let's define one.
First, add a prototype below the ``#include`` lines: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
95ae763b-bfe3-43f8-908f-ee3a53609d8d | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 1,030 | supabase-export-v2 | e8466ce88fec35e8 | (UTF-8 might not always be correct for system commands, but it's what :py:meth:`str.encode` uses by default, and the C API has special support for it.)
The function to encode a Python string into a UTF-8 buffer is named
:c:func:`PyUnicode_AsUTF8AndSize` [#why-pyunicodeasutf8]_. Call it like this: | trusted_official_docs | CPython Docs | (UTF-8 might not always be correct for system commands, but it's what :py:meth:`str.encode` uses by default, and the C API has special support for it.)
The function to encode a Python string into a UTF-8 buffer is named
:c:func:`PyUnicode_AsUTF8AndSize` [#why-pyunicodeasutf8]_. Call it like this: | (UTF-8 might not always be correct for system commands, but it's what :py:meth:`str.encode` uses by default, and the C API has special support for it.)
The function to encode a Python string into a UTF-8 buffer is named
:c:func:`PyUnicode_AsUTF8AndSize` [#why-pyunicodeasutf8]_. Call it like this: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
976b8c8b-47ed-4140-b446-bc245e2a031b | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 1,035 | supabase-export-v2 | d7822d842d6df820 | function. After ``spam_system`` returns, *arg* and the buffer it manages might be garbage-collected. * We must not modify it. This is why we use ``const``.
If :c:func:`PyUnicode_AsUTF8AndSize` was *not* successful, it returns a ``NULL``
pointer. When calling *any* Python C API, we always need to handle such error cases... | trusted_official_docs | CPython Docs | function. After ``spam_system`` returns, *arg* and the buffer it manages might be garbage-collected. * We must not modify it. This is why we use ``const``.
If :c:func:`PyUnicode_AsUTF8AndSize` was *not* successful, it returns a ``NULL``
pointer. When calling *any* Python C API, we always need to handle such error cases... | function. After ``spam_system`` returns, *arg* and the buffer it manages might be garbage-collected. * We must not modify it. This is why we use ``const``.
If :c:func:`PyUnicode_AsUTF8AndSize` was *not* successful, it returns a ``NULL``
pointer. When calling *any* Python C API, we always need to handle such error cases... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9de8a75c-e481-42c8-bc98-4516fc31009e | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 1,038 | supabase-export-v2 | c483518ac3e7284f | .. code-block:: c :emphasize-lines: 5-7
static PyObject *
spam_system(PyObject *self, PyObject *arg)
{
const char *command = PyUnicode_AsUTF8AndSize(arg);
if (command == NULL) {
return NULL;
}
int status = 3;
PyObject *result = PyLong_FromLong(status);
return result;
} | trusted_official_docs | CPython Docs | .. code-block:: c :emphasize-lines: 5-7
static PyObject *
spam_system(PyObject *self, PyObject *arg)
{
const char *command = PyUnicode_AsUTF8AndSize(arg);
if (command == NULL) {
return NULL;
}
int status = 3;
PyObject *result = PyLong_FromLong(status);
return result;
} | .. code-block:: c :emphasize-lines: 5-7
static PyObject *
spam_system(PyObject *self, PyObject *arg)
{
const char *command = PyUnicode_AsUTF8AndSize(arg);
if (command == NULL) {
return NULL;
}
int status = 3;
PyObject *result = PyLong_FromLong(status);
return result;
} | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a28f64cd-f8a0-47e2-b329-a5754beb4f97 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 1,075 | supabase-export-v2 | 70dedd59354a2e60 | .. rubric:: Footnotes
.. [#why-spam] ``spam`` is the favorite food of Monty Python fans... .. [#why-spammodule] The source file name is entirely up to you,
though some tools can be picky about the ``.c`` extension. This tutorial uses the traditional ``*module.c`` suffix. Some people would just use :file:`spam.c` to im... | trusted_official_docs | CPython Docs | .. rubric:: Footnotes
.. [#why-spam] ``spam`` is the favorite food of Monty Python fans... .. [#why-spammodule] The source file name is entirely up to you,
though some tools can be picky about the ``.c`` extension. This tutorial uses the traditional ``*module.c`` suffix. Some people would just use :file:`spam.c` to im... | .. rubric:: Footnotes
.. [#why-spam] ``spam`` is the favorite food of Monty Python fans... .. [#why-spammodule] The source file name is entirely up to you,
though some tools can be picky about the ``.c`` extension. This tutorial uses the traditional ``*module.c`` suffix. Some people would just use :file:`spam.c` to im... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a48b7af2-37d0-49ab-921a-bcbc0cabfb71 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 911 | supabase-export-v2 | 5c64ef701b0261df | you should be able to define functions in Python code before starting to write them in C. See :ref:`tutorial-index` for an introduction to Python itself.
The tutorial should be approachable for anyone who can write a basic C library. While we will mention several concepts that a C beginner would not be expected
to know... | trusted_official_docs | CPython Docs | you should be able to define functions in Python code before starting to write them in C. See :ref:`tutorial-index` for an introduction to Python itself.
The tutorial should be approachable for anyone who can write a basic C library. While we will mention several concepts that a C beginner would not be expected
to know... | you should be able to define functions in Python code before starting to write them in C. See :ref:`tutorial-index` for an introduction to Python itself.
The tutorial should be approachable for anyone who can write a basic C library. While we will mention several concepts that a C beginner would not be expected
to know... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a653eebd-96ad-40ad-a883-429e06bca82f | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 1,076 | supabase-export-v2 | 46fae48bb57ce523 | to explicitly include what you need. .. [#why-pymethoddef] The :c:type:`!PyMethodDef` structure is also used to create methods of classes, so there's no separate ":c:type:`!PyFunctionDef`". ..
[#why-pylongfromlong] The name :c:func:`PyLong_FromLong`
might not seem obvious. ``PyLong`` refers to a the Python :py:class:`... | trusted_official_docs | CPython Docs | to explicitly include what you need. .. [#why-pymethoddef] The :c:type:`!PyMethodDef` structure is also used to create methods of classes, so there's no separate ":c:type:`!PyFunctionDef`". ..
[#why-pylongfromlong] The name :c:func:`PyLong_FromLong`
might not seem obvious. ``PyLong`` refers to a the Python :py:class:`... | to explicitly include what you need. .. [#why-pymethoddef] The :c:type:`!PyMethodDef` structure is also used to create methods of classes, so there's no separate ":c:type:`!PyFunctionDef`". ..
[#why-pylongfromlong] The name :c:func:`PyLong_FromLong`
might not seem obvious. ``PyLong`` refers to a the Python :py:class:`... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a6c24dbb-b73c-43bc-b0d5-e7452b2dd21a | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 923 | supabase-export-v2 | d5e2e6694cc5b78b | in the C standard library, this function is already exposed in Python. In production, use :py:func:`os.system` or :py:func:`subprocess.run` rather than the module you'll write here.
We want this function to be callable from Python as follows: | trusted_official_docs | CPython Docs | in the C standard library, this function is already exposed in Python. In production, use :py:func:`os.system` or :py:func:`subprocess.run` rather than the module you'll write here.
We want this function to be callable from Python as follows: | in the C standard library, this function is already exposed in Python. In production, use :py:func:`os.system` or :py:func:`subprocess.run` rather than the module you'll write here.
We want this function to be callable from Python as follows: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
acc2f551-b29e-43b9-af41-70bd6b1a158d | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 972 | supabase-export-v2 | 5e4948f306efdace | >>> import spam Traceback (most recent call last): ... SystemError: module export hook for module 'spam' failed without setting an exception
Simply returning ``NULL`` is *not* correct behavior for an export hook,
and CPython complains about it. That's good -- it means that CPython found the function! Let's now make it ... | trusted_official_docs | CPython Docs | >>> import spam Traceback (most recent call last): ... SystemError: module export hook for module 'spam' failed without setting an exception
Simply returning ``NULL`` is *not* correct behavior for an export hook,
and CPython complains about it. That's good -- it means that CPython found the function! Let's now make it ... | >>> import spam Traceback (most recent call last): ... SystemError: module export hook for module 'spam' failed without setting an exception
Simply returning ``NULL`` is *not* correct behavior for an export hook,
and CPython complains about it. That's good -- it means that CPython found the function! Let's now make it ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ad44e73e-60ef-4833-92ef-a302bd673f83 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 994 | supabase-export-v2 | 6c424ab17b3c4a70 | Python objects and returns one. All Python objects -- regardless of the Python type -- are represented in C as pointers to the :c:type:`PyObject` structure.
Add such a function above the slots array:: | trusted_official_docs | CPython Docs | Python objects and returns one. All Python objects -- regardless of the Python type -- are represented in C as pointers to the :c:type:`PyObject` structure.
Add such a function above the slots array:: | Python objects and returns one. All Python objects -- regardless of the Python type -- are represented in C as pointers to the :c:type:`PyObject` structure.
Add such a function above the slots array:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b0e5aa43-0fb5-44c7-b18f-d798fc6c3328 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 931 | supabase-export-v2 | 823f426261e40039 | In this file, we'll include two headers: :file:`Python.h` to pull in all declarations of the Python C API, and :file:`stdlib.h` for the :c:func:`system` function. [#stdlib-h]_
Add the following lines to :file:`spammodule.c`: | trusted_official_docs | CPython Docs | In this file, we'll include two headers: :file:`Python.h` to pull in all declarations of the Python C API, and :file:`stdlib.h` for the :c:func:`system` function. [#stdlib-h]_
Add the following lines to :file:`spammodule.c`: | In this file, we'll include two headers: :file:`Python.h` to pull in all declarations of the Python C API, and :file:`stdlib.h` for the :c:func:`system` function. [#stdlib-h]_
Add the following lines to :file:`spammodule.c`: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b7b2bd32-5c8e-4c12-ae6e-27f123dfd68d | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 954 | supabase-export-v2 | f8f038d1e5c33bca | .. tip::
If you don't have ``pip`` installed, run ``python -m ensurepip``,
preferably in a :ref:`virtual environment <venv-def>`. (Or, if you prefer another tool that can build and install
``pyproject.toml``-based projects, use that.) | trusted_official_docs | CPython Docs | .. tip::
If you don't have ``pip`` installed, run ``python -m ensurepip``,
preferably in a :ref:`virtual environment <venv-def>`. (Or, if you prefer another tool that can build and install
``pyproject.toml``-based projects, use that.) | .. tip::
If you don't have ``pip`` installed, run ``python -m ensurepip``,
preferably in a :ref:`virtual environment <venv-def>`. (Or, if you prefer another tool that can build and install
``pyproject.toml``-based projects, use that.) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c3200a25-c209-49f5-88f9-6b685766fca2 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 993 | supabase-export-v2 | ab478620e454fd72 | need to write a layer of glue code to convert arguments from Python objects to C values, and the C return value back to Python.
One of the simplest ways to write glue code is a ":c:data:`METH_O`" function,
which takes two Python objects and returns one. All Python objects -- regardless of the Python type -- are represe... | trusted_official_docs | CPython Docs | need to write a layer of glue code to convert arguments from Python objects to C values, and the C return value back to Python.
One of the simplest ways to write glue code is a ":c:data:`METH_O`" function,
which takes two Python objects and returns one. All Python objects -- regardless of the Python type -- are represe... | need to write a layer of glue code to convert arguments from Python objects to C values, and the C return value back to Python.
One of the simplest ways to write glue code is a ":c:data:`METH_O`" function,
which takes two Python objects and returns one. All Python objects -- regardless of the Python type -- are represe... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ca90944b-f7c8-438d-90b6-2157b747b2db | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 1,017 | supabase-export-v2 | ed342abaabcb7355 | 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``.
The Python C API provides a function to create a Python :py:type:`int` object
from a C ``int`` value: :c:func:`PyLong_FromLong`. [#why-pylongfromlong]_ | trusted_official_docs | CPython Docs | 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``.
The Python C API provides a function to create a Python :py:type:`int` object
from a C ``int`` value: :c:func:`PyLong_FromLong`. [#why-pylongfromlong]_ | 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``.
The Python C API provides a function to create a Python :py:type:`int` object
from a C ``int`` value: :c:func:`PyLong_FromLong`. [#why-pylongfromlong]_ | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
cb6b3edb-51ee-4a7f-8d60-d231cf612e20 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 1,033 | supabase-export-v2 | 318508b87a2e7ea8 | static PyObject * spam_system(PyObject *self, PyObject *arg) { const char *command = PyUnicode_AsUTF8AndSize(arg, NULL); int status = 3; PyObject *result = PyLong_FromLong(status); return result; }
If :c:func:`PyUnicode_AsUTF8AndSize` is successful, *command* will point to the
resulting C string -- a zero-terminated ar... | trusted_official_docs | CPython Docs | static PyObject * spam_system(PyObject *self, PyObject *arg) { const char *command = PyUnicode_AsUTF8AndSize(arg, NULL); int status = 3; PyObject *result = PyLong_FromLong(status); return result; }
If :c:func:`PyUnicode_AsUTF8AndSize` is successful, *command* will point to the
resulting C string -- a zero-terminated ar... | static PyObject * spam_system(PyObject *self, PyObject *arg) { const char *command = PyUnicode_AsUTF8AndSize(arg, NULL); int status = 3; PyObject *result = PyLong_FromLong(status); return result; }
If :c:func:`PyUnicode_AsUTF8AndSize` is successful, *command* will point to the
resulting C string -- a zero-terminated ar... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
cc9bb328-1fc2-420c-9caa-8edf821ed1a0 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 1,003 | supabase-export-v2 | 32ecfbe522fd2dcd | functions, these definitions need to be collected in an array, with a zero-filled sentinel at the end. Add this array just below the ``spam_system`` function:
.. literalinclude:: ../includes/capi-extension/spammodule-01.c
:start-after: /// Module method table
:end-before: /// | trusted_official_docs | CPython Docs | functions, these definitions need to be collected in an array, with a zero-filled sentinel at the end. Add this array just below the ``spam_system`` function:
.. literalinclude:: ../includes/capi-extension/spammodule-01.c
:start-after: /// Module method table
:end-before: /// | functions, these definitions need to be collected in an array, with a zero-filled sentinel at the end. Add this array just below the ``spam_system`` function:
.. literalinclude:: ../includes/capi-extension/spammodule-01.c
:start-after: /// Module method table
:end-before: /// | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
cf3ab811-2506-4082-b148-22bae0044e8e | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 997 | supabase-export-v2 | 22e1bc737317650d | 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.
Recompile your extension to make sure you don't have syntax errors. We haven't yet added ``spam_system`` to the module, so you might get a
warning... | trusted_official_docs | CPython Docs | 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.
Recompile your extension to make sure you don't have syntax errors. We haven't yet added ``spam_system`` to the module, so you might get a
warning... | 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.
Recompile your extension to make sure you don't have syntax errors. We haven't yet added ``spam_system`` to the module, so you might get a
warning... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d19f4c27-bd6b-415e-aa04-5f5d50ac69fa | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 933 | supabase-export-v2 | 9a8e5a23430346e4 | .. literalinclude:: ../includes/capi-extension/spammodule-01.c :start-at: <Python.h> :end-at: <stdlib.h>
Be sure to put :file:`stdlib.h`, and any other standard library includes,
*after* :file:`Python.h`. On some systems, Python may define some pre-processor definitions
that affect the standard headers. | trusted_official_docs | CPython Docs | .. literalinclude:: ../includes/capi-extension/spammodule-01.c :start-at: <Python.h> :end-at: <stdlib.h>
Be sure to put :file:`stdlib.h`, and any other standard library includes,
*after* :file:`Python.h`. On some systems, Python may define some pre-processor definitions
that affect the standard headers. | .. literalinclude:: ../includes/capi-extension/spammodule-01.c :start-at: <Python.h> :end-at: <stdlib.h>
Be sure to put :file:`stdlib.h`, and any other standard library includes,
*after* :file:`Python.h`. On some systems, Python may define some pre-processor definitions
that affect the standard headers. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d2de9045-3244-43ed-add4-ae3b997142e2 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 934 | supabase-export-v2 | 2ce49ea91b22a211 | to put :file:`stdlib.h`, and any other standard library includes, *after* :file:`Python.h`. On some systems, Python may define some pre-processor definitions that affect the standard headers.
Running your build tool
======================= | trusted_official_docs | CPython Docs | to put :file:`stdlib.h`, and any other standard library includes, *after* :file:`Python.h`. On some systems, Python may define some pre-processor definitions that affect the standard headers.
Running your build tool
======================= | to put :file:`stdlib.h`, and any other standard library includes, *after* :file:`Python.h`. On some systems, Python may define some pre-processor definitions that affect the standard headers.
Running your build tool
======================= | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d46512c5-c761-45ef-9822-c2c4d7ef0d0f | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 1,001 | supabase-export-v2 | a02ee4243f87588c | To expose the C function to Python, you will need to provide several pieces of information in a structure called :c:type:`PyMethodDef` [#why-pymethoddef]_:
* ``ml_name``: the name of the Python function;
* ``ml_doc``: a docstring;
* ``ml_meth``: the C function to be called; and
* ``ml_flags``: a set of flags describing... | trusted_official_docs | CPython Docs | To expose the C function to Python, you will need to provide several pieces of information in a structure called :c:type:`PyMethodDef` [#why-pymethoddef]_:
* ``ml_name``: the name of the Python function;
* ``ml_doc``: a docstring;
* ``ml_meth``: the C function to be called; and
* ``ml_flags``: a set of flags describing... | To expose the C function to Python, you will need to provide several pieces of information in a structure called :c:type:`PyMethodDef` [#why-pymethoddef]_:
* ``ml_name``: the name of the Python function;
* ``ml_doc``: a docstring;
* ``ml_meth``: the C function to be called; and
* ``ml_flags``: a set of flags describing... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d71a7488-9ef1-4fd0-ba42-bba23e987804 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 920 | supabase-export-v2 | d9f6717a7c55422b | What we'll do =============
Let's create an extension module called ``spam`` [#why-spam]_,
which will include a Python interface to the C
standard library function :c:func:`system`. This function is defined in ``stdlib.h``. It takes a C string as argument, runs the argument as a system
command, and returns a result val... | trusted_official_docs | CPython Docs | What we'll do =============
Let's create an extension module called ``spam`` [#why-spam]_,
which will include a Python interface to the C
standard library function :c:func:`system`. This function is defined in ``stdlib.h``. It takes a C string as argument, runs the argument as a system
command, and returns a result val... | What we'll do =============
Let's create an extension module called ``spam`` [#why-spam]_,
which will include a Python interface to the C
standard library function :c:func:`system`. This function is defined in ``stdlib.h``. It takes a C string as argument, runs the argument as a system
command, and returns a result val... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d7ce28fb-ef7b-4a85-b73b-7d2e5d1267a2 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 1,022 | supabase-export-v2 | a345d1c57efea871 | static PyObject * spam_system(PyObject *self, PyObject *arg) { int status = 3; PyObject *result = PyLong_FromLong(status); return result; }
Recompile, restart the Python interpreter again,
and check that the function now returns 3: | trusted_official_docs | CPython Docs | static PyObject * spam_system(PyObject *self, PyObject *arg) { int status = 3; PyObject *result = PyLong_FromLong(status); return result; }
Recompile, restart the Python interpreter again,
and check that the function now returns 3: | static PyObject * spam_system(PyObject *self, PyObject *arg) { int status = 3; PyObject *result = PyLong_FromLong(status); return result; }
Recompile, restart the Python interpreter again,
and check that the function now returns 3: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
deaf42c7-3966-4e15-a9c9-e27d7bc2532b | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 1,064 | supabase-export-v2 | cf66550846dbb77a | // A workaround void *PyInit_spam(void) { return NULL; }
This is a shim for an old-style :ref:`initialization function <extension-export-hook>`,
which was required in extension modules for CPython 3.14 and below. Current CPython does not need it, but some build tools may still assume that
all extension modules need to ... | trusted_official_docs | CPython Docs | // A workaround void *PyInit_spam(void) { return NULL; }
This is a shim for an old-style :ref:`initialization function <extension-export-hook>`,
which was required in extension modules for CPython 3.14 and below. Current CPython does not need it, but some build tools may still assume that
all extension modules need to ... | // A workaround void *PyInit_spam(void) { return NULL; }
This is a shim for an old-style :ref:`initialization function <extension-export-hook>`,
which was required in extension modules for CPython 3.14 and below. Current CPython does not need it, but some build tools may still assume that
all extension modules need to ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
e519889b-ebc2-42c3-a2a7-6be0676bcee1 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 918 | supabase-export-v2 | 9f4d6a54fcda269b | that were added in CPython 3.15. To create an extension that's compatible with earlier versions of CPython, please follow an earlier version of this documentation.
This tutorial uses C syntax added in C11 and C++20. If your extension needs to be compatible with earlier standards,
please follow tutorials in documentati... | trusted_official_docs | CPython Docs | that were added in CPython 3.15. To create an extension that's compatible with earlier versions of CPython, please follow an earlier version of this documentation.
This tutorial uses C syntax added in C11 and C++20. If your extension needs to be compatible with earlier standards,
please follow tutorials in documentati... | that were added in CPython 3.15. To create an extension that's compatible with earlier versions of CPython, please follow an earlier version of this documentation.
This tutorial uses C syntax added in C11 and C++20. If your extension needs to be compatible with earlier standards,
please follow tutorials in documentati... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
e55fd9c4-8ba5-40ea-8189-7bd3fc89c467 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 1,067 | supabase-export-v2 | 6ecd7a09224c682a | Compiling directly ------------------
Using a third-party build tool is heavily recommended,
as it will take care of various details of your platform and Python
installation, of naming the resulting extension, and, later, of distributing
your work. | trusted_official_docs | CPython Docs | Compiling directly ------------------
Using a third-party build tool is heavily recommended,
as it will take care of various details of your platform and Python
installation, of naming the resulting extension, and, later, of distributing
your work. | Compiling directly ------------------
Using a third-party build tool is heavily recommended,
as it will take care of various details of your platform and Python
installation, of naming the resulting extension, and, later, of distributing
your work. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ea4ac577-ff8c-4bd0-a18c-6e19f3b30844 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 992 | supabase-export-v2 | ba87acccbac4fd3f | Exposing a function ===================
To expose the :c:func:`system` C function directly to Python,
we'll need to write a layer of glue code to convert arguments from Python
objects to C values, and the C return value back to Python. | trusted_official_docs | CPython Docs | Exposing a function ===================
To expose the :c:func:`system` C function directly to Python,
we'll need to write a layer of glue code to convert arguments from Python
objects to C values, and the C return value back to Python. | Exposing a function ===================
To expose the :c:func:`system` C function directly to Python,
we'll need to write a layer of glue code to convert arguments from Python
objects to C values, and the C return value back to Python. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ebb4e6c9-5114-4961-848a-0c83c81961a5 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 964 | supabase-export-v2 | deafd1250ae31e13 | .. literalinclude:: ../includes/capi-extension/spammodule-01.c :start-after: /// Export hook prototype :end-before: ///
.. tip::
The 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. | trusted_official_docs | CPython Docs | .. literalinclude:: ../includes/capi-extension/spammodule-01.c :start-after: /// Export hook prototype :end-before: ///
.. tip::
The 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. | .. literalinclude:: ../includes/capi-extension/spammodule-01.c :start-after: /// Export hook prototype :end-before: ///
.. tip::
The 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. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ec74c84e-b482-448b-aca8-05e35070bdba | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 922 | supabase-export-v2 | 6cf6b08068c659b4 | #include <stdlib.h> int system(const char *command);
Note that like many functions in the C standard library,
this function is already exposed in Python. In production, use :py:func:`os.system` or :py:func:`subprocess.run`
rather than the module you'll write here. | trusted_official_docs | CPython Docs | #include <stdlib.h> int system(const char *command);
Note that like many functions in the C standard library,
this function is already exposed in Python. In production, use :py:func:`os.system` or :py:func:`subprocess.run`
rather than the module you'll write here. | #include <stdlib.h> int system(const char *command);
Note that like many functions in the C standard library,
this function is already exposed in Python. In production, use :py:func:`os.system` or :py:func:`subprocess.run`
rather than the module you'll write here. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ee020992-16e3-443c-8a7c-19b5b50a11a5 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 1,008 | supabase-export-v2 | ed9f2d70af0b748a | your extension again, and test it. Be sure to restart the Python interpreter, so that ``import spam`` picks up the new version of the module.
You should now be able to call the function: | trusted_official_docs | CPython Docs | your extension again, and test it. Be sure to restart the Python interpreter, so that ``import spam`` picks up the new version of the module.
You should now be able to call the function: | your extension again, and test it. Be sure to restart the Python interpreter, so that ``import spam`` picks up the new version of the module.
You should now be able to call the function: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
f66f6f94-8240-4222-969f-7274af125a78 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 978 | supabase-export-v2 | c89f27de097e05ac | static PyModuleDef_Slot spam_slots[] = { {Py_mod_abi, &abi_info}, {Py_mod_name, "spam"}, {Py_mod_doc, "A wonderful module with an example function"}, {0, NULL} };
The ``PyABIInfo_VAR(abi_info);`` macro and the :c:data:`Py_mod_abi` slot
are a bit of boilerplate that helps prevent extensions compiled for
a different vers... | trusted_official_docs | CPython Docs | static PyModuleDef_Slot spam_slots[] = { {Py_mod_abi, &abi_info}, {Py_mod_name, "spam"}, {Py_mod_doc, "A wonderful module with an example function"}, {0, NULL} };
The ``PyABIInfo_VAR(abi_info);`` macro and the :c:data:`Py_mod_abi` slot
are a bit of boilerplate that helps prevent extensions compiled for
a different vers... | static PyModuleDef_Slot spam_slots[] = { {Py_mod_abi, &abi_info}, {Py_mod_name, "spam"}, {Py_mod_doc, "A wonderful module with an example function"}, {0, NULL} };
The ``PyABIInfo_VAR(abi_info);`` macro and the :c:data:`Py_mod_abi` slot
are a bit of boilerplate that helps prevent extensions compiled for
a different vers... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
f76ec595-b351-4a21-b3c7-f7c1c2b5a0c8 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 1,043 | supabase-export-v2 | c2b27939a22c5fe9 | Now, all that is left is calling the C library function :c:func:`system` with the ``char *`` buffer, and using its result instead of the ``3``:
.. code-block:: c
:emphasize-lines: 8 | trusted_official_docs | CPython Docs | Now, all that is left is calling the C library function :c:func:`system` with the ``char *`` buffer, and using its result instead of the ``3``:
.. code-block:: c
:emphasize-lines: 8 | Now, all that is left is calling the C library function :c:func:`system` with the ``char *`` buffer, and using its result instead of the ``3``:
.. code-block:: c
:emphasize-lines: 8 | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
f9a5e0b5-6f4e-41da-8052-1d9f64cd848b | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 915 | supabase-export-v2 | 14a66097d087c15c | You need to have a suitable C compiler and Python development headers installed. On Linux, headers are often in a package like ``python3-dev`` or ``python3-devel``.
You need to be able to install Python packages. This tutorial uses `pip <https://pip.pypa.io/>`__ (``pip install``), but you
can substitute any tool that c... | trusted_official_docs | CPython Docs | You need to have a suitable C compiler and Python development headers installed. On Linux, headers are often in a package like ``python3-dev`` or ``python3-devel``.
You need to be able to install Python packages. This tutorial uses `pip <https://pip.pypa.io/>`__ (``pip install``), but you
can substitute any tool that c... | You need to have a suitable C compiler and Python development headers installed. On Linux, headers are often in a package like ``python3-dev`` or ``python3-devel``.
You need to be able to install Python packages. This tutorial uses `pip <https://pip.pypa.io/>`__ (``pip install``), but you
can substitute any tool that c... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
fa308fed-97c7-4479-b569-64c17e17e997 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 1,032 | supabase-export-v2 | b315623a231e1ee7 | .. code-block:: c :emphasize-lines: 4
static PyObject *
spam_system(PyObject *self, PyObject *arg)
{
const char *command = PyUnicode_AsUTF8AndSize(arg, NULL);
int status = 3;
PyObject *result = PyLong_FromLong(status);
return result;
} | trusted_official_docs | CPython Docs | .. code-block:: c :emphasize-lines: 4
static PyObject *
spam_system(PyObject *self, PyObject *arg)
{
const char *command = PyUnicode_AsUTF8AndSize(arg, NULL);
int status = 3;
PyObject *result = PyLong_FromLong(status);
return result;
} | .. code-block:: c :emphasize-lines: 4
static PyObject *
spam_system(PyObject *self, PyObject *arg)
{
const char *command = PyUnicode_AsUTF8AndSize(arg, NULL);
int status = 3;
PyObject *result = PyLong_FromLong(status);
return result;
} | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
fceb9157-91e5-4db0-b773-4e6f7fb702f2 | CPython Docs | file://datasets/cpython/Doc/extending/first-extension-module.rst | unknown | 79099511-b1a9-4664-8cc8-cd28a911d085 | 1,029 | supabase-export-v2 | fa00df2fa1db23ea | use the information in it, we will need to convert it to a C value -- in this case, a C string (``const char *``).
There's a slight type mismatch here: Python's :py:class:`str` objects store
Unicode text, but C strings are arrays of bytes. So, we'll need to *encode* the data, and we'll use the UTF-8 encoding for it. (U... | trusted_official_docs | CPython Docs | use the information in it, we will need to convert it to a C value -- in this case, a C string (``const char *``).
There's a slight type mismatch here: Python's :py:class:`str` objects store
Unicode text, but C strings are arrays of bytes. So, we'll need to *encode* the data, and we'll use the UTF-8 encoding for it. (U... | use the information in it, we will need to convert it to a C value -- in this case, a C string (``const char *``).
There's a slight type mismatch here: Python's :py:class:`str` objects store
Unicode text, but C strings are arrays of bytes. So, we'll need to *encode* the data, and we'll use the UTF-8 encoding for it. (U... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
054aa0f3-7ca4-4cbc-9658-407257882364 | CPython Docs | file://datasets/cpython/Doc/extending/windows.rst | unknown | 7441b7ea-0136-4b9d-aa40-f20581901c69 | 1,091 | supabase-export-v2 | da3f024caeff367d | memory; instead, the code already uses the DLL's lookup table, and the lookup table is modified at runtime to point to the functions and data.
In Unix, there is only one type of library file (:file:`.a`) which contains code
from several object files (:file:`.o`). During the link step to create a shared
object file (:fi... | trusted_official_docs | CPython Docs | memory; instead, the code already uses the DLL's lookup table, and the lookup table is modified at runtime to point to the functions and data.
In Unix, there is only one type of library file (:file:`.a`) which contains code
from several object files (:file:`.o`). During the link step to create a shared
object file (:fi... | memory; instead, the code already uses the DLL's lookup table, and the lookup table is modified at runtime to point to the functions and data.
In Unix, there is only one type of library file (:file:`.a`) which contains code
from several object files (:file:`.o`). During the link step to create a shared
object file (:fi... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
080fd60d-ee7a-42bf-aed0-c774a05ed28d | CPython Docs | file://datasets/cpython/Doc/extending/windows.rst | unknown | 7441b7ea-0136-4b9d-aa40-f20581901c69 | 1,111 | supabase-export-v2 | b805eb3a0ff79f1e | The second command created :file:`ni.dll` (and :file:`.obj` and :file:`.lib`), which knows how to find the necessary functions from spam, and also from the Python executable.
Not every identifier is exported to the lookup table. If you want any other
modules (including Python) to be able to see your identifiers, you ha... | trusted_official_docs | CPython Docs | The second command created :file:`ni.dll` (and :file:`.obj` and :file:`.lib`), which knows how to find the necessary functions from spam, and also from the Python executable.
Not every identifier is exported to the lookup table. If you want any other
modules (including Python) to be able to see your identifiers, you ha... | The second command created :file:`ni.dll` (and :file:`.obj` and :file:`.lib`), which knows how to find the necessary functions from spam, and also from the Python executable.
Not every identifier is exported to the lookup table. If you want any other
modules (including Python) to be able to see your identifiers, you ha... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
0a5e2ec5-9f04-4710-bbeb-72d8235b3d21 | CPython Docs | file://datasets/cpython/Doc/extending/windows.rst | unknown | 7441b7ea-0136-4b9d-aa40-f20581901c69 | 1,109 | supabase-export-v2 | 886c41bcb4e853b8 | cl /LD /DPy_NO_LINK_LIB /I/python/include spam.c ../libs/pythonXY.lib cl /LD /DPy_NO_LINK_LIB /I/python/include ni.c spam.lib ../libs/pythonXY.lib
The first command created three files: :file:`spam.obj`, :file:`spam.dll`
and :file:`spam.lib`. :file:`Spam.dll` does not contain any Python
functions (such as :c:func:`Py... | trusted_official_docs | CPython Docs | cl /LD /DPy_NO_LINK_LIB /I/python/include spam.c ../libs/pythonXY.lib cl /LD /DPy_NO_LINK_LIB /I/python/include ni.c spam.lib ../libs/pythonXY.lib
The first command created three files: :file:`spam.obj`, :file:`spam.dll`
and :file:`spam.lib`. :file:`Spam.dll` does not contain any Python
functions (such as :c:func:`Py... | cl /LD /DPy_NO_LINK_LIB /I/python/include spam.c ../libs/pythonXY.lib cl /LD /DPy_NO_LINK_LIB /I/python/include ni.c spam.lib ../libs/pythonXY.lib
The first command created three files: :file:`spam.obj`, :file:`spam.dll`
and :file:`spam.lib`. :file:`Spam.dll` does not contain any Python
functions (such as :c:func:`Py... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
0dc735ed-d26c-43ff-ad6c-ce18dbf815eb | CPython Docs | file://datasets/cpython/Doc/extending/windows.rst | unknown | 7441b7ea-0136-4b9d-aa40-f20581901c69 | 1,092 | supabase-export-v2 | 9e6c775b0f71449b | will look for it in the object files in the libraries; if it finds it, it will include all the code from that object file.
In Windows, there are two types of library, a static library and an import
library (both called :file:`.lib`). A static library is like a Unix :file:`.a`
file; it contains code to be included as ne... | trusted_official_docs | CPython Docs | will look for it in the object files in the libraries; if it finds it, it will include all the code from that object file.
In Windows, there are two types of library, a static library and an import
library (both called :file:`.lib`). A static library is like a Unix :file:`.a`
file; it contains code to be included as ne... | will look for it in the object files in the libraries; if it finds it, it will include all the code from that object file.
In Windows, there are two types of library, a static library and an import
library (both called :file:`.lib`). A static library is like a Unix :file:`.a`
file; it contains code to be included as ne... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
1d7ff631-1047-473d-ac1b-c7fbbb33c170 | CPython Docs | file://datasets/cpython/Doc/extending/windows.rst | unknown | 7441b7ea-0136-4b9d-aa40-f20581901c69 | 1,082 | supabase-export-v2 | 2c7b8168a8c8c56e | .. note::
This chapter mentions a number of filenames that include an encoded Python
version number. These filenames are represented with the version number shown
as ``XY``; in practice, ``'X'`` will be the major version number and ``'Y'``
will be the minor version number of the Python release you're working with. F... | trusted_official_docs | CPython Docs | .. note::
This chapter mentions a number of filenames that include an encoded Python
version number. These filenames are represented with the version number shown
as ``XY``; in practice, ``'X'`` will be the major version number and ``'Y'``
will be the minor version number of the Python release you're working with. F... | .. note::
This chapter mentions a number of filenames that include an encoded Python
version number. These filenames are represented with the version number shown
as ``XY``; in practice, ``'X'`` will be the major version number and ``'Y'``
will be the minor version number of the Python release you're working with. F... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
23204de9-16ea-423e-94be-2f2d690fddc9 | CPython Docs | file://datasets/cpython/Doc/extending/windows.rst | unknown | 7441b7ea-0136-4b9d-aa40-f20581901c69 | 1,079 | supabase-export-v2 | 017cec9b56c3b63e | **************************************** Building C and C++ Extensions on Windows ****************************************
This chapter briefly explains how to create a Windows extension module for
Python using Microsoft Visual C++, and follows with more detailed background
information on how it works. The explanatory ... | trusted_official_docs | CPython Docs | **************************************** Building C and C++ Extensions on Windows ****************************************
This chapter briefly explains how to create a Windows extension module for
Python using Microsoft Visual C++, and follows with more detailed background
information on how it works. The explanatory ... | **************************************** Building C and C++ Extensions on Windows ****************************************
This chapter briefly explains how to create a Windows extension module for
Python using Microsoft Visual C++, and follows with more detailed background
information on how it works. The explanatory ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2691d119-26d1-4952-ab05-495d48a8d1bf | CPython Docs | file://datasets/cpython/Doc/extending/windows.rst | unknown | 7441b7ea-0136-4b9d-aa40-f20581901c69 | 1,107 | supabase-export-v2 | 65ed4f03c5e4d3a9 | 2. Manually by defining :c:macro:`Py_NO_LINK_LIB` macro before including :file:`Python.h`. You must pass :file:`pythonXY.lib` to the linker.
To build two DLLs, spam and ni (which uses C functions found in spam), you
could use these commands:: | trusted_official_docs | CPython Docs | 2. Manually by defining :c:macro:`Py_NO_LINK_LIB` macro before including :file:`Python.h`. You must pass :file:`pythonXY.lib` to the linker.
To build two DLLs, spam and ni (which uses C functions found in spam), you
could use these commands:: | 2. Manually by defining :c:macro:`Py_NO_LINK_LIB` macro before including :file:`Python.h`. You must pass :file:`pythonXY.lib` to the linker.
To build two DLLs, spam and ni (which uses C functions found in spam), you
could use these commands:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
27bdb52c-87bc-429c-bfc3-bae1d5799cf7 | CPython Docs | file://datasets/cpython/Doc/extending/windows.rst | unknown | 7441b7ea-0136-4b9d-aa40-f20581901c69 | 1,093 | supabase-export-v2 | dd0503b3580a0c5f | import library may be generated, which will need to be used for all future DLLs that depend on the symbols in the application or DLL.
Suppose you are building two dynamic-load modules, B and C, which should share
another block of code A. On Unix, you would *not* pass :file:`A.a` to the
linker for :file:`B.so` and :file... | trusted_official_docs | CPython Docs | import library may be generated, which will need to be used for all future DLLs that depend on the symbols in the application or DLL.
Suppose you are building two dynamic-load modules, B and C, which should share
another block of code A. On Unix, you would *not* pass :file:`A.a` to the
linker for :file:`B.so` and :file... | import library may be generated, which will need to be used for all future DLLs that depend on the symbols in the application or DLL.
Suppose you are building two dynamic-load modules, B and C, which should share
another block of code A. On Unix, you would *not* pass :file:`A.a` to the
linker for :file:`B.so` and :file... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
29e26b1d-5e72-4e31-8205-9c464dc83651 | CPython Docs | file://datasets/cpython/Doc/extending/windows.rst | unknown | 7441b7ea-0136-4b9d-aa40-f20581901c69 | 1,088 | supabase-export-v2 | de85bf27ac6c0ce3 | Differences Between Unix and Windows ====================================
Unix and Windows use completely different paradigms for run-time loading of
code. Before you try to build a module that can be dynamically loaded, be aware
of how your system works. | trusted_official_docs | CPython Docs | Differences Between Unix and Windows ====================================
Unix and Windows use completely different paradigms for run-time loading of
code. Before you try to build a module that can be dynamically loaded, be aware
of how your system works. | Differences Between Unix and Windows ====================================
Unix and Windows use completely different paradigms for run-time loading of
code. Before you try to build a module that can be dynamically loaded, be aware
of how your system works. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3ea26b53-2d32-4b87-b37c-97544d974bbd | CPython Docs | file://datasets/cpython/Doc/extending/windows.rst | unknown | 7441b7ea-0136-4b9d-aa40-f20581901c69 | 1,102 | supabase-export-v2 | b25892ac18001a33 | configure-aware link with the library. The header file chooses :file:`pythonXY_d.lib` for Debug, :file:`pythonXY.lib` for Release, and :file:`pythonX.lib` for Release with the :ref:`Limited API <stable-application-binary-interface>` enabled.
To build two DLLs, spam and ni (which uses C functions found in spam), you
co... | trusted_official_docs | CPython Docs | configure-aware link with the library. The header file chooses :file:`pythonXY_d.lib` for Debug, :file:`pythonXY.lib` for Release, and :file:`pythonX.lib` for Release with the :ref:`Limited API <stable-application-binary-interface>` enabled.
To build two DLLs, spam and ni (which uses C functions found in spam), you
co... | configure-aware link with the library. The header file chooses :file:`pythonXY_d.lib` for Debug, :file:`pythonXY.lib` for Release, and :file:`pythonX.lib` for Release with the :ref:`Limited API <stable-application-binary-interface>` enabled.
To build two DLLs, spam and ni (which uses C functions found in spam), you
co... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
41dc244b-c0e3-4a6f-803e-2d73a6ea0b42 | CPython Docs | file://datasets/cpython/Doc/extending/windows.rst | unknown | 7441b7ea-0136-4b9d-aa40-f20581901c69 | 1,101 | supabase-export-v2 | 9f983689bcfd82d1 | When creating DLLs in Windows, you can use the CPython library in two ways:
1. By default, inclusion of :file:`PC/pyconfig.h` directly or via
:file:`Python.h` triggers an implicit, configure-aware link with the
library. The header file chooses :file:`pythonXY_d.lib` for Debug,
:file:`pythonXY.lib` for Release, and :... | trusted_official_docs | CPython Docs | When creating DLLs in Windows, you can use the CPython library in two ways:
1. By default, inclusion of :file:`PC/pyconfig.h` directly or via
:file:`Python.h` triggers an implicit, configure-aware link with the
library. The header file chooses :file:`pythonXY_d.lib` for Debug,
:file:`pythonXY.lib` for Release, and :... | When creating DLLs in Windows, you can use the CPython library in two ways:
1. By default, inclusion of :file:`PC/pyconfig.h` directly or via
:file:`Python.h` triggers an implicit, configure-aware link with the
library. The header file chooses :file:`pythonXY_d.lib` for Debug,
:file:`pythonXY.lib` for Release, and :... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4614df24-58fb-4ed3-91c8-2ca6e95297fe | CPython Docs | file://datasets/cpython/Doc/extending/windows.rst | unknown | 7441b7ea-0136-4b9d-aa40-f20581901c69 | 1,110 | supabase-export-v2 | 3bc40004fc8c4e59 | and :file:`spam.lib`. :file:`Spam.dll` does not contain any Python functions (such as :c:func:`PyArg_ParseTuple`), but it does know how to find the Python code thanks to :file:`pythonXY.lib`.
The second command created :file:`ni.dll` (and :file:`.obj` and
:file:`.lib`), which knows how to find the necessary functions ... | trusted_official_docs | CPython Docs | and :file:`spam.lib`. :file:`Spam.dll` does not contain any Python functions (such as :c:func:`PyArg_ParseTuple`), but it does know how to find the Python code thanks to :file:`pythonXY.lib`.
The second command created :file:`ni.dll` (and :file:`.obj` and
:file:`.lib`), which knows how to find the necessary functions ... | and :file:`spam.lib`. :file:`Spam.dll` does not contain any Python functions (such as :c:func:`PyArg_ParseTuple`), but it does know how to find the Python code thanks to :file:`pythonXY.lib`.
The second command created :file:`ni.dll` (and :file:`.obj` and
:file:`.lib`), which knows how to find the necessary functions ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5b9cdaa3-5354-4a83-8f19-bca8ff7dc406 | CPython Docs | file://datasets/cpython/Doc/extending/windows.rst | unknown | 7441b7ea-0136-4b9d-aa40-f20581901c69 | 1,094 | supabase-export-v2 | 18089c9dbb4b9277 | the linker for B and C. :file:`A.lib` does not contain code; it just contains information which will be used at runtime to access A's code.
In Windows, using an import library is sort of like using ``import spam``; it
gives you access to spam's names, but does not create a separate copy. On Unix,
linking with a library... | trusted_official_docs | CPython Docs | the linker for B and C. :file:`A.lib` does not contain code; it just contains information which will be used at runtime to access A's code.
In Windows, using an import library is sort of like using ``import spam``; it
gives you access to spam's names, but does not create a separate copy. On Unix,
linking with a library... | the linker for B and C. :file:`A.lib` does not contain code; it just contains information which will be used at runtime to access A's code.
In Windows, using an import library is sort of like using ``import spam``; it
gives you access to spam's names, but does not create a separate copy. On Unix,
linking with a library... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5c37820a-82c9-4535-9b50-1a4013587f80 | CPython Docs | file://datasets/cpython/Doc/extending/windows.rst | unknown | 7441b7ea-0136-4b9d-aa40-f20581901c69 | 1,085 | supabase-export-v2 | dd32b37e4f71e183 | A Cookbook Approach ===================
There are two approaches to building extension modules on Windows, just as there
are on Unix: use the ``setuptools`` package to control the build process, or
do things manually. The setuptools approach works well for most extensions;
documentation on using ``setuptools`` to build... | trusted_official_docs | CPython Docs | A Cookbook Approach ===================
There are two approaches to building extension modules on Windows, just as there
are on Unix: use the ``setuptools`` package to control the build process, or
do things manually. The setuptools approach works well for most extensions;
documentation on using ``setuptools`` to build... | A Cookbook Approach ===================
There are two approaches to building extension modules on Windows, just as there
are on Unix: use the ``setuptools`` package to control the build process, or
do things manually. The setuptools approach works well for most extensions;
documentation on using ``setuptools`` to build... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5eac1c0e-c528-4305-a7a2-37432db12aac | CPython Docs | file://datasets/cpython/Doc/extending/windows.rst | unknown | 7441b7ea-0136-4b9d-aa40-f20581901c69 | 1,112 | supabase-export-v2 | b8297a498fb1bf12 | other modules (including Python) to be able to see your identifiers, you have to say ``_declspec(dllexport)``, as in ``void _declspec(dllexport) initspam(void)`` or ``PyObject _declspec(dllexport) *NiGetSpamData(void)``.
Developer Studio will throw in a lot of import libraries that you do not really
need, adding about ... | trusted_official_docs | CPython Docs | other modules (including Python) to be able to see your identifiers, you have to say ``_declspec(dllexport)``, as in ``void _declspec(dllexport) initspam(void)`` or ``PyObject _declspec(dllexport) *NiGetSpamData(void)``.
Developer Studio will throw in a lot of import libraries that you do not really
need, adding about ... | other modules (including Python) to be able to see your identifiers, you have to say ``_declspec(dllexport)``, as in ``void _declspec(dllexport) initspam(void)`` or ``PyObject _declspec(dllexport) *NiGetSpamData(void)``.
Developer Studio will throw in a lot of import libraries that you do not really
need, adding about ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
73e6267b-9a0d-4113-af8a-898de60891be | CPython Docs | file://datasets/cpython/Doc/extending/windows.rst | unknown | 7441b7ea-0136-4b9d-aa40-f20581901c69 | 1,100 | supabase-export-v2 | b1426c1337930a12 | Windows Python is built in Microsoft Visual C++; using other compilers may or may not work. The rest of this section is MSVC++ specific.
When creating DLLs in Windows, you can use the CPython library in two ways: | trusted_official_docs | CPython Docs | Windows Python is built in Microsoft Visual C++; using other compilers may or may not work. The rest of this section is MSVC++ specific.
When creating DLLs in Windows, you can use the CPython library in two ways: | Windows Python is built in Microsoft Visual C++; using other compilers may or may not work. The rest of this section is MSVC++ specific.
When creating DLLs in Windows, you can use the CPython library in two ways: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8f8a0756-621f-46b2-9b74-4febb45e8730 | CPython Docs | file://datasets/cpython/Doc/extending/windows.rst | unknown | 7441b7ea-0136-4b9d-aa40-f20581901c69 | 1,108 | supabase-export-v2 | 2329c80d09779839 | To build two DLLs, spam and ni (which uses C functions found in spam), you could use these commands::
cl /LD /DPy_NO_LINK_LIB /I/python/include spam.c ../libs/pythonXY.lib
cl /LD /DPy_NO_LINK_LIB /I/python/include ni.c spam.lib ../libs/pythonXY.lib | trusted_official_docs | CPython Docs | To build two DLLs, spam and ni (which uses C functions found in spam), you could use these commands::
cl /LD /DPy_NO_LINK_LIB /I/python/include spam.c ../libs/pythonXY.lib
cl /LD /DPy_NO_LINK_LIB /I/python/include ni.c spam.lib ../libs/pythonXY.lib | To build two DLLs, spam and ni (which uses C functions found in spam), you could use these commands::
cl /LD /DPy_NO_LINK_LIB /I/python/include spam.c ../libs/pythonXY.lib
cl /LD /DPy_NO_LINK_LIB /I/python/include ni.c spam.lib ../libs/pythonXY.lib | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
98c72bec-e7c5-4b0e-a8e7-623a8d21fcbc | CPython Docs | file://datasets/cpython/Doc/extending/windows.rst | unknown | 7441b7ea-0136-4b9d-aa40-f20581901c69 | 1,106 | supabase-export-v2 | 93e1e7a78c8ead54 | The second command created :file:`ni.dll` (and :file:`.obj` and :file:`.lib`), which knows how to find the necessary functions from spam, and also from the Python executable.
2. Manually by defining :c:macro:`Py_NO_LINK_LIB` macro before including
:file:`Python.h`. You must pass :file:`pythonXY.lib` to the linker. | trusted_official_docs | CPython Docs | The second command created :file:`ni.dll` (and :file:`.obj` and :file:`.lib`), which knows how to find the necessary functions from spam, and also from the Python executable.
2. Manually by defining :c:macro:`Py_NO_LINK_LIB` macro before including
:file:`Python.h`. You must pass :file:`pythonXY.lib` to the linker. | The second command created :file:`ni.dll` (and :file:`.obj` and :file:`.lib`), which knows how to find the necessary functions from spam, and also from the Python executable.
2. Manually by defining :c:macro:`Py_NO_LINK_LIB` macro before including
:file:`Python.h`. You must pass :file:`pythonXY.lib` to the linker. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9c17fc37-0421-47fc-a284-c3a2c3bbb8ca | CPython Docs | file://datasets/cpython/Doc/extending/windows.rst | unknown | 7441b7ea-0136-4b9d-aa40-f20581901c69 | 1,080 | supabase-export-v2 | 45ba0f58694a2f02 | Windows programmer learning to build Python extensions and the Unix programmer interested in producing software which can be successfully built on both Unix and Windows.
Module authors are encouraged to use the distutils approach for building
extension modules, instead of the one described in this section. You will sti... | trusted_official_docs | CPython Docs | Windows programmer learning to build Python extensions and the Unix programmer interested in producing software which can be successfully built on both Unix and Windows.
Module authors are encouraged to use the distutils approach for building
extension modules, instead of the one described in this section. You will sti... | Windows programmer learning to build Python extensions and the Unix programmer interested in producing software which can be successfully built on both Unix and Windows.
Module authors are encouraged to use the distutils approach for building
extension modules, instead of the one described in this section. You will sti... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a2a0c50a-9dba-4768-9eda-6ec26907b26b | CPython Docs | file://datasets/cpython/Doc/extending/windows.rst | unknown | 7441b7ea-0136-4b9d-aa40-f20581901c69 | 1,090 | supabase-export-v2 | 42ac89da5be6ab9d | changed to point to the actual locations in the program where the functions and data are placed in memory. This is basically a link operation.
In Windows, a dynamic-link library (:file:`.dll`) file has no dangling
references. Instead, an access to functions or data goes through a lookup
table. So the DLL code does not ... | trusted_official_docs | CPython Docs | changed to point to the actual locations in the program where the functions and data are placed in memory. This is basically a link operation.
In Windows, a dynamic-link library (:file:`.dll`) file has no dangling
references. Instead, an access to functions or data goes through a lookup
table. So the DLL code does not ... | changed to point to the actual locations in the program where the functions and data are placed in memory. This is basically a link operation.
In Windows, a dynamic-link library (:file:`.dll`) file has no dangling
references. Instead, an access to functions or data goes through a lookup
table. So the DLL code does not ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d156383c-d32e-4fe6-91c3-8fcd62a20982 | CPython Docs | file://datasets/cpython/Doc/extending/windows.rst | unknown | 7441b7ea-0136-4b9d-aa40-f20581901c69 | 1,105 | supabase-export-v2 | 7eb46ccde6f63eef | does not contain any Python functions (such as :c:func:`PyArg_ParseTuple`), but it does know how to find the Python code thanks to the implicitly linked :file:`pythonXY.lib`.
The second command created :file:`ni.dll` (and :file:`.obj` and
:file:`.lib`), which knows how to find the necessary functions from spam,
and a... | trusted_official_docs | CPython Docs | does not contain any Python functions (such as :c:func:`PyArg_ParseTuple`), but it does know how to find the Python code thanks to the implicitly linked :file:`pythonXY.lib`.
The second command created :file:`ni.dll` (and :file:`.obj` and
:file:`.lib`), which knows how to find the necessary functions from spam,
and a... | does not contain any Python functions (such as :c:func:`PyArg_ParseTuple`), but it does know how to find the Python code thanks to the implicitly linked :file:`pythonXY.lib`.
The second command created :file:`ni.dll` (and :file:`.obj` and
:file:`.lib`), which knows how to find the necessary functions from spam,
and a... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
f9077d21-ea86-47dd-862a-f564753e32ef | CPython Docs | file://datasets/cpython/Doc/extending/windows.rst | unknown | 7441b7ea-0136-4b9d-aa40-f20581901c69 | 1,104 | supabase-export-v2 | 0f49e21090e692f0 | cl /LD /I/python/include spam.c cl /LD /I/python/include ni.c spam.lib
The first command created three files: :file:`spam.obj`, :file:`spam.dll`
and :file:`spam.lib`. :file:`Spam.dll` does not contain any Python
functions (such as :c:func:`PyArg_ParseTuple`), but it does know how to find
the Python code thanks to th... | trusted_official_docs | CPython Docs | cl /LD /I/python/include spam.c cl /LD /I/python/include ni.c spam.lib
The first command created three files: :file:`spam.obj`, :file:`spam.dll`
and :file:`spam.lib`. :file:`Spam.dll` does not contain any Python
functions (such as :c:func:`PyArg_ParseTuple`), but it does know how to find
the Python code thanks to th... | cl /LD /I/python/include spam.c cl /LD /I/python/include ni.c spam.lib
The first command created three files: :file:`spam.obj`, :file:`spam.dll`
and :file:`spam.lib`. :file:`Spam.dll` does not contain any Python
functions (such as :c:func:`PyArg_ParseTuple`), but it does know how to find
the Python code thanks to th... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
fdc6fd09-ffc7-499d-9f1a-8df6a9197768 | CPython Docs | file://datasets/cpython/Doc/extending/windows.rst | unknown | 7441b7ea-0136-4b9d-aa40-f20581901c69 | 1,089 | supabase-export-v2 | ed86c7f1ae5ceb78 | paradigms for run-time loading of code. Before you try to build a module that can be dynamically loaded, be aware of how your system works.
In Unix, a shared object (:file:`.so`) file contains code to be used by the
program, and also the names of functions and data that it expects to find in the
program. When the file ... | trusted_official_docs | CPython Docs | paradigms for run-time loading of code. Before you try to build a module that can be dynamically loaded, be aware of how your system works.
In Unix, a shared object (:file:`.so`) file contains code to be used by the
program, and also the names of functions and data that it expects to find in the
program. When the file ... | paradigms for run-time loading of code. Before you try to build a module that can be dynamically loaded, be aware of how your system works.
In Unix, a shared object (:file:`.so`) file contains code to be used by the
program, and also the names of functions and data that it expects to find in the
program. When the file ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2438b288-b0f9-4001-92fc-7957fc8bdf93 | CPython Docs | file://datasets/cpython/Doc/extending/building.rst | unknown | 325d34c1-c45e-42af-bd21-001fde77ffdf | 1,119 | supabase-export-v2 | 00995debdbfff635 | Building C and C++ Extensions with setuptools =============================================
Building, packaging and distributing extension modules is best done with
third-party tools, and is out of scope of this document. One suitable tool is Setuptools, whose documentation can be found at
https://setuptools.pypa.io/en... | trusted_official_docs | CPython Docs | Building C and C++ Extensions with setuptools =============================================
Building, packaging and distributing extension modules is best done with
third-party tools, and is out of scope of this document. One suitable tool is Setuptools, whose documentation can be found at
https://setuptools.pypa.io/en... | Building C and C++ Extensions with setuptools =============================================
Building, packaging and distributing extension modules is best done with
third-party tools, and is out of scope of this document. One suitable tool is Setuptools, whose documentation can be found at
https://setuptools.pypa.io/en... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a9018443-53c5-4e95-ba77-e3af4fe68cec | CPython Docs | file://datasets/cpython/Doc/extending/building.rst | unknown | 325d34c1-c45e-42af-bd21-001fde77ffdf | 1,114 | supabase-export-v2 | 77f875252a807781 | ***************************** Building C and C++ Extensions *****************************
A C extension for CPython is a shared library (for example, a ``.so`` file on
Linux, ``.pyd`` on Windows), which exports an *initialization function*. | trusted_official_docs | CPython Docs | ***************************** Building C and C++ Extensions *****************************
A C extension for CPython is a shared library (for example, a ``.so`` file on
Linux, ``.pyd`` on Windows), which exports an *initialization function*. | ***************************** Building C and C++ Extensions *****************************
A C extension for CPython is a shared library (for example, a ``.so`` file on
Linux, ``.pyd`` on Windows), which exports an *initialization function*. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ca47304b-231a-4d29-a80c-b5749c8c3152 | CPython Docs | file://datasets/cpython/Doc/extending/building.rst | unknown | 325d34c1-c45e-42af-bd21-001fde77ffdf | 1,120 | supabase-export-v2 | 840f5b7a3fc41dd7 | best done with third-party tools, and is out of scope of this document. One suitable tool is Setuptools, whose documentation can be found at https://setuptools.pypa.io/en/latest/setuptools.html.
The :mod:`distutils` module, which was included in the standard library
until Python 3.12, is now maintained as part of Setup... | trusted_official_docs | CPython Docs | best done with third-party tools, and is out of scope of this document. One suitable tool is Setuptools, whose documentation can be found at https://setuptools.pypa.io/en/latest/setuptools.html.
The :mod:`distutils` module, which was included in the standard library
until Python 3.12, is now maintained as part of Setup... | best done with third-party tools, and is out of scope of this document. One suitable tool is Setuptools, whose documentation can be found at https://setuptools.pypa.io/en/latest/setuptools.html.
The :mod:`distutils` module, which was included in the standard library
until Python 3.12, is now maintained as part of Setup... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
0323a249-a8e5-470a-8e26-0f6ee51784b0 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,218 | supabase-export-v2 | 03036457d217932a | you do not want to support keyword arguments and this is non-``NULL``, raise a :exc:`TypeError` with a message saying that keyword arguments are not supported.
Here is a toy ``tp_call`` implementation:: | trusted_official_docs | CPython Docs | you do not want to support keyword arguments and this is non-``NULL``, raise a :exc:`TypeError` with a message saying that keyword arguments are not supported.
Here is a toy ``tp_call`` implementation:: | you do not want to support keyword arguments and this is non-``NULL``, raise a :exc:`TypeError` with a message saying that keyword arguments are not supported.
Here is a toy ``tp_call`` implementation:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
044933c1-e849-49fa-b8c6-dd2bbf592f67 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,220 | supabase-export-v2 | 1ead2fcbf3d2d6ae | * newdatatype_call(PyObject *op, PyObject *args, PyObject *kwds) { newdatatypeobject *self = (newdatatypeobject *) op; PyObject *result; const char *arg1; const char *arg2; const char *arg3;
if (!PyArg_ParseTuple(args, "sss:call", &arg1, &arg2, &arg3)) {
return NULL;
}
result = PyUnicode_FromFormat(
"Returning -- v... | trusted_official_docs | CPython Docs | * newdatatype_call(PyObject *op, PyObject *args, PyObject *kwds) { newdatatypeobject *self = (newdatatypeobject *) op; PyObject *result; const char *arg1; const char *arg2; const char *arg3;
if (!PyArg_ParseTuple(args, "sss:call", &arg1, &arg2, &arg3)) {
return NULL;
}
result = PyUnicode_FromFormat(
"Returning -- v... | * newdatatype_call(PyObject *op, PyObject *args, PyObject *kwds) { newdatatypeobject *self = (newdatatypeobject *) op; PyObject *result; const char *arg1; const char *arg2; const char *arg3;
if (!PyArg_ParseTuple(args, "sss:call", &arg1, &arg2, &arg3)) {
return NULL;
}
result = PyUnicode_FromFormat(
"Returning -- v... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
05f74273-b00b-4b13-ac80-0d4dcda4b5d9 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,159 | supabase-export-v2 | 46f72bf07569b72c | static PyObject * newdatatype_repr(PyObject *op) { newdatatypeobject *self = (newdatatypeobject *) op; return PyUnicode_FromFormat("Repr-ified_newdatatype{{size:%d}}", self->obj_UnderlyingDatatypePtr->size); }
If no :c:member:`~PyTypeObject.tp_repr` handler is specified, the interpreter will supply a
representation tha... | trusted_official_docs | CPython Docs | static PyObject * newdatatype_repr(PyObject *op) { newdatatypeobject *self = (newdatatypeobject *) op; return PyUnicode_FromFormat("Repr-ified_newdatatype{{size:%d}}", self->obj_UnderlyingDatatypePtr->size); }
If no :c:member:`~PyTypeObject.tp_repr` handler is specified, the interpreter will supply a
representation tha... | static PyObject * newdatatype_repr(PyObject *op) { newdatatypeobject *self = (newdatatypeobject *) op; return PyUnicode_FromFormat("Repr-ified_newdatatype{{size:%d}}", self->obj_UnderlyingDatatypePtr->size); }
If no :c:member:`~PyTypeObject.tp_repr` handler is specified, the interpreter will supply a
representation tha... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
076d10d8-a8ac-4377-9cb8-21f4ef0e04ff | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,192 | supabase-export-v2 | a62544d6cf9b6334 | static PyObject * newdatatype_getattr(PyObject *op, char *name) { newdatatypeobject *self = (newdatatypeobject *) op; if (strcmp(name, "data") == 0) { return PyLong_FromLong(self->data); }
PyErr_Format(PyExc_AttributeError,
"'%.100s' object has no attribute '%.400s'",
Py_TYPE(self)->tp_name, name);
return NULL;
} | trusted_official_docs | CPython Docs | static PyObject * newdatatype_getattr(PyObject *op, char *name) { newdatatypeobject *self = (newdatatypeobject *) op; if (strcmp(name, "data") == 0) { return PyLong_FromLong(self->data); }
PyErr_Format(PyExc_AttributeError,
"'%.100s' object has no attribute '%.400s'",
Py_TYPE(self)->tp_name, name);
return NULL;
} | static PyObject * newdatatype_getattr(PyObject *op, char *name) { newdatatypeobject *self = (newdatatypeobject *) op; if (strcmp(name, "data") == 0) { return PyLong_FromLong(self->data); }
PyErr_Format(PyExc_AttributeError,
"'%.100s' object has no attribute '%.400s'",
Py_TYPE(self)->tp_name, name);
return NULL;
} | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
0d0ee56a-3d14-4695-96cb-633e6b99f00d | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,240 | supabase-export-v2 | a20cf3e72083d836 | is a concrete instance of the type you are implementing, use the :c:func:`PyObject_TypeCheck` function. A sample of its use might be something like the following::
if (!PyObject_TypeCheck(some_object, &MyType)) {
PyErr_SetString(PyExc_TypeError, "arg #1 not a mything");
return NULL;
} | trusted_official_docs | CPython Docs | is a concrete instance of the type you are implementing, use the :c:func:`PyObject_TypeCheck` function. A sample of its use might be something like the following::
if (!PyObject_TypeCheck(some_object, &MyType)) {
PyErr_SetString(PyExc_TypeError, "arg #1 not a mything");
return NULL;
} | is a concrete instance of the type you are implementing, use the :c:func:`PyObject_TypeCheck` function. A sample of its use might be something like the following::
if (!PyObject_TypeCheck(some_object, &MyType)) {
PyErr_SetString(PyExc_TypeError, "arg #1 not a mything");
return NULL;
} | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
12d9a9e1-8bfc-44c8-b36e-c9478b83fab9 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,139 | supabase-export-v2 | c2a7580f10472320 | clean-up to perform, you can put it here. The object itself needs to be freed here as well. Here is an example of this function::
static void
newdatatype_dealloc(PyObject *op)
{
newdatatypeobject *self = (newdatatypeobject *) op;
free(self->obj_UnderlyingDatatypePtr);
Py_TYPE(self)->tp_free(self);
} | trusted_official_docs | CPython Docs | clean-up to perform, you can put it here. The object itself needs to be freed here as well. Here is an example of this function::
static void
newdatatype_dealloc(PyObject *op)
{
newdatatypeobject *self = (newdatatypeobject *) op;
free(self->obj_UnderlyingDatatypePtr);
Py_TYPE(self)->tp_free(self);
} | clean-up to perform, you can put it here. The object itself needs to be freed here as well. Here is an example of this function::
static void
newdatatype_dealloc(PyObject *op)
{
newdatatypeobject *self = (newdatatypeobject *) op;
free(self->obj_UnderlyingDatatypePtr);
Py_TYPE(self)->tp_free(self);
} | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
1790ecbf-01c5-493b-9580-10b379056f96 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,210 | supabase-export-v2 | 8abbf96d52e23ce5 | This function, if you choose to provide it, should return a hash number for an instance of your data type. Here is a simple example::
static Py_hash_t
newdatatype_hash(PyObject *op)
{
newdatatypeobject *self = (newdatatypeobject *) op;
Py_hash_t result;
result = self->some_size + 32767 * self->some_number;
if (re... | trusted_official_docs | CPython Docs | This function, if you choose to provide it, should return a hash number for an instance of your data type. Here is a simple example::
static Py_hash_t
newdatatype_hash(PyObject *op)
{
newdatatypeobject *self = (newdatatypeobject *) op;
Py_hash_t result;
result = self->some_size + 32767 * self->some_number;
if (re... | This function, if you choose to provide it, should return a hash number for an instance of your data type. Here is a simple example::
static Py_hash_t
newdatatype_hash(PyObject *op)
{
newdatatypeobject *self = (newdatatypeobject *) op;
Py_hash_t result;
result = self->some_size + 32767 * self->some_number;
if (re... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
1a31cddd-dc99-42fe-81d8-88bed471a830 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,230 | supabase-export-v2 | ed2a6d8ab8517333 | weak reference implementation is to allow any type to participate in the weak reference mechanism without incurring the overhead on performance-critical objects (such as numbers).
.. seealso::
Documentation for the :mod:`weakref` module. | trusted_official_docs | CPython Docs | weak reference implementation is to allow any type to participate in the weak reference mechanism without incurring the overhead on performance-critical objects (such as numbers).
.. seealso::
Documentation for the :mod:`weakref` module. | weak reference implementation is to allow any type to participate in the weak reference mechanism without incurring the overhead on performance-critical objects (such as numbers).
.. seealso::
Documentation for the :mod:`weakref` module. | 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.