Wrapping C with Python; free(char *) invalid pointer -


I'm following the tutorial on wrapping C / C ++ with Python. I have copied the example code verbatim, but it will still be listed below.

Hello. C
  #include & lt; Stdio.h & gt; #include & lt; Python H & gt; // Original C Function char * Hello (four * what) {printf ("Hello% s! \ N", what); What to return; } // 1) wrapper function which gives Python Stactic pie object returns. * Hello_Apple (pie object * SPE, pie object * AGR) {char * input; Four * result; PyObject * ret; // parse arguments (! PyArg_ParseTuple (args, "s", and input)) {return tap; } // the result of the actual function = halo (input); // create the resulting string in a python object ret = PyString_FromString (the result); Free (results); Return writ; }   

The script Hello C defines a simple "Hello" function, as well as an envelope that returns a python object, and (hyperactivity) C is free The four * pointer is where the code fails with run-time error: Error in '/ usr / bin / python': Free (): Invalid Pointer: 0x00000000011fbd44 . Although I believe that this scope should be limited, just move on to the rest, just ... ...

Hello C is included in the definition of module, That is, its methods are called in Python. The module is defined as such:

hellomodule.c
  #include "hello.c" #include & lt; Python H & gt; // 2) Python module static PyMethodDef HelloMethods [] = {{"hello", hello_use, METH_VARARGS, "say hello"}, {tap, zero, 0, zero}}; // 3) module init function DL_EXPORT (zero) inithello (zero) {Py_InitModule ("Hello", Hello Matthew); }   

Finally, a Python script has been implemented to create modules:

setup.py
  #! / Usr / bin / (files) = "hello", ext_modules = "extension" #, "hello.c" [extension_mod])   

once setup.py is run, the module can be imported into any Python script, and its members should work with the exception of the invalid indicator error, be accessible, and have been proved on this Please do not take any advantage for several hours, please help. According to

/ p>

In addition to this, you have to leave yourself any memory, besides # es, et and et # formats.

eliminate the free (result); Calls should stop crashing.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -