SWIG & C/C++ Python API connected - SEGFAULT -


My task is to create a dual program In the beginning, I start the C program which uses Python C / C + + API to dragon some Python The method says. After that method it is said that the method is a function created with SWIG. After the segmentation mistake, I show my sample with a backtrack from GDB.

main.c:

  #include & lt; Python J & gt; # Include & lt; Stdio.h & gt; #include "utils.h" int main (int argc, char ** argv) {printf ("Calling from C! \ N"); pay raise (); Int i; For (i = 0; i <11; ++ i) {Py_Initialize (); PyObject * pname = PyString_FromString ("py_function"); PyObject * module = PyImport_Import (pname); PyObject * dict = PyModule_GetDict (module); PyObject * func = PyDict_GetItemString (dict, "ink"); PyObject_CallObject (funk, tap); Py_DECREF (module); Py_DECREF (pname); Printf ("\ tbe last \ n"); Py_Finalize (); Printf ("\ tafter finally \ n"); } Return 0; }  

utils.c

#include & lt; Stdio.h & gt; #include "utils.h" increase by zero (zero) {printf ("Increment number:% u \ n", ++ counter); }

py_function.py

  # / usr / bin / python2.6 '' 'py_function.py - dragon source Python Embedding '' 'designed to display the use of import' utils def ink (): Print 'I'm hiking!' Utils.increment ()  

and last feel that my Makefile & amp; SWIG Config file

Makefile:

  cc = gcc cflaj = -c-g-val -stdi = ctta all: main main: main O utils.o utils_wrap.o $ (cc) main.o utils.o -lpython2.6 -o sample big sip -Wall -python -o utils_wrap.c utils.i $ (cc) utils.o utils_wrap.o room sharing -o _utils.so Mukyko main C $ (CC) $ (Sifelaji) key. cI / usr / include / python2.6 -o main.o utils.o: utils.c utils.h $ (CC) $ (CFLAGS) -fPIC utils.c -o $ @ utils_wrap.o: utils_wrap.c $ (cc) -c -fPIC utils_wrap.c I / usr / contains / python2.6 -o $ @ clean:  < / P> 

(GDB) runs Rograming start: / home / enable marxin / programming / python2 / sample [Thread libthread_db using debugging] to call the C! Counter for the increase: 1 I am incremental! Incremental Counter: After finishing final 2, I am incrementing after finishing! Incrementian Counter: After finalizing the final form after 3 finalization, I am increasing the salary! After the finalization of the increment counter 4, the program received signal SIGSEGV, segmentation fault after finalization.

Backcount: (GDB) backside

  # 0xb7ed3e4e in PyObject_Malloc () in /usr/lib/libpython2.6.so.1.0 # 1 0xb7ca2b2c ?? () # 2 in 0xb7f8dd40 ?? () /usr/lib/libpython2.6.so.1.0 from # 3 0xb7eb014c ?? () /usr/lib/libpython2.6.so.1.0 from # 4 0xb7f86ff4 ?? () /usr/lib/libpython2.6.so.1.0 from # 5 0xb7f99820 ?? () /usr/lib/libpython2.6.so.1.0 from # 6 in 0x00000001 ?? () # 7 in 0xb7f8dd40 ?? () Of # /usr/lib/libpython2.6.so.1.0 8 0xb7f4f014 /usr/lib/libpython2.6.so.1.0 # 9 _PyObject_GC_Malloc (from 0xb7f99820) ?? () In /usr/lib/libpython2.6.so.1.0 # 11 0xb7ee8760 _PyType_Lookup (# 10 from /usr/lib/libpython2.6.so.1.0 in 0xb7f4f104 _PyObject_GC_NewVar ()) / usr / lib / from libpython2. 6.so.1.0 # 12 in 0xb7f99820 ?? () /usr/lib/libpython2.6.so.1.0 from # 13 in 0x00000001 ?? () # 14 in 0xb7f8dd40 ?? () /usr/lib/libpython2.6.so.1.0 from # 15 0xb7ef13ed in ?? () /usr/lib/libpython2.6.so.1.0 from # 16 0xb7f86ff4 ?? () /usr/lib/libpython2.6.so.1.0 from # 170x00000001 ?? () # 18 in 0xbfff0c34 ?? () # 19 in 0xb7e993c3 ?? () /usr/lib/libpython2.6.so.1.0 to # 200x00000001 ?? () # 21 in 0xbfff0c70 ?? () # 22 in 0xb7f99da0 ?? () /usr/lib/libpython2.6.so.1.0 from # 23 0xb7f86ff4 ?? () /usr/lib/libpython2.6.so.1.0 from # 24 0xb7f86ff4 ?? () /usr/lib/libpython2.6.so.1.0 from # 25 0x080a6b0c ?? () # 26 0x080a6b0c in ?? () PyObject_CallFunctionObjArgs () # of /usr/lib/libpython2.6.so.1.0 in # 28 0xb7f86ff4 27 0xb7e99420 ?? () /usr/lib/libpython2.6.so.1.0 from # 29 0xb7f86ff4 ?? () /usr/lib/libpython2.6.so.1.0 from # 30 0x800e55eb ?? () # 31 in 0x080a6b0c ?? () # 32 PyObject_IsSubclass (in 0xb7e9958c) in /usr/lib/libpython2.6.so.1.0 # 33 0xb7f8dd40 ?? () From /usr/lib/libpython2.6.so.1.0 # 34 0x080a9020 ?? () # 35 PyFPE_counter (in 0xb7fb78f0) in /usr/lib/libpython2.6.so.1.0 # 36 0xb7f86ff4 ?? () /usr/lib/libpython2.6.so.1.0 from # 37 in 0x00000000 ?? ()  

Thanks for your help and advice, Marxin


Comments