Re: Can you fix up wrapper function argument signatures?

2006-11-27 Thread Diez B. Roggisch
Gerard Brunick schrieb: > Consider: > > >>> def negate(func): > ... def wrapper(*args, **kwargs): > ... return not func(*args, **kwargs) > ... return wrapper > ... > >>> def f(x): > ... return x > 10 > ... > >>> g = negate(f) > >>> g(20) > False > >>> g(5) > True > > Now

Can you fix up wrapper function argument signatures?

2006-11-27 Thread Gerard Brunick
Consider: >>> def negate(func): ... def wrapper(*args, **kwargs): ... return not func(*args, **kwargs) ... return wrapper ... >>> def f(x): ... return x > 10 ... >>> g = negate(f) >>> g(20) False >>> g(5) True Now g has the argument signature of (*args, **kwargs). Pop-up

Re: Yield in a wrapper function

2005-11-18 Thread Bengt Richter
er(x): > if x < 0: > return foo('ABC') > else: > return foo('XYZ') > >When I run this, variable three letters are shown and it takes 3 >seconds for the whole thing to complete. The problem is that the whole >iteration is glogge

Re: Yield in a wrapper function

2005-11-18 Thread Peter Otten
er(x): > if x < 0: > return foo('ABC') > else: > return foo('XYZ') > > When I run this, variable three letters are shown and it takes 3 > seconds for the whole thing to complete. The problem is that the whole > iteration is glogged up i

Yield in a wrapper function

2005-11-18 Thread [EMAIL PROTECTED]
kes 3 seconds for the whole thing to complete. The problem is that the whole iteration is glogged up in the wrapper() function because the first letter is shown after 3 seconds and then all letters are shown at the same time. How do I wrap functions that return iterators? ...if possible. -- http:/

Re: C Wrapper Function, crashing Python?

2005-10-14 Thread Tony Nelson
; > > > > > > // make function call, which returns a char * > > > result = doStuff(in, a, b); > > > > > > // save result in Python string > > > finalResult = PyString_FromString(result); > > > > > > // free memory &g

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 ke

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 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: > Fr

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

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

2005-10-12 Thread Jeremy Moles
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,

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

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
*) malloc(...); finalResults = results; while (...) { *results++ = some_val; } return finalResults; } ...is that correct? As I mentioned earlier, when I run these functions from C I have no troubles...I can run them 5, 10, 15 times, etc. From Python, using my wrapper function is when I

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
nt - returns an int; GetVal - returns a char * > > > > a = GetVal(aString, count(aString, ",")); > > > > b = GetVal(bString, count(bString, ",")); > > > > > > > > // make function call, which returns a char * > > > &g

Re: C Wrapper Function, crashing Python?

2005-10-12 Thread Java and Swing
> > > // make function call, which returns a char * > > > result = doStuff(in, a, b); > > > > > > // save result in Python string > > > finalResult = PyString_FromString(result); > > > > > > // free memory > > > PyM

Re: C Wrapper Function, crashing Python?

2005-10-12 Thread Java and Swing
emory > > PyMem_Free(result); > > PyMem_Free(a); > > PyMem_Free(b); > > > > // return the result as a Python string > > return finalResult; > > } > > > > ...from python I can call this function 4 times...works fine. WHen I >

Re: C Wrapper Function, crashing Python?

2005-10-12 Thread Java and Swing
emory > > PyMem_Free(result); > > PyMem_Free(a); > > PyMem_Free(b); > > > > // return the result as a Python string > > return finalResult; > > } > > > > ...from python I can call this function 4 times...works fine. WHen I >

Re: C Wrapper Function, crashing Python?

2005-10-12 Thread Antoon Pardon
> } > > ...from python I can call this function 4 times...works fine. WHen I > call it for the fifth time python.exe crashes. im thinking some memory > problem in the wrapper function perhaps...but I am not sure. The > actually C function, doStuff can be called 5, 6,7...N times w

Re: C Wrapper Function, crashing Python?

2005-10-12 Thread Java and Swing
// free memory > > PyMem_Free(result); > > PyMem_Free(a); > > PyMem_Free(b); > > > > // return the result as a Python string > > return finalResult; > > } > > > > ...from python I can call this function 4 times...works fine

Re: C Wrapper Function, crashing Python?

2005-10-12 Thread Java and Swing
Mem_Free(result); > PyMem_Free(a); > PyMem_Free(b); > > // return the result as a Python string > return finalResult; > } > > ...from python I can call this function 4 times...works fine. WHen I > call it for the fifth time python.exe crashes. im thi

C Wrapper Function, crashing Python?

2005-10-12 Thread Java and Swing
PyMem_Free(result); PyMem_Free(a); PyMem_Free(b); // return the result as a Python string return finalResult; } ...from python I can call this function 4 times...works fine. WHen I call it for the fifth time python.exe crashes. im thinking some memory problem in the wrapper

Re: Wrapper function

2005-10-11 Thread Java and Swing
So, I write the C code...as shown previously. Then, I do something like... c:\> python >> from distutils.core import setup, Extension >> >>setup( >>name="DLLTester", >>ext_modules = [Extension("DLLTester", ["test.c"])] >>) c:\> python setup.py build_ext -i ..is that it? If so, then

Re: Wrapper function

2005-10-11 Thread Robert Kern
Java and Swing wrote: > When I compile, I get two warnings..which are ok. Then when I build my > DLL I get.. > > Linking... >Creating library Release/MyDLL.lib and object Release/MyDLL.exp > test.obj : error LNK2001: unresolved external symbol _PyBuildValue > Release/MyDLL.dll : fatal error

Re: Wrapper function

2005-10-11 Thread Java and Swing
Diez, yes you were right! But I have other problems now. I now have... #include #include #include "Python.h" int doStuff(const char *input, const char *d) {...} static PyObject *wrap_doStuff(PyObject *self, PyObject *args) { int result; char *input = 0; char *d = 0;

Re: Wrapper function

2005-10-11 Thread Robert Kern
Java and Swing wrote: > I am having trouble with a wrapper function... > > My C code looks like > --- > #include > #include > #include "Python.h" > > int doStuff(const char *input, const char *d) {...} > > PyObject *wrap_doSt

Re: Wrapper function

2005-10-11 Thread Diez B. Roggisch
> PyObject *wrap_doStuff(PyObject *, PyObject *args) { ^ I guess you need a parameter name here Diez -- http://mail.python.org/mailman/listinfo/python-list

Wrapper function

2005-10-11 Thread Java and Swing
I am having trouble with a wrapper function... My C code looks like --- #include #include #include "Python.h" int doStuff(const char *input, const char *d) {...} PyObject *wrap_doStuff(PyObject *, PyObject *args) { int result; char *input = 0;