python-c-api Questions

1

I'm new to the Python C-API. Currently I get objects from the embedded Python module via PyObject* a = (PyObject*) PyObject_GetAttrString(pModule, "a"); std::cout << "a as long...
Baran asked 9/10, 2020 at 16:58

2

Solved

I have a python modules written in C, it has a main module and a submodule(name with a dot, not sure this can be called real submodule): PyMODINIT_FUNC initsysipc(void) { PyObject *module = Py_Ini...
Devindevina asked 20/9, 2020 at 12:19

1

Solved

I'm building a C Python extension which makes use of a "third party" library— in this case, one that I've built using a separate build process and toolchain. Call this library libplumbus....
Barnie asked 9/9, 2020 at 4:42

3

Solved

I have a simple C-extension(see example below) that sometimes prints using the printf function. I'm looking for a way to wrap the calls to the function from that C-extensions so that all those prin...
Dimmer asked 27/7, 2020 at 10:0

0

I'm trying to build a python extension which has a function returns a np.array. But it breaks when compiled with MinGW32 but works with VS2019. I tried to comment the code setting the flag NPY_ARRA...
Bellicose asked 29/7, 2020 at 6:0

1

Solved

I have a C function that involves decompressing data using zstd. I am attempting to call that function using Cython. Using this page from the docs as a guide I can compile and run the code below wi...
Caressa asked 30/6, 2020 at 17:17

3

Solved

I was going through the tutorial for defining 'new types' in python, https://docs.python.org/2/extending/newtypes.html, and I did not understand the purpose of using Py_DECREF in this piece of cod...
Perforate asked 27/6, 2014 at 5:40

1

Solved

I'm writing a C extension for Python that wraps a C library. The C library has a few enum types and I've written corresponding IntEnums for these, for example: from enum import IntEnum # _enum_con...
Paddie asked 27/4, 2020 at 3:22

1

Solved

Note: Since asking this question, I discovered later on that python -m pip install -e . will install the extension to cmod with .venv/lib/python3.8/site-packages/hello-c-extension.egg-link pointing...
Leftwich asked 3/4, 2020 at 3:39

1

Solved

On one server with GCC 4.4.7/GCOV 4.4.7, I'm able to run the tests successfully. However on a different server with GCC 4.8.5/GCOV 4.8.5, running the tests results in this error: profiling:/path/t...
Yorkshire asked 21/2, 2020 at 17:33

2

I'm writing a Python module in C. I need to report errors that can't be described by built-in Python exceptions. I therefore wish to throw exceptions of my own type. The problem is, that Python pol...
Amoebic asked 20/6, 2011 at 12:21

1

Solved

To build a python project managed with poetry I need to build C extensions first (an equivalent to python setup.py build). poetry is able to do this according to this github issue. But to me it's n...
Lighten asked 5/2, 2020 at 10:27

1

Solved

I'm trying to understand sub-interpreters and GIL. But my experiment is failing often(The same code rarely works). Gathering info from SO questions and few sites, I have the following code which s...
Refutation asked 9/1, 2020 at 14:39

2

Solved

If I build CPython from source on Windows I encounter problems when I want to pip install a package that contains a C-Extension. It seems like the error happens while linking the libraries. For exa...
Baste asked 1/12, 2019 at 15:1

2

I am failing to open numpy with the Python C API. I have the following code #include<Python.h> int main() { Py_Initialize(); PyRun_SimpleString("import numpy"); PyObject* numpy = PyImpor...
Hoehne asked 1/11, 2016 at 12:46

1

Solved

I have a C++ program, I want to import a Python module and list all function names in this module. How can I do it? I used the following code to get the dict from a module: PyDictObject* pDict = ...
Vo asked 24/9, 2019 at 7:44

1

Solved

Everywhere, I can easily find an example about writing a method with Python C Extensions and use it in Python. Like this one: Python 3 extension example $ python3 >>> import hello >&gt...
Beulahbeuthel asked 18/5, 2019 at 21:53

2

Solved

I got the following file structure for my Python C Extension project: . ├── setup.py ├── source    ├── cppimplementation    │   └── fastfile.cpp    └── fastfilepackage    ├── __init__.py    └...
Hermie asked 21/5, 2019 at 19:0

1

Solved

I want to check if an object is an instance of a certain class. In Python I can do this with isinstance(obj, cls). In C/C++, I found a function named PyObject_IsInstance. But it seems not to work l...
Dichroism asked 20/5, 2019 at 3:57

3

Solved

I'm embedding Python interpreter to a C program. However, it might happen that while running some python script via PyRun_SimpleString() will run into infinite loop or execute for too long. Conside...
Transmundane asked 14/9, 2009 at 11:19

1

Solved

I have a Numpy vector of bools and I'm trying to use the C API to get a bytes object as quickly as possible from it. (Ideally, I want to map the binary value of the vector to the bytes object.) I ...
Agitator asked 27/4, 2019 at 0:30

1

I am writing a C program that spawns multiple C threads, with one Python sub-interpreter per thread. The sub-interpreters do not share any mutable Python variables, they are isolated from each othe...
Uranography asked 29/12, 2018 at 1:3

2

Solved

If I do something like: >>> x = int(1,2,3,4,5) I immediately get a fatal error (one that would end program execution if it was in a pre-written script) Traceback (most recent call last)...
Ludewig asked 27/11, 2013 at 2:46

2

Solved

Let’s say I have a PyListObject, and I want to append a PyObject. I can use the PyList_Append API which is documented in the List Objects C-API. But for my use case, I want to pop an element from t...
Jelene asked 16/2, 2019 at 9:3

1

Solved

I've been successfully using cppyy for automatic python bindings for a C++ project I'm working on. I recently included the Eigen library, but I'm having trouble using this together with cppyy. Does...
Enterovirus asked 17/12, 2018 at 15:59

© 2022 - 2025 — McMap. All rights reserved.