blueloveTH před 1 měsícem
rodič
revize
68db88b501
2 změnil soubory, kde provedl 11 přidání a 8 odebrání
  1. 4 2
      include/pocketpy/common/serialize.h
  2. 7 6
      tests/922_py_compile.py

+ 4 - 2
include/pocketpy/common/serialize.h

@@ -37,9 +37,11 @@ void* c11_deserializer__read_bytes(c11_deserializer* self, int size);
         c11_serializer__write_bytes(self, &value, sizeof(T)); \
     } \
     static inline T c11_deserializer__read_##name(c11_deserializer* self){ \
-        T* p = (T*)(self->data + self->index); \
+        const void* p = self->data + self->index; \
         self->index += sizeof(T); \
-        return *p; \
+        T retval;\
+        memcpy(&retval, p, sizeof(T)); \
+        return retval; \
     }
 
 DEF_ATOMIC_INLINE_RW(i8, int8_t)

+ 7 - 6
tests/922_py_compile.py

@@ -1,13 +1,14 @@
 from py_compile import compile
-import os
 
-if not os.path.exists('tmp'):
-    os.mkdir('tmp')
+try:
+    import os
+except ImportError:
+    print('os is not enabled, skipping test...')
+    exit(0)
 
-compile('python/heapq.py', 'tmp/heapq1.pyc')
-assert os.path.exists('tmp/heapq1.pyc')
+compile('python/heapq.py', 'heapq1.pyc')
+assert os.path.exists('heapq1.pyc')
 
-os.chdir('tmp')
 import heapq1
 import heapq