Questions tagged [python-extensions]

Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability.

323 questions
1
vote
0 answers

Passing double arrays from Python to C++ extensions

I understand a basic C++ function wrapped for Python looks like this: int square(int n) { return n*n; } static PyObject* square_wrapper(PyObject* self, PyObject* args) { int n = 0; if(!PyArg_ParseTuple(args, "i", &n)) return…
1
vote
1 answer

Passing byte string from Python to C

I am writing a python extension in C and I am trying to pass a bytes object to my function. Obviously the 's' token is for strings; I have tried 'O', 'N', and a few others with no luck. Is there a token I can use to parse a bytes object? If not is…
Daniel
  • 547
  • 5
  • 25
1
vote
1 answer

Need guidance regarding reference counting

I'm chasing a memory leak that seems to come from a long-running process which contains a C extension that I wrote. I've been poring over the code and the Extensions docs and I'm sure it's correct but I'd like to make sure regarding the reference…
musbur
  • 567
  • 4
  • 16
1
vote
0 answers

"corrupted double-linked list" after C++ python extension program terminates

I am developing a program that extends python with C++ code, and it looks like I'm missing something in initialization or cleanup. The symptom is that when the program terminates it prints out something like this: *** glibc detected *** ...…
Michael
  • 5,775
  • 2
  • 34
  • 53
1
vote
1 answer

How would I create a Python library that is extended by using C?

My goal is to create a Python library that I can import into any of my projects, and I wish to have the library made faster by the use of the C language (similar to how NumPy works). However, after following many different tutorials and videos, I…
Pencilcaseman
  • 360
  • 6
  • 16
1
vote
1 answer

Why does PyArg_ParseTuple always return false?

My PyFLoat_ParseTuple call always return false, with correct call from python side. I am working on wrapping my C++ for Python and using python extension. I had a successful project, and generating the current one based on that. I always had a crash…
Charlie
  • 21
  • 4
1
vote
1 answer

Can't correctly convert Numpy array to c array for Python Extension (c++)

I'm developing a Python extension in c++. I'm am really rusty in c++ however and don't have the necessary experience to figure this out it seems. I'm trying to read in numpy arrays, do the calculations I want to do and then return a numpy array. The…
Mineral
  • 197
  • 1
  • 1
  • 10
1
vote
1 answer

C code crashes attempting Python remote procedure call via xmlrpc

I'm trying to create C code that creates an Python xmlrpc client and calls methods on the xmlrpc server (I'm thinking of using this as IPC for a hook DLL). Here's the code ... I'm not going to layer in reference counting until it works. #include…
MikeRand
  • 4,788
  • 9
  • 41
  • 70
1
vote
1 answer

Using Python object exported from DLL in an exe

I have a two-part event generator: pyglobalexe (a stub to simulate events): #pragma comment(lib, "pyglobalextension.lib") #include __declspec(dllimport) PyObject* PyInit_pyglobalextension; __declspec(dllimport) PyObject*…
MikeRand
  • 4,788
  • 9
  • 41
  • 70
1
vote
0 answers

How to free memory early for a PyObject?

I have a large (numpy ndarray) object whose memory I want to free as soon as I am finished with it in my Python extension (or I will quickly run out of memory). How can I safely do this? It seems that in Python, something like del arr followed by…
Zach Boyd
  • 419
  • 1
  • 5
  • 23
1
vote
2 answers

Creating .so file using ctypes when opencv is included in C++ code

I am trying to create .so file of a c++ file(twocams.cpp) which includes main() and another C++ file (say abc.h). abc.c includes opencv. while creating an object using ctypes, g++ -fPIC -shared twocams.cpp -o twocams.so Test =…
1
vote
2 answers

Python extension in C - Metaclass

I have the following python code: class Meta(type): def __call__(cls, *args, **kwargs): obj = type.__call__(cls, *args, **kwargs) # Only do checks for subclasses if cls.__name__ == 'Parent': return obj …
Nelson
  • 922
  • 1
  • 9
  • 23
1
vote
0 answers

Very different size of *.so and *.pyd, why?

I managed to build *.pyd library. Sweat, blood, tears and gore aside, it turned out to be about 4 (four) times smaller than the corresponding *.so library. While the code seems to work, I cannot help but to wonder why the difference is so huge. Is…
wvxvw
  • 8,089
  • 10
  • 32
  • 61
1
vote
0 answers

Python extension build chokes on `std::unique_ptr` on Mac

I have a toy project that's implemented as a C++ library and exposed to Python using a Cython wrapper. After not touching the project for a few months, I tried to build it from scratch today and got the following error. gcc -Wno-unused-result…
Daniel Standage
  • 8,136
  • 19
  • 69
  • 116
1
vote
1 answer

Trouble with DateTime object methods in C++ extension

I'm working on a C++ extension for Python 3 and trying to pass a DateTime object to my function. the PyDateTime_Check function seems to work and returns true, but when I try to get the year from the DateTime object it returns 65535. I'm passing…
Lucian
  • 174
  • 10