|
32 | 32 | from types import EllipsisType |
33 | 33 | from typing import Any, Dict, Tuple, Union |
34 | 34 |
|
35 | | -from typing_extensions import Literal |
36 | | - |
37 | 35 | from xdis.codetype import to_portable |
38 | 36 | from xdis.cross_types import LongTypeForPython3, UnicodeForPython3 |
39 | 37 | from xdis.magics import GRAAL3_MAGICS, PYPY3_MAGICS, RUSTPYTHON_MAGICS, magic_int2tuple |
@@ -92,15 +90,14 @@ def long(n: int) -> LongTypeForPython3: |
92 | 90 | TYPE_UNKNOWN = "?" |
93 | 91 |
|
94 | 92 | # Graal Array types |
95 | | -ARRAY_TYPE_BOOLEAN = Literal['B'] |
96 | | -ARRAY_TYPE_BYTE = 'b' |
97 | | -ARRAY_TYPE_DOUBLE = 'd' |
98 | | -ARRAY_TYPE_INT = 'i' |
99 | | -ARRAY_TYPE_LONG = 'l' |
100 | | -ARRAY_TYPE_OBJECT = 'o' |
101 | | -ARRAY_TYPE_SHORT = 's' |
102 | | -ARRAY_TYPE_STRING = 'S' |
103 | | - |
| 93 | +ARRAY_TYPE_BOOLEAN = "B" |
| 94 | +ARRAY_TYPE_BYTE = "b" |
| 95 | +ARRAY_TYPE_DOUBLE = "d" |
| 96 | +ARRAY_TYPE_INT = "i" |
| 97 | +ARRAY_TYPE_LONG = "l" |
| 98 | +ARRAY_TYPE_OBJECT = "o" |
| 99 | +ARRAY_TYPE_SHORT = "s" |
| 100 | +ARRAY_TYPE_STRING = "S" |
104 | 101 |
|
105 | 102 |
|
106 | 103 | # The keys in the following dictionary are unmarshal codes, like "s", |
@@ -218,52 +215,46 @@ def t_graal_readArray(self, save_ref: bool, bytes_for_s: bool) -> tuple: |
218 | 215 | """ |
219 | 216 | Python equivalent of Python Graal's readArray() from |
220 | 217 | MarshalModuleBuiltins.java |
221 | | - """ |
222 | | - """ |
223 | | - Main object unmarshalling read routine. Reads from self.fp |
224 | | - the next byte which is a key in UNMARSHAL_DISPATCH_TABLE |
225 | | - defined above when the high-order bit, FLAG_REF is not set. |
226 | | - FLAG_REF indicates whether to save the resulting object in |
| 218 | +
|
| 219 | + Array object unmarshalling read routine. Reads from self.fp |
| 220 | + the next byte which is a key in ARRAY_TYPE defined above. |
| 221 | +
|
| 222 | + Parameter save_ref indicates whether to save the resulting object in |
227 | 223 | our internal object cache. |
228 | 224 | """ |
229 | 225 | byte1 = ord(self.fp.read(1)) |
230 | 226 |
|
231 | | - # FLAG_REF indicates whether we "intern" or |
232 | | - # save a reference to the object. |
233 | | - # byte1 without that reference is the |
234 | | - # marshal type code, an ASCII character. |
235 | | - save_ref = False |
236 | | - if byte1 & FLAG_REF: |
237 | | - # Since 3.4, "flag" is the marshal.c name |
238 | | - save_ref = True |
239 | | - byte1 = byte1 & (FLAG_REF - 1) |
240 | 227 | marshal_type = chr(byte1) |
241 | 228 |
|
242 | 229 | # print(marshal_type) # debug |
243 | 230 |
|
244 | 231 | match marshal_type: |
245 | | - case "B": |
246 | | - return tuple() |
247 | | - |
| 232 | + # case "B": |
| 233 | + # ret = tuple() |
248 | 234 | # case "b": |
249 | 235 | # return "OK" |
250 | 236 | case "d": |
251 | | - return self.graal_readDoubleArray() |
| 237 | + ret = self.graal_readDoubleArray() |
252 | 238 | case "i": |
253 | | - return self.graal_readIntArray() |
| 239 | + ret = self.graal_readIntArray() |
254 | 240 | case "o": |
255 | | - return self.graal_readObjectArray() |
| 241 | + ret = self.graal_readObjectArray() |
256 | 242 | # case "l": |
257 | 243 | # return "Internal server error" |
258 | 244 | # case "s": |
259 | 245 | # return "Internal server error" |
260 | 246 | case "S": |
261 | | - return self.graal_readStringArray() |
| 247 | + ret = self.graal_readStringArray() |
262 | 248 | case _: |
263 | 249 | # The underscore '_' acts as a wildcard |
264 | 250 | # It matches anything if no previous case did (the 'default' case) |
265 | | - print(f"XXX {marshal_type}") |
266 | | - return tuple() |
| 251 | + print(f"XXX Whoah {marshal_type}") |
| 252 | + ret = tuple() |
| 253 | + if save_ref: |
| 254 | + n = len(self.intern_objects) |
| 255 | + print("appending at %d: %s" % (n, ret)) |
| 256 | + self.intern_objects.append(ret) |
| 257 | + return ret |
267 | 258 |
|
268 | 259 | def graal_readByte(self) -> int: |
269 | 260 | """ |
@@ -377,9 +368,9 @@ def r_ref(self, obj, save_ref): |
377 | 368 | # This is only needed in the Python 2.4 - 2.7 code branch. |
378 | 369 | def r_object(self, bytes_for_s: bool = False): |
379 | 370 | """ |
380 | | - Main object unmarshalling read routine. Reads from self.fp |
| 371 | + Main object unmarshaling read routine. Reads from self.fp |
381 | 372 | the next byte which is a key in UNMARSHAL_DISPATCH_TABLE |
382 | | - defined above when the high-order bit, FLAG_REF is not set. |
| 373 | + defined above clearing the high-order bit, FLAG_REF. |
383 | 374 | FLAG_REF indicates whether to save the resulting object in |
384 | 375 | our internal object cache. |
385 | 376 | """ |
@@ -1078,8 +1069,7 @@ def t_graal_CodeUnit(self, save_ref, bytes_for_s: bool = False): |
1078 | 1069 | # Since Python 3.4 |
1079 | 1070 | def t_object_reference(self, save_ref=None, bytes_for_s: bool = False): |
1080 | 1071 | refnum = unpack("<i", self.fp.read(4))[0] |
1081 | | - o = self.intern_objects[refnum] |
1082 | | - return o |
| 1072 | + return self.intern_objects[refnum] |
1083 | 1073 |
|
1084 | 1074 | def t_unknown(self, save_ref=None, bytes_for_s: bool = False): |
1085 | 1075 | raise KeyError("?") |
|
0 commit comments