Skip to main content

All Questions

Filter by
Sorted by
Tagged with
0 votes
1 answer
73 views

How to properly deepcopy linked objects in C Extension

In Python, I have a pair of classes like class Internal: def __init__(self, ref): self.ref = ref class External: def __init__(self): self.storage = [1,2,3] self.int = ...
Askold Ilvento's user avatar
14 votes
1 answer
911 views

Defining a Python enum in a C extension - am I doing this right?

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 and ...
Bartosz Golaszewski's user avatar
0 votes
0 answers
60 views

Why should we almost always reassign an object members before decrementing their reference counts?

I was reading through this tutorial in order to learn how to write C extension module to define new types. At some point the following tp_init implementation was given: static int Custom_init(...
sifadil's user avatar
  • 33
1 vote
1 answer
217 views

PyLongObject memory leak

There is a memory leak in my encode method. static const size_t _bits_per_digit = sizeof(digit) * CHAR_BIT; /** * Returns a Python int storing the bitstream of the Elias gamma encoded input list. */...
user avatar
1 vote
1 answer
152 views

Use PyObject_Realloc correctly

https://github.com/python/cpython/blob/master/Include/objimpl.h#L83 says PyObject_Realloc(p != NULL, 0) does not return NULL, or free the memory at p. PyObject_Realloc doesn't free the memory. I've ...
user avatar
0 votes
1 answer
103 views

How to combine own C-extension in own Python Package

I created own Python Package in which I want to add own Python C Extension, because in Python Package I'm importing this C-Ext. I want to install it from local files, not pypi. I have dist files of C ...
rozumir's user avatar
  • 905
7 votes
1 answer
4k views

Including and distributing third party libraries with a Python C extension

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....
trbabb's user avatar
  • 2,115
1 vote
1 answer
369 views

How to return a pointer to a C++ object to python using boost if the class of that object is declared in another boost module?

Okay, maybe I'm not finding an answer because I'm not sure how to word it, but I have a class called Info and another class called Packet, both are compiled into Python extensions using boost, and I ...
qwerty_99's user avatar
  • 798
0 votes
0 answers
27 views

Python C++ module causing a core dump when accessing the same PyObject* attribute more than once [duplicate]

So I've finally managed to import the C module into python. However, I'm getting a core dump when I try to access the attribute of an object more than once. Here's the code: node.h: #pragma once #...
qwerty_99's user avatar
  • 798
0 votes
0 answers
46 views

dynamic module does not define init function error when importing .so file compiled with boost python (Python 3.7) [duplicate]

This might have already been posted somewhere else but I couldn't find anything that worked. I have the following libraries / tools installed : boost: boost-python36.x86_64 boost-python36-devel.x86_64 ...
qwerty_99's user avatar
  • 798
1 vote
1 answer
237 views

How to convert a Python deque to a C++ container?

I have to pass a Python deque to a C++ function but I can't find any documentation on how to convert a deque to a C++ container (for this case, either a deque or a vector would do). Searched ...
qwerty_99's user avatar
  • 798
1 vote
0 answers
154 views

How fast is PyObject_CallMethod compared to pure python?

I'm trying to optimize some python code by isolating part of the code into a C++ extension. However, since the code is heavily object-oriented, I'll need to set some attributes as PyObject*. My ...
qwerty_99's user avatar
  • 798
0 votes
1 answer
315 views

Proper way to call a different method from the same C-extension module?

I'm converting a pure-Python module to a C-extension to familiarize myself with the C API. The Python implementation is as follows: _CRC_TABLE_ = [0] * 256 def initialize_crc_table(): if ...
Kamikaze Rusher's user avatar
1 vote
0 answers
533 views

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(!...
Aidan Lethaby's user avatar
1 vote
1 answer
2k views

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 ...
Daniel's user avatar
  • 597

15 30 50 per page