QUERY · ISSUE
uctypes incompatibility with OBJ_REPR_B
bug
Port, board and/or hardware
unix, 32-bit, obj_repr_b
MicroPython version
based on v1.27.0-preview-154-g44986b1f04
Reproduction
- Make a build with OBJ_REPR_B
- Look at the uctypes constants
Expected behaviour
All the constants are distinct
Observed behaviour
Some of the constants are duplicates
>>> import uctypes
>>> assert uctypes.INT8 != uctypes.BFINT8
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AssertionError:
Additional Information
See more discussion at https://github.com/micropython/micropython/pull/17688#discussion_r2357500386
Patch to add a REPR_B coverage build to ci.sh:
diff --git a/tools/ci.sh b/tools/ci.sh
index 901059991e..5afe089ccb 100755
--- a/tools/ci.sh
+++ b/tools/ci.sh
@@ -543,6 +543,14 @@ CI_UNIX_OPTS_SANITIZE_UNDEFINED=(
LDFLAGS_EXTRA="-fsanitize=undefined -fno-sanitize=nonnull-attribute"
)
+CI_UNIX_OPTS_REPR_B=(
+ VARIANT=coverage
+ CFLAGS_EXTRA="-DMICROPY_OBJ_REPR=MICROPY_OBJ_REPR_B -Dmp_int_t=int32_t -Dmp_uint_t=uint32_t"
+ MICROPY_FORCE_32BIT=1
+ RUN_TESTS_MPY_CROSS_FLAGS="--mpy-cross-flags=\"-march=x86 -msmall-int-bits=30\""
+
+)
+
function ci_unix_build_helper {
make ${MAKEOPTS} -C mpy-cross
make ${MAKEOPTS} -C ports/unix "$@" submodules
@@ -688,6 +696,15 @@ function ci_unix_32bit_setup {
python3 --version
}
+function ci_unix_coverage_repr_b_build {
+ ci_unix_build_helper "${CI_UNIX_OPTS_REPR_B[@]}"
+ ci_unix_build_ffi_lib_helper gcc -m32
+}
+
+function ci_unix_coverage_repr_b_run_tests {
+ ci_unix_run_tests_helper "${CI_UNIX_OPTS_REPR_B[@]}"
+}
+
function ci_unix_coverage_32bit_build {
ci_unix_build_helper VARIANT=coverage MICROPY_FORCE_32BIT=1
ci_unix_build_ffi_lib_helper gcc -m32
--
2.47.3
Code of Conduct
Yes, I agree
CANDIDATE · ISSUE
bytearray(uctypes.bytes_at(0, 8)) segfaults in memcpy
bugproposed-close
Port, board and/or hardware
Unix port
MicroPython version
MicroPython v1.27.0-preview.107.gd1607598f on 2025-09-09; linux [GCC 14.2.0] version
Reproduction
import uctypes
arr = uctypes.bytes_at(0, 8)
arr2 = bytearray(arr)
arr2[0] = 1
Expected behaviour
A Python-level exception when the source buffer refers to an unreadable address (e.g., ValueError or OSError), or the unix port rejects bytes_at(0, 8) up front.
Observed behaviour
Program received signal SIGSEGV, Segmentation fault.
[#0] 0x7ffff7d95780 → __memcpy_avx_unaligned_erms()
[#1] 0x5555555fa3fd → memcpy(__dest=<optimised out>, __src=<optimised out>, __len=0x8)
[#2] 0x5555555fa3fd → array_construct(typecode=0x1, initializer=<optimised out>)
[#3] 0x5555555fa73b → bytearray_make_new(type_in=<optimised out>, n_args=0x1, n_kw=<optimised out>, args=0x7ffff7e27de0)
[#4] 0x555555618eff → type_call(self_in=<optimised out>, n_args=<optimised out>, n_kw=<optimised out>, args=<optimised out>)
[#5] 0x5555555ed738 → mp_call_function_n_kw(fun_in=0x55555571d070 <mp_type_bytearray>, n_args=0x1, n_kw=0x0, args=0x7ffff7e27de0)
[#6] 0x555555629936 → mp_execute_bytecode(code_state=0x7ffff7e27da0, inject_exc=<optimised out>)
[#7] 0x555555602482 → fun_bc_call(self_in=0x7ffff7e27ce0, n_args=<optimised out>, n_kw=<optimised out>, args=0x0)
[#8] 0x5555555ed738 → mp_call_function_n_kw(fun_in=0x7ffff7e27ce0, n_args=0x0, n_kw=0x0, args=0x0)
[#9] 0x5555555f0211 → mp_call_function_0(fun=<optimised out>)
Additional Information
No, I've provided everything above.
Code of Conduct
Yes, I agree