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
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
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
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
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:/
;
> > >
> > > // make function call, which returns a char *
> > > result = doStuff(in, a, b);
> > >
> > > // save result in Python string
> > > finalResult = PyString_FromString(result);
> > >
> > > // free memory
&g
"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
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
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
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)
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
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
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,
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..
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
"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
*) 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
"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
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) {
> [...]
> >
"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
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
> > > // make function call, which returns a char *
> > > result = doStuff(in, a, b);
> > >
> > > // save result in Python string
> > > finalResult = PyString_FromString(result);
> > >
> > > // free memory
> > > PyM
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
>
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
>
> }
>
> ...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
// 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
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
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
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
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
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;
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
> PyObject *wrap_doStuff(PyObject *, PyObject *args) {
^
I guess you need a parameter name here
Diez
--
http://mail.python.org/mailman/listinfo/python-list
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;
34 matches
Mail list logo