| 261 | } |
| 262 | |
| 263 | const char *PythonModule::getStringFromAll(char* buffer, int len) { |
| 264 | if (wrapper.getCurrentArg() >= wrapper.getNumberArgs()) { |
| 265 | return 0; |
| 266 | } |
| 267 | |
| 268 | PyObject *o = |
| 269 | PyTuple_GetItem(wrapper.getCurrentArgv(), wrapper.getCurrentArg()); |
| 270 | wrapper.incrCurrentArg(); |
| 271 | |
| 272 | // check if int |
| 273 | if (PyLong_Check(o) || PyBool_Check(o)) { |
| 274 | PyErr_Clear(); |
| 275 | int data = PyLong_AsLong(o); |
| 276 | if (PyErr_Occurred()) { |
| 277 | return 0; |
| 278 | } |
| 279 | snprintf(buffer, len, "%d", data); |
| 280 | return buffer; |
| 281 | } |
| 282 | // check if double |
| 283 | else if (PyFloat_Check(o)) { |
| 284 | PyErr_Clear(); |
| 285 | double data = PyFloat_AsDouble(o); |
| 286 | if (PyErr_Occurred()) { |
| 287 | return 0; |
| 288 | } |
| 289 | snprintf(buffer, len, "%.20f", data); |
| 290 | return buffer; |
| 291 | } |
| 292 | |
| 293 | #if PY_MAJOR_VERSION >= 3 |
| 294 | if (!PyUnicode_Check(o)) { |
| 295 | return 0; |
| 296 | } |
| 297 | |
| 298 | // PyObject *space = PyUnicode_FromString(" "); |
| 299 | // PyObject *empty = PyUnicode_FromString(""); |
| 300 | // PyObject *newo = PyUnicode_Replace(o, space, empty, -1); |
| 301 | const char* res = trimSpaces(o); |
| 302 | // Py_DECREF(newo); |
| 303 | // Py_DECREF(space); |
| 304 | // Py_DECREF(empty); |
| 305 | |
| 306 | int lenres = int(strlen(res)) + 1; |
| 307 | if (lenres > len) { |
| 308 | lenres = len; |
| 309 | } |
| 310 | |
| 311 | strncpy(buffer, res, lenres); |
| 312 | |
| 313 | return buffer; |
| 314 | #else |
| 315 | if (!PyString_Check(o)) { |
| 316 | return 0; |
| 317 | } |
| 318 | |
| 319 | return PyString_AS_STRING(o); |
| 320 | #endif |
no test coverage detected