problem about python-c-api-Collection of common programming errors


  • Mo Zo
    python c cython python-c-api python-c-extension
    So, the python docs for writing extension says this:”We want to expose our instancevariables as attributes. There are anumber of ways to do that. Thesimplest way is to define memberdefinitions:static PyMemberDef Noddy_members[] = {{“first”, T_OBJECT_EX, offsetof(Noddy, first), 0,”first name”},{“last”, T_OBJECT_EX, offsetof(Noddy, last), 0,”last name”},{“number”, T_INT, offsetof(Noddy, number), 0,”noddy number”},{NULL} /* Sentinel */ };and put the definitions in thetp_members slot:Noddy_members,

  • dizgam
    python python-3.x python-c-api
    I m learning python c api functions and keen to learn python 3.1 stable version. Found a same kind of issue recently and triedPyModule_AddIntConstant(PyObject *module, const char *name, long value) Runtime error occurred for this function call.Is there something wrong with the function in python 3.1?

  • Amro
    c++ python boost-python python-c-api python-embedding
    I have a C++ application dynamically linked to the Python interpreter. I want to be able to import python modules from a particular directory. I want to modify the PYTHONPATH for my process so that sys.path will include the paths that I added to the PYTHONPATH. That seems to be the way it works according to this documentation:http://docs.python.org/c-api/intro.html#embedding-pythonHowever, when I print sys.path from Python-land it has the original contents of PYTHONPATH and not the one I set.

  • i30817
    c++ python c python-c-api
    Edit done: I am wrapping a custom python dll with the purpose of removing the custom code eventually and using a recent python instead of the ancient version that is being used now. One of the functions initializes a python extension, and callsPyObject* _PyObject_New(PyTypeObject *type)In my wrapper the (c) object produced by this call is crashing on PyErr_Print() (yes i’ve wrapped it too).I’d like to experiment with replacing the Repr or Str calls to something of my choosing to see if those are

  • user763305
    c++ python numpy python-c-api python-embedding
    I am new of python embedding. I am trying to embed python + numpy code inside a C++ callback function (inside a dll)the problem i am facing is the following. if i have:Py_Initialize(); // some python glue // python invocation Py_Finalize();everything works fine.but if i have:Py_Initialize(); _import_array(); //to initialize numpy C-API // some python glue + numpy array object creation // python invocation via PyObject_CallObject() Py_Finalize();this crashes at the second time it reaches _import_

  • Jason Sundram
    c++ python segmentation-fault python-c-api pycairo
    I am running OSX Lion and trying to import the python module for goocanvas, using python2.7.I managed to successfully compile pygoocanvas-0.14.1, but when I try to import goocanvas through the python2.7 console, I get a segfault. After some debugging, I’m led to this code:DL_EXPORT (void) initgoocanvas (void) {PyObject *m, *d;fprintf(stderr,”init<< \n”);// Pycairo_IMPORT; // XXX removed, it expands to the line below, anywaysPycairo_CAPI = (Pycairo_CAPI_t*) PyCObject_Import(“cairo”, “CAP

  • Adam
    python python-c-api
    I have a C++ library which uses Python callbacks. The callback, i.e. PyObject*, is stored in an object of class UnaryFunction, and the constructor Py_INCREFs it. The destuctor Py_XDECREFs it. That’s the problem. The interpreter segfaults on that DECREF.My solution is to just not DECREF it, but that seems wrong. What is the proper way to INC/DEC the reference count of a function, and more importantly, why does the interpreter try to GC a function body when there are other live references to it?Ed

  • user763305
    python python-c-api
    Having some trouble with this code. Trying to return a tuple of tuples (coordinates) from a C++ module Im writing. It looks right to me, the dirty list contains two Coords so len is 2, the x and y values of the items in the list are 0,0 and 0,1 respectively. First time Im attempting this so I might very well have misunderstood the docs or something. Any hints?PyObject* getDirty() {int len = dirty.size();PyObject* tuple = PyTuple_New(len);int count = 0;for (std::list<Coord>::iterator i = di

  • Amro
    python c python-c-api python-embedding
    I am having problems using the Embedded Python for C as per the Documentation – Whenever I try using imported modules I get an :Unhandled exception at 0x1e089e85 in PythonIncl.exe: 0xC0000005:Access violation reading location 0x00000004.The error occurs in the PyObject_GetAttrString() method and the documentation isn’t much help. I have also tried using tutorials as in an Example from IBM, but always get the same access violation.The following is the example code from one of the tutorials which

  • J.T. Davies
    c++ python-3.3 python-c-api python-embedding
    I am attempting to emulate the Python/C API’s PyRun_InteractiveLoop() function, but from a different input system used by my employer. The Python FAQ (http://docs.python.org/3/faq/extending.html#how-do-i-tell-incomplete-input-from-invalid-input) has the following code, used to check if a given character array is a complete Python block:#include <Python.h> #include <node.h> #include <errcode.h> #include <grammar.h> #include <parsetok.h> #include <compile.h>int

  • epicbrew
    c++ python c callback python-c-api
    I am trying to call methods in a python class from C++. The C++ method from which this is called is a C++ callback.Within this method when I am trying to call python method, it was giving segmentation fault.I have saved an instance of python function in a global variable like pFunc = PyDict_GetItemString(pDict, “PlxMsgWrapper”); (pFunc is global variable of type PyObject*)where PlxMsgWrapper is a python method, which will be used in the callback.In the callback, the arguments are created as PyOb

  • PeterG
    python c python-c-api python-embedding
    Im trying to call python functions from C code, and i followed a sample from hereI also have the correct include file directries, library directries, and linked the python32.lib (im using python 32) however the error was that python/C APIs such as PyString_FromString, PyInt_FromLong, PyInt_AsLong are undefined (error in the debugger)this is strange because im also using other APIs, but they’re all fine… whats the problem here??int main(int argc, char *argv[]) {PyObject *pName, *pModule, *pDict

  • Michael
    python distutils python-c-api
    I’m writing a Python extension in C that requires the CoreFoundation framework (among other things). This compiles fine with:gcc -o foo foo.c -framework CoreFoundation -framework Python(“-framework” is an Apple-only gcc extension, but that’s okay because I’m using their specific framework anyway)How do I tell setup.py to pass this flag to gcc?I tried this, but it doesn’t seem to work (it compiles, but then complains of undefined symbols when I try to run it):from distutils.core import setup, Ext

  • Figus
    python c gcc python-c-api python-c-extension
    I’m starting the study of Python/C API and I make the first code to test some functions, I write this:file: test.c#include “Python.h”int main() {PyObject* none = Py_BuildValue(“”); }I compile with command:gcc -I/usr/include/python2.7 test.cI’ve the error undefined reference to `Py_BuildValue’After I run:gcc -I/usr/include/python2.7 –shared -fPIC hashmem.cthis compile without errors, but when I run the compiled file I’ve aSegmentation fault (core dumped)How do I set the gcc parameters?I’ve ubunt

  • Mark
    mingw python-imaging-library python-c-api
    I’m trying to compile Python Imaging Library on Windows 7 64-bit by running pip install pilI’ve set my compiler to MinGW. It looks like it’s going fine until it’s time to compile _imaging.c. It fails on this monster gcc call: C:\MinGW\bin\gcc.exe -shared -s build\temp.win-amd64-2.7\Release\_imaging.o build\temp.win-amd64-2.7\Release\decode.o build\temp.win-amd64-2.7\Release\encode.o build\temp.win-amd64-2.7\Release\map.o build\temp.win-amd64-2.7\Release\display.o build\temp.win-amd64-2.7\Relea