[Python-Dev] String conversion issues implementing new curses module method addchstr, etc.

Heracles steve at integrityintegrators.net
Wed Feb 25 23:00:53 CET 2009


Hello,

I submitted my first patch recently for the curses color_set and wcolor_set
functions.  I am now working on addchstr, addchnstr, mvaddchstr,
mvaddchnstr, mvwaddchstr, mvwaddchnstr, waddchstr and waddchnstr.

I have implemented the non window specific methods as follows:

static PyObject *
PyCurses_AddChstr(PyObject *self, PyObject *args)
{
  int x, y, n;

  PyStringObject *pS = NULL;
 
  switch (PyTuple_Size(args)) {
  case 1:
    if (!PyArg_ParseTuple(args, "S;(String) expected for addchstr", &pS))
		return NULL;    
	return PyCursesCheckERR(addchstr((chtype*)PyString_AsString(pS)),
"addchstr");    
  case 2:
    if (!PyArg_ParseTuple(args, "Si;(String, int) expected for addchnstr",
&pS, &n))
		return NULL;
    return PyCursesCheckERR(addchnstr((chtype*)PyString_AsString(pS), n),
"addchnstr");    
  case 3:
    if (!PyArg_ParseTuple(args,"iiS;(int, int, String) expected for
mvaddchstr", &y, &x, &pS)) 
		return NULL;
    return PyCursesCheckERR(mvaddchstr(y, x,
(chtype*)PyString_AsString(pS)), "mvaddchstr");
  case 4:
    if (!PyArg_ParseTuple(args,"iiSi;(int, int, String, int) expected for
mvaddchnstr", &y, &x, &pS, &n))
		return NULL;
    return PyCursesCheckERR(mvaddchnstr(y, x,
(chtype*)PyString_AsString(pS), n), "mvaddchnstr");
  default:
    PyErr_SetString(PyExc_TypeError, "addchstr requires 1 to 4 arguments");
  }  
  return NULL;
}


Now the thing is that when I make calls from python like so:

   curses.addchstr(5,10, "@ < Row 5, Col 10")
   curses.addchstr(8,10, "Below you should see ABCDEFG")
   curses.addchstr(9,10, "ABCDEFG")
   curses.addchstr(12,10, "Below you should see ABCD")
   curses.addchnstr(13,10, "ABCDEFGHI", 4)

What prints out on the screen is gobledygook not the strings you would
expect below.

Any thoughts on how to correctly convert the PyStringObject arguments to
chtype* pointers so that the ncurses library will be able to understand
them?
-- 
View this message in context: http://www.nabble.com/String-conversion-issues-implementing-new-curses-module-method-addchstr%2C-etc.-tp22211983p22211983.html
Sent from the Python - python-dev mailing list archive at Nabble.com.



More information about the Python-Dev mailing list