obs-scripting: Add Py 3.8+ C-API changes

Closes obsproject/obs-studio#3689
This commit is contained in:
PatTheMav 2021-01-27 09:31:30 -08:00 committed by jp9000
parent 44ace7618f
commit ecdc81ba0f
3 changed files with 68 additions and 1 deletions

View file

@ -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;

View file

@ -39,6 +39,14 @@
#include <Python.h>
#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

View file

@ -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("");