lib/base/console.cpp: fix eConsoleAppContainer write (when called with one string...
authorghost <andreas.monzner@multimedia-labs.de>
Mon, 5 Jul 2010 14:59:47 +0000 (16:59 +0200)
committerghost <andreas.monzner@multimedia-labs.de>
Mon, 5 Jul 2010 15:00:25 +0000 (17:00 +0200)
lib/base/console.cpp

index add8706..43f9f61 100644 (file)
@@ -516,18 +516,15 @@ eConsolePy_write(eConsolePy* self, PyObject *args)
 {
        int len;
        char *data;
 {
        int len;
        char *data;
-       if (PyArg_ParseTuple(args, "si", &data, &len))
-               ;
-       else
+       int ret = -1;
+       Py_ssize_t argc = PyTuple_Size(args);
+       if (argc > 1)
+               ret = PyArg_ParseTuple(args, "si", &data, &len);
+       else if (argc == 1)
        {
                PyObject *ob;
        {
                PyObject *ob;
-               if (!PyArg_ParseTuple(args, "O", &ob) || !PyString_Check(ob))
-               {
-                       PyErr_SetString(PyExc_TypeError,
-                               "1st arg must be a string, optionaly 2nd arg can be the string length");
-                       return NULL;
-               }
-               else
+               ret = !PyArg_ParseTuple(args, "O", &ob) || !PyString_Check(ob);
+               if (!ret)
                {
                        Py_ssize_t length;
                        if (!PyString_AsStringAndSize(ob, &data, &length))
                {
                        Py_ssize_t length;
                        if (!PyString_AsStringAndSize(ob, &data, &length))
@@ -536,6 +533,12 @@ eConsolePy_write(eConsolePy* self, PyObject *args)
                                len = 0;
                }
        }
                                len = 0;
                }
        }
+       if (ret)
+       {
+               PyErr_SetString(PyExc_TypeError,
+                       "1st arg must be a string, optionaly 2nd arg can be the string length");
+               return NULL;
+       }
        self->cont->write(data, len);
        Py_RETURN_NONE;
 }
        self->cont->write(data, len);
        Py_RETURN_NONE;
 }