Re: C wrapper

2006-11-07 Thread Gabriel Genellina
At Tuesday 7/11/2006 17:43, Sheldon wrote: > And what are those non-static functions used for? The *only* purpose > of your module should be to provide the Python bindings... I wrote the C module to do some number crunching. Now I just need to "connect" it to my python program. Should the initm

Re: C wrapper

2006-11-07 Thread Sheldon
Gabriel Genellina skrev: > At Tuesday 7/11/2006 17:27, Sheldon wrote: > > >Here is the file/module name: _msgpps_functions.c > >Here is the initfunction: > > > >PyMODINIT_FUNC init_msgpps_functions(void) { > > PyObject* m; > > m=Py_InitModule("_msgpps_functions",_msgpps_functionsMethods); > >

Re: C wrapper

2006-11-07 Thread Sheldon
Hi, > For a module called foo.c the initialization function must be called > initfoo (*not* init_foo) Ok, I fixed this part. Thanks > And what are those non-static functions used for? The *only* purpose > of your module should be to provide the Python bindings... I wrote the C module to do so

Re: C wrapper

2006-11-07 Thread Gabriel Genellina
At Tuesday 7/11/2006 17:27, Sheldon wrote: Here is the file/module name: _msgpps_functions.c Here is the initfunction: PyMODINIT_FUNC init_msgpps_functions(void) { PyObject* m; m=Py_InitModule("_msgpps_functions",_msgpps_functionsMethods); ErrorObject = PyString_FromString("_msgpps_functi

Re: C wrapper

2006-11-07 Thread Gabriel Genellina
At Tuesday 7/11/2006 17:10, Sheldon wrote: > Take a look at the documentation for creating extension modules, > especially the following page: > > http://docs.python.org/ext/methodTable.html > > "The initialization function must be named initname(), where name is the > name of the module, and sh

Re: C wrapper

2006-11-07 Thread Sheldon
Robert Kern skrev: > Sheldon wrote: > > > This function is there and is called init_mymodule() but I have other > > functions that are not static. > > Is the module's name "_mymodule"? Or is it "mymodule"? > > -- > Robert Kern > > "I have come to believe that the whole world is an enigma, a harml

Re: C wrapper

2006-11-07 Thread Robert Kern
Sheldon wrote: > This function is there and is called init_mymodule() but I have other > functions that are not static. Is the module's name "_mymodule"? Or is it "mymodule"? -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by o

Re: C wrapper

2006-11-07 Thread Sheldon
Farshid Lashkari skrev: > Sheldon wrote: > > Can anyone give me some idea as to what this error means? > > > > "ImportError: dynamic module does not define init function " > > > > I am new at this and there is still a lot to learn. > > > > Any help is appreciated, > > Take a look at the documenta

Re: C wrapper

2006-11-07 Thread Farshid Lashkari
Sheldon wrote: > Can anyone give me some idea as to what this error means? > > "ImportError: dynamic module does not define init function " > > I am new at this and there is still a lot to learn. > > Any help is appreciated, Take a look at the documentation for creating extension modules, espe

Re: C Wrapper Function, crashing Python?

2005-10-14 Thread Tony Nelson
In article <[EMAIL PROTECTED]>, "Java and Swing" <[EMAIL PROTECTED]> wrote: > one more update... > > if I remove PyMem_Free and free(...) ...so no memory clean up...I can > still only call doStuff 4 times, the 5th attemp crashes Python. > > Java and Swing wrote: > > update: > > if I use C's fre

Re: C Wrapper Function, crashing Python?

2005-10-12 Thread Java and Swing
Bernhard Herzog wrote: > "Java and Swing" <[EMAIL PROTECTED]> writes: > > > char *foo(const char *in) { > > char *tmp; > > tmp = (char *) malloc((strlen(in) * sizeof(char)) + 1); > > strcpy(tmp, in); > > ... > > ... > > free(tmp); > > return someValue; > > } > > > > Is

Re: C Wrapper Function, crashing Python?

2005-10-12 Thread Bernhard Herzog
"Java and Swing" <[EMAIL PROTECTED]> writes: > char *foo(const char *in) { > char *tmp; > tmp = (char *) malloc((strlen(in) * sizeof(char)) + 1); > strcpy(tmp, in); > ... > ... > free(tmp); > return someValue; > } > > Is that appropriate? I was under the impression tha

Re: C Wrapper Function, crashing Python?

2005-10-12 Thread Java and Swing
As far as my C Wrapper functions are concerned...I no longer have the need for free(...). I do use PyMem_Free, for structures I allocated by using PyMem_New(...). In my C code I do have things such as... char *foo(const char *in) { char *tmp; tmp = (char *) malloc((strlen(in) * sizeof(ch

Re: C Wrapper Function, crashing Python?

2005-10-12 Thread Bernhard Herzog
"Java and Swing" <[EMAIL PROTECTED]> writes: > thanks for the tip, however even when I do not free aString or bString, > i'm still crashing at the malloc in the c function, not the wrapper. Do you have any more places where you use free incorrectly? In my experience, calling free with invalid va

Re: C Wrapper Function, crashing Python?

2005-10-12 Thread Java and Swing
thanks for the tip, however even when I do not free aString or bString, i'm still crashing at the malloc in the c function, not the wrapper. Bernhard Herzog wrote: > "Java and Swing" <[EMAIL PROTECTED]> writes: > > > static PyObject *wrap_doStuff(PyObject *self, PyObject *args) { > [...] > >

Re: C Wrapper Function, crashing Python?

2005-10-12 Thread Bernhard Herzog
"Java and Swing" <[EMAIL PROTECTED]> writes: > static PyObject *wrap_doStuff(PyObject *self, PyObject *args) { [...] > char *aString = 0; > char *bString = 0; [...] > int ok = PyArg_ParseTuple(args, "sss", &in, &aString, &bString); [...] > free(aString); > free(bStrin

Re: C Wrapper Function, crashing Python?

2005-10-12 Thread Java and Swing
ok, further digging...I found that in the C function GetVal...it is crashing where I try to malloc some memory. Note, I have no problems when running this from C..just from Python using my wrapper. GetVal looks something like.. MY_NUM *GetVal(const char *in, const int x) { MY_NUM *results, *re

Re: C Wrapper Function, crashing Python?

2005-10-12 Thread Java and Swing
Sorry about the double post... anyhow, after putting in debug statements I found that it was crashing when it called, free(result)so I removed the free(result). now it crashes when it gets to, b = GetVal(bString, count(bString, ",")); ..any ideas? Java and Swing wrote: > Antoon, >I just

Re: C Wrapper Function, crashing Python?

2005-10-12 Thread Java and Swing
Antoon, I just saw that to. I updated the code like so... static PyObject *wrap_doStuff(PyObject *self, PyObject *args) { // this will store the result in a Python object PyObject *finalResult; // get arguments from Python char *result = 0; char *in= 0;

Re: C Wrapper Function, crashing Python?

2005-10-12 Thread Java and Swing
Antoon, I just saw that to. I updated the code like so... static PyObject *wrap_doStuff(PyObject *self, PyObject *args) { // this will store the result in a Python object PyObject *finalResult; // get arguments from Python char *result = 0; char *in= 0;

Re: C Wrapper Function, crashing Python?

2005-10-12 Thread Antoon Pardon
Op 2005-10-12, Java and Swing schreef <[EMAIL PROTECTED]>: > static PyObject *wrap_doStuff(PyObject *self, PyObject *args) { > // this will store the result in a Python object > PyObject *finalResult; > > // get arguments from Python > char *result = 0; > char *in= 0;

Re: C Wrapper Function, crashing Python?

2005-10-12 Thread Java and Swing
one more update... if I remove PyMem_Free and free(...) ...so no memory clean up...I can still only call doStuff 4 times, the 5th attemp crashes Python. Java and Swing wrote: > update: > if I use C's free(result), free(a) free(b) instead of PyMem_Free...I > only get one successfuly use/call of do

Re: C Wrapper Function, crashing Python?

2005-10-12 Thread Java and Swing
update: if I use C's free(result), free(a) free(b) instead of PyMem_Free...I only get one successfuly use/call of doStuff. i.e. // this works doStuff(...) // python crashes here doStuff(...) Java and Swing wrote: > static PyObject *wrap_doStuff(PyObject *self, PyObject *args) { > // this w