python c extensions are modules written in C/C++ and can be imported and used by python interpreter
Questions tagged [python-c-extension]
257 questions
0
votes
3 answers
Wrong math result with calling C extension in Python
I am calling the pow() function of C's math library. My installation is Python3.5 on Windows 10 but I tried the same program in Python2.7 with same result. The return from the function is not as expected. Not sure what's happening. The code is given…

coder.in.me
- 1,048
- 9
- 19
0
votes
1 answer
Return data from struct using Numpy Array
I am writing Python C-extensions to a library and wish to return data as an Numpy Array. The library has a function that returns data from a sensor into a C structure. I would like to take the data from that structure and return it as a Numpy…

Steve Caldara
- 233
- 1
- 2
- 5
0
votes
1 answer
Python: C++ extension returning multiple values
I am writing a C++ extension for python script and want to return multiple values like what we can do in python function.
Simple Example in python:
def test():
return 0,0
tuple seems to be the closest answer
#include…

Mark Jin
- 2,616
- 3
- 25
- 37
0
votes
0 answers
python3 C extension nosetests
I have written some C extensions for my package, when I test the package with unit test, there is no error, however, when I use nose tests, there is error complaining
*** Error in `python3': munmap_chunk(): invalid pointer: 0x0000000002111800 ***…

1a1a11a
- 1,187
- 2
- 16
- 25
0
votes
1 answer
Python C extension causes stat ENOENT
I am attempting to implement a C extension in Python. The extension works, but as soon as the module is imported, errno is set to ENOENT (2).
simple.c
#include
#include
static PyMethodDef KeypadMethods[] = {
{NULL, NULL,…

FamousJameous
- 1,565
- 11
- 25
0
votes
1 answer
fread with fopen64 under MinGW64 kills the process
I'm building my x64 python c library extension from x86 one.
I found out fread with a file pointer opend by fopen64 killed the python process because of an error APPCRASHof ntdll.dll. It doesn't happen under x86 build and neither happen if the file…

fx-kirin
- 1,906
- 1
- 20
- 33
0
votes
0 answers
Python C Extension - Memory Leak despite Refcount = 1 on returned PyObjects
I'm repeatedly calling a python module I wrote in C++ using the Python C API. My python program repeatedly calls my module's pyParse function, which does a bunch of stuff and returns a PyTuple that contains more PyTuple objects as elements. Every…

JoseOrtiz3
- 1,785
- 17
- 28
0
votes
1 answer
In C/C++ extensions to Python, what reference count should a returned PyObject* have?
Lets say you wrote a C++ (or C) extension to python, called module. It returns an array of arrays. What should the returned array, and its arrays, have as reference counts?
The python code would be something like
import my_module
from sys import…

JoseOrtiz3
- 1,785
- 17
- 28
0
votes
0 answers
Crash in PyObject_Hash
I am hitting a periodic crash when calling PyObject_Hash. Below is the traceback:
(gdb) bt
#0 PyObject_Hash (v=0x0) at Objects/object.c:1107
#1 0x00002ac08c50c8e8 in tuplehash (v=) at Objects/tupleobject.c:351
#2 …

aks
- 304
- 3
- 8
0
votes
0 answers
How do I use ctypes with stdin in binary and fscanf
I am not have any success with this situation.
On Ubuntu 14 with Python 3.5.1, I want to pass sys.stdin to C/C++ with only ctypes and use libc.fscanf. I have tried libc.stdin as well. I believe this has to be done in binary because that is how…

mszlazak
- 59
- 1
- 6
0
votes
0 answers
PyDict key not setting correctly when more than 1 threads are used
I am developing a Python C extension for a computation intensive algorithm, and for optimization purposes, I am using pthreads, to execute C code in parallel. In each thread, I update a dictionary, after some processing. The dictionary is shared…

Muhammad Sadiq Alvi
- 1,099
- 1
- 13
- 23
0
votes
0 answers
bayesopt: segmentation fault
I use bayesopt with the python bindings.
When running an optimization, it fails after the initialization step. It computes the first starting_points, and then runs nlopt. Here's the backtrace:
Program received signal SIGSEGV, Segmentation fault.…

DevShark
- 8,558
- 9
- 32
- 56
0
votes
1 answer
Debugging a c-extension in python
I run bayesopt with python bindings. So I have a bayesopt.so that I import from python (a C-extension).
When I run it, it core dumps. I want to load this core dump in gdb to see what the issue is. How can I do this? Or get information on it?
I tried…

DevShark
- 8,558
- 9
- 32
- 56
0
votes
1 answer
Achieve real parallelism python C-Extension
I have written a python C Extension. Its working fine. But Now for more efficient execution, I need to write a multithreaded/parallel-executing version of the same extension.
Can you please tell me, how to write a Python C-Extension code that runs…

Muhammad Sadiq Alvi
- 1,099
- 1
- 13
- 23
0
votes
1 answer
Import standard Python library from C
I am writing a Python 3 C extension where I want to use a MappingProxyType (from types import MappingProxyType). From what I saw in the Cpython source code, MappingProxyType is written in Python and not in C.
How can I use this type from C? I…

jleeothon
- 2,907
- 4
- 19
- 35