473,799 Members | 3,214 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SystemError: new style getargs format but argument is not a tuple

I am trying to embed a c function in my python script for a first time.
When I try to call it I get an error

SystemError: new style getargs format but argument is not a tuple

Guido said on some mailing list, that it is probably an effect of the
lack of METH_VARARGS in the functions' array, but it's ok in my source
code. Here is the full code:

#include <python2.4/Python.h>

static PyObject * mandelpixel(PyO bject *self, PyObject *args)
{
double z_real = 0, z_imag = 0, z_real2 = 0, z_imag2 = 0, c_real,
c_imag, bailoutsquare;
int iteration_numbe r;
register int i;
PyObject coord;
if (!PyArg_ParseTu ple(args, "Oid", &coord, &iteration_numb er,
&bailoutsquare) )
return NULL;
if (!PyArg_ParseTu ple(&coord, "dd", &c_real, &c_imag))
return NULL;

for(i = 1; i <= iteration_numbe r; i++)
{
z_imag = 2 * z_real * z_imag + c_imag;
z_real = z_real2 - z_imag2 + c_real;
z_real2 = z_real * z_real;
z_imag2 = z_imag * z_imag;
if (z_real2 + z_imag2 bailoutsquare)
return Py_BuildValue(" i", i);
}
return Py_BuildValue(" i", 0);
}

static PyMethodDef MandelcMethods[] =
{
{
"mandelpixe l", mandelpixel, METH_VARARGS, "check the pixel for
Mandelbrot set"
},
{
NULL, NULL, 0, NULL
}
};

PyMODINIT_FUNC initmandelc(voi d)
{
(void) Py_InitModule ("mandelc", MandelcMethods) ;
}

int main(int argc, char **argv)
{
Py_SetProgramNa me(argv[0]);
Py_Initialize() ;
initmandelc();
return 0;
}

Greets
zefciu
Feb 26 '07 #1
11 10853
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

zefciu wrote:
I am trying to embed a c function in my python script for a first
time. When I try to call it I get an error

SystemError: new style getargs format but argument is not a tuple

Guido said on some mailing list, that it is probably an effect of
the lack of METH_VARARGS in the functions' array, but it's ok in my
source code. Here is the full code:

#include <python2.4/Python.h>

static PyObject * mandelpixel(PyO bject *self, PyObject *args) {
double z_real = 0, z_imag = 0, z_real2 = 0, z_imag2 = 0, c_real,
c_imag, bailoutsquare; int iteration_numbe r; register int i;
PyObject coord; if (!PyArg_ParseTu ple(args, "Oid", &coord,
&iteration_numb er, &bailoutsquare) ) return NULL; if
(!PyArg_ParseTu ple(&coord, "dd", &c_real, &c_imag)) return NULL;
Is coord always tuple?

- --
Thinker Li - th*****@branda. to th********@gmai l.com
http://heaven.branda.to/~thinker/GinGin_CGI.py
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF4wQB1LD UVnWfY8gRAtWsAK CavY85KUtoppRSj 0uQTeVnmLu5UwCg yfk1
0c5fkRgKaejDja1 YWdKkaTg=
=vMjd
-----END PGP SIGNATURE-----

Feb 26 '07 #2
Thinker wrote:
zefciu wrote:
>>I am trying to embed a c function in my python script for a first
time. When I try to call it I get an error

SystemError : new style getargs format but argument is not a tuple

Guido said on some mailing list, that it is probably an effect of
the lack of METH_VARARGS in the functions' array, but it's ok in my
source code. Here is the full code:
Is coord always tuple?
Yes it is. The script launches it with tuple and two numeric arguments.
On the other hand when I try it in interactive mode with
mandelpixel((1, 1), 1, 1) it segfaults, which I completely don't understand.

zefciu
Feb 26 '07 #3
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

zefciu wrote:
I am trying to embed a c function in my python script for a first
time. When I try to call it I get an error

SystemError: new style getargs format but argument is not a tuple

Guido said on some mailing list, that it is probably an effect of
the lack of METH_VARARGS in the functions' array, but it's ok in my
source code. Here is the full code:

#include <python2.4/Python.h>

static PyObject * mandelpixel(PyO bject *self, PyObject *args) {
double z_real = 0, z_imag = 0, z_real2 = 0, z_imag2 = 0, c_real,
c_imag, bailoutsquare; int iteration_numbe r; register int i;
PyObject coord;
It should be "PyObject *coord;" .
Maybe, it is what is wrong with your program!

- --
Thinker Li - th*****@branda. to th********@gmai l.com
http://heaven.branda.to/~thinker/GinGin_CGI.py
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF4xDz1LD UVnWfY8gRAmAAAJ 9FJPqGyeI0Inxrc vdNXHtGMXWK1wCg 570r
z3hcYDsjmqRp4Bn pEFjbDy0=
=REQM
-----END PGP SIGNATURE-----

Feb 26 '07 #4
Thinker wrote:
It should be "PyObject *coord;" .
Maybe, it is what is wrong with your program!

Should it? The gcc shows me a warning then:

warning: 'coord' is used uninitialized in this function

and during the execution I get the same error *plus* a segfault.

zefciu
Feb 26 '07 #5
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

zefciu wrote:
Thinker wrote:
>It should be "PyObject *coord;" . Maybe, it is what is wrong with
your program!

Should it? The gcc shows me a warning then:

warning: 'coord' is used uninitialized in this function

and during the execution I get the same error *plus* a segfault.

zefciu
Yes! Please refer http://docs.python.org/api/arg-parsing.html#l2h-210
And your second PyArg_ParseTupl e() call, should not make a reference
on coord.
It should be PyArg_ParseTupl e(coord, ...) since you declare coord as a
pointer.
You can add some printf() to throw out messages to make sure where the
program stop at.
If you can compile the module with debug information and use gdb to
backtrace dump file,
it would be useful.

- --
Thinker Li - th*****@branda. to th********@gmai l.com
http://heaven.branda.to/~thinker/GinGin_CGI.py
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF4xaG1LD UVnWfY8gRAsW7AK C7D3oZ8p8iWVFcB vkiVwMSrG1oNwCg 36ym
e1Fa0AO3KzSD5Fc Ys0LK7P4=
=kYLW
-----END PGP SIGNATURE-----

Feb 26 '07 #6
Thinker wrote:
You can add some printf() to throw out messages to make sure where the
program stop at.
If you can compile the module with debug information and use gdb to
backtrace dump file,
it would be useful.
Did it. The arguments are parsed, but the coord tuple isn't. But can
PyArg_ParseTupl e be used to tuples other than function arguments? If
not, what should I use?

zefciu
Feb 26 '07 #7
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

zefciu wrote:
Thinker wrote:
>You can add some printf() to throw out messages to make sure
where the program stop at. If you can compile the module with
debug information and use gdb to backtrace dump file, it would be
useful.

Did it. The arguments are parsed, but the coord tuple isn't. But
can PyArg_ParseTupl e be used to tuples other than function
arguments? If not, what should I use?
Since PyArg_ParseTupl e() is supposed to parse arguments, I recommand you
to use PyTuple_GetItem () or PyTuple_GET_ITE M(). You can find more
functions
at http://docs.python.org/api/genindex.html .

- --
Thinker Li - th*****@branda. to th********@gmai l.com
http://heaven.branda.to/~thinker/GinGin_CGI.py
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF4xyq1LD UVnWfY8gRAilNAK DFTKwahXpuxFImh R57Yw5efAGP1wCf R/qU
o774g2YB5gMBLrU a9YltDSQ=
=/tWC
-----END PGP SIGNATURE-----

Feb 26 '07 #8
Thinker wrote:
Since PyArg_ParseTupl e() is supposed to parse arguments, I recommand you
to use PyTuple_GetItem () or PyTuple_GET_ITE M().
Ok. Now I do it this way:

c_real = PyFloat_AsDoubl e(PyTuple_GetIt em(coord,0));
c_imag = PyFloat_AsDoubl e(PyTuple_GetIt em(coord,1));

And it worked... once. The problem is really funny - in the interactive
the function fails every second time.
>>mandelpixel(( 1.5, 1.5), 9, 2.2)
args parsed
coord parsed
ii3
>>mandelpixel(( 1.5, 1.5), 9, 2.2)
TypeError: bad argument type for built-in operation
>>mandelpixel(( 1.5, 1.5), 9, 2.2)
args parsed
coord parsed
ii3
>>mandelpixel(( 1.5, 1.5), 9, 2.2)
TypeError: bad argument type for built-in operation

etcaetera.... (the "args parsed" "coord parsed" and "i" are effect of
printfs in the code, as you see when it fails, it doesn't even manage to
parse the arguments.

zefciu
Feb 26 '07 #9
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

zefciu wrote:
Thinker wrote:
>Since PyArg_ParseTupl e() is supposed to parse arguments, I
recommand you to use PyTuple_GetItem () or PyTuple_GET_ITE M().

Ok. Now I do it this way:

c_real = PyFloat_AsDoubl e(PyTuple_GetIt em(coord,0)); c_imag =
PyFloat_AsDoubl e(PyTuple_GetIt em(coord,1));

And it worked... once. The problem is really funny - in the
interactive the function fails every second time.
>>>mandelpixel( (1.5, 1.5), 9, 2.2)
args parsed coord parsed ii3
>>>mandelpixel( (1.5, 1.5), 9, 2.2)
TypeError: bad argument type for built-in operation
I guess it is caused by ill handling reference count of coord.
You should call Py_INCREF() to get a reference since it is borrowed
from PyArg_ParseTupl e().
You can find more information at http://docs.python.org/ext/refcounts.html

- --
Thinker Li - th*****@branda. to th********@gmai l.com
http://heaven.branda.to/~thinker/GinGin_CGI.py
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF4yuP1LD UVnWfY8gRAqOmAJ 0SaIwpnRk/GZYm2Z5nnC7xH7E YKwCgjz8o
0Z/S7i5PULQMeAFI7U/Cy5I=
=4C3l
-----END PGP SIGNATURE-----

Feb 26 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3061
by: Gerrit Holl | last post by:
Hi, I found a cool way to trigger a SystemError: >>> exec CodeType(0,0,0,0,"",(),(),(),"","",0,"") XXX lineno: 0, opcode: 0 Traceback (most recent call last): File "<stdin>", line 1, in ? File "/usr/lib/python2.2/site-packages/", line 0, in File "/usr/lib/python2.2/site-packages/", line 0, in
1
3865
by: Newgene | last post by:
Hi, group, I am trying to dynamically add a method to class by following this post: http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/2ec2ad7a0a5d54a1/928e91be352c6bfc?q=%22new.code(%22+%22import+new&_done=%2Fgroup%2Fcomp.lang.python%2Fsearch%3Fgroup%3Dcomp.lang.python%26q%3D%22new.code(%22+%22import+new%26qt_g%3D1%26&_doneTitle=Back+to+Search&&d#928e91be352c6bfc But I got the Error like the below: ...
11
2029
by: vbgunz | last post by:
Hello all, I am just learning Python and have come across something I feel might be a bug. Please enlightenment me... The following code presents a challenge. How in the world do you provide an argument for *arg4? ## ============================================================ def argPrecedence(par1, par2=0, par3=0, *par4, **par5): print 'par1 =', par1, ' # positional argument' print 'par2 =', par2, ' # keyword argument'
38
2058
by: looping | last post by:
For Python developers around. >From Python 2.5 doc: The list of base classes in a class definition can now be empty. As an example, this is now legal: class C(): pass nice but why this syntax return old-style class, same as "class C:", and not the new style "class C(object):" ?
2
2659
by: robert | last post by:
From the trace of a 2.3.5 software i got: \'SystemError: C:\\\\sf\\\\python\\\\dist23\\\\src\\\\Objects\\\\cellobject.c:22: bad argument to internal function\\n\'] from the middle of normal function / or its call. What is this?
18
2760
by: Joel Hedlund | last post by:
Hi! The question of type checking/enforcing has bothered me for a while, and since this newsgroup has a wealth of competence subscribed to it, I figured this would be a great way of learning from the experts. I feel there's a tradeoff between clear, easily readdable and extensible code on one side, and safe code providing early errors and useful tracebacks on the other. I want both! How do you guys do it? What's the pythonic way? Are...
2
1490
by: gregpinero | last post by:
I might just be being dumb tonight, but why doesn't this work: Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: not enough arguments for format string (I'm in Python 2.4 if that matters) Thanks,
21
7274
by: Martin Geisler | last post by:
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkjlQNwACgkQ6nfwy35F3Tj8ywCgox+XdmeDTAKdN9Q8KZAvfNe4 0/4AmwZGClr8zmonPAFnFsAOtHn4JhfY =hTwE -----END PGP SIGNATURE-----
4
6343
by: mattehz | last post by:
Hey there, I am trying to upload old source files and came across these errors: Warning: Invalid argument supplied for foreach() in /home/mattehz/public_html/acssr/trunk/inc_html.php on line 59 Notice: Undefined index: args in /home/mattehz/public_html/acssr/trunk/inc_error.php on line 92 Warning: Invalid argument supplied for foreach() in /home/mattehz/public_html/acssr/trunk/inc_error.php on line 92
0
10490
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10260
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10243
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10030
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9078
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7570
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5590
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4146
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.