Skip to main content
Filter by
Sorted by
Tagged with
0 votes
2 answers
178 views

I have a library written in C++ for which I would like to make a Python wrapper. The directory structure of my repository is similar to the following: . ├── include # C++ library headers │   └── … ├── ...
tsnorri's user avatar
  • 2,139
1 vote
0 answers
89 views

I am using the Python C API and want to embed Python runtime into my app. The first thing is how to let Python load everything from a memory block, which stores the Zipped Python standard library ...
Frank's user avatar
  • 11
1 vote
0 answers
84 views

I'm updating a Python package that contains some C extensions. In a previous version I had all parameters set up in the setuptools setup() function, and now I am porting that setup into a new version ...
user3758232's user avatar
0 votes
0 answers
167 views

I tried to use pytsk3 in my python project to extract files from .img files. Pytsk3 (https://github.com/py4n6/pytsk) is a python binding for the Sleuth Kit. It works fine on my laptop (windows 11 pro ...
user29792845's user avatar
0 votes
0 answers
55 views

I have a c++ application that implements its own Python interpreter and console. The user can enter Python code into the console, and that text gets sent to another thread where I make calls to the ...
BenMB's user avatar
  • 33
0 votes
0 answers
52 views

I'm using C++/Qt to run my Qt application. Development Version: Python: 3.12 Qt: 6.6.3 C++: std 17 Visual Studio 2022 Inside my code, I use Python/C API to run python script like: PyObject* pModule ...
Johnson Qing's user avatar
0 votes
1 answer
68 views

Can a simple mutex pthread_mutex be a replacement for GIL in a multithreaded Python C extension? For eg: if I put mutex locks around Py_INCREF or PyMem_Alloc, would that suffice? Tried using the GIL, ...
mantle core's user avatar
1 vote
1 answer
153 views

I want to create an instance of a Python class with the C API. My specific use case is the PySerial Object. My Python code would be: import serial test = serial.Serial() I couldn't find any clue or ...
Cutyno's user avatar
  • 215
1 vote
1 answer
37 views

The documentation for PyList_New says that these two APIs are safe before the list is fully initialized: PyList_SetItem() and PyList_SET_ITEM(). But if an error happens in the middle of initializing ...
John's user avatar
  • 2,038
3 votes
1 answer
107 views

I'm trying to run the script below in Debug mode (Release works fine). I've linked against python310_d.lib and python310_d.dll which have been built from the source code found here https://github.com/...
Davide Rizzotti's user avatar
0 votes
1 answer
262 views

I'm using a new Python/C API PyErr_GetRaisedException added in 3.12 version to retrieve exception and then using other Python/C APIs to get exception type, value, and traceback details. Then I'm ...
user17562396's user avatar
1 vote
1 answer
40 views

I am writing a Python wrapper for a C function but I have some very strange behaviour. The C code is: static PyObject* f12_wrapper(PyObject* self, PyObject* args, PyObject* kwargs) { PyObject* ...
bourneeoo's user avatar
  • 482
8 votes
1 answer
386 views

The Vectorcall protocol is a new calling convention for Python's C API defined in PEP 590. The idea is to speed up calls in Python by avoiding the need to build intermediate tuples and dicts, and ...
Chayim Friedman's user avatar
0 votes
0 answers
52 views

Environement: Python version: 3.9.6 (default, May 7 2023, 23:32:45) PySide6 version: 6.7.0 When I create an instance of QRasterWindow, calling the metric method is ok: Py_Initialize(); PyObject *...
Blady's user avatar
  • 1
0 votes
1 answer
136 views

I have a package A that uses a special package A.B, both are 3rd and 4th party packages written in C using Boost. Because it there is some special setup A.B is not included as a submodule but only as ...
Daraan's user avatar
  • 5,166
3 votes
1 answer
98 views

PEP 442 introduced the tp_finalize callback to Python type definitions (as a one-to-one equivalent of Pythons classes' __del__ function), and recommends using this for any non-trivial destruction. The ...
mont29's user avatar
  • 398
0 votes
0 answers
64 views

I want to embed a Python interpreter in my C++ project using the pybind11 embedded interpreter. During runtime, Python modules from different locations can be loaded and deleted. To achieve this, I ...
Christoph Meyer's user avatar
0 votes
1 answer
90 views

To speed up custom MFCC calculations, I had to write some code in C, wrap it with Python's C API & numpy's C API, and compile it with disutils.core in order to import it from python code. I was ...
FloopyBeep's user avatar
1 vote
1 answer
95 views

Checking docs: Supporting Cyclic Garbage Collection Python’s support for detecting and collecting garbage which involves circular references requires support from object types which are “containers” ...
WhiteGoat's user avatar
0 votes
1 answer
78 views

Let's say I have this Python function: def foo(bar): bar() And this C function void bar() { } How can I create a PyObject with Python C API that holds a pointer to bar function so I can call the ...
Marko Devcic's user avatar
  • 1,099
2 votes
1 answer
58 views

I'm coding a C extension for Python. I used the non-limited API and recently switched to Python's limited API. And with that new API, I can't see a way to get the value of the global __debug__ ...
Nicolas V's user avatar
0 votes
0 answers
32 views

I have the following module written in C using Python C-api: #include <Python.h> static PyObject* init_factorial(PyObject* self, PyObject* args) { long long n; if (!PyArg_ParseTuple(...
Maxim Postnikov's user avatar
1 vote
1 answer
1k views

In a Polars DataFrame, I have 3 columns (A, B, D) storing value of type double. For n rows, and a starting value of some double number, the calculation is performed as shown below: value of column A = ...
mindoverflow's user avatar
1 vote
1 answer
217 views

In Python c-api: how can I create a heap type that has a metaclass? I'm well aware of PyType_FromSpec and derivatives and they can do this (from documentation): Changed in version 3.12: The function ...
oBrstisf8o's user avatar
0 votes
1 answer
49 views

What I've tried: faulthandler is really useful to get a traceback where segfault occurred but it doesn't allow handling it properly. import faulthandler faulthandler.enable() import ctypes try: ...
FamousSnake's user avatar
0 votes
3 answers
108 views

I am working on a Python C project that involves a couple of dynamically allocated structures like queues and threading structures. I am mainly looking to improve the readability. It looks something ...
BaccaRuler MC's user avatar
3 votes
1 answer
546 views

I'm working on a Python project with a setup.py that has something like this1: setup( cmdclass={"build_ext": my_build_ext}, ext_modules=[ Extension("A", ["a.c&...
Yay295's user avatar
  • 1,875
0 votes
1 answer
163 views

I write a function that executes a Python string in C++ using the Python C API. The function works perfectly. When I run it, it executes the Python string. The problem occurs when I make a .so file ...
Lakshit Karsoliya's user avatar
1 vote
1 answer
1k views

The Python 3.12 embedding documentation for embedding gives this example: #define PY_SSIZE_T_CLEAN #include <Python.h> int main(int argc, char *argv[]) { wchar_t *program = Py_DecodeLocale(...
Anthon's user avatar
  • 78.3k
0 votes
1 answer
87 views

I have code that embeds Python. That embedded Python uses NumPy and hence, I need to explicitly load libpython, to make NumPy work. The driving code is in C++ (tests in Google Test). There is a bug ...
Dmitry Kabanov's user avatar
0 votes
2 answers
1k views

I am using this code: PyThreadState * thread = PyEval_SaveThread(); PyGILState_STATE gil = PyGILState_Ensure(); // ... PyGILState_Release(gil); PyEval_RestoreThread(thread); In Python 3.11.8 it ...
sndth's user avatar
  • 21
1 vote
1 answer
255 views

Here is a small c++ program that embeds python. It works with python 3.11.6, but segfaults with python 3.12.0: #include <iostream> #include "omp.h" #include "Python.h" int ...
fffred's user avatar
  • 697
1 vote
2 answers
177 views

I have the following program which uses Python C API. It creates a number of threads (NUM_THREADS constant). In each thread there is an infinite loop that does a very simple operation: creates a ...
fgalan's user avatar
  • 12.4k
1 vote
1 answer
107 views

I want to write a numpy gufunc python extension using the numpy C-api that takes two matrices of arbitrary dimensionality, takes the mean across one dimension, and then subtracts one result from the ...
Aaron Earle-Richardson's user avatar
0 votes
1 answer
173 views

A bunch of unicode-related functionality was removed from the Python 3.12 C-API. Unfortunately for me, there's a very old piece of code (~2010) in our library that uses these and I need to migrate ...
Nobilis's user avatar
  • 7,498
1 vote
0 answers
63 views

I have a code in Python C API like this: PyObject* result = PyObject_CallMethod(/* some function with some arguments */); // Do something with result Py_XDECREF(result); I'm almost sure this code is ...
fgalan's user avatar
  • 12.4k
1 vote
1 answer
118 views

I have the following code in Python, which uses pyjexl module: import pyjexl jexl = pyjexl.JEXL() jexl.add_transform("lowercase", lambda x: str(x).lower()) I want to do the same using ...
fgalan's user avatar
  • 12.4k
0 votes
2 answers
88 views

In this part of the talk on GIL by Larry Hastings, there is an explanation about how ironclad provides C-extension compatibility with IronPython. This is the interesting part of the talk: We ...
Saleh's user avatar
  • 1,962
0 votes
0 answers
36 views

Assuming I have a C function I would like to wrap by the Nympy(Python)-C API to create a Python extension module. This module should be capable of accepting Numpy array that can have multiple types ...
Gideon Kogan's user avatar
0 votes
1 answer
380 views

I'm using Python C API in my C++ program. I have a function like this one (simplified) that returns the a string with the type of a given PyObject passed as argument: #include <Python.h> static ...
fgalan's user avatar
  • 12.4k
0 votes
1 answer
86 views

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
0 votes
1 answer
135 views

I am getting a linking error in my Visual Studio C project. Those are related to external functions of C-Python API not being resolved in the linking stage. One of them being: unresolved external ...
LakshyaK2011's user avatar
2 votes
1 answer
203 views

Upgraded to Python 3.12.0 from 3.11.7 and previously working C-API code now segfaults inside tp_alloc somewhere. I was first scrounging around to see if there was some breaking change between 3.11 and ...
firmament's user avatar
  • 139
2 votes
1 answer
70 views

The CPython Tutorial defines a custom initializer for a custom type which has the following lines : if (first) { tmp = self->first; Py_INCREF(first); self->first = first; ...
Carpetfizz's user avatar
  • 9,269
1 vote
0 answers
224 views

From the official example, I understand that I can modify sys.path before the interpreter initializes using the following code(exception handlings are omitted): PyConfig config; ...
Hans's user avatar
  • 61
1 vote
1 answer
181 views

I am using the Python C API, and I keep encountering the error ModuleNotFoundError: No module named '/home/user_1/project/ml/multiply. This is my c++ file, its path is /home/user_1/project/ml/testcapi....
catfriendly's user avatar
0 votes
0 answers
69 views

I'm using visual studio to import a python file from a c/c++ file to use a function(named lalala) defined in PythonApplication7.py. I'm trying to use Python-C-API to do this. The C file is: #include &...
Dzhou's user avatar
  • 1
1 vote
1 answer
234 views

I have a dynamic array type in C++ that I would like to expose through the buffer protocol. The type is already exposed as a sequence in Python, but I want to build NumPy arrays with the C++ array ...
javidcf's user avatar
  • 59.9k
3 votes
4 answers
695 views

Context: one can compile C code such that it can be used as a Python module. The compiled object is a shared library with a specific naming, so Python can find and load it as a module. Great. I have ...
pbuck's user avatar
  • 4,590
1 vote
0 answers
77 views

I have a C++ script, where I load a python file to execute a function to evaluate a Graph Neural Network. This function gets executed to evaluate data in an event loop, so the script gets executed for ...
Lukas Kretschmann's user avatar

1
2 3 4 5
28