File tree Expand file tree Collapse file tree 2 files changed +20
-6
lines changed
com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules Expand file tree Collapse file tree 2 files changed +20
-6
lines changed Original file line number Diff line number Diff line change 78
78
import com .oracle .graal .python .nodes .function .PythonBuiltinBaseNode ;
79
79
import com .oracle .graal .python .nodes .function .PythonBuiltinNode ;
80
80
import com .oracle .graal .python .nodes .function .builtins .PythonBinaryBuiltinNode ;
81
+ import com .oracle .graal .python .parser .sst .SerializationUtils ;
81
82
import com .oracle .graal .python .runtime .ExecutionContext .ForeignCallContext ;
82
83
import com .oracle .graal .python .runtime .PythonContext ;
83
84
import com .oracle .graal .python .runtime .PythonOptions ;
@@ -151,6 +152,25 @@ public boolean run() {
151
152
}
152
153
}
153
154
155
+ @ Builtin (name = "get_magic" )
156
+ @ GenerateNodeFactory
157
+ public abstract static class GetMagic extends PythonBuiltinNode {
158
+ // it's b'\x0c\xaf\xaf\xe1', original magic number of GraalPython
159
+ private static int BASE_MAGIC_NUMBER = 212840417 ;
160
+
161
+ @ Specialization
162
+ public PBytes run () {
163
+ // The magic number in CPython is usually increased by 10.
164
+ int number = BASE_MAGIC_NUMBER + 10 * SerializationUtils .VERSION ;
165
+ byte [] magicNumber = new byte [4 ];
166
+ magicNumber [0 ] = (byte ) (number >>> 24 );
167
+ magicNumber [1 ] = (byte ) (number >>> 16 );
168
+ magicNumber [2 ] = (byte ) (number >>> 8 );
169
+ magicNumber [3 ] = (byte ) (number );
170
+ return factory ().createBytes (magicNumber );
171
+ }
172
+ }
173
+
154
174
@ Builtin (name = "__create_dynamic__" , minNumOfPositionalArgs = 2 )
155
175
@ GenerateNodeFactory
156
176
public abstract static class CreateDynamic extends PythonBuiltinNode {
Original file line number Diff line number Diff line change 40
40
# Package context -- the full module name for package imports
41
41
_py_package_context = None
42
42
43
-
44
- @__graalpython__ .builtin
45
- def get_magic ():
46
- return b'\x0c \xaf \xaf \xe1 '
47
-
48
-
49
43
@__graalpython__ .builtin
50
44
def create_dynamic (module_spec , filename = None ):
51
45
global _py_package_context
You can’t perform that action at this time.
0 commit comments