python c extensions are modules written in C/C++ and can be imported and used by python interpreter
Questions tagged [python-c-extension]
257 questions
0
votes
1 answer
Can I develop C extensions for Python 2.7 through 3.1 on Windows *without* installing Visual Studio 2008?
I'm aware that Python extensions on Windows typically have to be built with the same version of Visual Studio used to compile Python itself, and I'm further aware that Python 2.7 through 3.1 are built using Visual Studio 2008. But the machine I'm…

Benjamin Pollack
- 27,594
- 16
- 81
- 105
0
votes
1 answer
fseek with SEEK_END returns a "Invalid argument" error to manage large data(7GB) with python x86 C extension lib on windows7 x64
I've been trying to manage large binary data(7GB) within python x86 original extension library.
But fseek with SEEK_END doesn't work well.
I put _FILE_OFFSET_BITS 64 macro. I also tried fseeko64, but it raises an error.
With Less than 2GB files or…

fx-kirin
- 1,906
- 1
- 20
- 33
0
votes
0 answers
Prevent delay while returning from C-Python api
I have C-Python api like below. It works fine, but the problem is while invoking this method
from python script say
In script.py:
offset=0
size=4
write_object(offset,size)
This calls write_this_c() C API and returns quickly to the next printf…

webminal.org
- 44,948
- 37
- 94
- 125
0
votes
1 answer
Show native import attempts in python3
I wrote a Python 3 extension module in C but cannot seem to get Python to import it.
Is there any way to let Python print out which shared libraries (.so on Linux) it tries to load and why it fails?
Sadly all the docs I read don't really help since…

abergmeier
- 13,224
- 13
- 64
- 120
0
votes
1 answer
why python c extension lost pointer trace after realloc?
#include
int isCodeValid() {
char *base = calloc(512, 1);
// free(base);
// base = calloc(512,1);
base = realloc(512, 1);
free(base);
return 1;
}
static PyMethodDef CodecMethods[] = {
{ NULL, NULL, 0, NULL }…

davyzhang
- 2,419
- 3
- 26
- 34
0
votes
1 answer
What's the proper way to clean up static python object references in a CPython extension module?
The CPython headers define a macro to declare a method that is run to initialize your module on import: PyMODINIT_FUNC
My initializer creates references to other python objects, what is the best way to ensure that these objects are properly cleaned…

fmoo
- 769
- 5
- 11
0
votes
0 answers
Will recompilation affect the running program?
If I recompile a program when it is still running, will the program still be executed as the original before recompilation?
I just find some answers from Is it safe to recompile an executable while it's running?, but I have a more complicated…

Hailiang Zhang
- 17,604
- 23
- 71
- 117
0
votes
1 answer
calling third party c functions from python
I have a requirement of calling third party c functions from inside python.
To do this I created a c api which has all the python specific c code ( using METH_VARARGS) to call the third party functions. I linked this code liba.so with the 3 party…

marvel
- 33
- 7
0
votes
1 answer
calling legacy c functions from python
I want to call legacy c third party functions from python.
I created a C api to make the function calls simpler.
In my python file
I tried to import the *.so for the api which links with the legacy code library.
But I kept seeing a libxxx ( the…

marvel
- 33
- 7
0
votes
1 answer
Python object extension which gets a list in constructor never passes the creation step (SIGSEV), why?
I've been fighting for a lot of time with an error and I've run short of ideas on what's happening and why it doesn't work.
First of all, I'm trying to create a new object type for Python through a C extension. This object is created using a list,…

Dows
- 1
0
votes
1 answer
How to neatly pass char[] to PyObject_CallMethod in Python C extension
I have a python object called "m1", which has a method "coor()". I will pass it to C"++" extension and call "coor()" inside. First I tried:
PyArrayObject *coor = (PyArrayObject *) PyObject_CallMethod(m1,"coor","()",NULL);
and found the following…

Hailiang Zhang
- 17,604
- 23
- 71
- 117
0
votes
1 answer
How to pass a python list to a C extension function and append some values?
Say I have a python list:
l=[[1,2],[3,4]]
I want to pass it to the following C extension:
PyObject *acc(PyObject *self, PyObject *args)
{
PyObject * l;
PyArg_ParseTuple(args, "O", &l);
//l.append([5,6]
}
I just wonder how to modify the above…

Hailiang Zhang
- 17,604
- 23
- 71
- 117
0
votes
1 answer
using ctypes to link c++ and python in linux
I am writing a program in python. now i want to use ctypes to use some functions of a class i have in c++.
so basically , i have an array of data in python. i have another program in c++ which is supposed to use that array and transform it to an…

Mohammad Havaei
- 1
- 1
-1
votes
1 answer
Trying to create a new type for python
I am trying to create a new type for python (2.5).
I am trying to follow: python's documentation, however i am unable to compile the basic bit:
#include
typedef struct {
PyObject_HEAD
/* Type-specific fields go here. */
}…

cdvv7788
- 2,021
- 1
- 18
- 26
-1
votes
1 answer
extending python using C extensions
I am trying to learn how to extend python using C extensions and so far I have been able to go through the official python docs for the same.
Browsing through, I have found this helpful resource which explains how to extend python using C…

JohnJ
- 6,736
- 13
- 49
- 82