diff --git a/PyRainmeter.cpp b/PyRainmeter.cpp index 7fcc59c..6db0d51 100644 --- a/PyRainmeter.cpp +++ b/PyRainmeter.cpp @@ -193,10 +193,10 @@ PyObject* CreateRainmeterObject(void *rm) { if (!(rainmeterType.tp_flags & Py_TPFLAGS_READY)) { + rainmeterType.tp_new = PyType_GenericNew; PyType_Ready(&rainmeterType); } - Py_INCREF(&rainmeterType); - RainmeterObject *obj = PyObject_New(RainmeterObject, &rainmeterType); - obj->rm = rm; + PyObject *obj = PyObject_CallObject((PyObject*) &rainmeterType, NULL); + ((RainmeterObject*)obj)->rm = rm; return (PyObject*) obj; } diff --git a/PythonPlugin.cpp b/PythonPlugin.cpp index 0f67224..b61ed36 100644 --- a/PythonPlugin.cpp +++ b/PythonPlugin.cpp @@ -169,12 +169,12 @@ PLUGIN_EXPORT double Update(void* data) if (resultObj != NULL) { result = PyFloat_Check(resultObj) ? PyFloat_AsDouble(resultObj) : 0.0; + Py_DECREF(resultObj); } else { PyErr_Clear(); } - Py_XDECREF(resultObj); PyEval_SaveThread(); return result; }