File tree Expand file tree Collapse file tree 4 files changed +31
-10
lines changed Expand file tree Collapse file tree 4 files changed +31
-10
lines changed Original file line number Diff line number Diff line change @@ -85,3 +85,12 @@ bool modulsp_init( void )
85
85
END_BOOST_PY (false )
86
86
return true ;
87
87
}
88
+
89
+
90
+ dict& DeferredDict::get () {
91
+ if (!_pDict) {
92
+ _pDict = std::make_shared<dict>();
93
+ }
94
+
95
+ return *_pDict;
96
+ }
Original file line number Diff line number Diff line change @@ -55,6 +55,18 @@ typedef void (*ModuleInitFn)( scope );
55
55
static CSPModule g_##package##_##name##_Init( XSTRINGIFY(package.name), &PyInit_##package##_##name ); \
56
56
void PyInit_##package##_##name( scope name )
57
57
58
+ // ---------------------------------------------------------------------------------
59
+ // A deferred version of boost::python::dict. Thanks to spitice!
60
+ // There was a change in Python that results in an access violation when Python is
61
+ // not ready, yet.
62
+ // ---------------------------------------------------------------------------------
63
+ class DeferredDict {
64
+ private:
65
+ std::shared_ptr<dict> _pDict;
66
+ public:
67
+ dict& get ();
68
+ };
69
+
58
70
// ---------------------------------------------------------------------------------
59
71
// This is a module definition structure. The way our module system is going to
60
72
// work is you declare a module via BOOST_PYTHON_MODULE. Then the CPythonManager
Original file line number Diff line number Diff line change @@ -147,8 +147,8 @@ T* __obj__(CPointer* pPtr)
147
147
// ============================================================================
148
148
// Use this macro to add the class to the ExposedClasses dict
149
149
#define STORE_CLASS (classname, pyname ) \
150
- extern dict g_oExposedClasses; \
151
- g_oExposedClasses[XSTRINGIFY(classname)] = scope().attr(pyname);
150
+ extern DeferredDict g_oExposedClasses; \
151
+ g_oExposedClasses.get() [XSTRINGIFY(classname)] = scope().attr(pyname);
152
152
153
153
154
154
// ============================================================================
@@ -202,12 +202,12 @@ END_CLASS_INFO()
202
202
#define BEGIN_CLASS_INFO (classname ) \
203
203
{ \
204
204
typedef classname functionInfoClass; \
205
- extern dict g_oClassInfo; \
205
+ extern DeferredDict g_oClassInfo; \
206
206
dict classInfoDict; \
207
- if (g_oClassInfo.contains ( #classname )) \
208
- classInfoDict = extract<dict>(g_oClassInfo[ #classname ]); \
207
+ if (g_oClassInfo.get (). contains ( #classname )) \
208
+ classInfoDict = extract<dict>(g_oClassInfo. get () [ #classname ]); \
209
209
else \
210
- g_oClassInfo[ #classname ] = classInfoDict;
210
+ g_oClassInfo. get () [ #classname ] = classInfoDict;
211
211
212
212
// Finish a class info dictionary
213
213
#define END_CLASS_INFO () \
Original file line number Diff line number Diff line change @@ -1018,16 +1018,16 @@ void export_functions(scope _memory)
1018
1018
// ============================================================================
1019
1019
// >> GLOBAL VARIABLES
1020
1020
// ============================================================================
1021
- dict g_oExposedClasses;
1022
- dict g_oClassInfo;
1021
+ DeferredDict g_oExposedClasses;
1022
+ DeferredDict g_oClassInfo;
1023
1023
1024
1024
#define ADD_NATIVE_TYPE_SIZE (name, type ) \
1025
1025
scope ().attr(" TYPE_SIZES" )[name] = sizeof(type);
1026
1026
1027
1027
void export_global_variables (scope _memory)
1028
1028
{
1029
- _memory.attr (" EXPOSED_CLASSES" ) = g_oExposedClasses;
1030
- _memory.attr (" CLASS_INFO" ) = g_oClassInfo;
1029
+ _memory.attr (" EXPOSED_CLASSES" ) = g_oExposedClasses. get () ;
1030
+ _memory.attr (" CLASS_INFO" ) = g_oClassInfo. get () ;
1031
1031
1032
1032
// Don't remove this! It's required for the ADD_NATIVE_TYPE_SIZE macro.
1033
1033
_memory.attr (" TYPE_SIZES" ) = dict ();
You can’t perform that action at this time.
0 commit comments