# \#c-api

**URL:** https://discuss.python.org/tag/c-api/35.md

[Latest](https://discuss.python.org/latest.md) · [Categories](https://discuss.python.org/categories.md) · [Tags](https://discuss.python.org/tags.md)

---

## [C-API for initializing statically linked extension modules](https://discuss.python.org/t/c-api-for-initializing-statically-linked-extension-modules/43396)

<div class="topic-metadata">

**Author:** [@itamaro](https://discuss.python.org/u/itamaro)\
**Replies:** 36\
**Last updated:** [November 17, 2026, 3:27pm UTC](https://discuss.python.org/t/c-api-for-initializing-statically-linked-extension-modules/43396 "2026-11-17T15:27:34Z")

</div>

At Meta, our Python “applications” (conceptually similar to a packaged venv) are statically linked binaries, with the main exe containing the Python interpreter, as well as native extensions statically linked into it. T…

---

## [Recompile with -fPIC, syntax correct](https://discuss.python.org/t/recompile-with-fpic-syntax-correct/109702)

<div class="topic-metadata">

**Author:** [@emians](https://discuss.python.org/u/emians)\
**Replies:** 1\
**Last updated:** [November 5, 2026, 3:58pm UTC](https://discuss.python.org/t/recompile-with-fpic-syntax-correct/109702 "2026-11-05T15:58:58Z")

</div>

Hello folks, building for Ardour 9.8, i got this after prompting the python3 waf executable: /usr/bin/ld: /usr/local/lib/libtag.a(id3v2framefactory.cpp.o): relocation R\_X86\_64\_TPOFF32 against \`\_ZN12\_GLOBAL\_\_N\_118embedd…

---

## [PEP 820 – PySlot: Unified slot system for the C API](https://discuss.python.org/t/pep-820-pyslot-unified-slot-system-for-the-c-api/105552)

<div class="topic-metadata">

**Author:** [@encukou](https://discuss.python.org/u/encukou)\
**Replies:** 23\
**Last updated:** [April 29, 2026, 10:11am UTC](https://discuss.python.org/t/pep-820-pyslot-unified-slot-system-for-the-c-api/105552 "2026-04-29T10:11:02Z")

</div>

Hello, I’ve written PEP 820, slightly simplified from last year’s “pre-PEP” thread, a proposal to unify PyType\_Slot and PyModuleDef\_Slot, and fix some of their shortcomings. The abstract: Replace type and module slot…

---

## [C API: \`PyArg\_Parse\` to a C \`bool\` (\`\<stdbool.h\>\`)](https://discuss.python.org/t/c-api-pyarg-parse-to-a-c-bool-stdbool-h/106189)

<div class="topic-metadata">

**Author:** [@lucascolley](https://discuss.python.org/u/lucascolley)\
**Replies:** 8\
**Last updated:** [February 18, 2026, 12:27pm UTC](https://discuss.python.org/t/c-api-pyarg-parse-to-a-c-bool-stdbool-h/106189 "2026-02-18T12:27:35Z")

</div>

Hi! I’m quite new to C, and one thing that surprised me while looking into SciPy’s C extensions is how Python bools are typically converted to C ints under the hood. It seems the idiomatic way for this is the p (predicat…

---

## [Pre-PEP: Unified slot system for the C API](https://discuss.python.org/t/pre-pep-unified-slot-system-for-the-c-api/78873)

<div class="topic-metadata">

**Author:** [@encukou](https://discuss.python.org/u/encukou)\
**Replies:** 7\
**Last updated:** [January 6, 2026, 1:53pm UTC](https://discuss.python.org/t/pre-pep-unified-slot-system-for-the-c-api/78873 "2026-01-06T13:53:40Z")

</div>

Here’s a proposal for the C API that’s been cooking for… um, a long time. Still rough around some of the edges, but I hit a self-imposed deadline to get it out, so here it is. (Please ignore formatting, this is reST r…

---

## [Annotating internal code with constexpr, consteval, and constinit](https://discuss.python.org/t/annotating-internal-code-with-constexpr-consteval-and-constinit/105450)

<div class="topic-metadata">

**Author:** [@clin1234](https://discuss.python.org/u/clin1234)\
**Replies:** 2\
**Last updated:** [December 31, 2025, 1:58pm UTC](https://discuss.python.org/t/annotating-internal-code-with-constexpr-consteval-and-constinit/105450 "2025-12-31T13:58:25Z")

</div>

Since there exist #ifdef \_\_cplusplus conditions throughout CPython’s codebase (not just for extern “C“)

---

## [Seeking Help and Advice on CPython Reference Counting Semantics](https://discuss.python.org/t/seeking-help-and-advice-on-cpython-reference-counting-semantics/103625)

<div class="topic-metadata">

**Author:** [@wr-web](https://discuss.python.org/u/wr-web)\
**Replies:** 4\
**Last updated:** [December 3, 2025, 3:52am UTC](https://discuss.python.org/t/seeking-help-and-advice-on-cpython-reference-counting-semantics/103625 "2025-12-03T03:52:52Z")

</div>

The CPython reference counting semantics generally fall into the following three categories: Return borrowed reference Return new reference Steal reference Currently, there are two issues with CPython referen…

---

## [Best Practices for Packaging Embedded Python Libraries for to Prevent Unauthorized Modification](https://discuss.python.org/t/best-practices-for-packaging-embedded-python-libraries-for-to-prevent-unauthorized-modification/105045)

<div class="topic-metadata">

**Author:** [@realybin](https://discuss.python.org/u/realybin)\
**Replies:** 5\
**Last updated:** [November 26, 2025, 4:16pm UTC](https://discuss.python.org/t/best-practices-for-packaging-embedded-python-libraries-for-to-prevent-unauthorized-modification/105045 "2025-11-26T16:16:47Z")

</div>

I am working for embedding Python in C++ applications. In Android testbeds, embedded Python resources are often extracted to the app’s private data directory. However, these files typically remain unencrypted, meaning t…

---

## [How to get latest debugging symbols and debug binaries](https://discuss.python.org/t/how-to-get-latest-debugging-symbols-and-debug-binaries/104516)

<div class="topic-metadata">

**Author:** [@realybin](https://discuss.python.org/u/realybin)\
**Replies:** 2\
**Last updated:** [November 5, 2025, 5:00am UTC](https://discuss.python.org/t/how-to-get-latest-debugging-symbols-and-debug-binaries/104516 "2025-11-05T05:00:12Z")

</div>

I can’t see any options in python-manager-25.0 and I can’t find the these things after using legacy installer by searching in Everything with pattern python\*\_d.lib

---

## [Does PyObject\_GetTypeData need the GIL?](https://discuss.python.org/t/does-pyobject-gettypedata-need-the-gil/104637)

<div class="topic-metadata">

**Author:** [@da-woods](https://discuss.python.org/u/da-woods)\
**Replies:** 6\
**Last updated:** [October 30, 2025, 7:36am UTC](https://discuss.python.org/t/does-pyobject-gettypedata-need-the-gil/104637 "2025-10-30T07:36:08Z")

</div>

My feeling (from looking at the implementation) is that in practice is doesn’t, but that the official story will be that it does. (It would be really useful if it didn’t)

---

## [Struct \_PyGenObject has been moved to internal/pycore\_genobject.h](https://discuss.python.org/t/struct-pygenobject-has-been-moved-to-internal-pycore-genobject-h/104217)

<div class="topic-metadata">

**Author:** [@sumerc](https://discuss.python.org/u/sumerc)\
**Replies:** 4\
**Last updated:** [October 21, 2025, 10:47am UTC](https://discuss.python.org/t/struct-pygenobject-has-been-moved-to-internal-pycore-genobject-h/104217 "2025-10-21T10:47:26Z")

</div>

Hi, Related to C API: Remove private C API functions (move them to the internal C API) · Issue #106320 · python/cpython · GitHub, 3.14 started failing for GitHub - sumerc/yappi: Yet Another Python Profiler, but this tim…

---

## [Frame state always \`running\` in \`sys.setprofile\` callback](https://discuss.python.org/t/frame-state-always-running-in-sys-setprofile-callback/104384)

<div class="topic-metadata">

**Author:** [@sumerc](https://discuss.python.org/u/sumerc)\
**Replies:** 1\
**Last updated:** [October 21, 2025, 10:46am UTC](https://discuss.python.org/t/frame-state-always-running-in-sys-setprofile-callback/104384 "2025-10-21T10:46:45Z")

</div>

Hi, During adding support for 3.14in Yappi profiler, we realized incorrect wall-time calculations in tests. Digging the issue it turns out that it basically fails to return if a frame is suspended or not in a profiler c…

---

## [Pass Value From Python Script to C++ Program](https://discuss.python.org/t/pass-value-from-python-script-to-c-program/104439)

<div class="topic-metadata">

**Author:** [@Jillinger](https://discuss.python.org/u/Jillinger)\
**Replies:** 12\
**Last updated:** [October 19, 2025, 7:08pm UTC](https://discuss.python.org/t/pass-value-from-python-script-to-c-program/104439 "2025-10-19T19:08:33Z")

</div>

I want to simply pass the value of a variable to the c++ application. I am trying this code: /\* Import the Python script \*/ pModule = PyImport\_ImportModule("test1"); if (pModule != nullptr) { res = PyModule\_AddSt…

---

## [Fatal Python error: \_Py\_CheckRecursiveCall: Unrecoverable stack overflow (used -406047 kB) while calling a Python object](https://discuss.python.org/t/fatal-python-error-py-checkrecursivecall-unrecoverable-stack-overflow-used-406047-kb-while-calling-a-python-object/104183)

<div class="topic-metadata">

**Author:** [@hroncok](https://discuss.python.org/u/hroncok)\
**Replies:** 1\
**Last updated:** [October 6, 2025, 12:35pm UTC](https://discuss.python.org/t/fatal-python-error-py-checkrecursivecall-unrecoverable-stack-overflow-used-406047-kb-while-calling-a-python-object/104183 "2025-10-06T12:35:56Z")

</div>

Hello, Around a month ago, the Fedora KiCad maintainer reported that kicad started crashing when we updated to Python 3.14: I maintain the KiCad packages. We have a new bug report: 2393850 – kicad crashes during pyt…

---

## [How to passing user data for \`PyMethodDef\`](https://discuss.python.org/t/how-to-passing-user-data-for-pymethoddef/103458)

<div class="topic-metadata">

**Author:** [@realybin](https://discuss.python.org/u/realybin)\
**Replies:** 4\
**Last updated:** [September 1, 2025, 5:52pm UTC](https://discuss.python.org/t/how-to-passing-user-data-for-pymethoddef/103458 "2025-09-01T17:52:07Z")

</div>

I’ve read many documents on how to create a method for a type using additional data. I want a feature similar to PyGetSetDef.closure that allows passing user data when there is no good way to do it otherwise. struct PyM…

---

## [\`Py\_VISIT(Py\_TYPE(self))\` in tp\_traverse for ZstdCompressor and ZstdDecompressor](https://discuss.python.org/t/py-visit-py-type-self-in-tp-traverse-for-zstdcompressor-and-zstddecompressor/100944)

<div class="topic-metadata">

**Author:** [@kli6891](https://discuss.python.org/u/kli6891)\
**Replies:** 1\
**Last updated:** [August 2, 2025, 8:47am UTC](https://discuss.python.org/t/py-visit-py-type-self-in-tp-traverse-for-zstdcompressor-and-zstddecompressor/100944 "2025-08-02T08:47:49Z")

</div>

Hi all, I’m learning heap allocated types work by studying examples in the standard library. The documentation for tp\_traverse states that: Heap types (Py\_TPFLAGS\_HEAPTYPE) must visit their type with: Py\_VISIT(Py\_TYP…

---

## [Module slot for checking ABI compatibility](https://discuss.python.org/t/module-slot-for-checking-abi-compatibility/96443)

<div class="topic-metadata">

**Author:** [@encukou](https://discuss.python.org/u/encukou)\
**Replies:** 8\
**Last updated:** [June 27, 2025, 1:42pm UTC](https://discuss.python.org/t/module-slot-for-checking-abi-compatibility/96443 "2025-06-27T13:42:57Z")

</div>

Expanding Da Woods’ idea: Currently, for checking whether an extension module is ABI-compatible, CPython relies on: an ABI tag in the extension filename (for example, in NumPy’s \_umath\_linalg.cpython-313t-x86\_64-linu…

---

## [Ergonomics of signal checks with detached thread state](https://discuss.python.org/t/ergonomics-of-signal-checks-with-detached-thread-state/94355)

<div class="topic-metadata">

**Author:** [@zwol](https://discuss.python.org/u/zwol)\
**Replies:** 1\
**Last updated:** [June 9, 2025, 3:53pm UTC](https://discuss.python.org/t/ergonomics-of-signal-checks-with-detached-thread-state/94355 "2025-06-09T15:53:15Z")

</div>

I’m working on an addition to the C-API that would make it possible to check for pending Unix signals (most importantly, the SIGINT delivered when the user presses control-C to interrupt a running calculation) from insid…

---

## [Open question: Can we change the field type of PyTupleObject and PyListObject?](https://discuss.python.org/t/open-question-can-we-change-the-field-type-of-pytupleobject-and-pylistobject/91318)

<div class="topic-metadata">

**Author:** [@kj0](https://discuss.python.org/u/kj0)\
**Replies:** 3\
**Last updated:** [May 9, 2025, 9:36am UTC](https://discuss.python.org/t/open-question-can-we-change-the-field-type-of-pytupleobject-and-pylistobject/91318 "2025-05-09T09:36:44Z")

</div>

I want to change the PyObject ob\_item fields in our list and tuple implementation to support tagged integers. This will involve changing their type (but not their field names nor their width). The docs for PyListObject …

---

## [Python 3.13 embedded in Android,How to Attach Android sub-thread?](https://discuss.python.org/t/python-3-13-embedded-in-android-how-to-attach-android-sub-thread/90953)

<div class="topic-metadata">

**Author:** [@Qinglin](https://discuss.python.org/u/Qinglin)\
**Replies:** 0\
**Last updated:** [May 6, 2025, 1:33pm UTC](https://discuss.python.org/t/python-3-13-embedded-in-android-how-to-attach-android-sub-thread/90953 "2025-05-06T13:33:09Z")

</div>

I’m trying to embed Python 3.13t(–disable-gil) into an Android app, and I’m calling the following code in the JNI called by the main thread extern "C" JNIEXPORT jint JNICALL Java\_com\_test\_cpyvm\_MainActivity\_runPython(JN…

---

## [C-API: confusion when to implement GC—docs vs stdlib](https://discuss.python.org/t/c-api-confusion-when-to-implement-gc-docs-vs-stdlib/88791)

<div class="topic-metadata">

**Author:** [@ariebovenberg](https://discuss.python.org/u/ariebovenberg)\
**Replies:** 2\
**Last updated:** [April 18, 2025, 6:57pm UTC](https://discuss.python.org/t/c-api-confusion-when-to-implement-gc-docs-vs-stdlib/88791 "2025-04-18T18:57:27Z")

</div>

I’m currently implementing an extension library for CPython, and I’m a bit confused about when GC support is required. To my understanding, the docs seem at odds with what I see in the stdlib (datetime, for example). Th…

---

## [PyImport\_Import does not want to import from working dir](https://discuss.python.org/t/pyimport-import-does-not-want-to-import-from-working-dir/79945)

<div class="topic-metadata">

**Author:** [@Iuliean](https://discuss.python.org/u/Iuliean)\
**Replies:** 4\
**Last updated:** [April 8, 2025, 11:40am UTC](https://discuss.python.org/t/pyimport-import-does-not-want-to-import-from-working-dir/79945 "2025-04-08T11:40:35Z")

</div>

I am trying to call some python code from my c++ app but i cannot for the love of god get PyImport\_Import to import the module/file from the working dir of the app int main(int argc, char \*argv\[\]) { PyObject \*pName…

---

## [Deprecating the direct use of str internals, e.g. PyASCIIObject, PyCompactUnicodeObject, PyUnicodeObject structs](https://discuss.python.org/t/deprecating-the-direct-use-of-str-internals-e-g-pyasciiobject-pycompactunicodeobject-pyunicodeobject-structs/82543)

<div class="topic-metadata">

**Author:** [@encukou](https://discuss.python.org/u/encukou)\
**Replies:** 22\
**Last updated:** [March 29, 2025, 11:14pm UTC](https://discuss.python.org/t/deprecating-the-direct-use-of-str-internals-e-g-pyasciiobject-pycompactunicodeobject-pyunicodeobject-structs/82543 "2025-03-29T23:14:03Z")

</div>

Hello, In the C API, I’d like to deprecate direct use of str internals – specifically: PyASCIIObject, PyCompactUnicodeObject, PyUnicodeObject structs the PyUnicode\_IS\_COMPACT macro See a preview of porting notes. Al…

---

## [Making \`PyObject\` opaque in the limited API](https://discuss.python.org/t/making-pyobject-opaque-in-the-limited-api/77206)

<div class="topic-metadata">

**Author:** [@encukou](https://discuss.python.org/u/encukou)\
**Replies:** 6\
**Last updated:** [January 17, 2025, 10:00pm UTC](https://discuss.python.org/t/making-pyobject-opaque-in-the-limited-api/77206 "2025-01-17T22:00:23Z")

</div>

Hello, I’ve spent some time gathering thoughts about a new version of the stable ABI, and I’d like to start some focused discussion around it. There are a lot of things to design and discuss (EOL dates, file/wheel name…

---

## [Deprecating support for nested non-tuple sequences in PyArg\_ParseTuple()](https://discuss.python.org/t/deprecating-support-for-nested-non-tuple-sequences-in-pyarg-parsetuple/75933)

<div class="topic-metadata">

**Author:** [@storchaka](https://discuss.python.org/u/storchaka)\
**Replies:** 6\
**Last updated:** [January 8, 2025, 5:31pm UTC](https://discuss.python.org/t/deprecating-support-for-nested-non-tuple-sequences-in-pyarg-parsetuple/75933 "2025-01-08T17:31:56Z")

</div>

There is a rarely used feature in PyArg\_ParseTuple(). It supports parsing nested sequences. For example, resource.setrlimit used PyArg\_ParseTuple(args, "i(OO):setrlimit", &resource, &curobj, &maxobj) to parse its argumen…

---

## [C API for iterable unpacking](https://discuss.python.org/t/c-api-for-iterable-unpacking/75193)

<div class="topic-metadata">

**Author:** [@rtobar](https://discuss.python.org/u/rtobar)\
**Replies:** 4\
**Last updated:** [December 30, 2024, 12:23pm UTC](https://discuss.python.org/t/c-api-for-iterable-unpacking/75193 "2024-12-30T12:23:32Z")

</div>

Hi everyone, I just found myself writing some code in a C extension to mimic the behaviour of simple target list assignments, e.g. a, b = c, which should work for any iterable c. From what I could gather after perusing …

---

## [Interrupting long running PyObject\_Call inside subinterpreter](https://discuss.python.org/t/interrupting-long-running-pyobject-call-inside-subinterpreter/75120)

<div class="topic-metadata">

**Author:** [@813gan](https://discuss.python.org/u/813gan)\
**Replies:** 6\
**Last updated:** [December 24, 2024, 10:05pm UTC](https://discuss.python.org/t/interrupting-long-running-pyobject-call-inside-subinterpreter/75120 "2024-12-24T22:05:38Z")

</div>

I’m working on Python foreign function interface for Elisp. Python methods are called in separated pthread with PyObject\_Call. I’m creating sub-interpreters to isolate Elisp packages from each other. I want user to be…

---

## [C API docs for free-threading?](https://discuss.python.org/t/c-api-docs-for-free-threading/74183)

<div class="topic-metadata">

**Author:** [@ngoldbaum](https://discuss.python.org/u/ngoldbaum)\
**Replies:** 3\
**Last updated:** [December 16, 2024, 5:50pm UTC](https://discuss.python.org/t/c-api-docs-for-free-threading/74183 "2024-12-16T17:50:20Z")

</div>

I noticed today that this page in the C API docs which describes the GIL and the macros for releasing and acquiring it has no mention of the free-threaded build. I think that is a little confusing, since the semantics ar…

---

## [How to add attribute to PyObject correctly, PyObject size calculated staticly?](https://discuss.python.org/t/how-to-add-attribute-to-pyobject-correctly-pyobject-size-calculated-staticly/48400)

<div class="topic-metadata">

**Author:** [@nevercodecorrect](https://discuss.python.org/u/nevercodecorrect)\
**Replies:** 2\
**Last updated:** [December 10, 2024, 12:36pm UTC](https://discuss.python.org/t/how-to-add-attribute-to-pyobject-correctly-pyobject-size-calculated-staticly/48400 "2024-12-10T12:36:47Z")

</div>

I try to add an additonal taint attribute so I could do some dynamic track on all PyObjects. typedef struct \_object { \_PyObject\_HEAD\_EXTRA Py\_ssize\_t ob\_refcnt; PyTypeObject \*ob\_type; int tainted;//1 tai…

---

## [How serious is the PyFunction\_AddWatcher warning about not modifying the function?](https://discuss.python.org/t/how-serious-is-the-pyfunction-addwatcher-warning-about-not-modifying-the-function/73119)

<div class="topic-metadata">

**Author:** [@jgarvin](https://discuss.python.org/u/jgarvin)\
**Replies:** 4\
**Last updated:** [December 5, 2024, 12:38am UTC](https://discuss.python.org/t/how-serious-is-the-pyfunction-addwatcher-warning-about-not-modifying-the-function/73119 "2024-12-05T00:38:00Z")

</div>

Quoting the docs here: The callback may inspect but must not modify func ; doing so could have unpredictable effects, including infinite recursion. I’d like to modify the function’s globals object to point to a wrapp…

[Next page](https://discuss.python.org/tag/c-api/35.md?match_all_tags=true&page=1&tags%5B%5D=c-api)
