@@ -92,9 +92,44 @@ internal static void Shutdown() {
92
92
//===================================================================
93
93
// Return the clr python module (new reference)
94
94
//===================================================================
95
- public static IntPtr GetCLRModule ( ) {
95
+ public static IntPtr GetCLRModule ( IntPtr ? fromList = null ) {
96
96
root . InitializePreload ( ) ;
97
97
#if ( PYTHON32 || PYTHON33 || PYTHON34 )
98
+ // update the module dictionary with the contents of the root dictionary
99
+ root . LoadNames ( ) ;
100
+ IntPtr py_mod_dict = Runtime . PyModule_GetDict ( py_clr_module ) ;
101
+ IntPtr clr_dict = Runtime . _PyObject_GetDictPtr ( root . pyHandle ) ; // PyObject**
102
+ clr_dict = ( IntPtr ) Marshal . PtrToStructure ( clr_dict , typeof ( IntPtr ) ) ;
103
+ Runtime . PyDict_Update ( py_mod_dict , clr_dict ) ;
104
+
105
+ // find any items from the fromlist and get them from the root if they're not
106
+ // aleady in the module dictionary
107
+ if ( fromList != null && fromList != IntPtr . Zero ) {
108
+ if ( Runtime . PyTuple_Check ( fromList . GetValueOrDefault ( ) ) )
109
+ {
110
+ Runtime . Incref ( py_mod_dict ) ;
111
+ PyDict mod_dict = new PyDict ( py_mod_dict ) ;
112
+
113
+ Runtime . Incref ( fromList . GetValueOrDefault ( ) ) ;
114
+ PyTuple from = new PyTuple ( fromList . GetValueOrDefault ( ) ) ;
115
+ foreach ( PyObject item in from ) {
116
+ if ( mod_dict . HasKey ( item ) )
117
+ continue ;
118
+
119
+ string s = item . AsManagedObject ( typeof ( string ) ) as string ;
120
+ if ( null == s )
121
+ continue ;
122
+
123
+ ManagedType attr = root . GetAttribute ( s , true ) ;
124
+ if ( null == attr )
125
+ continue ;
126
+
127
+ Runtime . Incref ( attr . pyHandle ) ;
128
+ mod_dict . SetItem ( s , new PyObject ( attr . pyHandle ) ) ;
129
+ }
130
+ }
131
+ }
132
+
98
133
Runtime . Incref ( py_clr_module ) ;
99
134
return py_clr_module ;
100
135
#else
@@ -145,12 +180,12 @@ public static IntPtr __import__(IntPtr self, IntPtr args, IntPtr kw) {
145
180
// do the Incref()ed return here, since we've already found
146
181
// the module.
147
182
if ( mod_name == "clr" ) {
148
- return GetCLRModule ( ) ;
183
+ return GetCLRModule ( fromList ) ;
149
184
}
150
185
if ( mod_name == "CLR" ) {
151
186
Exceptions . deprecation ( "The CLR module is deprecated. " +
152
187
"Please use 'clr'." ) ;
153
- return GetCLRModule ( ) ;
188
+ return GetCLRModule ( fromList ) ;
154
189
}
155
190
string realname = mod_name ;
156
191
if ( mod_name . StartsWith ( "CLR." ) ) {
0 commit comments