Skip to content

Commit 5f800d3

Browse files
Fix python binding issues #226 (#234)
Co-authored-by: gangatp <pradeep.gangatharan@autodesk.com>
1 parent e35ccd5 commit 5f800d3

File tree

6 files changed

+33
-23
lines changed

6 files changed

+33
-23
lines changed

Examples/RTTI/RTTI_component/Bindings/CSharp/RTTI.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ namespace RTTI {
2222
/// <summary>
2323
/// Exception class for RTTI errors
2424
/// </summary>
25-
public class RTTIException : Exception
25+
public class ERTTIException : Exception
2626
{
2727
private readonly int _errorCode;
2828
private readonly string _errorMessage;
2929

3030
/// <summary>
31-
/// Initializes a new instance of the RTTIException class
31+
/// Initializes a new instance of the ERTTIException class
3232
/// </summary>
3333
/// <param name="errorCode">The error code</param>
3434
/// <param name="errorMessage">The error message</param>
35-
public RTTIException(int errorCode, string errorMessage = "") : base(FormatMessage(errorCode, errorMessage))
35+
public ERTTIException(int errorCode, string errorMessage = "") : base(FormatMessage(errorCode, errorMessage))
3636
{
3737
_errorCode = errorCode;
3838
_errorMessage = errorMessage;
@@ -99,9 +99,9 @@ private static string FormatMessage(int errorCode, string errorMessage)
9999
string errorName = GetErrorName(errorCode);
100100
string errorDesc = GetErrorDescription(errorCode);
101101
if (!string.IsNullOrEmpty(errorMessage))
102-
return $"RTTIException {errorName} ({errorCode}): {errorDesc} - {errorMessage}";
102+
return $"ERTTIException {errorName} ({errorCode}): {errorDesc} - {errorMessage}";
103103
else
104-
return $"RTTIException {errorName} ({errorCode}): {errorDesc}";
104+
return $"ERTTIException {errorName} ({errorCode}): {errorDesc}";
105105
}
106106

107107
private static string GetErrorName(int errorCode)
@@ -209,7 +209,7 @@ public static void ThrowError(IntPtr Handle, Int32 errorCode)
209209
}
210210
}
211211

212-
throw new RTTIException(errorCode, sMessage);
212+
throw new ERTTIException(errorCode, sMessage);
213213
}
214214

215215
/**

Examples/RTTI/RTTI_component/Bindings/Python/RTTI.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,14 @@ def _checkBinaryVersion(self):
327327
raise ERTTIException(ErrorCodes.INCOMPATIBLEBINARYVERSION)
328328

329329
def checkError(self, instance, errorCode):
330-
if errorCode != ErrorCodes.SUCCESS.value:
330+
ec = globals().get('ErrorCodes')
331+
if ec is None:
332+
# Interpreter shutdown: ErrorCodes may already be cleared; avoid noisy teardown
333+
return
334+
if errorCode != ec.SUCCESS.value:
331335
if instance:
332336
if instance._wrapper != self:
333-
raise ERTTIException(ErrorCodes.INVALIDCAST, 'invalid wrapper call')
337+
raise ERTTIException(ec.INVALIDCAST, 'invalid wrapper call')
334338
message,_ = self.GetLastError(instance)
335339
raise ERTTIException(errorCode, message)
336340

Examples/RTTI/RTTI_component/Bindings/WASM/rtti_bindings.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Copyright (C) 2021 ADSK
44
55
All rights reserved.
66
7-
This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.0-develop.
7+
This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.1-develop.
88
99
Abstract: C++ Emscripten wrapper for WebAssembly
1010
@@ -99,13 +99,13 @@ EMSCRIPTEN_BINDINGS(RTTI) {
9999
class_<CTurtle, base<CReptile>>("CTurtle")
100100
.smart_ptr<std::shared_ptr<CTurtle>>("shared_ptr<CTurtle>")
101101
;
102-
class_<CAnimalIterator>("CAnimalIterator")
102+
class_<CAnimalIterator, base<CBase>>("CAnimalIterator")
103103
.smart_ptr<std::shared_ptr<CAnimalIterator>>("shared_ptr<CAnimalIterator>")
104104
.function("GetNextAnimal", &CAnimalIterator::GetNextAnimal)
105105
.function("GetNextOptinalAnimal", &wrap_AnimalIterator_GetNextOptinalAnimal)
106106
.function("GetNextMandatoryAnimal", &wrap_AnimalIterator_GetNextMandatoryAnimal)
107107
;
108-
class_<CZoo>("CZoo")
108+
class_<CZoo, base<CBase>>("CZoo")
109109
.smart_ptr<std::shared_ptr<CZoo>>("shared_ptr<CZoo>")
110110
.function("Iterator", &CZoo::Iterator)
111111
;

Examples/RTTI/RTTI_component/Examples/Python/build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ set -euxo pipefail
55
cd "$(dirname "$0")"
66
source ../../../../../Build/build.inc
77

8+
which python3
9+
810
echo "Test C++ library"
911
RUN "python3 RTTI_Example.py" $PWD/../../Implementations/Cpp/build
1012

Examples/RTTI/RTTI_component/Implementations/Pascal/Interfaces/rtti_interfaces.pas

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ interface
3232
**************************************************************************************************************************)
3333

3434
IRTTIBase = interface
35-
['{F71073EA-4326-4BF0-B1B7-6B5326CE0668}']
35+
['{6D5C237C-E78B-4657-B893-C8BE11BC6794}']
3636

3737
function GetLastErrorMessage(out AErrorMessage: String): Boolean;
3838
procedure ClearErrorMessages();
@@ -48,7 +48,7 @@ interface
4848
**************************************************************************************************************************)
4949

5050
IRTTIAnimal = interface(IRTTIBase)
51-
['{710CB19F-03E6-4023-BACC-3C1A157E4C0A}']
51+
['{8B7F3A98-3978-4C5F-90AC-F3D2FA2CC468}']
5252

5353
function Name(): String;
5454
end;
@@ -59,7 +59,7 @@ interface
5959
**************************************************************************************************************************)
6060

6161
IRTTIMammal = interface(IRTTIAnimal)
62-
['{B282E29A-0B7B-444D-AFB2-F7E36D634D07}']
62+
['{D9FFF1D8-FFFB-4EB4-AF81-25F9266571AA}']
6363

6464
end;
6565

@@ -69,7 +69,7 @@ interface
6969
**************************************************************************************************************************)
7070

7171
IRTTIReptile = interface(IRTTIAnimal)
72-
['{9C3113BD-DBDB-479C-8109-0A9373897F4E}']
72+
['{AB96FE19-A8D1-4610-8EE6-0EB949DFB518}']
7373

7474
end;
7575

@@ -79,7 +79,7 @@ interface
7979
**************************************************************************************************************************)
8080

8181
IRTTIGiraffe = interface(IRTTIMammal)
82-
['{7A758ACC-C9D8-4C26-8758-E0012209395E}']
82+
['{CFF41F38-7171-4D6E-A8DD-F0247C7C8FC2}']
8383

8484
end;
8585

@@ -89,7 +89,7 @@ interface
8989
**************************************************************************************************************************)
9090

9191
IRTTITiger = interface(IRTTIMammal)
92-
['{8C10281D-9072-4B57-AF39-64903EA0A46B}']
92+
['{B3279D23-3017-4F14-BA80-2481BDC18F9D}']
9393

9494
procedure Roar();
9595
end;
@@ -100,7 +100,7 @@ interface
100100
**************************************************************************************************************************)
101101

102102
IRTTISnake = interface(IRTTIReptile)
103-
['{F7EA7F1B-BDA5-4E51-BA15-54AB1E92580D}']
103+
['{02B026CC-EBE1-4A50-80C5-3E0E00419AE4}']
104104

105105
end;
106106

@@ -110,7 +110,7 @@ interface
110110
**************************************************************************************************************************)
111111

112112
IRTTITurtle = interface(IRTTIReptile)
113-
['{E5BFFA76-FC6C-4C82-9302-E1BE903BCCFA}']
113+
['{D5071CDA-CFDB-41A2-BA42-CF2B3EB75381}']
114114

115115
end;
116116

@@ -120,7 +120,7 @@ interface
120120
**************************************************************************************************************************)
121121

122122
IRTTIAnimalIterator = interface(IRTTIBase)
123-
['{F99A080B-B278-4A43-9523-FB353C9928FA}']
123+
['{30B15DE2-9548-4F1F-8A1C-28798D38ECF5}']
124124

125125
function GetNextAnimal(): TObject;
126126
function GetNextOptinalAnimal(out AAnimal: TObject): Boolean;
@@ -133,7 +133,7 @@ interface
133133
**************************************************************************************************************************)
134134

135135
IRTTIZoo = interface(IRTTIBase)
136-
['{CA530586-4F80-45D7-B879-8FD0A52388E8}']
136+
['{4CE7CE21-14C4-4F98-801A-3E952D434366}']
137137

138138
function Iterator(): TObject;
139139
end;

Source/buildbindingpython.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,14 @@ func buildDynamicPythonImplementation(componentdefinition ComponentDefinition, w
402402

403403

404404
w.Writeln(" def checkError(self, instance, errorCode):")
405-
w.Writeln(" if errorCode != ErrorCodes.SUCCESS.value:")
405+
w.Writeln(" ec = globals().get('ErrorCodes')")
406+
w.Writeln(" if ec is None:")
407+
w.Writeln(" # Interpreter shutdown: ErrorCodes may already be cleared; avoid noisy teardown")
408+
w.Writeln(" return")
409+
w.Writeln(" if errorCode != ec.SUCCESS.value:")
406410
w.Writeln(" if instance:")
407411
w.Writeln(" if instance._wrapper != self:")
408-
w.Writeln(" raise E%sException(ErrorCodes.INVALIDCAST, 'invalid wrapper call')", NameSpace)
412+
w.Writeln(" raise E%sException(ec.INVALIDCAST, 'invalid wrapper call')", NameSpace)
409413
w.Writeln(" message,_ = self.%s(instance)", componentdefinition.Global.ErrorMethod)
410414
w.Writeln(" raise E%sException(errorCode, message)", NameSpace)
411415
w.Writeln(" ")

0 commit comments

Comments
 (0)