Skip to content

Commit

Permalink
Fix refcounting in Date.from_date (#630)
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio committed Mar 11, 2024
2 parents db74385 + b4e5d6e commit d56825f
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions SWIG/date.i
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,17 @@ static inline PyObject* PyDate_FromDate(int year, int month, int day) {
return PyObject_CallFunction(pydate_type, "iii", year, month, day);
}

#define PyDateTime_GET_YEAR(o) PyLong_AsLong(PyObject_GetAttr(o, pydate_yearstr))
#define PyDateTime_GET_MONTH(o) PyLong_AsLong(PyObject_GetAttr(o, pydate_monthstr))
#define PyDateTime_GET_DAY(o) PyLong_AsLong(PyObject_GetAttr(o, pydate_daystr))
static inline long pyobject_getattr_long(PyObject* obj, PyObject* attr) {
PyObject* val = PyObject_GetAttr(obj, attr);
QL_REQUIRE(val != nullptr, "missing attribute");
long res = PyLong_AsLong(val);
Py_DECREF(val);
return res;
}

#define PyDateTime_GET_YEAR(o) pyobject_getattr_long(o, pydate_yearstr)
#define PyDateTime_GET_MONTH(o) pyobject_getattr_long(o, pydate_monthstr)
#define PyDateTime_GET_DAY(o) pyobject_getattr_long(o, pydate_daystr)

#else
#include <datetime.h>
Expand Down

0 comments on commit d56825f

Please sign in to comment.