Bas van Sisseren
a14ce77b28
py/binary.c: Fix bug when packing big-endian 'Q' values.
Without bugfix:
struct.pack('>Q', 16)
b'\x00\x00\x00\x10\x00\x00\x00\x00'
With bugfix:
struct.pack('>Q', 16)
b'\x00\x00\x00\x00\x00\x00\x00\x10'
7 years ago
Alexander Steffen
55f33240f3
all: Use the name MicroPython consistently in comments
There were several different spellings of MicroPython present in comments,
when there should be only one.
7 years ago
Damien George
9aeba3e41b
py/binary: Add missing "break" statements.
7 years ago
Damien George
6cfa61a4cc
py/binary: Handle storing big-ints to all arrays types.
Prior to this patch only 'q' and 'Q' type arrays could store big-int
values. With this patch any big int that is stored to an array is handled
by the big-int implementation, regardless of the typecode of the array.
This allows arrays to work with all type sizes on all architectures.
8 years ago
Paul Sokolovsky
af90461931
py/binary: mp_binary_get_size: Raise error on unsupported typecodes.
Previouly, we had errors checked in callers, which led to duplicate code
or missing checks in some places.
8 years ago
Damien George
a3c61004c2
py/binary: Do zero extension when storing a value larger than word size.
8 years ago
Damien George
999cedb90f
py: Wrap all obj-ptr conversions in MP_OBJ_TO_PTR/MP_OBJ_FROM_PTR.
This allows the mp_obj_t type to be configured to something other than a
pointer-sized primitive type.
This patch also includes additional changes to allow the code to compile
when sizeof(mp_uint_t) != sizeof(void*), such as using size_t instead of
mp_uint_t, and various casts.
9 years ago
Damien George
88a9103b3c
py/binary: Make use of MP_ALIGN.
9 years ago
Paul Sokolovsky
91fc075a33
py/objarray: Allow to create array of void pointers, as extension to CPython.
Using 'P' format specifier (matches struct module). This is another shortcut
for FFI, just as previously introduced "array of objects" ('O').
9 years ago
Damien George
81794fcd31
py/binary: Add support for array('q') and array('Q').
9 years ago
Kaspar Schleiser
f5dd6f7f37
py/binary: Make return type of mp_binary_get_size size_t instead of int.
Fixes sign-compare warning.
10 years ago
Damien George
9472907ae1
py: Fix handling of negative numbers in struct.pack of q/Q.
10 years ago
Damien George
271d18eb08
py: Support conversion of bignum to bytes.
This gets int.to_bytes working for bignum, and also struct.pack with 'q'
and 'Q' args on 32-bit machines.
Addresses issue #1155 .
10 years ago
Paul Sokolovsky
24c1000741
objarray: Support array('O'), array of objects, as extension to CPython.
Might be useful at least for memoryview hacks.
10 years ago
David Steinberg
0b3014ce3a
py: Add support for floats in mp_binary_{get,set}_val()
- This then provides support for floats in the struct package
10 years ago
Paul Sokolovsky
91232d3850
binary: Rework array accessors. They work with native, not stdint types.
10 years ago
Damien George
963a5a3e82
py, unix: Allow to compile with -Wsign-compare.
See issue #699 .
10 years ago
Damien George
51dfcb4bb7
py: Move to guarded includes, everywhere in py/ core.
Addresses issue #1022 .
10 years ago
Damien George
be6d8be91e
py: Rename mp_obj_int_get to mp_obj_int_get_truncated; fix struct.pack.
mp_obj_int_get_truncated is used as a "fast path" int accessor that
doesn't check for overflow and returns the int truncated to the machine
word size, ie mp_int_t.
Use mp_obj_int_get_truncated to fix struct.pack when packing maximum word
sized values.
Addresses issues #779 and #998 .
10 years ago
Damien George
c9f8f653ad
py: Add support for float/double arrays in array module.
Addresses issue #981 .
10 years ago
Damien George
9336ee320a
py: Make mp_binary_set_val work on big endian machine.
10 years ago
Damien George
42f3de924b
py: Convert [u]int to mp_[u]int_t where appropriate.
Addressing issue #50 .
10 years ago
Damien George
953074315e
py: Enable struct/binary-helper to parse q and Q sized ints.
Addresses issue #848 .
10 years ago
Paul Sokolovsky
78fde4819c
modstruct: Implement 'O', 'P', 's' types for packed structs.
This is required to deal with, well, packed C structs containing pointers.
10 years ago
Damien George
4abff7500f
py: Change uint to mp_uint_t in runtime.h, stackctrl.h, binary.h.
Part of code cleanup, working towards resolving issue #50 .
10 years ago
Paul Sokolovsky
ecca53bd34
py: binary.c: Properly implement alignment for native unpacked structs.
10 years ago
Paul Sokolovsky
5fa5ca40e6
binary: Factor out mp_binary_set_int().
10 years ago
Damien George
40f3c02682
Rename machine_(u)int_t to mp_(u)int_t.
See discussion in issue #50 .
11 years ago
Paul Sokolovsky
f3de62e6c2
binary: machine_uint_t vs uint dichotomy starts doing real damage.
11 years ago
Paul Sokolovsky
7a2f166949
modstruct: Fix alignment handling issues.
Also, factor out mp_binary_get_int() function.
11 years ago
Paul Sokolovsky
59c675a64c
py: Include mpconfig.h before all other includes.
It defines types used by all other headers.
Fixes #691 .
11 years ago
Paul Sokolovsky
62798831be
modstruct: Add one more extension to typecodes - 'S', a pointer to C string.
Also, add comment with description of extension to CPython's typecodes.
11 years ago
Damien George
fb510b3bf9
Rename bultins config variables to MICROPY_PY_BUILTINS_*.
This renames:
MICROPY_PY_FROZENSET -> MICROPY_PY_BUILTINS_FROZENSET
MICROPY_PY_PROPERTY -> MICROPY_PY_BUILTINS_PROPERTY
MICROPY_PY_SLICE -> MICROPY_PY_BUILTINS_SLICE
MICROPY_ENABLE_FLOAT -> MICROPY_PY_BUILTINS_FLOAT
See issue #35 for discussion.
11 years ago
Damien George
04b9147e15
Add license header to (almost) all files.
Blanket wide to all .c and .h files. Some files originating from ST are
difficult to deal with (license wise) so it was left out of those.
Also merged modpyb.h, modos.h, modstm.h and modtime.h in stmhal/.
11 years ago
Paul Sokolovsky
0f836ef893
modstruct: Add 'O' typecode for passing mp_obj_t.
Useful as callback data, etc.
11 years ago
Paul Sokolovsky
4e4fa94c4c
modstruct: Use proper int accessor which checks input value type.
11 years ago
Paul Sokolovsky
6204460461
modstruct: Initial implementation of struct.pack().
11 years ago
Paul Sokolovsky
1355cf42f2
modstruct: Fix .calcsize() to account for struct type/alignment.
11 years ago
Paul Sokolovsky
5695e07256
modstruct: Support 'q' & 'Q' type codes.
11 years ago
Damien George
71e9bfa20d
py: Add mp_binary_set_val_array_from_int, to store an int directly.
11 years ago
Paul Sokolovsky
0c43cf9154
modstruct: Basic implementation of native struct alignment and types.
11 years ago
Paul Sokolovsky
ef9124f5ff
binary: Rename array accessors for clarity.
11 years ago
Paul Sokolovsky
6582d64d01
modstruct: Refactor to support both LE and BE packed structs.
11 years ago
Paul Sokolovsky
e9db840480
py: Start implementing "struct" module.
Only calcsize() and unpack() functions provided so far, for little-endian
byte order. Format strings don't support repition spec (like "2b3i").
Unfortunately, dealing with all the various binary type sizes and alignments
will lead to quite a bloated "binary" helper functions - if optimizing for
speed. Need to think if using dynamic parametrized algos makes more sense.
11 years ago
xbe
efe3422394
py: Clean up includes.
Remove unnecessary includes. Add includes that improve portability.
11 years ago
Damien George
438c88dd2f
Add arbitrary precision integer support.
Some functionality is still missing (eg and, or, bit shift), and some
things are buggy (eg subtract).
11 years ago
Damien George
96056a6272
py: Revent some long int configuration.
11 years ago
Damien George
36109d246f
Small change to configuration of long int.
11 years ago
Paul Sokolovsky
76f8cedb52
mp_binary_get_val(): Fix value type.
11 years ago
Paul Sokolovsky
c203324e6c
objarray: Refactor to use array accessors from binary.c .
11 years ago