Questions tagged [pycxx]

16 questions
8
votes
1 answer

Should {tp_alloc, tp_dealloc} and {tp_new, tp_free} be considered as pairs?

Is it true that whatever is created in tp_alloc should be destroyed in tp_dealloc? And similarly for {tp_new, tp_free}? It looks like an obvious symmetry, but I would be grateful for clarification. My actual use case is this: I have: class OSClass…
P i
  • 29,020
  • 36
  • 159
  • 267
5
votes
1 answer

Python cannot create instances

I am trying to create a simple Python extension using PyCXX. And I'm compiling against my Python 2.5 installation. My goal is to be able to do the following in Python: import Cats kitty = Cats.Kitty() if type(kitty) == Cats.Kitty: …
Miquella
  • 1,074
  • 2
  • 13
  • 25
3
votes
2 answers

Creating an inheritable Python type with PyCxx

A friend and I have been toying around with various Python C++ wrappers lately, trying to find one that meets the needs of both some professional and hobby projects. We've both honed in on PyCxx as a good balance between being lightweight and easy…
Toji
  • 33,927
  • 22
  • 105
  • 115
3
votes
1 answer

How to access numpy array within PyCXX

I would like to convert numpy array to some double* or stl vector on the c++ side. I'm actually using PyCXX for this and I can't figure out the way to access the data. I'm currently able to access and return the data buffer like this : Py::Object…
recursix
  • 333
  • 2
  • 9
3
votes
2 answers

Documentation for PyCFunction_New / PyCFunction_NewEx

I'm struggling to understand some PyCXX code (C++ Python wrapper) that revolves around PyCFunction_New. Could someone explain how this function works? (I can't figure it out from the CPython source code.) Here I will detail the problem I'm having.…
P i
  • 29,020
  • 36
  • 159
  • 267
1
vote
2 answers

How to tidy/fix PyCXX's creation of new-style Python extension-class?

I've nearly finished rewriting a C++ Python wrapper (PyCXX). The original allows old and new style extension classes, but also allows one to derive from the new-style classes: import test // ok a = test.new_style_class(); // also ok class Derived(…
P i
  • 29,020
  • 36
  • 159
  • 267
1
vote
1 answer

Why does PyCXX handle new-style classes in the way it does?

I'm picking apart some C++ Python wrapper code that allows the consumer to construct custom old style and new style Python classes from C++. The original code comes from PyCXX, with old and new style classes here and here. I have however rewritten…
P i
  • 29,020
  • 36
  • 159
  • 267
1
vote
2 answers

Delay-Load in Windows

I am trying to get my head around some code (adapted straight from PyCXX). It is a multiplatform C++ Python wrapper. EDIT: Original code here. It appears to be catering for some particular phenomenon that only exists in Windows: #ifdef…
P i
  • 29,020
  • 36
  • 159
  • 267
0
votes
0 answers

How to write an image file from python to C++ using PyCxx

I would like to be able to write an image from Python (or any binary file for that matter) to C++, using PyCxx and have the C++ layer write that to a file. I can't find any binary type in PyCXX that would enable this - the closest thing is Py::Bytes…
user252652
  • 179
  • 1
  • 1
  • 9
0
votes
0 answers

No clickable 'run'/'step' button showing up in PyCX simulator GUI

All code can run without error messages, but the pycxsimulator GUI doesn't generate clickable tabs or 'run' buttons to visualize the simulation, even though the plot does indeed show up. I think it is a backend issue (which I have been having, and…
0
votes
0 answers

python pycxx first testing case build error

trying to use pycxx. using: python 3.5 64-bit, windows 7 64-bit, pycxx 6.2.8 have written a simple cxx file to test out. but the build had error, tried to search the solution but failed aaa.cxx as: #include "CXX/Objects.hxx" Py::List haha(Py::List…
0
votes
1 answer

Debugging my Python C extension lead to "PyThreadState_Get: no current thread"

When I Debug my Python C extension using Visual Studio the program abort with the message: "PyThreadState_Get: no current thread". In Release the program works fine and if I add debugging information it still works fine. How to solve the problem?
Vivian De Smedt
  • 1,019
  • 2
  • 16
  • 26
0
votes
2 answers

C-API: Allocating "PyTypeObject-extension"

I have found some code in PyCXX that may be buggy. Is it indeed a bug, and if so, what is the right way to fix it? Here is the problem: struct PythonClassInstance { PyObject_HEAD ExtObjBase* m_pycxx_object; } : { : table->tp_new =…
P i
  • 29,020
  • 36
  • 159
  • 267
0
votes
2 answers

Coding static to instance method trampoline function with templates

I'm trying to recode some rather ugly template coding. For reference, the original is here: https://codereview.stackexchange.com/questions/69545/recode-c-c-trampoline-function-macros-using-templates class Final : Base { void Foo(){...} void…
P i
  • 29,020
  • 36
  • 159
  • 267
0
votes
1 answer

Load module into embedded Python runtime using PyCXX

I'm using PyCXX to create a C++ wrapper around an embedded Python runtime. PyCXX doesn't seem to have an example of executables, so I'm trying to adapt the existing example code. I can get the Python interpreter up and running easily: extern "C" int…
P i
  • 29,020
  • 36
  • 159
  • 267
1
2