python3.8.patch 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. From 4b663ecf264020b1d7003a137ce84b06d7ec4ce6 Mon Sep 17 00:00:00 2001
  2. From: bartus <szczepaniak.bartek+github@gmail.com>
  3. Date: Sat, 16 Nov 2019 20:29:30 +0100
  4. Subject: [PATCH] Add python 3.8 support.
  5. ---
  6. source/blender/python/generic/py_capi_utils.c | 27 +++++++++++++++----
  7. 1 file changed, 22 insertions(+), 5 deletions(-)
  8. diff --git a/source/blender/python/generic/py_capi_utils.c b/source/blender/python/generic/py_capi_utils.c
  9. index 545e0506f84..a7eab70600b 100644
  10. --- a/source/blender/python/generic/py_capi_utils.c
  11. +++ b/source/blender/python/generic/py_capi_utils.c
  12. @@ -696,9 +696,16 @@ PyObject *PyC_UnicodeFromByte(const char *str)
  13. ****************************************************************************/
  14. PyObject *PyC_DefaultNameSpace(const char *filename)
  15. {
  16. + #if PY_VERSION_HEX >= 0x03080000
  17. + PyObject *modules = PyImport_GetModuleDict();
  18. + PyObject *builtins = PyEval_GetBuiltins();
  19. + #else
  20. PyInterpreterState *interp = PyThreadState_GET()->interp;
  21. + PyObject *modules = interp->modules;
  22. + PyObject *builtins = interp->builtins;
  23. + #endif
  24. PyObject *mod_main = PyModule_New("__main__");
  25. - PyDict_SetItemString(interp->modules, "__main__", mod_main);
  26. + PyDict_SetItemString(modules, "__main__", mod_main);
  27. Py_DECREF(mod_main); /* sys.modules owns now */
  28. PyModule_AddStringConstant(mod_main, "__name__", "__main__");
  29. if (filename) {
  30. @@ -706,8 +713,8 @@ PyObject *PyC_DefaultNameSpace(const char *filename)
  31. * note: this wont map to a real file when executing text-blocks and buttons. */
  32. PyModule_AddObject(mod_main, "__file__", PyC_UnicodeFromByte(filename));
  33. }
  34. - PyModule_AddObject(mod_main, "__builtins__", interp->builtins);
  35. - Py_INCREF(interp->builtins); /* AddObject steals a reference */
  36. + PyModule_AddObject(mod_main, "__builtins__", builtins);
  37. + Py_INCREF(builtins); /* AddObject steals a reference */
  38. return PyModule_GetDict(mod_main);
  39. }
  40. @@ -734,15 +741,25 @@ bool PyC_NameSpace_ImportArray(PyObject *py_dict, const char *imports[])
  41. /* restore MUST be called after this */
  42. void PyC_MainModule_Backup(PyObject **main_mod)
  43. {
  44. + #if PY_VERSION_HEX >= 0x03080000
  45. + PyObject *modules = PyImport_GetModuleDict();
  46. + #else
  47. PyInterpreterState *interp = PyThreadState_GET()->interp;
  48. - *main_mod = PyDict_GetItemString(interp->modules, "__main__");
  49. + PyObject *modules = interp->modules;
  50. + #endif
  51. + *main_mod = PyDict_GetItemString(modules, "__main__");
  52. Py_XINCREF(*main_mod); /* don't free */
  53. }
  54. void PyC_MainModule_Restore(PyObject *main_mod)
  55. {
  56. + #if PY_VERSION_HEX >= 0x03080000
  57. + PyObject *modules = PyImport_GetModuleDict();
  58. + #else
  59. PyInterpreterState *interp = PyThreadState_GET()->interp;
  60. - PyDict_SetItemString(interp->modules, "__main__", main_mod);
  61. + PyObject *modules = interp->modules;
  62. + #endif
  63. + PyDict_SetItemString(modules, "__main__", main_mod);
  64. Py_XDECREF(main_mod);
  65. }
  66. --
  67. 2.24.0