<div class="gmail_quote">On Mon, Oct 11, 2010 at 07:06, Ioan Ferencik <span dir="ltr"><<a href="mailto:ioan.ferencik@tkk.fi">ioan.ferencik@tkk.fi</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
I  would like to ask where can I find more detailed info on<br>
PyArg_ParseTuple function.<br>
<br>
I find the doc limited on the matter.<br>
Mainly I am curious why the function requires an address of a pointer.<br>
<br>
I have issues in the following case:<br>
in python<br>
int jmax = 16<br>
<br>
print type(jmax)<br>
<br>
<type 'int'><br>
<br>
which is just all right<br>
  but following C code seems to be working<br>
PyObject *jmax_o = NULL;<br>
<br>
if(!PyArg_ParseTuple(args, "i", &jmax_o)){<br>
                goto error;<br>
        }<br>
<br>
but PyInt_Check(jmax_o) fails.<br>
<br>
I tried to debug and this is what i could see<br>
<br>
Program received signal SIGSEGV, Segmentation fault.<br>
0x00007ffff67a75bd in fprintf (self=<value optimized out>, args=(16,))<br>
at /usr/include/bits/stdio2.h:98<br>
98          return __fprintf_chk (__stream, __USE_FORTIFY_LEVEL - 1, __fmt,<br>
<br>
so for some reason the jmax_o can not be converted to int.<br>
<br>
I use a x86_64 ubuntu and i suspect it could be because of 64 bits arch.<br>
<br>
Cheers<br>
<br>
Ioan Ferencik<br>
PhD student<br>
Aalto University<br>
School of Science and Technology<br>
Faculty Of Civil and Env. Engineering<br>
Lahti Center<br>
Tel: +358505122707<br></blockquote><div><br></div><div>The following is probably what you want:</div><div><br></div><div>"""</div><div>int jmax_o;</div><br>if(!PyArg_ParseTuple(args, "i", &jmax_o)){<br>
               goto error;<br>       }</div><div class="gmail_quote">"""</div><div class="gmail_quote"><br></div><div class="gmail_quote">PyArg_ParseTuple takes the arguments passed in, a format string, and then the resulting values from conversion. The "i" format, as you already knew, is for ints, and it converts your value into an *actual int* -- not a Python int. Because of that, you wouldn't need the PyInt_Check -- that's for checking PyObjects to see if they are Python ints.</div>