Skip to content
Advertisement

Tag: ctypes

ndpointer in ctypes structure field

I cannot figure out how to use numpy.ndpointer as a field in a python ctypes structure. Here is some basic code, showing how I can do this without using ndpointer, but I would like to know if it’s possible to use ndpointer as well if it’s possible! Using the above code this works fine But when I call this, I

Does calling a c function via ctypes in python release the GIL during execution of the C code

I want to call some c function from python to be able to improve performance of my code. But I cannot find online whether when I call a C function using the ctypes libraries the GIL is released. As a simple example: Is the GIL released during the call to fun.sleep? Answer According to [Python.Docs]: ctypes.CFUNCTYPE(restype, *argtypes, use_errno=False, use_last_error=False) (emphasis

Using PR_SET_NAME from Python

I’ve been using the following code for a while: With Python-2.6 on RHEL6 this works, changing process name to “meow”. With Python-3.7 on RHEL7, however, after going through same code, the process name becomes “m” — just the first letter of the string. What’s going on? Answer The ctypes prctl is probably expecting 8-bit strings, and in Python 3 you’re

How to set arbitrary size array in ctypes?

So I have a function imported from a .dll library that takes in a pointer to a struct of the form: The idea of function is that if A is NULL, then function(D*) will update A with the size of the required buffer. Hence, if on the other hand B is an array of size A, then function(D*) will return

how to write C++ DLL file for python correctly?

this is my test.cpp file.(I also used makefile to create dll file) when I run following code in python everything is ok and I get this output from python. but when I change my test.cpp in this way(I just uncommented iostream): I get the following error from python. this is also my dependencies enter image description here by the way

Advertisement