Questions tagged [python-extensions]

Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability.

323 questions
3
votes
1 answer

python3 C extension module with cp1252 encoded string

I am writing a Python3 extension module for an existing C++ library which returns a string that appears to be in cp1252 encoding. The C++ function signature is int get_name(std::string& name); where name is the output variable that contains a…
3
votes
1 answer

Segmentation fault in C python extension

I'm writing a C extension module for python3.7. I have a simple structure as PyObject: typedef struct { PyObject_HEAD double attacker; double victim; double game_hardness; int inflation; } RatingSystem; And initialiser: static…
pomo_mondreganto
  • 2,028
  • 2
  • 28
  • 56
3
votes
0 answers

How to compile a C extension using clang or ICC?

I am trying to compile a python module using a compiler other than 'gcc', specifically 'icc' (for efficiency reasons). I tried forcing the compilation setting 'cc' to 'clang' but still that did not work as my extension was built using GCC. Anyway,…
PintoDoido
  • 1,011
  • 16
  • 35
3
votes
1 answer

How to pass a large string from Python to a C++ extension method efficiently?

Introduction I am working on project where a lot of textual data needs to be processed. Many quite big (hundreds of MB) text files. The python is the requirement (don't ask why). I want to use C++ extensions to increase the performance. I decided to…
nosbor
  • 2,826
  • 3
  • 39
  • 63
3
votes
0 answers

Cython: avoid compiling all C/C++ files on each extension. Objective: distribute in PyPi

The Cython project I am currently working on includes some 20 C++ files that act as C++ implementation. On top I have built three Extension Modules written in Cython, each of them capturing different but interconnected functionalities of the C++…
ibarrond
  • 6,617
  • 4
  • 26
  • 45
3
votes
0 answers

passing python3 file stream to C++ extern function

Okay there, i have some code in python that opens a file -> process it -> and writes data to other file. def ELECrypt(myFile, outFile, code): Code = list(bytes(code,'utf-8')) with open(myFile, 'rb') as bFil: with open(outFile, 'wb')…
3
votes
0 answers

How to convert a PyCapsule into a ctype?

I am trying to get a python c extension to work. The extension is used in a package which registers a python callback with the extension and then the extension calls it to communicate with the python code. The extension has a struct variable which I…
viterbi
  • 419
  • 5
  • 11
3
votes
4 answers

Error exporting symbol when building Python C Extension in Windows

I'm working on porting a Python module to Windows. I have a toy example as follows. The folder structure is: foo/ libfoo/ foo.c setup.py setup.py from setuptools import setup, Extension sources = ['libfoo/foo.c'] foo =…
nbui
  • 182
  • 1
  • 9
3
votes
2 answers

How to add an alternative constructor to the target language (specifically Python) in SWIG wrapping C++ code

I am creating Python interfaces to some C++ code that I cannot change, using SWIG. One of the C++ classes has a constructor that creates a partially initialized object that cannot be used as yet, an initialization function has to be called on it…
doetoe
  • 765
  • 7
  • 16
3
votes
1 answer

Unable to compile swig generated wrapper for c++ python extension

Hi I am trying the swig python extension, in c++, example - on an Mit page My header is - shapes.h #include class Shape { public: Shape() { nshapes++; } ~Shape() { nshapes--; } double x,…
Ankit Mishra
  • 474
  • 3
  • 11
3
votes
1 answer

Can't import module created using SWIG

I'm trying to build python extension. I've create simple library that export single function. It's just a single file - testlib.c that implements function called 'apicall'. Then I create SWIG interface file: %module testlibpy …
Evgeny Lazin
  • 9,193
  • 6
  • 47
  • 83
3
votes
1 answer

Python C++ extension Singleton

I'm trying to write a C++ extension for Python (3.x) that allows me to use a specific hardware shield for the Raspberry Pi. I haven't got any experience in writing C and/or C++, but using the documentation on the Python website, I actually got…
bennierex
  • 31
  • 1
3
votes
1 answer

Compiling Python extensions with different Visual Studio version

According to the Python documentation, when compiling a Python extension on Windows, "you should use the same version of VC++ that was used to build Python itself". The explanation usually given is that the mismatch in VC runtime version will cause…
Ray
  • 4,531
  • 1
  • 23
  • 32
3
votes
1 answer

What's the difference between tp_clear, tp_dealloc and tp_free?

I have a custom python module for fuzzy string search, implementing Levenshtein distance calculation, it contains a python type, called levtree which has two members a pointer to a wlevtree C type (called tree) which does all the calculations and a…
woggioni
  • 1,261
  • 1
  • 9
  • 19
3
votes
1 answer

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 method. I can't seem to find any documentation on…
Paul D.
  • 1,785
  • 2
  • 19
  • 25