[Python-Dev] Adding support to curses library
Heracles
steve at integrityintegrators.net
Wed Feb 25 17:03:16 CET 2009
I took the suggestion and fired up a debugger and now I'm eating crow.
First of all, here is a complete listing of the method as it is written now:
------------------ Snippet -----------------------------------
static PyObject *
PyCurses_color_set(PyObject *self, PyObject *args)
{
short color_pair_number = 0;
void * opts = NULL;
int erg = ERR;
/* These macros ought to be documented in the API docs
but they aren't yet. */
PyCursesInitialised
PyCursesInitialisedColor
/* Per ncurses Man Page:
The routine color_set sets the current color of the given window to
the foreground/background combination described by the
color_pair_number.
The parameter opts is reserved for future use, applications must
supply a
null pointer. */
switch(PyTuple_Size(args))
{
case 1:
/* Dont make them pass a useless null pointer. */
if (!PyArg_ParseTuple(args, "h", &color_pair_number)) return NULL;
case 2:
/* Allow them to pass the opts pointer so that when ncurses is later
updated.
This method will still work. */
if (!PyArg_ParseTuple(args, "hO&", &color_pair_number, &opts)) return
NULL;
default:
PyErr_SetString(PyExc_TypeError, "color_set requires 1 or 2 arguments
(color_pair_number[, opts]?)");
return NULL;
}
erg = color_set(color_pair_number, NULL);
if (erg == ERR)
return PyCursesCheckERR(erg, "color_set");
else
return NULL; /* PyInt_FromLong((long) 1L); */
}
------------------ End Snippet -------------------------------------
Oddly enough, running the debugger showed me a different result than I
expected by my bracketing approach. I falsely presumed that if by
commenting out the line where the call to color_set is made, and running the
program produces no segmentation fault, while commenting the same line back
in reprduces the segmentation fault, that I could deduce that the line thus
commented out was the source of the problem. Stupid me, that is apparently
not the case.
Apparently the segmentation fault is produced by a call to
Python/getargs.c:Line 1207
if(! (*convert)(arg,addr))
Which is invoked as a result of calling this line in the function listed
above:
if (!PyArg_ParseTuple(args, "hO&", &color_pair_number, &opts)) return
NULL;
A.M. Kuchling wrote:
>
> On Wed, Feb 25, 2009 at 06:30:06AM -0800, Heracles wrote:
>> is commented back in it does fail. I am not sure exactly how a debugger
>> will
>> help in this case since the color_set call goes directly to the ncurses
>> library. If in fact that the issue is the ncurses library then it seems
>> that there is no feasible solution until that library is fixed, in which
>> case this patch is sort of useless.
> ...
>> erg = color_set(color_pair_number, NULL); // Debating on forcing null
>
> What is color_pair_number in the C code? If it's some incorrect value
> (-1? 255?), maybe ncurses is indexing off an array and crashing.
>
> This is why a debugger might help; you could run the test program
> until the crash and then print out the values of the relevant
> variables. e.g. is stdscr set to a non-NULL value? There might be a
> debugging version of ncurses that will let you look at the variables
> inside the ncurses code, which may make the problem clear.
>
> --amk
>
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> http://mail.python.org/mailman/options/python-dev/lists%40nabble.com
>
>
:wistle::wistle::wistle:
--
View this message in context: http://www.nabble.com/Adding-support-to-curses-library-tp22191916p22205860.html
Sent from the Python - python-dev mailing list archive at Nabble.com.
More information about the Python-Dev
mailing list