Questions tagged [python-c-extension]

python c extensions are modules written in C/C++ and can be imported and used by python interpreter

257 questions
0
votes
1 answer

Creating a Python type in C using an external library: ctypes or setuptools?

I'm writing some sort of Python C extension. It uses my own *.so library and headers from another project (let's say they're in /usr/local/lib/otherproject.so and /usr/local/include/otherproject.h). I don't know which strategy to follow. I came up…
jleeothon
  • 2,907
  • 4
  • 19
  • 35
0
votes
1 answer

Most efficient way to convert a multidimensional numpy array to ctypes array

Hello, I am using ctypes module in python to run some image processing C code from python, for the purpose of optimisation of my code, and reducing the execution time. For this purpose, I am reading an image into a numpy array and then applying 2D…
ironstein
  • 416
  • 8
  • 23
0
votes
1 answer

Segmentation fault on calling Python C-extension module

I have a C extension module that I am building and using on CentOS using distutils . python setup.py build_ext --inplace However the moment I try to use the same (recompiling again of course to generate the .so file) in a 64 bit Ubuntu machine…
Alex Punnen
  • 5,287
  • 3
  • 59
  • 71
0
votes
0 answers

Link .so files while running an appication

In my application I have used a .so(shared object) file which is written using python c++ extension and compiled with g++ using the -c argument(to postpone the linking). Now, I need to link two other .so files, which may be present in different…
user2109788
  • 1,266
  • 2
  • 12
  • 29
0
votes
1 answer

Segmentation fault with PyType_IsSubtype

I'm getting the following error when debugging a C extension in gdb Program received signal SIGSEGV, Segmentation fault. PyType_IsSubtype (a=0xc0089ca71d1afbb6, b=0x7fffed5441e0) at Objects/typeobject.c:1150 1150 Objects/typeobject.c: No such…
irios
  • 165
  • 1
  • 11
0
votes
1 answer

PyArg_ParseTuple causing segmentation fault

I'm trying to call a c function from my extension and have narrowed the problem down to this test case. #import "Python.h" ... // Called from python with test_method(0, 0, 'TEST') static PyObject* test_method(PyObject *args) { int ok, x, y,…
jtm
  • 1,535
  • 18
  • 19
0
votes
0 answers

Python C package source code header files are missing

I am working on modifying source code for python C extension module ceODBC. I set up the C source code of ceODBC in Visual studio as a C++ project and linked python source code (so including Python.h in ceODBC won't cause any issue). However, there…
Joy3223
  • 1
  • 1
0
votes
1 answer

Function in C extension randomly stops python program execution

I am relatively new to C extensions for python. I wrote an extension that shows a behavior that seems weird to me. When I run a python script using this extension the script stops randomly after the routine in the extensions has been successfully…
Samufi
  • 2,465
  • 3
  • 19
  • 43
0
votes
1 answer

Cross compiling my c python extension for kodi / xbmc android

I need to compile my c extension that is invokable by python in kodi. Can anyone please list the steps involved. I think I have actually cross compiled the c extension but it wouldn't work with kodi.
bir433
  • 61
  • 5
0
votes
2 answers

Python 3 compatibility issue

Description of problem I have to migrate some code to Python 3. The compilation terminated with success. But I have a problem on the runtime: static PyObject* Parser_read(PyObject * const self, PyObject * unused0, PyObject * unused1) { …
Wael Ben Zid El Guebsi
  • 2,670
  • 1
  • 17
  • 15
0
votes
1 answer

How to link python's static library for C extensions?

I am trying to write an C++ extension for python which involves Python C API. According to my previous experience on doing this with Visual Studio, I just need to include python's header files and link python's static libraries and everything would…
0
votes
2 answers

Importing Class in Python Subpackage imports more than requested

Overview I'm running some scientific simulations and I want to process the resulting data in Python. The simulation produces a custom data type that is not used outside of the chain of programs that the authors of the simulation produced, so…
Joel
  • 2,065
  • 2
  • 19
  • 30
0
votes
3 answers

convert PyFloatObject to float

I have a PyFloatObject that I want to convert to a C float. However, PyObjectFloat only provides a conversion to double. Can I safely cast a double to a float, or is there a function to convert PyObject to float i.e. PyObject_AsFloat.
ragingSloth
  • 1,094
  • 8
  • 22
0
votes
1 answer

Python C-extension class with a dynamic size

I try to write C-extension which contains python class. This class takes a filename as a parameter fname of constructor, then loads that file to memory and stores as a config. Below what I have: typedef struct { PyObject_HEAD XmlConfig…
San4ez
  • 8,091
  • 4
  • 41
  • 62
0
votes
1 answer

Accessing global variables from a python callback of C extension API

I am new to python and C-extensions. I am writing a python code where I have created two threads and have defined a callback function py_cb(). In one thread I am appending to a global list after certain time intervals, whereas from the other thread,…