Re: python/C++ wrapper

2007-03-14 Thread Szabolcs Nagy
- A c++ program receives a 2D-matrix from python as input and gives a 2D-matrix as output back to python. pyogre uses swig ogre is a 3d realtime rendering engine written in c++ so there are many matrix manipulation there and also pyogre does not modify the original code cgkit is a computer

Re: python/C++ wrapper

2007-03-14 Thread Roman Yakovenko
On 14 Mar 2007 02:38:32 -0700, Szabolcs Nagy [EMAIL PROTECTED] wrote: - A c++ program receives a 2D-matrix from python as input and gives a 2D-matrix as output back to python. pyogre uses swig Well, pyogre has few problems with maintenance, and new bindings to Ogre engine was created using

Re: python/C++ wrapper

2007-03-14 Thread Szabolcs Nagy
Well, pyogre has few problems with maintenance, and new bindings to Ogre engine was created using Boost.Python( http://www.ogre3d.org/wiki/index.php/PyOgre ) oh last time i played with pyogre they made a transition from boost to swig :) so they are back again at boost (the problem with boost

Re: python/C++ wrapper

2007-03-14 Thread John Pye
Check out this example from NumPy. This would be the way sanctioned by the scipy community, as you benefit from a large library of matrix routines that you can use to prepare/postprocess the data. http://www.scipy.org/Cookbook/SWIG_and_NumPy --

Re: python/C++ wrapper

2007-03-14 Thread Gabriel Genellina
En Wed, 14 Mar 2007 01:55:55 -0300, Frank [EMAIL PROTECTED] escribió: is there anyone here that calls C++ programs from python via swig? It I suggest you read the responses to your previous question; also search the list archives for this month. -- Gabriel Genellina --

Re: python/C++ wrapper

2007-03-14 Thread Frank
On Mar 14, 1:42 pm, Gabriel Genellina [EMAIL PROTECTED] wrote: En Wed, 14 Mar 2007 01:55:55 -0300, Frank [EMAIL PROTECTED] escribió: is there anyone here that calls C++ programs from python via swig? It I suggest you read the responses to your previous question; also search the list

python/C++ wrapper

2007-03-13 Thread Frank
Hi, is there anyone here that calls C++ programs from python via swig? It seems that there are a lot of different ways to do that. For me it would be important that the original c++ code (which is available) does not need to be changed and the whole compilation process (swig - python

Re: python/C++ wrapper

2007-03-13 Thread Roman Yakovenko
On 13 Mar 2007 21:55:55 -0700, Frank [EMAIL PROTECTED] wrote: Hi, is there anyone here that calls C++ programs from python via swig? It seems that there are a lot of different ways to do that. For me it would be important that the original c++ code (which is available) does not need to be

C wrapper

2006-11-07 Thread Sheldon
Hi, 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, /Sheldon -- http://mail.python.org/mailman/listinfo/python-list

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, especially

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 documentation for creating

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 our own

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 harmless enigma that

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 should be

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 =

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 some

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); ErrorObject =

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

create a c++ wrapper for python class?

2006-05-10 Thread Mark Harrison
is a big help. So, I'm looking for a C++ wrapper generator, so that I can write a class in Python, and then have a .h and .cpp generated that will give me a corresponding C++ class. Of course, the usual restrictions apply: no dynamically added methods, accessing all instance data via getters

Re: create a c++ wrapper for python class?

2006-05-10 Thread Diez B. Roggisch
, and the comprehensive Python library is a big help. So, I'm looking for a C++ wrapper generator, so that I can write a class in Python, and then have a .h and .cpp generated that will give me a corresponding C++ class. Of course, the usual restrictions apply: no dynamically added methods, accessing

Re: Python C wrapper question

2006-03-27 Thread Dave Mandelin
Shi, Jue wrote: Hello, Gurus, I have a question on wrapping C function in Python. My C code is like this: typedef void (WINAPI *myCallBack) (unsigned int myarg1, unsigned int myarg2) bool myfunc(myCallBack callfunc) Now I want to call myfunc in Python, what should I do? I replied to

Python C wrapper question

2006-03-24 Thread Shi, Jue
Hello, Gurus, I have a question on wrapping C function in Python. My C code is like this: typedef void (WINAPI *myCallBack) (unsigned int myarg1, unsigned int myarg2) bool myfunc(myCallBack callfunc) Now I want to call myfunc in Python, what should I do? Thanks, Stone --

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 free(result),

Re: Pass a tuple (or list) to a C wrapper function

2005-10-13 Thread Fredrik Lundh
Jeremy Moles wrote: Probably what you want to do though is just keep the tuple as is and iterate over it using the PySequence_* protocol: http://docs.python.org/api/sequence.html I did post a complete and tested example a few days ago, which contained code that showed how to do this. a

Re: Pass a tuple (or list) to a C wrapper function

2005-10-13 Thread Java and Swing
Fredrik...I forgot about that...wish Google Groups had a way to quickly find the topics a user posts. anyhow, for receiving an object from python..is it ok = PyArg_ParseTuple(args, sO, x, y); ...is it sO or s0 is it O (as in the letter) or 0 (as in the number)? I would think O the

Re: Pass a tuple (or list) to a C wrapper function

2005-10-13 Thread Java and Swing
Fredrik, ...I tried using your code... static long *get_long_array(PyObject *data, int *data_size) { int i, size; long* out; PyObject* seq; seq = PySequence_Fast(data, expected a sequence); if (!seq) return NULL; size = PySequence_Size(seq); if (size 0)

Re: Pass a tuple (or list) to a C wrapper function

2005-10-13 Thread Java and Swing
I got it. I had get_long_array placed after the method that was calling it.. i.e. void doStuf(...) { x = get_long_array(...); } static long *get_long_array(PyObject *data, int *data_size) { ... } ...I put get_long_array before it in my code..and its fine. Thanks Java and Swing wrote:

When to free memory for C wrapper?

2005-10-13 Thread Java and Swing
I have been posting lately about writing a C wrapper so Python can access my C functions. In my wrapper function I have something like... static PyObject *wrap_doStuff(PyObject *self, PyObject *args) { PyObject *data; char *result; long *d; PyArg_ParseTuple(args, O:wrap_doStuff

Re: When to free memory for C wrapper?

2005-10-13 Thread Java and Swing
. This leaves the caller with the responsibility to call Py_DECREF() when they are done with the result; this soon becomes second nature. URL: http://www.python.org/doc/api/refcounts.html So does that mean before my C wrapper function exits, or returns I should Py_DECREF any PyObject's I have? For example

Re: Pass a tuple (or list) to a C wrapper function

2005-10-13 Thread Fredrik Lundh
Java and Swing wrote: and I get this error.. C:\project\myapp.c(549) : error C2040: 'get_long_array' : 'long *(struct _object *,int *)' differs in levels of indirection from 'int ()' so what's on line 549 in myapp.c? what other warnings did you get from the compiler? do you have other

Re: Pass a tuple (or list) to a C wrapper function

2005-10-13 Thread Fredrik Lundh
Java and Swing wrote: anyhow, for receiving an object from python..is it ok = PyArg_ParseTuple(args, sO, x, y); ...is it sO or s0 is it O (as in the letter) or 0 (as in the number)? I would think O the letter..but it looks like a zero. eh? if you're not sure, what keeps you from

C Wrapper Function, crashing Python?

2005-10-12 Thread Java and Swing
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; char *aString = 0; char *bString = 0;

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

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

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
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=

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=

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
this is crashing when calling from Python via C wrapper? Java and Swing wrote: 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

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(bString); aString

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) { [...] char

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 values

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

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 that when you

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 that appropriate? I was

Pass a tuple (or list) to a C wrapper function

2005-10-12 Thread Java and Swing
I have a C function which takes an array of long values.. I understand that I can pass a tuple to a C wrapper function and in the C wrapper function have.. int ok = PyArg_ParseTuple(args, s(ll), a, b, c); ..that's great if my tuple only contained two longs..but what if it contained 50 would I

Re: Pass a tuple (or list) to a C wrapper function

2005-10-12 Thread Jeremy Moles
On Wed, 2005-10-12 at 13:06 -0700, Java and Swing wrote: I have a C function which takes an array of long values.. I understand that I can pass a tuple to a C wrapper function and in the C wrapper function have.. int ok = PyArg_ParseTuple(args, s(ll), a, b, c); ..that's great if my tuple