From b46e2e19c3a840e8e110f0b768efc73add56c33f Mon Sep 17 00:00:00 2001 From: KyleMiles Date: Wed, 31 May 2023 17:16:41 -0400 Subject: Simplify template simplifier API; remove cursed RustString stuff --- python/demangle.py | 24 ++++++++++-------------- python/generator.cpp | 12 +++--------- 2 files changed, 13 insertions(+), 23 deletions(-) (limited to 'python') diff --git a/python/demangle.py b/python/demangle.py index ce57b601..d3d01c97 100644 --- a/python/demangle.py +++ b/python/demangle.py @@ -171,23 +171,19 @@ def simplify_name_to_qualified_name(input_name, simplify=True): 'std::wstring' >>> """ - result = None + name = None if isinstance(input_name, str): - result = core.BNRustSimplifyStrToFQN(input_name, simplify) - assert result is not None, "core.BNRustSimplifyStrToFQN returned None" + name = core.BNRustSimplifyStrToFQN(input_name, simplify) + assert name is not None, "core.BNRustSimplifyStrToFQN returned None" elif isinstance(input_name, types.QualifiedName): - result = core.BNRustSimplifyStrToFQN(str(input_name), True) - assert result is not None, "core.BNRustSimplifyStrToFQN returned None" + name = core.BNRustSimplifyStrToFQN(str(input_name), True) + assert name is not None, "core.BNRustSimplifyStrToFQN returned None" else: raise TypeError("Parameter must be of type `str` or `types.QualifiedName`") - native_result = [] - for name in result: - if name == b'': - break - native_result.append(name.decode("utf-8")) - name_count = len(native_result) + result = types.QualifiedName._from_core_struct(name) + core.BNFreeQualifiedName(name) + if len(result) == 0: + return None + return result - native_result = types.QualifiedName(native_result) - core.BNRustFreeStringArray(result, name_count + 1) - return native_result diff --git a/python/generator.cpp b/python/generator.cpp index 9f5e24eb..fb9c3567 100644 --- a/python/generator.cpp +++ b/python/generator.cpp @@ -437,12 +437,9 @@ int main(int argc, char* argv[]) // From python -> C python3 requires str -> str.encode('charmap') bool swizzleArgs = true; - if (name == "BNFreeString" || name == "BNRustFreeString") + if (name == "BNFreeString") swizzleArgs = false; - // Rust-allocated strings are deallocated differently - bool rustFFI = name.rfind("BNRust", 0) == 0; - bool callbackConvention = false; if (name == "BNAllocString") { @@ -467,7 +464,7 @@ int main(int argc, char* argv[]) for (auto& j : i.second->GetParameters()) { fprintf(out, "\t\t"); - if (name == "BNFreeString" || name == "BNRustFreeString") + if (name == "BNFreeString") { // BNFreeString expects a pointer to a string allocated by the core, so do not use // a c_char_p here, as that would be allocated by the Python runtime. This can @@ -568,10 +565,7 @@ int main(int argc, char* argv[]) fprintf(out, "\tresult = "); fprintf(out, "%s\n", stringArgFuncCall.c_str()); fprintf(out, "\tstring = str(pyNativeStr(ctypes.cast(result, ctypes.c_char_p).value))\n"); - if (rustFFI) - fprintf(out, "\tBNRustFreeString(result)\n"); - else - fprintf(out, "\tBNFreeString(result)\n"); + fprintf(out, "\tBNFreeString(result)\n"); fprintf(out, "\treturn string\n"); } else if (pointerResult) -- cgit v1.3.1