diff --git a/deps/obs-scripting/obs-scripting-python-import.c b/deps/obs-scripting/obs-scripting-python-import.c index d80618e72..9be85161c 100644 --- a/deps/obs-scripting/obs-scripting-python-import.c +++ b/deps/obs-scripting/obs-scripting-python-import.c @@ -143,6 +143,13 @@ bool import_python(const char *python_path) IMPORT_FUNC(_Py_NoneStruct); IMPORT_FUNC(PyTuple_New); +#if defined(Py_DEBUG) || PY_VERSION_HEX >= 0x030900b0 + IMPORT_FUNC(_Py_Dealloc); +#endif +#if PY_VERSION_HEX >= 0x030900b0 + IMPORT_FUNC(PyType_GetFlags); +#endif + #undef IMPORT_FUNC success = true; diff --git a/deps/obs-scripting/obs-scripting-python-import.h b/deps/obs-scripting/obs-scripting-python-import.h index cf22587eb..3b51359c0 100644 --- a/deps/obs-scripting/obs-scripting-python-import.h +++ b/deps/obs-scripting/obs-scripting-python-import.h @@ -39,6 +39,14 @@ #include #endif +#if defined(HAVE_ATTRIBUTE_UNUSED) || defined(__MINGW32__) +#if !defined(UNUSED) +#define UNUSED __attribute__((unused)) +#endif +#else +#define UNUSED +#endif + #ifdef _MSC_VER #pragma warning(pop) #endif @@ -135,11 +143,23 @@ PY_EXTERN PyObject *(*Import_PyLong_FromUnsignedLongLong)(unsigned long long); PY_EXTERN int (*Import_PyArg_VaParse)(PyObject *, const char *, va_list); PY_EXTERN PyObject(*Import__Py_NoneStruct); PY_EXTERN PyObject *(*Import_PyTuple_New)(Py_ssize_t size); +#if PY_VERSION_HEX >= 0x030900b0 +PY_EXTERN int (*Import_PyType_GetFlags)(PyTypeObject *o); +#endif +#if defined(Py_DEBUG) || PY_VERSION_HEX >= 0x030900b0 +PY_EXTERN void (*Import__Py_Dealloc)(PyObject *obj); +#endif extern bool import_python(const char *python_path); #ifndef NO_REDEFS #define PyType_Ready Import_PyType_Ready +#if PY_VERSION_HEX >= 0x030900b0 +#define PyType_GetFlags Import_PyType_GetFlags +#endif +#if defined(Py_DEBUG) || PY_VERSION_HEX >= 0x030900b0 +#define _Py_Dealloc Import__Py_Dealloc +#endif #define PyObject_GenericGetAttr Import_PyObject_GenericGetAttr #define PyObject_IsTrue Import_PyObject_IsTrue #define Py_DecRef Import_Py_DecRef @@ -210,6 +230,44 @@ extern bool import_python(const char *python_path); #define PyArg_VaParse Import_PyArg_VaParse #define _Py_NoneStruct (*Import__Py_NoneStruct) #define PyTuple_New Import_PyTuple_New +#if PY_VERSION_HEX >= 0x030800f0 +static inline void Import__Py_DECREF(const char *filename UNUSED, + int lineno UNUSED, PyObject *op) +{ + if (--op->ob_refcnt != 0) { +#ifdef Py_REF_DEBUG + if (op->ob_refcnt < 0) { + _Py_NegativeRefcount(filename, lineno, op); + } +#endif + } else { + _Py_Dealloc(op); + } +} + +#undef Py_DECREF +#define Py_DECREF(op) Import__Py_DECREF(__FILE__, __LINE__, _PyObject_CAST(op)) + +static inline void Import__Py_XDECREF(PyObject *op) +{ + if (op != NULL) { + Py_DECREF(op); + } +} + +#undef Py_XDECREF +#define Py_XDECREF(op) Import__Py_XDECREF(_PyObject_CAST(op)) +#endif + +#if PY_VERSION_HEX >= 0x030900b0 +static inline int Import_PyType_HasFeature(PyTypeObject *type, + unsigned long feature) +{ + return ((PyType_GetFlags(type) & feature) != 0); +} +#define PyType_HasFeature(t, f) Import_PyType_HasFeature(t, f) +#endif + #endif #endif diff --git a/deps/obs-scripting/obs-scripting-python.c b/deps/obs-scripting/obs-scripting-python.c index cd5c694bf..3fc6a5535 100644 --- a/deps/obs-scripting/obs-scripting-python.c +++ b/deps/obs-scripting/obs-scripting-python.c @@ -1654,7 +1654,9 @@ bool obs_scripting_load_python(const char *python_path) /* ---------------------------------------------- */ /* Load main interface module */ - add_to_python_path(SCRIPT_DIR); + char *absolute_script_path = os_get_abs_path_ptr(SCRIPT_DIR); + add_to_python_path(absolute_script_path); + bfree(absolute_script_path); #if __APPLE__ char *exec_path = os_get_executable_path_ptr("");