[Python-Dev] Adding support to curses library
Heracles
steve at integrityintegrators.net
Wed Feb 25 15:30:06 CET 2009
Thank you for your reply,
and no, that is not the exact code. I must have wiped out the return
statement when I copied it in. The return statement is in the code. Also
the code has been modified so that the call to color_set reads as follows:
erg = color_set(color_pair_number, NULL); // Debating on forcing null
Never the less, as I said in my earlier post, the above line is the exact
line where the error occurs. This is provable simply because when the code
is compiled with that line commented out, it doesn't fail, and when the line
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.
Bugzilla from nnorwitz at gmail.com wrote:
>
> On Tue, Feb 24, 2009 at 2:18 PM, Heracles
> <steve at integrityintegrators.net> wrote:
>>
>> Hello,
>>
>> I am working on a patch to add to the _cursesmodule.c file of the Python
>> core libraries. I figured I would take on one of the implemented
>> functions
>> to try to get my feet wet contributing to the project. At any rate, I
>> have
>> the following function defined in the 2.7.a version updated from SVN this
>> morning:
>
> I'm glad you are interested in developing Python. I'm not sure if
> this is the best forum. OTOH, I'm not sure if comp.lang.python would
> be appropriate either.
>
> I'd suggest making a proper patch and submitting it to
> http://bugs.python.org
>
>> ------------- Snippet ---------------------------
>> // Insert new method color_set Steve Owens 2/24/2009
>> // The curses library color_set function has the following signature:
>> // int color_set(short color_pair_number, void* opts);
>> static PyObject *
>> PyCurses_color_set(PyObject *self, PyObject *args)
>> {
>> short color_pair_number;
>> void * opts;
>> int erg;
>>
>> // 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;
>> break;
>> 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;
>> break;
>> default:
>> PyErr_SetString(PyExc_TypeError, "color_set requires 1 or 2
>> arguments
>> (color_pair_number[, opts]?)");
>> return NULL;
>> }
>>
>> erg = color_set(color_pair_number, opts); // Debating on forcing null
>> here.
>>
>> if (erg == ERR)
>> return PyCursesCheckERR(erg, "color_set");
>> else
>> PyInt_FromLong((long) 1L);
>
> I did a cursory review of the patch and if this is the exact code,
> this is a problem. You are missing a return statement. The compiler
> should have issued a warning for this too.
>
>> }
>> -------------End Snippet ---------------------------
>>
>> I also have the following added in (see last line of the snippet):
>>
>> ------------- Snippet ---------------------------
>> static PyMethodDef PyCurses_methods[] = {
>> {"baudrate", (PyCFunction)PyCurses_baudrate, METH_NOARGS},
>> {"beep", (PyCFunction)PyCurses_beep, METH_NOARGS},
>> {"can_change_color", (PyCFunction)PyCurses_can_change_color,
>> METH_NOARGS},
>> {"cbreak", (PyCFunction)PyCurses_cbreak, METH_VARARGS},
>> {"color_content", (PyCFunction)PyCurses_Color_Content,
>> METH_VARARGS},
>> {"color_pair", (PyCFunction)PyCurses_color_pair, METH_VARARGS},
>> {"color_set", (PyCFunction)PyCurses_color_set, METH_VARARGS},
>> -------------End Snippet ---------------------------
>>
>> The code compiles and installs fine, but when I run the following unit
>> test,
>> I get a segmentation fault:
>>
>> ------------- Snippet ---------------------------
>> import unittest, curses
>> from test import test_support
>>
>> def testCursesColorSet(stdscrn):
>> curses.init_pair(1, curses.COLOR_RED, curses.COLOR_WHITE)
>> curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_BLUE);
>> i = curses.color_set(1, NULL);
>> stdscrn.addstr("RED/BLACK (%0)\n".format(i))
>> i = curses.color_set(2, NULL);
>> stdscrn.print("WHITE/BLUE (%0)\n".format(i))
>> i = curses.color_set(0, NULL);
>> stdscrn.print("Default (%0)\n".format(i))
>>
>>
>> def test_main(stdscrn):
>> curses.savetty()
>> if curses.has_color():
>> testCursesColorSet(stdscrn)
>> else
>> stdscr.addstr( "Test Aborted: Color not supported on this
>> terminal.")
>>
>>
>> if __name__ == '__main__':
>> curses.wrapper(test_main)
>> -------------End Snippet ---------------------------
>>
>> It turns out that by commenting out this line in the _cursesmodule.c
>> code,
>> allows the unit test to run
>> obviously reporting the error as expected:
>>
>> ------------- Snippet ---------------------------
>> //erg = color_set(color_pair_number, opts); // Debating on forcing null
>> here.
>> -------------End Snippet ---------------------------
>>
>> At any rate I am stuck. I am still trying to build just a plain C file
>> which will test the color_set function
>> outside of python, but that is another task.
>>
>> Any suggestions?
>
> Beyond what I said above, typically you need to go the next step.
> Fire up a debugger and determine exactly where and why it's crashing.
>
> Good luck!
>
> n
> _______________________________________________
> 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
>
>
--
View this message in context: http://www.nabble.com/Adding-support-to-curses-library-tp22191916p22203899.html
Sent from the Python - python-dev mailing list archive at Nabble.com.
More information about the Python-Dev
mailing list