Skip to content

Commit 17a212b

Browse files
author
Roberto De Ioris
committed
rename wrapper to uobject
1 parent f6ae6cd commit 17a212b

13 files changed

Lines changed: 281 additions & 238 deletions

‎Source/UnrealEnginePython/Private/PyActor.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void APyActor::PreInitializeComponents()
2323

2424
FScopePythonGIL gil;
2525

26-
py_uobject = ue_get_python_wrapper(this);
26+
py_uobject = ue_get_python_uobject(this);
2727
if (!py_uobject)
2828
{
2929
unreal_engine_py_log_error();
@@ -295,7 +295,7 @@ APyActor::~APyActor()
295295
Py_XDECREF(py_actor_instance);
296296

297297
#if defined(UEPY_MEMORY_DEBUG)
298-
UE_LOG(LogPython, Warning, TEXT("Python AActor %p (mapped to %p) wrapper XDECREF'ed"), this, py_uobject ? py_uobject->ue_object : nullptr);
298+
UE_LOG(LogPython, Warning, TEXT("Python AActor %p (mapped to %p) wrapper XDECREF'ed"), this, py_uobject ? py_uobject->py_proxy : nullptr);
299299
#endif
300300

301301
// this could trigger the distruction of the python/uobject mapper

‎Source/UnrealEnginePython/Private/PyCharacter.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ APyCharacter::~APyCharacter()
453453
Py_XDECREF(py_character_instance);
454454

455455
#if defined(UEPY_MEMORY_DEBUG)
456-
UE_LOG(LogPython, Warning, TEXT("Python ACharacter (mapped to %p) wrapper XDECREF'ed"), py_uobject ? py_uobject->ue_object : nullptr);
456+
UE_LOG(LogPython, Warning, TEXT("Python ACharacter (mapped to %p) wrapper XDECREF'ed"), py_uobject ? py_uobject->py_proxy : nullptr);
457457
#endif
458458

459459
// this could trigger the distruction of the python/uobject mapper

‎Source/UnrealEnginePython/Private/PyHUD.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ APyHUD::~APyHUD()
253253
Py_XDECREF(py_hud_instance);
254254

255255
#if defined(UEPY_MEMORY_DEBUG)
256-
UE_LOG(LogPython, Warning, TEXT("Python AHUD %p (mapped to %p) wrapper XDECREF'ed"), this, py_uobject ? py_uobject->ue_object : nullptr);
256+
UE_LOG(LogPython, Warning, TEXT("Python AHUD %p (mapped to %p) wrapper XDECREF'ed"), this, py_uobject ? py_uobject->py_proxy : nullptr);
257257
#endif
258258

259259
// this could trigger the distruction of the python/uobject mapper

‎Source/UnrealEnginePython/Private/PyPawn.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ APyPawn::~APyPawn()
250250

251251

252252
#if defined(UEPY_MEMORY_DEBUG)
253-
UE_LOG(LogPython, Warning, TEXT("Python APawn (mapped to %p) wrapper XDECREF'ed"), py_uobject ? py_uobject->ue_object : nullptr);
253+
UE_LOG(LogPython, Warning, TEXT("Python APawn (mapped to %p) wrapper XDECREF'ed"), py_uobject ? py_uobject->py_proxy : nullptr);
254254
#endif
255255

256256
// this could trigger the distruction of the python/uobject mapper

‎Source/UnrealEnginePython/Private/PyUserWidget.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ UPyUserWidget::~UPyUserWidget()
365365
Py_XDECREF(py_user_widget_instance);
366366

367367
#if defined(UEPY_MEMORY_DEBUG)
368-
UE_LOG(LogPython, Warning, TEXT("Python UUserWidget %p (mapped to %p) wrapper XDECREF'ed"), this, py_uobject ? py_uobject->ue_object : nullptr);
368+
UE_LOG(LogPython, Warning, TEXT("Python UUserWidget %p (mapped to %p) wrapper XDECREF'ed"), this, py_uobject ? py_uobject->py_proxy : nullptr);
369369
#endif
370370

371371
// this could trigger the distruction of the python/uobject mapper

‎Source/UnrealEnginePython/Private/PythonComponent.cpp‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void UPythonComponent::InitializePythonComponent() {
2424

2525
FScopePythonGIL gil;
2626

27-
py_uobject = ue_get_python_wrapper(this);
27+
py_uobject = ue_get_python_uobject(this);
2828
if (!py_uobject) {
2929
unreal_engine_py_log_error();
3030
return;
@@ -191,7 +191,7 @@ void UPythonComponent::SetPythonAttrObject(FString attr, UObject *object)
191191

192192
FScopePythonGIL gil;
193193

194-
ue_PyUObject *py_obj = ue_get_python_wrapper(object);
194+
ue_PyUObject *py_obj = ue_get_python_uobject(object);
195195
if (!py_obj) {
196196
PyErr_Format(PyExc_Exception, "PyUObject is in invalid state");
197197
unreal_engine_py_log_error();
@@ -425,7 +425,7 @@ UObject *UPythonComponent::CallPythonComponentMethodObject(FString method_name,
425425
ret = PyObject_CallMethod(py_component_instance, TCHAR_TO_UTF8(*method_name), NULL);
426426
}
427427
else {
428-
PyObject *py_arg_uobject = (PyObject *)ue_get_python_wrapper(arg);
428+
PyObject *py_arg_uobject = (PyObject *)ue_get_python_uobject(arg);
429429
if (!py_arg_uobject) {
430430
unreal_engine_py_log_error();
431431
return nullptr;
@@ -566,7 +566,7 @@ UPythonComponent::~UPythonComponent()
566566
Py_XDECREF(py_component_instance);
567567

568568
#if defined(UEPY_MEMORY_DEBUG)
569-
UE_LOG(LogPython, Warning, TEXT("Python UActorComponent %p (mapped to %p) wrapper XDECREF'ed"), this, py_uobject ? py_uobject->ue_object : nullptr);
569+
UE_LOG(LogPython, Warning, TEXT("Python UActorComponent %p (mapped to %p) wrapper XDECREF'ed"), this, py_uobject ? py_uobject->py_proxy : nullptr);
570570
#endif
571571

572572
// this could trigger the distruction of the python/uobject mapper

‎Source/UnrealEnginePython/Private/Slate/UEPyIStructureDetailsView.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static PyMethodDef ue_PyIStructureDetailsView_methods[] = {
9494
static void ue_PyIStructureDetailsView_dealloc(ue_PyIStructureDetailsView *self)
9595
{
9696
#if defined(UEPY_MEMORY_DEBUG)
97-
UE_LOG(LogPython, Warning, TEXT("Destroying ue_PyIStructureDetailsView %p mapped to IStructureDetailsView %p"), self, &self->istructure_details_view.Get());
97+
UE_LOG(LogPython, Warning, TEXT("Destroying ue_PyIStructureDetailsView %p mapped to IStructureDetailsView %p"), self, self->istructure_details_view.Get());
9898
#endif
9999
Py_DECREF(self->ue_py_struct);
100100
Py_TYPE(self)->tp_free((PyObject *)self);

‎Source/UnrealEnginePython/Private/UEPyModule.cpp‎

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@ static PyObject *py_ue_get_py_proxy(ue_PyUObject *self, PyObject * args)
148148
return (PyObject *)self->py_proxy;
149149
}
150150

151-
Py_INCREF(Py_None);
152-
return Py_None;
151+
Py_RETURN_NONE;
153152
}
154153

155154
static PyMethodDef unreal_engine_methods[] = {
@@ -982,6 +981,7 @@ void ue_pydelegates_cleanup(ue_PyUObject *self)
982981
// start deallocating delegates mapped to the object
983982
if (!self || !self->python_delegates_gc)
984983
return;
984+
UE_LOG(LogPython, Warning, TEXT("Delegates = %d"), self->python_delegates_gc->size());
985985
for (UPythonDelegate *py_delegate : *(self->python_delegates_gc))
986986
{
987987
if (py_delegate && py_delegate->IsValidLowLevel())
@@ -2096,7 +2096,7 @@ void unreal_engine_init_py_module()
20962096

20972097
// utility functions
20982098

2099-
ue_PyUObject *ue_get_python_wrapper(UObject *ue_obj)
2099+
ue_PyUObject *ue_get_python_uobject(UObject *ue_obj)
21002100
{
21012101
if (!ue_obj || !ue_obj->IsValidLowLevel() || ue_obj->IsPendingKillOrUnreachable())
21022102
return nullptr;
@@ -2122,10 +2122,20 @@ ue_PyUObject *ue_get_python_wrapper(UObject *ue_obj)
21222122
//Py_INCREF(ue_py_object);
21232123
return ue_py_object;
21242124
}
2125-
2125+
Py_INCREF(it->second);
21262126
return it->second;
21272127
}
21282128

2129+
ue_PyUObject *ue_get_python_uobject_noinc(UObject *ue_obj)
2130+
{
2131+
ue_PyUObject *ret = ue_get_python_uobject(ue_obj);
2132+
if (ret)
2133+
{
2134+
Py_DECREF(ret);
2135+
}
2136+
return ret;
2137+
}
2138+
21292139
void unreal_engine_py_log_error()
21302140
{
21312141
PyObject *type = NULL;
@@ -2327,11 +2337,7 @@ PyObject *ue_py_convert_property(UProperty *prop, uint8 *buffer)
23272337
auto value = casted_prop->GetObjectPropertyValue_InContainer(buffer);
23282338
if (value)
23292339
{
2330-
ue_PyUObject *ret = ue_get_python_wrapper(value);
2331-
if (!ret)
2332-
return PyErr_Format(PyExc_Exception, "uobject is in invalid state");
2333-
Py_INCREF(ret);
2334-
return (PyObject *)ret;
2340+
Py_RETURN_UOBJECT(value);
23352341
}
23362342
Py_RETURN_NONE;
23372343
}
@@ -2341,11 +2347,7 @@ PyObject *ue_py_convert_property(UProperty *prop, uint8 *buffer)
23412347
auto value = casted_prop->GetPropertyValue_InContainer(buffer);
23422348
if (value)
23432349
{
2344-
ue_PyUObject *ret = ue_get_python_wrapper(value);
2345-
if (!ret)
2346-
return PyErr_Format(PyExc_Exception, "uobject is in invalid state");
2347-
Py_INCREF(ret);
2348-
return (PyObject *)ret;
2350+
Py_RETURN_UOBJECT(value);
23492351
}
23502352
return PyErr_Format(PyExc_Exception, "invalid UClass type for %s", TCHAR_TO_UTF8(*casted_prop->GetName()));
23512353
}
@@ -2397,11 +2399,7 @@ PyObject *ue_py_convert_property(UProperty *prop, uint8 *buffer)
23972399
UObject *strong_obj = value.Get();
23982400
if (strong_obj)
23992401
{
2400-
ue_PyUObject *ret = ue_get_python_wrapper(strong_obj);
2401-
if (!ret)
2402-
return PyErr_Format(PyExc_Exception, "uobject is in invalid state");
2403-
Py_INCREF(ret);
2404-
return (PyObject *)ret;
2402+
Py_RETURN_UOBJECT(strong_obj);
24052403
}
24062404
// nullptr
24072405
Py_INCREF(Py_None);
@@ -2410,11 +2408,7 @@ PyObject *ue_py_convert_property(UProperty *prop, uint8 *buffer)
24102408

24112409
if (auto casted_prop = Cast<UMulticastDelegateProperty>(prop))
24122410
{
2413-
ue_PyUObject *ret = ue_get_python_wrapper(casted_prop);
2414-
if (!ret)
2415-
return PyErr_Format(PyExc_Exception, "uobject is in invalid state");
2416-
Py_INCREF(ret);
2417-
return (PyObject *)ret;
2411+
Py_RETURN_UOBJECT(casted_prop);
24182412
}
24192413

24202414
if (auto casted_prop = Cast<UArrayProperty>(prop))
@@ -2967,7 +2961,7 @@ void ue_bind_events_for_py_class_by_attribute(UObject *u_obj, PyObject *py_class
29672961
{
29682962
if (n == 1)
29692963
{
2970-
if (!ue_bind_pyevent(ue_get_python_wrapper(actor), parts[0], item, true))
2964+
if (!ue_bind_pyevent(ue_get_python_uobject(actor), parts[0], item, true))
29712965
{
29722966
unreal_engine_py_log_error();
29732967
}
@@ -3234,8 +3228,7 @@ PyObject *ue_bind_pyevent(ue_PyUObject *u_obj, FString event_name, PyObject *py_
32343228
{
32353229
if (fail_on_wrong_property)
32363230
return PyErr_Format(PyExc_Exception, "unable to find event property %s", TCHAR_TO_UTF8(*event_name));
3237-
Py_INCREF(Py_None);
3238-
return Py_None;
3231+
Py_RETURN_NONE;
32393232
}
32403233

32413234
if (auto casted_prop = Cast<UMulticastDelegateProperty>(u_property))
@@ -3265,8 +3258,7 @@ PyObject *ue_bind_pyevent(ue_PyUObject *u_obj, FString event_name, PyObject *py_
32653258
return PyErr_Format(PyExc_Exception, "property %s is not an event", TCHAR_TO_UTF8(*event_name));
32663259
}
32673260

3268-
Py_INCREF(Py_None);
3269-
return Py_None;
3261+
Py_RETURN_NONE;
32703262
}
32713263

32723264
UFunction *unreal_engine_add_function(UClass *u_class, char *name, PyObject *py_callable, uint32 function_flags)

‎Source/UnrealEnginePython/Private/UEPyModule.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ typedef struct {
2424

2525

2626
void unreal_engine_py_log_error();
27-
ue_PyUObject *ue_get_python_wrapper(UObject *);
27+
ue_PyUObject *ue_get_python_uobject(UObject *);
28+
ue_PyUObject *ue_get_python_uobject_inc(UObject *);
2829
UWorld *ue_get_uworld(ue_PyUObject *);
2930
AActor *ue_get_actor(ue_PyUObject *);
3031
PyObject *ue_py_convert_property(UProperty *, uint8 *);

‎Source/UnrealEnginePython/Private/UEPyUClassesImporter.cpp‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ static PyObject *ue_PyUClassesImporter_getattro(ue_PyUClassesImporter *self, PyO
1515
{
1616
// swallow old exception
1717
PyErr_Clear();
18-
ue_PyUObject *u_ret = ue_get_python_wrapper(u_class);
19-
if (!u_ret)
20-
return PyErr_Format(PyExc_Exception, "PyUObject is in invalid state");
21-
Py_INCREF(u_ret);
22-
return (PyObject *)u_ret;
18+
Py_RETURN_UOBJECT(u_class);
2319
}
2420
}
2521
}

0 commit comments

Comments
 (0)