python-c-api Questions

1

Solved

The Vectorcall protocol is a new calling convention for Python's C API defined in PEP 590. The idea is to speed up calls in Python by avoiding the need to build intermediate tuples and dicts, and i...
Dna asked 25/8 at 20:35

3

Solved

I'm playing around with the C API for Python, but it is quite difficult to understand some corner cases. I could test it, but it seems a bug-prone and time consuming. So I come here to see if someb...

1

Solved

I'm working on a Python project with a setup.py that has something like this1: setup( cmdclass={"build_ext": my_build_ext}, ext_modules=[ Extension("A", ["a.c", &qu...
Herzel asked 24/4 at 20:51

37

Solved

I am trying to build a shared library using a C extension file but first I have to generate the output file using the command below: gcc -Wall utilsmodule.c -o Utilc After executing the command, I...
Glacialist asked 3/2, 2014 at 15:0

3

Solved

I am writing C extensions, and I'd like to make the signature of my methods visible for introspection. static PyObject* foo(PyObject *self, PyObject *args) { /* blabla [...] */ } PyDoc_STRVAR(...
Bayer asked 9/7, 2009 at 15:54

2

Solved

I have a C extension that is called from my multithreaded Python application. I use a static variable i somewhere in a C function, and I have a few i++ statements later on that can be run from diff...
Schuler asked 2/2, 2017 at 15:38

5

The python documentation states, that the reason cPickle is faster than Pickle is, that the former is implemented in C. What does that mean exactly? I am making a module for advanced mathematics i...
Aldrin asked 6/1, 2011 at 14:46

1

Solved

I am trying to leak memory from my C-extension forcefully. The code for the below is Pyobect* myfunc(PyObject* self, PyObject* args) { static int i = 213123; PyObject* temp = PyLong_FromLong(i); ...
Gerhardine asked 27/3, 2023 at 10:49

1

Solved

I'm trying to implement an algorithm in the form of the C programming language into my system that runs using the python programming language. I'm trying to implement the Python C API with the inte...
Wayfaring asked 1/2, 2023 at 6:33

1

I'm using multiple interpreters with multiple threads, and I'm trying to use PyThreadState_SetAsyncExc to stop a script, but it has no effect: void stop() { PyThreadState *ts = PyThreadState_Swap...
Davedaveda asked 9/12, 2019 at 13:11

4

I'd like to create an application with embedded python interpreter and basic debugging capabilities. Now I'm searching the API for functions which I could use to run code step-by-step and get the n...
Nakada asked 3/12, 2015 at 20:42

2

I made a Python module in C/C++ with Python C API. I use setuptools.Extension in my setup.py. It creates one .py file which loads a python module from some compiled .pyd file: def __bootstrap__(...
Parthena asked 21/3, 2018 at 14:39

0

There are PEP-554 and PEP-684. Both are designed to support multiple interpreters on Thread level. Does anyone know if these PEPs are implemented somewhere at least in experimental or pre-release v...
Shall asked 27/9, 2022 at 12:7

1

I am trying to build a Python-C interface, but when I looked at the source code, I am confused by PyObject and PyTypeObject. Can someone please explain the difference between them? It would be nice...
As asked 30/4, 2020 at 17:26

2

Solved

Question Suppose that I have implemented two Python types using the C extension API and that the types are identical (same data layouts/C struct) with the exception of their names and a few methods...
Extravagate asked 18/2, 2022 at 18:44

10

Solved

I'd like to call a custom function that is defined in a Python module from C. I have some preliminary code to do that, but it just prints the output to stdout. mytest.py import math def myabs(x): ...
Cimon asked 20/7, 2010 at 1:54

4

Solved

What is the best way to create class properties (as here and here) using the Python C-API? Static properties would also work in my case. Follow up: I tried to implement yak's suggestion. I define...
Humanist asked 15/4, 2012 at 11:26

5

Solved

I'm running some computationally heavy simulation in (home-made) C-based python extensions. Occasionally I get stuff wrong and would like to terminate a simulation. However, Ctrl-C doesn't seem to ...
Watkin asked 5/2, 2013 at 11:59

1

I am trying to install a Python (C-extension, if it matters) package that is located in a mounted directory, which for security reasons is read-only. However, by default pip will build the package ...
Deserted asked 22/10, 2021 at 18:30

2

I'm struggling how to create a python Enum object inside the Python C API. The enum class has assigned tp_base to PyEnum_Type, so it inherits Enum. But, I can't figure out a way to tell the Enum ba...
Risorgimento asked 25/6, 2021 at 13:28

1

Solved

I'm working on a Python C extension and I would like to expose a custom enum (as in: a class inheriting from enum.Enum) that would be entirely defined in C. It turned out to not be a trivial task a...
Averyaveryl asked 22/7, 2021 at 18:56

7

Solved

I'm using CPython and I have a C# dll. I'm trying to use Python for .NET to make them talk. I can't use IronPython because I need to integrate this into an existing CPython system. I'm completely ...
Determinative asked 6/11, 2012 at 21:22

6

Solved

The question I'm about to ask seems to be a duplicate of Python's use of __new__ and __init__?, but regardless, it's still unclear to me exactly what the practical difference between __ne...
Papilloma asked 1/2, 2011 at 5:7

3

Solved

I am writing a native function that will return multiple Python objects PyObject *V = PyList_New(0); PyObject *E = PyList_New(0); PyObject *F = PyList_New(0); return Py_BuildValue("ooo", V, E, F)...
Velma asked 16/8, 2010 at 23:25

1

I compile a python c module extension in Python 3.6. It works well in Python 3.6 environment but does not work in Python 3.7 and 3.8 environments, it gets error cannot import name 'cygrpc'. I wonde...
Bryantbryanty asked 2/11, 2020 at 23:33

© 2022 - 2024 — McMap. All rights reserved.