Skip to content

Commit 1a8cd3e

Browse files
author
David
committed
Created new type check functions for FProperty and updated py_ue_get_inner, py_ue_get_key_prop and py_ue_get_value_prop to use them.
1 parent d04c3af commit 1a8cd3e

File tree

3 files changed

+87
-16
lines changed

3 files changed

+87
-16
lines changed

Source/UnrealEnginePython/Private/UEPyModule.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,50 @@ template <typename T> T *ue_py_check_type(ue_PyUObject *py_obj)
7878
return Cast<T>(py_obj->ue_object);
7979
}
8080

81+
#if ENGINE_MINOR_VERSION >= 25
82+
83+
template <typename T> T *ue_py_check_ftype(PyObject *py_obj)
84+
{
85+
ue_PyFProperty *ue_py_prop = ue_is_pyfproperty(py_obj);
86+
if (!ue_py_prop)
87+
{
88+
return nullptr;
89+
}
90+
91+
// I cannot see any function IsValidLowLevel or IsPendingKillOrUnreachable in the FProperty definition in UnrealType.h
92+
//if (!ue_py_obj->ue_object || !ue_py_obj->ue_object->IsValidLowLevel() || ue_py_obj->ue_object->IsPendingKillOrUnreachable())
93+
//{
94+
// UE_LOG(LogPython, Error, TEXT("invalid UObject in ue_PyUObject %p"), ue_py_obj);
95+
// return nullptr;
96+
//}
97+
98+
if (!ue_py_prop->ue_fproperty)
99+
{
100+
UE_LOG(LogPython, Error, TEXT("invalid FProperty in ue_PyFProperty %p"), ue_py_prop);
101+
return nullptr;
102+
}
103+
104+
return CastField<T>(ue_py_prop->ue_fproperty);
105+
}
106+
107+
template <typename T> T *ue_py_check_ftype(ue_PyFProperty *py_prop)
108+
{
109+
// I cannot see any function IsValidLowLevel or IsPendingKillOrUnreachable in the FProperty definition in UnrealType.h
110+
//if (!py_obj->ue_object || !py_obj->ue_object->IsValidLowLevel() || py_obj->ue_object->IsPendingKillOrUnreachable())
111+
//{
112+
// UE_LOG(LogPython, Error, TEXT("invalid UObject in ue_PyUObject %p"), py_obj);
113+
// return nullptr;
114+
//}
115+
if (!py_prop->ue_fproperty)
116+
{
117+
UE_LOG(LogPython, Error, TEXT("invalid FProperty in ue_PyFProperty %p"), py_prop);
118+
return nullptr;
119+
}
120+
return CastField<T>(py_prop->ue_fproperty);
121+
}
122+
123+
#endif
124+
81125
uint8 *do_ue_py_check_struct(PyObject *py_obj, UScriptStruct* chk_u_struct);
82126

83127
template <typename T> T *ue_py_check_struct(PyObject *py_obj)

Source/UnrealEnginePython/Private/UObject/UEPyObject.cpp

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,13 +1457,15 @@ PyObject *py_ue_get_uproperty(ue_PyUObject *self, PyObject * args)
14571457
}
14581458
#endif
14591459

1460-
PyObject *py_ue_get_inner(ue_PyUObject *self, PyObject * args)
1460+
#if ENGINE_MINOR_VERSION >= 25
1461+
PyObject *py_ue_get_inner(ue_PyFProperty *self, PyObject * args)
14611462
{
14621463

1463-
ue_py_check(self);
1464+
// not clear if need this - this checks if the UObject is in some invalid state
1465+
// - Im not sure FProperty has such a state - although I have seen some mentions of PendingDelete possible
1466+
//ue_py_check(self);
14641467

1465-
#if ENGINE_MINOR_VERSION >= 25
1466-
FArrayProperty *f_property = ue_py_check_type<FArrayProperty>(self);
1468+
FArrayProperty *f_property = ue_py_check_ftype<FArrayProperty>(self);
14671469
if (!f_property)
14681470
return PyErr_Format(PyExc_Exception, "object is not a FArrayProperty");
14691471

@@ -1472,7 +1474,13 @@ PyObject *py_ue_get_inner(ue_PyUObject *self, PyObject * args)
14721474
Py_RETURN_NONE;
14731475

14741476
Py_RETURN_FPROPERTY(inner);
1477+
}
14751478
#else
1479+
PyObject *py_ue_get_inner(ue_PyUObject *self, PyObject * args)
1480+
{
1481+
1482+
ue_py_check(self);
1483+
14761484
UArrayProperty *u_property = ue_py_check_type<UArrayProperty>(self);
14771485
if (!u_property)
14781486
return PyErr_Format(PyExc_Exception, "object is not a UArrayProperty");
@@ -1482,16 +1490,18 @@ PyObject *py_ue_get_inner(ue_PyUObject *self, PyObject * args)
14821490
Py_RETURN_NONE;
14831491

14841492
Py_RETURN_UOBJECT(inner);
1485-
#endif
14861493
}
1494+
#endif
14871495

1488-
PyObject *py_ue_get_key_prop(ue_PyUObject *self, PyObject * args)
1496+
#if ENGINE_MINOR_VERSION >= 25
1497+
PyObject *py_ue_get_key_prop(ue_PyFProperty *self, PyObject * args)
14891498
{
14901499

1491-
ue_py_check(self);
1500+
// not clear if need this - this checks if the UObject is in some invalid state
1501+
// - Im not sure FProperty has such a state - although I have seen some mentions of PendingDelete possible
1502+
//ue_py_check(self);
14921503

1493-
#if ENGINE_MINOR_VERSION >= 25
1494-
FMapProperty *f_property = ue_py_check_type<FMapProperty>(self);
1504+
FMapProperty *f_property = ue_py_check_ftype<FMapProperty>(self);
14951505
if (!f_property)
14961506
return PyErr_Format(PyExc_Exception, "object is not a FMapProperty");
14971507

@@ -1500,7 +1510,13 @@ PyObject *py_ue_get_key_prop(ue_PyUObject *self, PyObject * args)
15001510
Py_RETURN_NONE;
15011511

15021512
Py_RETURN_FPROPERTY(key);
1513+
}
15031514
#else
1515+
PyObject *py_ue_get_key_prop(ue_PyUObject *self, PyObject * args)
1516+
{
1517+
1518+
ue_py_check(self);
1519+
15041520
UMapProperty *u_property = ue_py_check_type<UMapProperty>(self);
15051521
if (!u_property)
15061522
return PyErr_Format(PyExc_Exception, "object is not a UMapProperty");
@@ -1510,16 +1526,18 @@ PyObject *py_ue_get_key_prop(ue_PyUObject *self, PyObject * args)
15101526
Py_RETURN_NONE;
15111527

15121528
Py_RETURN_UOBJECT(key);
1513-
#endif
15141529
}
1530+
#endif
15151531

1516-
PyObject *py_ue_get_value_prop(ue_PyUObject *self, PyObject * args)
1532+
#if ENGINE_MINOR_VERSION >= 25
1533+
PyObject *py_ue_get_value_prop(ue_PyFProperty *self, PyObject * args)
15171534
{
15181535

1519-
ue_py_check(self);
1536+
// not clear if need this - this checks if the UObject is in some invalid state
1537+
// - Im not sure FProperty has such a state - although I have seen some mentions of PendingDelete possible
1538+
//ue_py_check(self);
15201539

1521-
#if ENGINE_MINOR_VERSION >= 25
1522-
FMapProperty *f_property = ue_py_check_type<FMapProperty>(self);
1540+
FMapProperty *f_property = ue_py_check_ftype<FMapProperty>(self);
15231541
if (!f_property)
15241542
return PyErr_Format(PyExc_Exception, "object is not a FMapProperty");
15251543

@@ -1528,7 +1546,13 @@ PyObject *py_ue_get_value_prop(ue_PyUObject *self, PyObject * args)
15281546
Py_RETURN_NONE;
15291547

15301548
Py_RETURN_FPROPERTY(value);
1549+
}
15311550
#else
1551+
PyObject *py_ue_get_value_prop(ue_PyUObject *self, PyObject * args)
1552+
{
1553+
1554+
ue_py_check(self);
1555+
15321556
UMapProperty *u_property = ue_py_check_type<UMapProperty>(self);
15331557
if (!u_property)
15341558
return PyErr_Format(PyExc_Exception, "object is not a UMapProperty");
@@ -1538,8 +1562,8 @@ PyObject *py_ue_get_value_prop(ue_PyUObject *self, PyObject * args)
15381562
Py_RETURN_NONE;
15391563

15401564
Py_RETURN_UOBJECT(value);
1541-
#endif
15421565
}
1566+
#endif
15431567

15441568
PyObject *py_ue_has_property(ue_PyUObject *self, PyObject * args)
15451569
{

Source/UnrealEnginePython/Private/UObject/UEPyObject.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,15 @@ PyObject *py_ue_get_property(ue_PyUObject *, PyObject *);
2626
PyObject *py_ue_get_property_array_dim(ue_PyUObject *, PyObject *);
2727
#if ENGINE_MINOR_VERSION >= 25
2828
PyObject *py_ue_get_fproperty(ue_PyUObject *, PyObject *);
29+
PyObject *py_ue_get_inner(ue_PyFProperty *, PyObject *);
30+
PyObject *py_ue_get_key_prop(ue_PyFProperty *, PyObject *);
31+
PyObject *py_ue_get_value_prop(ue_PyFProperty *, PyObject *);
2932
#else
3033
PyObject *py_ue_get_uproperty(ue_PyUObject *, PyObject *);
31-
#endif
3234
PyObject *py_ue_get_inner(ue_PyUObject *, PyObject *);
3335
PyObject *py_ue_get_key_prop(ue_PyUObject *, PyObject *);
3436
PyObject *py_ue_get_value_prop(ue_PyUObject *, PyObject *);
37+
#endif
3538
PyObject *py_ue_get_property_class(ue_PyUObject *, PyObject *);
3639
PyObject *py_ue_has_property(ue_PyUObject *, PyObject *);
3740
PyObject *py_ue_is_rooted(ue_PyUObject *, PyObject *);

0 commit comments

Comments
 (0)