Skip to content

Commit 60c3938

Browse files
committed
use cleaner way to instantiate PyRainmeter
1 parent 7dccf68 commit 60c3938

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

PyRainmeter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,10 @@ PyObject* CreateRainmeterObject(void *rm)
193193
{
194194
if (!(rainmeterType.tp_flags & Py_TPFLAGS_READY))
195195
{
196+
rainmeterType.tp_new = PyType_GenericNew;
196197
PyType_Ready(&rainmeterType);
197198
}
198-
Py_INCREF(&rainmeterType);
199-
RainmeterObject *obj = PyObject_New(RainmeterObject, &rainmeterType);
200-
obj->rm = rm;
199+
PyObject *obj = PyObject_CallObject((PyObject*) &rainmeterType, NULL);
200+
((RainmeterObject*)obj)->rm = rm;
201201
return (PyObject*) obj;
202202
}

PythonPlugin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,12 @@ PLUGIN_EXPORT double Update(void* data)
169169
if (resultObj != NULL)
170170
{
171171
result = PyFloat_Check(resultObj) ? PyFloat_AsDouble(resultObj) : 0.0;
172+
Py_DECREF(resultObj);
172173
}
173174
else
174175
{
175176
PyErr_Clear();
176177
}
177-
Py_XDECREF(resultObj);
178178
PyEval_SaveThread();
179179
return result;
180180
}

0 commit comments

Comments
 (0)