Skip to content

Commit 1491845

Browse files
author
Roberto De Ioris
committed
python2.7/python3.5 fixes
1 parent f35e7de commit 1491845

File tree

11 files changed

+33
-29
lines changed

11 files changed

+33
-29
lines changed

Source/UnrealEnginePython/Private/Http/UEPyIHttpRequest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static PyObject *py_ue_ihttp_request_set_content(ue_PyIHttpRequest *self, PyObje
7474

7575
if (PyUnicode_Check(py_obj))
7676
{
77-
self->http_request->SetContentAsString(UTF8_TO_TCHAR(PyUnicode_AsUTF8(py_obj)));
77+
self->http_request->SetContentAsString(UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(py_obj)));
7878
}
7979
else if (PyBytes_Check(py_obj))
8080
{

Source/UnrealEnginePython/Private/Slate/UEPySPythonShelf.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ static int ue_py_spython_shelf_init(ue_PySPythonShelf *self, PyObject *args, PyO
123123
{
124124
if (PyUnicode_Check(item))
125125
{
126-
FName class_name = FName(UTF8_TO_TCHAR(PyUnicode_AsUTF8(item)));
126+
FName class_name = FName(UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(item)));
127127
asset_picker_config.Filter.ClassNames.Add(class_name);
128128
}
129129
}
@@ -136,7 +136,7 @@ static int ue_py_spython_shelf_init(ue_PySPythonShelf *self, PyObject *args, PyO
136136
{
137137
if (PyUnicode_Check(item))
138138
{
139-
FName collection_name = FName(UTF8_TO_TCHAR(PyUnicode_AsUTF8(item)));
139+
FName collection_name = FName(UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(item)));
140140
asset_picker_config.Collections.Add(FCollectionNameType(collection_name, ECollectionShareType::CST_Local));
141141
}
142142
}

Source/UnrealEnginePython/Private/Slate/UEPySlate.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ FText FPythonSlateDelegate::GetterFText() const
557557
return FText();
558558
}
559559

560-
FText text = FText::FromString(PyUnicode_AsUTF8(str));
560+
FText text = FText::FromString(UEPyUnicode_AsUTF8(str));
561561
Py_DECREF(str);
562562
Py_DECREF(ret);
563563
return text;
@@ -581,7 +581,7 @@ FString FPythonSlateDelegate::GetterFString() const
581581
return FString();
582582
}
583583

584-
FString fstr = UTF8_TO_TCHAR(PyUnicode_AsUTF8(str));
584+
FString fstr = UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(str));
585585
Py_DECREF(str);
586586
Py_DECREF(ret);
587587
return fstr;

Source/UnrealEnginePython/Private/Slate/UEPySlate.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,14 @@ ue_PySWidget *ue_py_get_swidget(TSharedRef<SWidget> s_widget);
138138

139139
#define ue_py_slate_farguments_text(param, attribute) ue_py_slate_up(FText, GetterFText, param, attribute)\
140140
else if (PyUnicode_Check(value)) {\
141-
arguments.attribute(FText::FromString(UTF8_TO_TCHAR(PyUnicode_AsUTF8(value))));\
141+
arguments.attribute(FText::FromString(UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(value))));\
142142
}\
143143
ue_py_slate_down(param)
144144

145145

146146
#define ue_py_slate_farguments_string(param, attribute) ue_py_slate_up(FString, GetterFString, param, attribute)\
147147
else if (PyUnicode_Check(value)) {\
148-
arguments.attribute(UTF8_TO_TCHAR(PyUnicode_AsUTF8(value)));\
148+
arguments.attribute(UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(value)));\
149149
}\
150150
ue_py_slate_down(param)
151151

@@ -344,14 +344,14 @@ ue_PySWidget *ue_py_get_swidget(TSharedRef<SWidget> s_widget);
344344

345345
#define ue_py_slate_farguments_optional_string(param, attribute) { PyObject *value = ue_py_dict_get_item(kwargs, param);\
346346
if (PyUnicode_Check(value)) {\
347-
arguments.attribute(UTF8_TO_TCHAR(PyUnicode_AsUTF8(value)));\
347+
arguments.attribute(UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(value)));\
348348
}\
349349
}
350350

351351
#define ue_py_slate_farguments_optional_text(param, attribute) { PyObject *value = ue_py_dict_get_item(kwargs, param);\
352352
if (value) {\
353353
if (PyUnicode_Check(value)) {\
354-
arguments.attribute(FText::FromString(UTF8_TO_TCHAR(PyUnicode_AsUTF8(value))));\
354+
arguments.attribute(FText::FromString(UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(value))));\
355355
}\
356356
else {\
357357
PyErr_SetString(PyExc_TypeError, "unsupported type for attribute " param); \

Source/UnrealEnginePython/Private/UEPyAssetUserData.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ PyObject *py_ue_asset_import_data_set_sources(ue_PyUObject * self, PyObject * ar
5151

5252
if (PyUnicode_Check(py_files))
5353
{
54-
filenames.Add(FString(UTF8_TO_TCHAR(PyUnicode_AsUTF8(py_files))));
54+
filenames.Add(FString(UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(py_files))));
5555
}
5656
else
5757
{
@@ -68,7 +68,7 @@ PyObject *py_ue_asset_import_data_set_sources(ue_PyUObject * self, PyObject * ar
6868
Py_DECREF(py_iter);
6969
return PyErr_Format(PyExc_Exception, "argument is not a string or an interable of strings");
7070
}
71-
filenames.Add(FString(UTF8_TO_TCHAR(PyUnicode_AsUTF8(py_item))));
71+
filenames.Add(FString(UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(py_item))));
7272
}
7373

7474
Py_DECREF(py_iter);

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,7 @@ static int ue_PyUObject_setattro(ue_PyUObject *self, PyObject *attr_name, PyObje
11921192
// first of all check for UProperty
11931193
if (PyUnicodeOrString_Check(attr_name))
11941194
{
1195-
char *attr = (char *)PyUnicode_AsUTF8(attr_name);
1195+
const char *attr = UEPyUnicode_AsUTF8(attr_name);
11961196
// first check for property
11971197
UStruct *u_struct = nullptr;
11981198
if (self->ue_object->IsA<UStruct>())
@@ -1792,13 +1792,13 @@ void unreal_engine_py_log_error()
17921792
PyObject *item = PyList_GetItem(ret, i);
17931793
if (item)
17941794
{
1795-
UE_LOG(LogPython, Error, TEXT("%s"), UTF8_TO_TCHAR(PyUnicode_AsUTF8(PyObject_Str(item))));
1795+
UE_LOG(LogPython, Error, TEXT("%s"), UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(PyObject_Str(item))));
17961796
}
17971797
}
17981798
}
17991799
else
18001800
{
1801-
UE_LOG(LogPython, Error, TEXT("%s"), UTF8_TO_TCHAR(PyUnicode_AsUTF8(PyObject_Str(ret))));
1801+
UE_LOG(LogPython, Error, TEXT("%s"), UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(PyObject_Str(ret))));
18021802
}
18031803
}
18041804

@@ -2158,17 +2158,17 @@ bool ue_py_convert_pyobject(PyObject *py_obj, UProperty *prop, uint8 *buffer, in
21582158
{
21592159
if (auto casted_prop = Cast<UStrProperty>(prop))
21602160
{
2161-
casted_prop->SetPropertyValue_InContainer(buffer, UTF8_TO_TCHAR(PyUnicode_AsUTF8(py_obj)), index);
2161+
casted_prop->SetPropertyValue_InContainer(buffer, UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(py_obj)), index);
21622162
return true;
21632163
}
21642164
if (auto casted_prop = Cast<UNameProperty>(prop))
21652165
{
2166-
casted_prop->SetPropertyValue_InContainer(buffer, UTF8_TO_TCHAR(PyUnicode_AsUTF8(py_obj)), index);
2166+
casted_prop->SetPropertyValue_InContainer(buffer, UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(py_obj)), index);
21672167
return true;
21682168
}
21692169
if (auto casted_prop = Cast<UTextProperty>(prop))
21702170
{
2171-
casted_prop->SetPropertyValue_InContainer(buffer, FText::FromString(UTF8_TO_TCHAR(PyUnicode_AsUTF8(py_obj))), index);
2171+
casted_prop->SetPropertyValue_InContainer(buffer, FText::FromString(UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(py_obj))), index);
21722172
return true;
21732173
}
21742174
return false;
@@ -2574,7 +2574,7 @@ void ue_bind_events_for_py_class_by_attribute(UObject *u_obj, PyObject *py_class
25742574
PyObject *py_attr_name = PyList_GetItem(attrs, i);
25752575
if (!py_attr_name || !PyUnicodeOrString_Check(py_attr_name))
25762576
continue;
2577-
PyObject *item = PyObject_GetAttrString(py_class, PyUnicode_AsUTF8(py_attr_name));
2577+
PyObject *item = PyObject_GetAttrString(py_class, UEPyUnicode_AsUTF8(py_attr_name));
25782578
if (item && PyCallable_Check(item))
25792579
{
25802580
// check for ue_event signature
@@ -2583,7 +2583,7 @@ void ue_bind_events_for_py_class_by_attribute(UObject *u_obj, PyObject *py_class
25832583
{
25842584
if (PyUnicode_Check(event_signature))
25852585
{
2586-
FString event_name = FString(UTF8_TO_TCHAR(PyUnicode_AsUTF8(event_signature)));
2586+
FString event_name = FString(UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(event_signature)));
25872587
TArray<FString> parts;
25882588
int n = event_name.ParseIntoArray(parts, UTF8_TO_TCHAR("."));
25892589
if (n < 1 || n > 2)
@@ -2652,7 +2652,7 @@ void ue_autobind_events_for_pyclass(ue_PyUObject *u_obj, PyObject *py_class)
26522652
PyObject *py_attr_name = PyList_GetItem(attrs, i);
26532653
if (!py_attr_name || !PyUnicodeOrString_Check(py_attr_name))
26542654
continue;
2655-
FString attr_name = UTF8_TO_TCHAR(PyUnicode_AsUTF8(py_attr_name));
2655+
FString attr_name = UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(py_attr_name));
26562656
if (!attr_name.StartsWith("on_", ESearchCase::CaseSensitive))
26572657
continue;
26582658
// check if the attr is a callable

Source/UnrealEnginePython/Private/UEPySubclassing.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ int unreal_engine_py_init(ue_PyUObject *self, PyObject *args, PyObject *kwds)
2121
if (PyTuple_Size(args) == 3)
2222
{
2323
// TODO make it smarter on error checking
24-
UE_LOG(LogPython, Warning, TEXT("%s"), UTF8_TO_TCHAR(PyUnicode_AsUTF8(PyObject_Str(PyTuple_GetItem(args, 0)))));
25-
UE_LOG(LogPython, Warning, TEXT("%s"), UTF8_TO_TCHAR(PyUnicode_AsUTF8(PyObject_Str(PyTuple_GetItem(args, 1)))));
26-
UE_LOG(LogPython, Warning, TEXT("%s"), UTF8_TO_TCHAR(PyUnicode_AsUTF8(PyObject_Str(PyTuple_GetItem(args, 2)))));
24+
UE_LOG(LogPython, Warning, TEXT("%s"), UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(PyObject_Str(PyTuple_GetItem(args, 0)))));
25+
UE_LOG(LogPython, Warning, TEXT("%s"), UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(PyObject_Str(PyTuple_GetItem(args, 1)))));
26+
UE_LOG(LogPython, Warning, TEXT("%s"), UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(PyObject_Str(PyTuple_GetItem(args, 2)))));
2727

2828
PyObject *parents = PyTuple_GetItem(args, 1);
2929
ue_PyUObject *parent = (ue_PyUObject *)PyTuple_GetItem(parents, 0);

Source/UnrealEnginePython/Private/UObject/UEPyAudio.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ PyObject *py_ue_play_sound_at_location(ue_PyUObject *self, PyObject * args)
136136
}
137137
else if (PyUnicodeOrString_Check(sound))
138138
{
139-
sound_object = FindObject<USoundBase>(ANY_PACKAGE, UTF8_TO_TCHAR(PyUnicode_AsUTF8(sound)));
139+
sound_object = FindObject<USoundBase>(ANY_PACKAGE, UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(sound)));
140140
}
141141

142142
if (!sound_object)

Source/UnrealEnginePython/Private/UObject/UEPyObject.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ PyObject *py_ue_call_function(ue_PyUObject * self, PyObject * args, PyObject *kw
533533

534534
if (PyUnicodeOrString_Check(func_id))
535535
{
536-
function = self->ue_object->FindFunction(FName(UTF8_TO_TCHAR(PyUnicode_AsUTF8(func_id))));
536+
function = self->ue_object->FindFunction(FName(UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(func_id))));
537537
}
538538

539539
if (!function)

Source/UnrealEnginePython/Private/UnrealEnginePython.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ void FUnrealEnginePythonModule::StartupModule()
370370
}
371371
else
372372
{
373+
#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 6
373374
if (PyErr_ExceptionMatches(PyExc_ModuleNotFoundError))
374375
{
375376
UE_LOG(LogPython, Log, TEXT("ue_site Python module not found"));
@@ -379,6 +380,9 @@ void FUnrealEnginePythonModule::StartupModule()
379380
{
380381
unreal_engine_py_log_error();
381382
}
383+
#else
384+
unreal_engine_py_log_error();
385+
#endif
382386
}
383387

384388
// release the GIL

0 commit comments

Comments
 (0)