Skip to content

Commit 293aabf

Browse files
ChrisWu2024ADO SyncCopilot
authored
Sync changes from v26-0-0 (#15)
* Sync changes from v25-0-1 * Sync changes from v26-0-0 * Sync changes from v26-0-0 * Address reviewer feedback: fix WPrintf UB, isdraw init, PyKeyinArg, doc tuple, skewFactor default, sessionInfo leak, escape sequences Agent-Logs-Url: https://github.com/BentleySystems/MicroStationPython/sessions/1b74d22e-fccd-4873-9498-b3ea7566b8cd Co-authored-by: ChrisWu2024 <169880503+ChrisWu2024@users.noreply.github.com> * Remove .sourcemap.json --------- Co-authored-by: ADO Sync <ado-sync@bentley.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: ChrisWu2024 <169880503+ChrisWu2024@users.noreply.github.com>
1 parent 2af1edb commit 293aabf

109 files changed

Lines changed: 30262 additions & 6890 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

InternalAPI/MSPyCommon.h

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -329,31 +329,53 @@ py::class_<bvector<ValueType>, holder_type> bind_PointerVector(py::handle scope,
329329
return cls;
330330
}
331331

332+
// Generic conversion from Python object to C++ type
332333
template <typename T>
333334
T ConvertItemFromPyObject(const py::handle& item) {
334-
if (!py::isinstance<T>(item)) {
335-
throw std::invalid_argument("All items in the list must be of the correct item type");
335+
try {
336+
return py::cast<T>(item);
337+
} catch (const py::cast_error& e) {
338+
throw std::invalid_argument("Failed to cast item to expected type: " + std::string(e.what()));
336339
}
337-
return item.cast<T>();
338340
}
339341

340-
inline double ConvertItemFromPyObject(const py::handle& item) {
341-
if (!PyFloat_Check(item.ptr()) && !PyLong_Check(item.ptr())) {
342-
throw std::invalid_argument("Expected all items to be convertible to double");
342+
// Specialized conversion for double
343+
template <>
344+
inline double ConvertItemFromPyObject<double>(const py::handle& item) {
345+
try {
346+
return item.cast<double>();
347+
} catch (const py::cast_error& e) {
348+
throw std::invalid_argument("Failed to cast item to double: " + std::string(e.what()));
343349
}
344-
return item.cast<double>();
345350
}
346351

352+
// Specialized conversion for bool
353+
template <>
354+
inline bool ConvertItemFromPyObject<bool>(const py::handle& item) {
355+
try {
356+
return item.cast<bool>();
357+
} catch (const py::cast_error& e) {
358+
throw std::invalid_argument("Failed to cast item to bool: " + std::string(e.what()));
359+
}
360+
}
361+
362+
// Generic conversion from C++ type to Python object
347363
template <typename T>
348364
py::object ConvertItemToPyObject(const T& item) {
349365
return py::cast(item);
350366
}
351367

368+
// Specialized conversion for double
352369
inline py::object ConvertItemToPyObject(const double& item) {
353370
return py::float_(item);
354371
}
355372

356-
//Convert Python list to an existing C++ array
373+
// Specialized conversion for bool
374+
inline py::object ConvertItemToPyObject(const bool& item) {
375+
return py::bool_(item);
376+
}
377+
378+
// Convert Python list to an existing C++ array
357379
template <typename arrayType, typename itemType>
358380
void ConvertPyListToCppArray(const py::list& pyList, arrayType& cppArray) {
359381
cppArray.clear();
@@ -404,4 +426,4 @@ py::list ConvertCppArrayToPyList(const arrayType& cppArray) {
404426
ConvertCppArrayToPyList<cppArrayType, cppItemType>(pyList, cppArray);
405427

406428
#define CONVERT_CPPARRAY_TO_NEW_PYLIST(pyList, cppArray, cppArrayType, cppItemType) \
407-
py::list pyList = ConvertCppArrayToPyList<cppArrayType, cppItemType>(cppArray);
429+
py::list pyList = ConvertCppArrayToPyList<cppArrayType, cppItemType>(cppArray);

MSPython.mke

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ always:
6666
#
6767

6868
always:
69-
$(MakeProgram) $(_MakeFilePath)MSPythonCore.mke
69+
$(MakeProgram) $(_MakeFilePath)MSPythonCore\MSPythonCore.mke
7070
$(MakeProgram) $(_MakeFilePath)MSPythonWrapper\PyBentley\PyBentley.mke
7171
$(MakeProgram) $(_MakeFilePath)MSPythonWrapper\PyBentleyGeom\PyBentleyGeom.mke
7272
$(MakeProgram) $(_MakeFilePath)MSPythonWrapper\PyDgnPlatform\PyDgnPlatform.mke

MSPythonCore.mke

Lines changed: 0 additions & 93 deletions
This file was deleted.

MSPythonCore/MSPythonCore.mke

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
#--------------------------------------------------------------------------------------
2+
#
3+
# $Source: MSPython\MSPythonCore\MSPythonCore.mke $
4+
#
5+
# $Copyright: (c) 2023 Bentley Systems, Incorporated. All rights reserved. $
6+
#
7+
#--------------------------------------------------------------------------------------
8+
appName = MSPythonCore
9+
10+
%if defined (BSIBUILD)
11+
MSPythonSrc = $(SrcRoot)MSPython/
12+
%else
13+
MSPythonSrc = $(SrcRoot)
14+
%endif
15+
16+
PolicyFile = $(MSPythonSrc)/MSPythonAssertPolicy.mki
17+
SolutionPolicyMki = $(MSPythonSrc)/MSPythonSolutionPolicy.mki
18+
19+
%include mdl.mki
20+
#----------------------------------------------------------------------
21+
# Define macros specific to this program
22+
#----------------------------------------------------------------------
23+
baseDir = $(_MakeFilePath)
24+
25+
#----------------------------------------------------------------------
26+
# Create output directories
27+
#----------------------------------------------------------------------
28+
o = $(out)MSPythonCore/
29+
30+
always:
31+
!~@mkdir $(o)
32+
33+
always:
34+
~linkdir "$(BuildContext)PublicAPI/MsPythonCore=$(MSPythonSrc)/PublicAPI/MSPythonCore/"
35+
36+
#---------------------------------------------
37+
# Compile Native source files
38+
#---------------------------------------------
39+
MultiCompileDepends = $(_MakeFileSpec)
40+
41+
PchCompiland = $(MSPythonSrc)MSPythonPCH.cpp
42+
PchOutputDir = $(o)
43+
PchArgumentsDepends = $(MultiCompileDepends)
44+
PchExtraOptions + -Zm170 -wd4456 -wd4457 -wd4459 -wd4311 -wd4312 -wd4302 -wd4471 -wd4653 -wd4652 -wd4651
45+
46+
%include $(MSPythonSrc)/build/publicSDK/PreCompileHeader.mki
47+
48+
CCPchOpts = $(UsePrecompiledHeaderOptions)
49+
50+
dependencies = $(MSPythonSrc)MSPythonPCH.h
51+
52+
PyhonCoreSource = $(PyhonCore)ScriptEngineManager/source/
53+
PythonCoreDependencies = $(dependencies) \
54+
$(PythonInternalHeaders)MSPythonEngine.h \
55+
$(PythonPublicHeaders)ScriptEngineManager.h
56+
57+
%include MultiCppCompileRule.mki
58+
59+
$(o)ScriptEngineManager$(oext) : $(PyhonCoreSource)ScriptEngineManager.cpp $(PythonCoreDependencies) ${MultiCompileDepends}
60+
61+
$(o)MSPythonEngine$(oext) : $(PyhonCoreSource)MSPythonEngine.cpp $(PythonCoreDependencies) ${MultiCompileDepends}
62+
63+
%include MultiCppCompileGo.mki
64+
NATIVE_OBJS =% $(MultiCompileObjectList) \
65+
$(o)MSPythonPCH$(oext)
66+
67+
68+
#---------------------------------------------
69+
# Compile Managed source files (/clr)
70+
#---------------------------------------------
71+
%include compileForCLRStart.mki
72+
73+
CCPchOpts =
74+
MultiCompileDepends=$(_MakeFileSpec)
75+
76+
%include MultiCppCompileRule.mki
77+
78+
ScriptEngineManagerNetDependencies = $(dependencies) \
79+
$(PythonPublicHeaders)ScriptEngineManager.h
80+
81+
$(o)ScriptEngineManagerNet$(oext) : $(PyhonCoreSource)ScriptEngineManagerNet.cpp $(ScriptEngineManagerNetDependencies) ${MultiCompileDepends}
82+
83+
%include MultiCppCompileGo.mki
84+
MANAGED_OBJS =% $(MultiCompileObjectList)
85+
%include compileForCLRStop.mki
86+
87+
88+
DLM_NAME = $(appName)
89+
RIGHTSCOMPLIANT = false
90+
DLM_DEST = $(o)
91+
DLM_EXPORT_DEST = $(o)
92+
DLM_OBJECT_DEST = $(o)
93+
DLM_OBJECT_FILES = $(NATIVE_OBJS) $(MANAGED_OBJS)
94+
DLM_NO_DEF = 1
95+
DLM_NO_DLS = 1
96+
DLM_NO_IMPLIB = 0
97+
DLM_NOENTRY = 0
98+
DLM_NO_INITIALIZE_FUNCTION = 0
99+
100+
LINKER_LIBRARIES = $(PythonLibName) \
101+
$(ContextSubpartsLibs)Bentley.lib \
102+
$(ContextSubpartsLibs)BentleyAllocator.lib \
103+
$(ContextSubpartsLibs)DgnPlatform.lib \
104+
$(ContextSubpartsLibs)RmgrTools.lib \
105+
$(ContextSubpartsLibs)mdlbltin.lib
106+
107+
DLM_CONTEXT_LOCATION = $(BuildContext)Delivery/
108+
109+
%if defined (BSI)
110+
DLM_LIB_CONTEXT_LOCATION = $(BuildContext)Delivery/
111+
DLM_CREATE_LIB_CONTEXT_LINK = 1
112+
%else
113+
DLM_LIB_CONTEXT_LOCATION = $(ContextSubpartsLibs)
114+
%endif
115+
116+
117+
ASSEMBLY_NAME = $(DLM_NAME)
118+
ASSEMBLY_TITLE = $(DLM_NAME)
119+
ASSEMBLY_DESCRIPTION = Bentley MSPython Core Mixed Assembly
120+
ASSEMBLY_VERSION = 1.0.0.0
121+
ASSEMBLY_FILE_VERSION = 1.0.0.0
122+
ASSEMBLY_PRODUCT_NAME = MSPythonCore
123+
ASSEMBLY_COMPANY_NAME = $(companyName)
124+
ASSEMBLY_COPYRIGHT = $(Bentley_Copyright)
125+
126+
%if defined (BSI)
127+
128+
ASSEMBLY_STRONGNAME = 1
129+
%include $(SharedMki)isRightsCompliant.mki
130+
%include $(SharedMki)VersionedPartSignatureDefaults.mki
131+
132+
ASSEMBLY_KEYFILE =% $(ASSEMBLY_KEYFILE_DEFAULT)
133+
ASSEMBLY_TESTKEYFILE =% $(ASSEMBLY_TESTKEYFILE_DEFAULT)
134+
135+
%endif
136+
137+
138+
%include linkMixedAssembly.mki
139+

MSPythonCore/ScriptEngineManager/ScriptEngineManager.mki

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)