335 questions
1
vote
2
answers
169
views
Is it possible to include socketmodule.h in Python C extensions?
I'd like to invoke PySocketModule_ImportModuleAndAPI function defined in socketmodule.h in my Python C-extension.
1
vote
1
answer
791
views
How to convert PyFrameObject to PyObject
Maybe I'm missing something, but here is a problem:
I'm tracing python code by C extensions and my trace function got PyFrameObject* frame. Now I want to process the frame by Python code(embedded or ...
4
votes
2
answers
1k
views
Can I use ctypes to call back C function from python embedded in C?
I have a C program with embedded python code. I have compiled python 2.7.2 from source and linked my program against libpython2.7.a.
Now in my python code I wish to call back functions from other C ...
4
votes
2
answers
1k
views
Adding output file to Python extension
I've defined a custom build_ext to build a funky extension that I'm trying to make pip-friendly. The following is a trimmed version of what I'm doing.
foo_ext = Extension(
name='foo/_foo',
...
3
votes
1
answer
773
views
Monkey patching C extension in Python
Using the method discussed in question 972, I was unable to monkey patch the cursor() method in psycopg:
Tried to patch a methond in psycopg2 with types but it did not work:
>>> import ...
6
votes
2
answers
2k
views
Import and use standard Python module from inside Python C extension
I have Python extension module written in C. I want to use in this C code one of the standard Python modules, for example os or shutil. How is best to do this?
-1
votes
3
answers
866
views
Sporadic segfault in c++ python extension
I have a python object which accesses and downloads some text via HTTP.
I'm running this python object, and processing that text, using a c++ code.
I.e.
/* CPPCode.cxx */
int main(...) {
for(int ...
1
vote
0
answers
181
views
Issue with SFCB, the python-binding layer and python providers in ESX 4.0
We are writing SFCB providers in python, Since SFCB talks to only C++ providers we need to have an intermediate layer(cmpi-bindings, a python extension module) which can talk to SFCB and start the ...
1
vote
1
answer
1k
views
Python Extension not installing into subpackage
I'm trying to build a Python extension and package it up using distutils but the extension installs in the root package no matter how I name it. My directory layout looks like this:
foo/bar/...
14
votes
2
answers
12k
views
Method without return value in python c extension module
I'm trying to create a script in python that sends data through a parallel port. I'm creating my own module in C language.
The problem is: when I try to execute my module, python crashes. No errors, ...
10
votes
1
answer
7k
views
How to efficiently build a Python dictionary in C++
For performance reasons I want to port parts of my python program to C++ and I therefore try to write a simple extension for my program. The C++ part will build a dictionary, which then needs to be ...
1
vote
0
answers
421
views
SWIG C++ to Python: typemaps and methods accepting pointers to primitive type
I am writing a Python extension for an existing library. Some of the functions accept a pointer to a primitive, so the arg can act as output.
This is not very pythonic, so I want to use typemaps as ...
2
votes
3
answers
1k
views
SWIG interfacing C library to Python (SWIG generated classes are cumbersome to use)
I am using SWIG to generate Python language bindings to my C library. I have managed to build the bindings and exported data structures, but I'm having to jump through some hoops when using the ...
7
votes
1
answer
6k
views
Cython compilation error for free function (Cannot convert Python object argument to type 'FooBar *')
I am using Cython (0.15.2) to create an extension for Python (2.6.5). I have created a pxd file and a pyx file. Here are the contents of my pyx file:
cimport capifuncs
cdef class myArray:
cdef ...
2
votes
1
answer
893
views
Cython built extension fails to export data types and functions
I have just managed to build my first C extension for Python, using Cython to call into an existing C library.
I declared and defined my data types and functions into logical components (following ...
1
vote
1
answer
271
views
How to create separate files with dependencies for Cython and how to fix compilation error: Cannot convert Python object to 'mySet*'
I am trying to build my fisrt python extension, using Cython.
My C files are partitioned logically, and the functionality is "nested" - in that module C depends on functions defined in module B, ...
50
votes
9
answers
24k
views
Cython compiled C extension: ImportError: dynamic module does not define init function
I have just compiled part of my C library as an extension using Cython, as a "proof of concept". I managed to hack the code (const correctnes problems etc aside), to finally get an extension built.
...
0
votes
1
answer
544
views
Cython 1.1.2 and const correctness
I am experimenting with Cython to write a python extension for my C library. I have created a setup.py file - but when I try to build my pxd and pyx files, I get an error.
After some investigation, ...
3
votes
2
answers
9k
views
compile libdnet for python 2.7
I'm trying to use scapy on win32 python2.7
I've manage to compile all the other dependencies expect this one
can some help in the goal of reaching this executable ?
"dnet-1.12.win32-py2.7.exe"
(I ...
5
votes
1
answer
3k
views
Cmake on mac os x, link libraries with fullpath
I'm trying to build a python extension with cmake. This is the cmake list:
cmake_minimum_required(VERSION 2.8)
PROJECT(drtile)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
find_package(Vigra ...
6
votes
1
answer
607
views
Do function pointers remain valid across processes?
I have written an extension module that uses C++ function pointers to store sequences of function calls. I want to 'run' these call sequences in separate processes using python's multiprocessing ...
1
vote
1
answer
209
views
Exposing a new type to python at run time
I have gone through and defined my new types, stored them in a pytypeobject and called the following functions (after initializing the interpreter):
PyType_Ready(); //this takes my defined typed
...
2
votes
1
answer
2k
views
Possible to use wide-character members in Python extension objects?
It's simple to create a member for an object in a Python C extension with a base type of char *, using the T_STRING define in the PyMemberDef declaration.
Why does there not seem to be an equivalent ...
2
votes
1
answer
3k
views
Python extension for Upskirt: garbage at end of string
I've been trying to make a Python extension for Upskirt. I though it would not be too hard for a first C project since there are examples (example program in the Upskirt code and the Ruby extension).
...
1
vote
1
answer
504
views
C code crashes attempting Python remote procedure call via xmlrpc
I'm trying to create C code that creates an Python xmlrpc client and calls methods on the xmlrpc server (I'm thinking of using this as IPC for a hook DLL).
Here's the code ... I'm not going to layer ...
1
vote
1
answer
327
views
Using Python object exported from DLL in an exe
I have a two-part event generator:
pyglobalexe (a stub to simulate events):
#pragma comment(lib, "pyglobalextension.lib")
#include <Python.h>
__declspec(dllimport) PyObject* ...
7
votes
2
answers
729
views
Data corruption: Where's the bug‽
Last edit: I've figured out what the problem was (see my own answer below) but I cannot mark the question as answered, it would seem. If someone can answer the questions I have in my answer below, ...
25
votes
4
answers
2k
views
Tutorials on optimizing non-trivial Python applications with C extensions or Cython
The Python community has published helpful reference material showing how to profile Python code, and the technical details of Python extensions in C or in Cython. I am still searching for tutorials ...
53
votes
1
answer
23k
views
Create an object using Python's C API
Say I have my object layout defined as:
typedef struct {
PyObject_HEAD
// Other stuff...
} pyfoo;
...and my type definition:
static PyTypeObject pyfoo_T = {
PyObject_HEAD_INIT(NULL)
/...
2
votes
2
answers
1k
views
Importing a *.pyd library in IronPython's interpreter (ipy.exe)
Following this example, I've created a little hello.pyd library file, the contents of which are at the end of this question.
When I enter python interpreter I get the following:
D:\test\build\lib....
8
votes
1
answer
10k
views
.so module doesnt import in python: dynamic module does not define init function
I am trying to write a python wrapper for a C function. After writing all the code, and getting it to compile, Python can't import the module. I am following the example given here. I reproduce it ...
0
votes
1
answer
783
views
Python Extension Can't Use library_dirs
WHen specifying library_dirs in a Python distutils.core.Extension I get this error when trying to build:
/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/distutils/dist.py:263: ...
0
votes
2
answers
779
views
Can't call method in Python C extension
I'm working on making my first Python C extension, which defines a few functions and custom types. The strange thing is that the custom types are working, but not the regular functions. The top-...
3
votes
1
answer
1k
views
Using multiple modules/types with Python C API?
I've got two different Python extension modules; let's call them A and B. Module A contains a storage class type called container that I want to use within Module B as the return type of a class ...
4
votes
2
answers
4k
views
retrieving current URL from FireFox with python
I want to know what is the current url of active tab in running firefox instance from python module. Does FireFox have any API for this and does python know to work with it?