Skip to content

Commit

Permalink
python2.7/python3.5 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Roberto De Ioris committed Jun 30, 2018
1 parent f35e7de commit 1491845
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ static PyObject *py_ue_ihttp_request_set_content(ue_PyIHttpRequest *self, PyObje

if (PyUnicode_Check(py_obj))
{
self->http_request->SetContentAsString(UTF8_TO_TCHAR(PyUnicode_AsUTF8(py_obj)));
self->http_request->SetContentAsString(UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(py_obj)));
}
else if (PyBytes_Check(py_obj))
{
Expand Down
4 changes: 2 additions & 2 deletions Source/UnrealEnginePython/Private/Slate/UEPySPythonShelf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ static int ue_py_spython_shelf_init(ue_PySPythonShelf *self, PyObject *args, PyO
{
if (PyUnicode_Check(item))
{
FName class_name = FName(UTF8_TO_TCHAR(PyUnicode_AsUTF8(item)));
FName class_name = FName(UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(item)));
asset_picker_config.Filter.ClassNames.Add(class_name);
}
}
Expand All @@ -136,7 +136,7 @@ static int ue_py_spython_shelf_init(ue_PySPythonShelf *self, PyObject *args, PyO
{
if (PyUnicode_Check(item))
{
FName collection_name = FName(UTF8_TO_TCHAR(PyUnicode_AsUTF8(item)));
FName collection_name = FName(UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(item)));
asset_picker_config.Collections.Add(FCollectionNameType(collection_name, ECollectionShareType::CST_Local));
}
}
Expand Down
4 changes: 2 additions & 2 deletions Source/UnrealEnginePython/Private/Slate/UEPySlate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ FText FPythonSlateDelegate::GetterFText() const
return FText();
}

FText text = FText::FromString(PyUnicode_AsUTF8(str));
FText text = FText::FromString(UEPyUnicode_AsUTF8(str));
Py_DECREF(str);
Py_DECREF(ret);
return text;
Expand All @@ -581,7 +581,7 @@ FString FPythonSlateDelegate::GetterFString() const
return FString();
}

FString fstr = UTF8_TO_TCHAR(PyUnicode_AsUTF8(str));
FString fstr = UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(str));
Py_DECREF(str);
Py_DECREF(ret);
return fstr;
Expand Down
8 changes: 4 additions & 4 deletions Source/UnrealEnginePython/Private/Slate/UEPySlate.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,14 @@ ue_PySWidget *ue_py_get_swidget(TSharedRef<SWidget> s_widget);

#define ue_py_slate_farguments_text(param, attribute) ue_py_slate_up(FText, GetterFText, param, attribute)\
else if (PyUnicode_Check(value)) {\
arguments.attribute(FText::FromString(UTF8_TO_TCHAR(PyUnicode_AsUTF8(value))));\
arguments.attribute(FText::FromString(UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(value))));\
}\
ue_py_slate_down(param)


#define ue_py_slate_farguments_string(param, attribute) ue_py_slate_up(FString, GetterFString, param, attribute)\
else if (PyUnicode_Check(value)) {\
arguments.attribute(UTF8_TO_TCHAR(PyUnicode_AsUTF8(value)));\
arguments.attribute(UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(value)));\
}\
ue_py_slate_down(param)

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

#define ue_py_slate_farguments_optional_string(param, attribute) { PyObject *value = ue_py_dict_get_item(kwargs, param);\
if (PyUnicode_Check(value)) {\
arguments.attribute(UTF8_TO_TCHAR(PyUnicode_AsUTF8(value)));\
arguments.attribute(UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(value)));\
}\
}

#define ue_py_slate_farguments_optional_text(param, attribute) { PyObject *value = ue_py_dict_get_item(kwargs, param);\
if (value) {\
if (PyUnicode_Check(value)) {\
arguments.attribute(FText::FromString(UTF8_TO_TCHAR(PyUnicode_AsUTF8(value))));\
arguments.attribute(FText::FromString(UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(value))));\
}\
else {\
PyErr_SetString(PyExc_TypeError, "unsupported type for attribute " param); \
Expand Down
4 changes: 2 additions & 2 deletions Source/UnrealEnginePython/Private/UEPyAssetUserData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ PyObject *py_ue_asset_import_data_set_sources(ue_PyUObject * self, PyObject * ar

if (PyUnicode_Check(py_files))
{
filenames.Add(FString(UTF8_TO_TCHAR(PyUnicode_AsUTF8(py_files))));
filenames.Add(FString(UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(py_files))));
}
else
{
Expand All @@ -68,7 +68,7 @@ PyObject *py_ue_asset_import_data_set_sources(ue_PyUObject * self, PyObject * ar
Py_DECREF(py_iter);
return PyErr_Format(PyExc_Exception, "argument is not a string or an interable of strings");
}
filenames.Add(FString(UTF8_TO_TCHAR(PyUnicode_AsUTF8(py_item))));
filenames.Add(FString(UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(py_item))));
}

Py_DECREF(py_iter);
Expand Down
18 changes: 9 additions & 9 deletions Source/UnrealEnginePython/Private/UEPyModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,7 @@ static int ue_PyUObject_setattro(ue_PyUObject *self, PyObject *attr_name, PyObje
// first of all check for UProperty
if (PyUnicodeOrString_Check(attr_name))
{
char *attr = (char *)PyUnicode_AsUTF8(attr_name);
const char *attr = UEPyUnicode_AsUTF8(attr_name);
// first check for property
UStruct *u_struct = nullptr;
if (self->ue_object->IsA<UStruct>())
Expand Down Expand Up @@ -1792,13 +1792,13 @@ void unreal_engine_py_log_error()
PyObject *item = PyList_GetItem(ret, i);
if (item)
{
UE_LOG(LogPython, Error, TEXT("%s"), UTF8_TO_TCHAR(PyUnicode_AsUTF8(PyObject_Str(item))));
UE_LOG(LogPython, Error, TEXT("%s"), UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(PyObject_Str(item))));
}
}
}
else
{
UE_LOG(LogPython, Error, TEXT("%s"), UTF8_TO_TCHAR(PyUnicode_AsUTF8(PyObject_Str(ret))));
UE_LOG(LogPython, Error, TEXT("%s"), UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(PyObject_Str(ret))));
}
}

Expand Down Expand Up @@ -2158,17 +2158,17 @@ bool ue_py_convert_pyobject(PyObject *py_obj, UProperty *prop, uint8 *buffer, in
{
if (auto casted_prop = Cast<UStrProperty>(prop))
{
casted_prop->SetPropertyValue_InContainer(buffer, UTF8_TO_TCHAR(PyUnicode_AsUTF8(py_obj)), index);
casted_prop->SetPropertyValue_InContainer(buffer, UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(py_obj)), index);
return true;
}
if (auto casted_prop = Cast<UNameProperty>(prop))
{
casted_prop->SetPropertyValue_InContainer(buffer, UTF8_TO_TCHAR(PyUnicode_AsUTF8(py_obj)), index);
casted_prop->SetPropertyValue_InContainer(buffer, UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(py_obj)), index);
return true;
}
if (auto casted_prop = Cast<UTextProperty>(prop))
{
casted_prop->SetPropertyValue_InContainer(buffer, FText::FromString(UTF8_TO_TCHAR(PyUnicode_AsUTF8(py_obj))), index);
casted_prop->SetPropertyValue_InContainer(buffer, FText::FromString(UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(py_obj))), index);
return true;
}
return false;
Expand Down Expand Up @@ -2574,7 +2574,7 @@ void ue_bind_events_for_py_class_by_attribute(UObject *u_obj, PyObject *py_class
PyObject *py_attr_name = PyList_GetItem(attrs, i);
if (!py_attr_name || !PyUnicodeOrString_Check(py_attr_name))
continue;
PyObject *item = PyObject_GetAttrString(py_class, PyUnicode_AsUTF8(py_attr_name));
PyObject *item = PyObject_GetAttrString(py_class, UEPyUnicode_AsUTF8(py_attr_name));
if (item && PyCallable_Check(item))
{
// check for ue_event signature
Expand All @@ -2583,7 +2583,7 @@ void ue_bind_events_for_py_class_by_attribute(UObject *u_obj, PyObject *py_class
{
if (PyUnicode_Check(event_signature))
{
FString event_name = FString(UTF8_TO_TCHAR(PyUnicode_AsUTF8(event_signature)));
FString event_name = FString(UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(event_signature)));
TArray<FString> parts;
int n = event_name.ParseIntoArray(parts, UTF8_TO_TCHAR("."));
if (n < 1 || n > 2)
Expand Down Expand Up @@ -2652,7 +2652,7 @@ void ue_autobind_events_for_pyclass(ue_PyUObject *u_obj, PyObject *py_class)
PyObject *py_attr_name = PyList_GetItem(attrs, i);
if (!py_attr_name || !PyUnicodeOrString_Check(py_attr_name))
continue;
FString attr_name = UTF8_TO_TCHAR(PyUnicode_AsUTF8(py_attr_name));
FString attr_name = UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(py_attr_name));
if (!attr_name.StartsWith("on_", ESearchCase::CaseSensitive))
continue;
// check if the attr is a callable
Expand Down
6 changes: 3 additions & 3 deletions Source/UnrealEnginePython/Private/UEPySubclassing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ int unreal_engine_py_init(ue_PyUObject *self, PyObject *args, PyObject *kwds)
if (PyTuple_Size(args) == 3)
{
// TODO make it smarter on error checking
UE_LOG(LogPython, Warning, TEXT("%s"), UTF8_TO_TCHAR(PyUnicode_AsUTF8(PyObject_Str(PyTuple_GetItem(args, 0)))));
UE_LOG(LogPython, Warning, TEXT("%s"), UTF8_TO_TCHAR(PyUnicode_AsUTF8(PyObject_Str(PyTuple_GetItem(args, 1)))));
UE_LOG(LogPython, Warning, TEXT("%s"), UTF8_TO_TCHAR(PyUnicode_AsUTF8(PyObject_Str(PyTuple_GetItem(args, 2)))));
UE_LOG(LogPython, Warning, TEXT("%s"), UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(PyObject_Str(PyTuple_GetItem(args, 0)))));
UE_LOG(LogPython, Warning, TEXT("%s"), UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(PyObject_Str(PyTuple_GetItem(args, 1)))));
UE_LOG(LogPython, Warning, TEXT("%s"), UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(PyObject_Str(PyTuple_GetItem(args, 2)))));

PyObject *parents = PyTuple_GetItem(args, 1);
ue_PyUObject *parent = (ue_PyUObject *)PyTuple_GetItem(parents, 0);
Expand Down
2 changes: 1 addition & 1 deletion Source/UnrealEnginePython/Private/UObject/UEPyAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ PyObject *py_ue_play_sound_at_location(ue_PyUObject *self, PyObject * args)
}
else if (PyUnicodeOrString_Check(sound))
{
sound_object = FindObject<USoundBase>(ANY_PACKAGE, UTF8_TO_TCHAR(PyUnicode_AsUTF8(sound)));
sound_object = FindObject<USoundBase>(ANY_PACKAGE, UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(sound)));
}

if (!sound_object)
Expand Down
2 changes: 1 addition & 1 deletion Source/UnrealEnginePython/Private/UObject/UEPyObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ PyObject *py_ue_call_function(ue_PyUObject * self, PyObject * args, PyObject *kw

if (PyUnicodeOrString_Check(func_id))
{
function = self->ue_object->FindFunction(FName(UTF8_TO_TCHAR(PyUnicode_AsUTF8(func_id))));
function = self->ue_object->FindFunction(FName(UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(func_id))));
}

if (!function)
Expand Down
4 changes: 4 additions & 0 deletions Source/UnrealEnginePython/Private/UnrealEnginePython.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ void FUnrealEnginePythonModule::StartupModule()
}
else
{
#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 6
if (PyErr_ExceptionMatches(PyExc_ModuleNotFoundError))
{
UE_LOG(LogPython, Log, TEXT("ue_site Python module not found"));
Expand All @@ -379,6 +380,9 @@ void FUnrealEnginePythonModule::StartupModule()
{
unreal_engine_py_log_error();
}
#else
unreal_engine_py_log_error();
#endif
}

// release the GIL
Expand Down
8 changes: 4 additions & 4 deletions Source/UnrealEnginePython/Private/Wrappers/UEPyFARFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ void ue_sync_farfilter_name_array(PyObject *pylist, TArray<FName> &uelist)
for (int i = 0; i < (int)pylist_len; i++)
{
PyObject *py_item = PyList_GetItem(pylist, i);
uelist.Add(FName(UTF8_TO_TCHAR(PyUnicode_AsUTF8(py_item))));
uelist.Add(FName(UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(py_item))));
}
}

Expand All @@ -316,7 +316,7 @@ void py_ue_sync_farfilter(PyObject *pyobj)
for (int i = 0; i < (int)pyset_len; i++)
{
py_item = PyList_GetItem(pyset, i);
pyfilter->filter.RecursiveClassesExclusionSet.Add(FName(UTF8_TO_TCHAR(PyUnicode_AsUTF8(py_item))));
pyfilter->filter.RecursiveClassesExclusionSet.Add(FName(UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(py_item))));
}

PyObject *pykey, *pyvalue;
Expand All @@ -325,13 +325,13 @@ void py_ue_sync_farfilter(PyObject *pyobj)
pyfilter->filter.TagsAndValues.Reset();
while (PyDict_Next(pyfilter->tags_and_values, &pypos, &pykey, &pyvalue))
{
ukey = UTF8_TO_TCHAR(PyUnicode_AsUTF8(pykey));
ukey = UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(pykey));
pyset_len = PySet_Size(pyvalue);
for (int i = 0; i < (int)pyset_len; i++)
{
py_item = PyList_GetItem(pyset, i);
#if ENGINE_MINOR_VERSION < 20
pyfilter->filter.TagsAndValues.AddUnique(ukey, UTF8_TO_TCHAR(PyUnicode_AsUTF8(py_item)));
pyfilter->filter.TagsAndValues.AddUnique(ukey, UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(py_item)));
#else
pyfilter->filter.TagsAndValues.AddUnique(ukey, FString(UTF8_TO_TCHAR(PyUnicode_AsUTF8(py_item))));
#endif
Expand Down

0 comments on commit 1491845

Please sign in to comment.