Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability.
Questions tagged [python-extensions]
323 questions
0
votes
1 answer
_PyMem_DebugRawFree: bad ID: Allocated using API '', verified using API 'o'
My program crashed with the following message from CPython
Debug memory block at address p=0x8a6e80: API ''
0 bytes originally requested
The 7 pad bytes at p-7 are not all FORBIDDENBYTE (0xfd):
at p-7: 0x00 *** OUCH
at p-6:…

user7610
- 25,267
- 15
- 124
- 150
0
votes
0 answers
Python bdist_wheel + install works but sdist + install fails due to PEP 517
I'm working on a Python package, that wraps a C++ library using Pybind11 + cmake, the code is available at https://github.com/bayesmix-dev/pybmix
Since I'm working on Linux, in order to distribute it through PyPi, I understand that there are two…

mariob6
- 469
- 1
- 6
- 16
0
votes
0 answers
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(CustomObject *self, PyObject *args, PyObject *kwds)
{
…

sifadil
- 23
- 1
- 4
0
votes
1 answer
Importing python modules and extension modules with the same name
Let's say I built a package with a Python module and an extension module in it, but with the identical name
mypackage
|
+-- __init__.py
|
+-- mymodule.py
|
+-- mymodule.cpython-39-x86_64-linux-gnu.so
I have found that when I do from mypackage…

Tetheras
- 33
- 3
0
votes
0 answers
Use c++ python extension in google colab
I've made a python extension with c++ that runs in visual studio. I have 4 files from this:
BeeLib.exp
BeeLib.lib
BeeLib.pdb
BeeLib.pyd
I want to use these in google colab like I do in visual studio, I tried throwing these files into…

Dom
- 1,232
- 1
- 10
- 20
0
votes
0 answers
How to allow my custom object to be pickled?
I created a bit sequence custom type in C
typedef struct {
PyObject_VAR_HEAD
uint8_t data[1];
} BitStream;
static PyTypeObject BitStreamType = {
PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "my_module.BitStream",
.tp_dealloc = 0,
…

theonlygusti
- 11,032
- 11
- 64
- 119
0
votes
1 answer
How to reduce size of my custom python type?
I created my own custom Python type. It stores an internal array of bytes. Even when there's no bytes in the array, the object takes up 32 bytes. How can I reduce that?
Here's how I defined my type:
typedef struct {
PyObject_VAR_HEAD
uint8_t…

theonlygusti
- 11,032
- 11
- 64
- 119
0
votes
1 answer
Is there a way to version a Python C extension?
I have a python3 distribution that has one package and also a C extension. I would like to be able to specify the version of the C extension during imports in the tell.py script, but cannot seem to figure it out.
My directory structure looks…

deprekate
- 446
- 3
- 9
0
votes
1 answer
C-extension in Python - pyObject called Py_DECREF ,reference is 0,but memory leak
this is my code.
PyObject *dataPyParams = PyList_New(0);
for (int i = 0; i < figdata.dataSetList.size(); i++)
{
PyObject *pyParams = PyList_New(0);
for (int j = 0; j < figdata.dataSetList[i].size(); j++)
{
//std::cerr <<…

KeyboardMan
- 1
- 3
0
votes
1 answer
Why GCC-compiled Python libraries compatible across compiler versions while MSVC ones are not?
I am adding some Python packages (from pip) to a 3rd-party application's Python interpreter on both Linux and Windows. In the Linux release of their application they compiled Python against GCC 4.xx, while in their Windows release they compiled it…
user7989146
0
votes
1 answer
Building Python extension fails ("kernel32.lib" cannot be opened | "x64" conflicts with target machine type "x86")
I am trying to install the python extension line-profiler via pip on a fresh installation of Anaconda3. As the package requires a compiler, I have installed the Visual Studio Build Tools 2019 along with the Windows 10 SDK. In particular, I have…

Samufi
- 2,465
- 3
- 19
- 43
0
votes
1 answer
How to access/retrieve member variable of PyObject from within python extension
The function PyObject_Call() is used to call a method on a PyObject. But how to get/read a member variable of a PyObject?

cosas
- 43
- 5
0
votes
1 answer
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 Extension, and I wonder how to do it properly. I…

rozumir
- 845
- 9
- 20
0
votes
0 answers
Creating a new timer_t object after deleting a previous one doesn't work
I'll try to keep it as short as possible.
I'm making a python application which uses a C Extension (hw_timer).
This extension is in charge of creating a timer.
The Python application starts by calling hw_timer.StartTimer which instantiates a timer…

someCoder
- 185
- 3
- 15
0
votes
1 answer
copy and deepcopy in Python C API
How does one define copy and deepcopy methods for a Python type defined in a C extension?
Looking at the documentation, there doesn't appear to be a tp_ slot for these methods.

SU3
- 5,064
- 3
- 35
- 66