Skip to content

Commit 5f17cc8

Browse files
author
Roberto De Ioris
committed
fixed FARFilter reference counting
1 parent 6a0ee99 commit 5f17cc8

1 file changed

Lines changed: 29 additions & 12 deletions

File tree

‎Source/UnrealEnginePython/Private/Wrappers/UEPyFARFilter.cpp‎

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,17 @@ static int ue_py_farfilter_init(ue_PyFARFilter *self, PyObject *args, PyObject *
125125

126126
static void ue_py_farfilter_dealloc(ue_PyFARFilter *self)
127127
{
128+
self->filter.~FARFilter();
129+
128130
Py_XDECREF(self->class_names);
129131
Py_XDECREF(self->object_paths);
130132
Py_XDECREF(self->package_names);
131133
Py_XDECREF(self->package_paths);
132134
Py_XDECREF(self->recursive_classes_exclusion_set);
133135
Py_XDECREF(self->tags_and_values);
134136

135-
#if PY_MAJOR_VERSION < 3
136-
self->ob_type->tp_free((PyObject*)self);
137-
#else
137+
138138
Py_TYPE(self)->tp_free((PyObject*)self);
139-
#endif
140139
}
141140

142141
static PyObject * ue_py_farfilter_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
@@ -146,6 +145,9 @@ static PyObject * ue_py_farfilter_new(PyTypeObject *type, PyObject *args, PyObje
146145
self = (ue_PyFARFilter *)type->tp_alloc(type, 0);
147146
if (self != NULL)
148147
{
148+
149+
new(&self->filter) FARFilter();
150+
149151
self->class_names = PyList_New(0);
150152
if (self->class_names == NULL)
151153
{
@@ -174,34 +176,49 @@ static PyObject * ue_py_farfilter_new(PyTypeObject *type, PyObject *args, PyObje
174176
return NULL;
175177
}
176178

177-
self->recursive_classes_exclusion_set = PySet_New(0);
179+
self->recursive_classes_exclusion_set = PySet_New(NULL);
178180
if (self->recursive_classes_exclusion_set == NULL)
179181
{
180182
Py_DECREF(self);
181183
return NULL;
182184
}
183185

184186
PyObject *collections = PyImport_ImportModule("collections");
187+
if (!collections)
188+
{
189+
unreal_engine_py_log_error();
190+
Py_DECREF(self);
191+
return NULL;
192+
}
185193
PyObject *collections_module_dict = PyModule_GetDict(collections);
186194
PyObject *defaultdict_cls = PyDict_GetItemString(collections_module_dict, "defaultdict");
187195

188-
PyObject *main_module = PyImport_ImportModule("__main__");
189-
PyObject *main_dict = PyModule_GetDict(main_module);
190-
PyObject *builtins_module = PyDict_GetItemString(main_dict, "__builtins__");
196+
197+
PyObject *builtins_module = PyImport_ImportModule("builtins");
198+
if (!builtins_module)
199+
{
200+
unreal_engine_py_log_error();
201+
Py_DECREF(self);
202+
return NULL;
203+
}
191204
PyObject *builtins_dict = PyModule_GetDict(builtins_module);
192205
PyObject *set_cls = PyDict_GetItemString(builtins_dict, "set");
206+
// required because PyTuple_SetItem below will steal a reference
207+
Py_INCREF(set_cls);
208+
193209

194210
PyObject *py_args = PyTuple_New(1);
195211
PyTuple_SetItem(py_args, 0, set_cls);
196212
PyObject *default_dict = PyObject_CallObject(defaultdict_cls, py_args);
197-
Py_XDECREF(py_args);
198-
199-
self->tags_and_values = default_dict;
200-
if (self->tags_and_values == NULL)
213+
Py_DECREF(py_args);
214+
if (!default_dict)
201215
{
216+
unreal_engine_py_log_error();
202217
Py_DECREF(self);
203218
return NULL;
204219
}
220+
221+
self->tags_and_values = default_dict;
205222
}
206223

207224
return (PyObject *)self;

0 commit comments

Comments
 (0)