| 437 | } |
| 438 | |
| 439 | PythonContext::PythonContext(QObject *parent) : QObject(parent) |
| 440 | { |
| 441 | if(!initialised()) |
| 442 | return; |
| 443 | |
| 444 | // acquire the GIL and make sure this thread is init'd |
| 445 | PyGILState_STATE gil = PyGILState_Ensure(); |
| 446 | |
| 447 | // clone our own local context |
| 448 | context_namespace = PyDict_Copy(main_dict); |
| 449 | |
| 450 | PyObject *rlcompleter = PyDict_GetItemString(main_dict, "rlcompleter"); |
| 451 | |
| 452 | // for compatibility with earlier versions of python that took a char * instead of const char * |
| 453 | char noparams[1] = ""; |
| 454 | |
| 455 | // set global output that point to this context. It is responsible for deleting the context when |
| 456 | // it goes out of scope |
| 457 | PyObject *redirector = PyObject_CallFunction((PyObject *)&OutputRedirectorType, noparams); |
| 458 | if(redirector) |
| 459 | { |
| 460 | PyDict_SetItemString(context_namespace, "_renderdoc_internal", redirector); |
| 461 | |
| 462 | OutputRedirector *output = (OutputRedirector *)redirector; |
| 463 | output->context = this; |
| 464 | output->block = false; |
| 465 | Py_DECREF(redirector); |
| 466 | } |
| 467 | |
| 468 | if(rlcompleter) |
| 469 | { |
| 470 | PyObject *Completer = PyObject_SafeGetAttrString(rlcompleter, "Completer"); |
| 471 | |
| 472 | if(Completer) |
| 473 | { |
| 474 | // create a completer for our context's namespace |
| 475 | m_Completer = PyObject_CallFunction(Completer, "O", context_namespace); |
| 476 | |
| 477 | if(m_Completer) |
| 478 | { |
| 479 | PyDict_SetItemString(context_namespace, "_renderdoc_completer", m_Completer); |
| 480 | } |
| 481 | else |
| 482 | { |
| 483 | QString typeStr; |
| 484 | QString valueStr; |
| 485 | int finalLine = -1; |
| 486 | QList<QString> frames; |
| 487 | FetchException(typeStr, valueStr, finalLine, frames); |
| 488 | |
| 489 | // failure is not fatal |
| 490 | qWarning() << "Couldn't create completion object. " << typeStr << ": " << valueStr; |
| 491 | PyErr_Clear(); |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | Py_DecRef(Completer); |
| 496 | } |
nothing calls this directly
no test coverage detected