static bool get_double_attr_from_py(PyObject *py_obj, const char *name, double *result, bool *has_value) { PyObject *py_attr = get_py_attr(py_obj, name); if (!py_attr) { return false; } bool ret = get_double_from_py(py_attr, result, has_value); Py_DECREF(py_attr); return ret; }
static bool get_string_attr_from_py(PyObject *py_obj, const char *name, char **string, bool optional) { PyObject *py_attr = get_py_attr(py_obj, name); if (!py_attr) { return false; } bool ret = get_string_from_py(py_attr, string, optional); Py_DECREF(py_attr); return ret; }
static PyObject *get_py_fn(PyObject *py_module, const char *name) { PyObject *py_fn = get_py_attr(py_module, name); if (!py_fn) { goto on_error; } if (!PyCallable_Check(py_fn)) { log(LOG_ERR, "Unable to get %s(): object is not callable", name); goto on_error; } on_exit: return py_fn; on_error: log_python_exception(); Py_CLEAR(py_fn); goto on_exit; }
static PyObject *get_py_type(PyObject *py_module, const char *name) { PyObject *py_type = get_py_attr(py_module, name); if (!py_type) { goto on_error; } if (!PyType_Check(py_type)) { log(LOG_ERR, "Unable to get type %s: object is not a type", name); goto on_error; } on_exit: return py_type; on_error: log_python_exception(); Py_CLEAR(py_type); goto on_exit; }
GLdouble double_global_const_attr(const char* attr_str) { bool py_needed_init = false; if(!Py_IsInitialized() ) { Py_Initialize(); py_needed_init = true; } PyObject *py_attr = get_py_attr(attr_str); if(!py_attr) { return NULL; } GLdouble output = PyFloat_AsDouble(py_attr); Py_XDECREF(py_attr); if(py_needed_init) { Py_Finalize(); } return output; }
char char_global_const_attr(const char* attr_str) { bool py_needed_init = false; if(!Py_IsInitialized() ) { Py_Initialize(); py_needed_init = true; } PyObject *py_attr = get_py_attr(attr_str); if(!py_attr) { return NULL; } char output = PyString_AsString(py_attr)[0]; Py_XDECREF(py_attr); if(py_needed_init) { Py_Finalize(); } return output; }