[Python-Dev] Adding support to curses library (original) (raw)

Heracles steve at integrityintegrators.net
Wed Feb 25 15:24:51 CET 2009


Ulrich,

Thanks for the input. That is helpful to know.

H

Ulrich Berning-2 wrote: >> Heracles 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: >>>>------------- Snippet --------------------------- >>// Insert new method colorset Steve Owens 2/24/2009 >>// The curses library colorset function has the following signature: >>// int colorset(short colorpairnumber, void* opts); >>static PyObject * >>PyCursescolorset(PyObject *self, PyObject *args) >>{ >> short colorpairnumber; >> 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 colorset sets the current color of the given window >> to >> // the foreground/background combination described by the >>colorpairnumber. >> // The parameter opts is reserved for future use, applications must >>supply a >> // null pointer. >> switch(PyTupleSize(args)) >> { >> case 1: >> // Dont make them pass a useless null pointer. >> if (!PyArgParseTuple(args, "h", &colorpairnumber)) 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 (!PyArgParseTuple(args, "hO&", &colorpairnumber, &opts)) return >>NULL; >> break; >> default: >> PyErrSetString(PyExcTypeError, "colorset requires 1 or 2 >> arguments >>(colorpairnumber[, opts]?)"); >> return NULL; >> } >>>> erg = colorset(colorpairnumber, opts); // Debating on forcing null >>here. >>>> if (erg == ERR) >> return PyCursesCheckERR(erg, "colorset"); >> else >> PyIntFromLong((long) 1L); >>} >>-------------End Snippet --------------------------- >>>>I also have the following added in (see last line of the snippet): >>>>------------- Snippet --------------------------- >>static PyMethodDef PyCursesmethods[] = { >> {"baudrate", (PyCFunction)PyCursesbaudrate, METHNOARGS}, >> {"beep", (PyCFunction)PyCursesbeep, METHNOARGS}, >> {"canchangecolor", (PyCFunction)PyCursescanchangecolor, >>METHNOARGS}, >> {"cbreak", (PyCFunction)PyCursescbreak, METHVARARGS}, >> {"colorcontent", (PyCFunction)PyCursesColorContent, >>METHVARARGS}, >> {"colorpair", (PyCFunction)PyCursescolorpair, METHVARARGS}, >> {"colorset", (PyCFunction)PyCursescolorset, METHVARARGS}, >>-------------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 testsupport >>>>def testCursesColorSet(stdscrn): >> curses.initpair(1, curses.COLORRED, curses.COLORWHITE) >> curses.initpair(2, curses.COLORWHITE, curses.COLORBLUE); >> i = curses.colorset(1, NULL); >> stdscrn.addstr("RED/BLACK (%0)\n".format(i)) >> i = curses.colorset(2, NULL); >> stdscrn.print("WHITE/BLUE (%0)\n".format(i)) >> i = curses.colorset(0, NULL); >> stdscrn.print("Default (%0)\n".format(i)) >>>>>>def testmain(stdscrn): >> curses.savetty() >> if curses.hascolor(): >> testCursesColorSet(stdscrn) >> else >> stdscr.addstr( "Test Aborted: Color not supported on this >> terminal.") >>>>>>if name == 'main': >> curses.wrapper(testmain) >>-------------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 = colorset(colorpairnumber, 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 colorset function >>outside of python, but that is another task. >>>>Any suggestions? >>>>>>>>> As long as Python is written in C, please don't use C++ comments, some C > compilers don't like them. >> Ulli > _________________________ > 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-tp22191916p22203820.html Sent from the Python - python-dev mailing list archive at Nabble.com.



More information about the Python-Dev mailing list