Skip to content

Fix mpprintf argument type errors #17704

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/usercmodule/cexample/examplemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ static void example_AdvancedTimer_print(const mp_print_t *print, mp_obj_t self_i
mp_uint_t elapsed = mp_obj_get_int(example_Timer_time(self_in));

// We'll make all representations print at least the class name.
mp_printf(print, "%q()", MP_QSTR_AdvancedTimer);
mp_printf(print, "%q()", (qstr)MP_QSTR_AdvancedTimer);

// Decide what else to print based on print kind.
if (kind == PRINT_STR) {
// For __str__, let's attempt to make it more readable.
mp_printf(print, " # created %d seconds ago", elapsed / 1000);
mp_printf(print, " # created %d seconds ago", (int)(elapsed / 1000));
}
}

Expand Down
2 changes: 1 addition & 1 deletion extmod/modlwip.c
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ static const mp_obj_type_t lwip_socket_type;

static void lwip_socket_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
lwip_socket_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_printf(print, "<socket state=%d timeout=%d incoming=", self->state, self->timeout);
mp_printf(print, "<socket state=%d timeout=" INT_FMT " incoming=", self->state, self->timeout);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be UINT_FMT? Because self->timeout is mp_uint_t.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if (self->type == MOD_NETWORK_SOCK_STREAM) {
mp_printf(print, "%p off=%d>", self->incoming.tcp.pbuf, self->recv_offset);
} else {
Expand Down
3 changes: 0 additions & 3 deletions ports/cc3200/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,6 @@
#define MICROPY_MAKE_POINTER_CALLABLE(p) ((void *)((mp_uint_t)(p) | 1))
#define MP_SSIZE_MAX (0x7FFFFFFF)

#define UINT_FMT "%u"
#define INT_FMT "%d"

typedef int32_t mp_int_t; // must be pointer size
typedef unsigned int mp_uint_t; // must be pointer size
typedef long mp_off_t;
Expand Down
3 changes: 0 additions & 3 deletions ports/esp32/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,6 @@ void *esp_native_code_commit(void *, size_t, void *);
#define MICROPY_WRAP_MP_SCHED_EXCEPTION(f) IRAM_ATTR f
#define MICROPY_WRAP_MP_SCHED_KEYBOARD_INTERRUPT(f) IRAM_ATTR f

#define UINT_FMT "%u"
#define INT_FMT "%d"

typedef int32_t mp_int_t; // must be pointer size
typedef uint32_t mp_uint_t; // must be pointer size
typedef long mp_off_t;
Expand Down
3 changes: 0 additions & 3 deletions ports/esp8266/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,6 @@

#define MP_SSIZE_MAX (0x7fffffff)

#define UINT_FMT "%u"
#define INT_FMT "%d"

typedef int32_t mp_int_t; // must be pointer size
typedef uint32_t mp_uint_t; // must be pointer size
typedef long mp_off_t;
Expand Down
2 changes: 0 additions & 2 deletions ports/nrf/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,6 @@ void *nrf_native_code_commit(void *, unsigned int, void *);

#define MP_SSIZE_MAX (0x7fffffff)

#define UINT_FMT "%u"
#define INT_FMT "%d"
#define HEX2_FMT "%02x"

typedef int mp_int_t; // must be pointer size
Expand Down
2 changes: 0 additions & 2 deletions ports/pic16bit/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@

#define MICROPY_MAKE_POINTER_CALLABLE(p) ((void *)((mp_uint_t)(p)))

#define UINT_FMT "%u"
#define INT_FMT "%d"
typedef int mp_int_t; // must be pointer size
typedef unsigned int mp_uint_t; // must be pointer size

Expand Down
1 change: 1 addition & 0 deletions ports/powerpc/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
// This port is 64-bit
#define UINT_FMT "%lu"
#define INT_FMT "%ld"
#define HEX_FMT "%lx"
typedef signed long mp_int_t; // must be pointer size
typedef unsigned long mp_uint_t; // must be pointer size

Expand Down
1 change: 1 addition & 0 deletions ports/qemu/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@

#define UINT_FMT "%lu"
#define INT_FMT "%ld"
#define HEX_FMT "%lx"

typedef int32_t mp_int_t; // must be pointer size
typedef uint32_t mp_uint_t; // must be pointer size
Expand Down
2 changes: 0 additions & 2 deletions ports/renesas-ra/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,6 @@

// Assume that if we already defined the obj repr then we also defined these items
#ifndef MICROPY_OBJ_REPR
#define UINT_FMT "%u"
#define INT_FMT "%d"
typedef int mp_int_t; // must be pointer size
typedef unsigned int mp_uint_t; // must be pointer size
#endif
Expand Down
2 changes: 0 additions & 2 deletions ports/stm32/boards/ARDUINO_GIGA/mpconfigboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-giga-r1-wifi"

#define MICROPY_OBJ_REPR (MICROPY_OBJ_REPR_C)
#define UINT_FMT "%u"
#define INT_FMT "%d"
typedef int mp_int_t; // must be pointer size
typedef unsigned int mp_uint_t; // must be pointer size

Expand Down
2 changes: 0 additions & 2 deletions ports/stm32/boards/ARDUINO_NICLA_VISION/mpconfigboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-nicla-vision"

#define MICROPY_OBJ_REPR (MICROPY_OBJ_REPR_C)
#define UINT_FMT "%u"
#define INT_FMT "%d"
typedef int mp_int_t; // must be pointer size
typedef unsigned int mp_uint_t; // must be pointer size

Expand Down
2 changes: 0 additions & 2 deletions ports/stm32/boards/ARDUINO_OPTA/mpconfigboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-opta"

#define MICROPY_OBJ_REPR (MICROPY_OBJ_REPR_C)
#define UINT_FMT "%u"
#define INT_FMT "%d"
typedef int mp_int_t; // must be pointer size
typedef unsigned int mp_uint_t; // must be pointer size

Expand Down
2 changes: 0 additions & 2 deletions ports/stm32/boards/ARDUINO_PORTENTA_H7/mpconfigboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-portenta-h7"

#define MICROPY_OBJ_REPR (MICROPY_OBJ_REPR_C)
#define UINT_FMT "%u"
#define INT_FMT "%d"
typedef int mp_int_t; // must be pointer size
typedef unsigned int mp_uint_t; // must be pointer size

Expand Down
2 changes: 1 addition & 1 deletion ports/stm32/extint.c
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ static mp_obj_t extint_make_new(const mp_obj_type_t *type, size_t n_args, size_t

static void extint_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
extint_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_printf(print, "<ExtInt line=%u>", self->line);
mp_printf(print, "<ExtInt line=%u>", (int)self->line);
}

static const mp_rom_map_elem_t extint_locals_dict_table[] = {
Expand Down
2 changes: 1 addition & 1 deletion ports/stm32/led.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ void led_debug(int n, int delay) {

void led_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
pyb_led_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_printf(print, "LED(%u)", self->led_id);
mp_printf(print, "LED(%u)", (int)self->led_id);
}

/// \classmethod \constructor(id)
Expand Down
2 changes: 1 addition & 1 deletion ports/stm32/machine_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ static void mp_machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_
#endif
{
mp_printf(print, "UART(%u, baudrate=%u, bits=%u, parity=",
self->uart_id, uart_get_baudrate(self), bits);
self->uart_id, uart_get_baudrate(self), (int)bits);
}
if (!(cr1 & USART_CR1_PCE)) {
mp_print_str(print, "None");
Expand Down
2 changes: 0 additions & 2 deletions ports/stm32/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,6 @@ extern const struct _mp_obj_type_t network_lan_type;

// Assume that if we already defined the obj repr then we also defined these items
#ifndef MICROPY_OBJ_REPR
#define UINT_FMT "%u"
#define INT_FMT "%d"
typedef int mp_int_t; // must be pointer size
typedef unsigned int mp_uint_t; // must be pointer size
#endif
Expand Down
1 change: 1 addition & 0 deletions ports/stm32/mpconfigport_nanbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
// Types needed for nan-boxing
#define UINT_FMT "%llu"
#define INT_FMT "%lld"
#define HEX_FMT "%llx"
typedef int64_t mp_int_t;
typedef uint64_t mp_uint_t;

Expand Down
2 changes: 1 addition & 1 deletion ports/stm32/pin.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ static void pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t
mp_uint_t af_idx = pin_get_af(self);
const pin_af_obj_t *af_obj = pin_find_af_by_index(self, af_idx);
if (af_obj == NULL) {
mp_printf(print, ", alt=%d)", af_idx);
mp_printf(print, ", alt=%d)", (int)af_idx);
} else {
mp_printf(print, ", alt=Pin.%q)", af_obj->name);
}
Expand Down
2 changes: 1 addition & 1 deletion ports/stm32/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ static uint32_t compute_dtg_from_ticks(mp_int_t ticks) {

// Given the 8-bit value stored in the DTG field of the BDTR register, compute
// the number of ticks.
static mp_int_t compute_ticks_from_dtg(uint32_t dtg) {
static unsigned compute_ticks_from_dtg(uint32_t dtg) {
if ((dtg & 0x80) == 0) {
return dtg & 0x7F;
}
Expand Down
61 changes: 33 additions & 28 deletions ports/unix/coverage.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,13 @@ static void pairheap_test(size_t nops, int *ops) {
if (mp_pairheap_is_empty(pairheap_lt, heap)) {
mp_printf(&mp_plat_print, " -");
} else {
mp_printf(&mp_plat_print, " %d", mp_pairheap_peek(pairheap_lt, heap) - &node[0]);
mp_printf(&mp_plat_print, " %d", (int)(mp_pairheap_peek(pairheap_lt, heap) - &node[0]));
;
}
}
mp_printf(&mp_plat_print, "\npop all:");
while (!mp_pairheap_is_empty(pairheap_lt, heap)) {
mp_printf(&mp_plat_print, " %d", mp_pairheap_peek(pairheap_lt, heap) - &node[0]);
mp_printf(&mp_plat_print, " %d", (int)(mp_pairheap_peek(pairheap_lt, heap) - &node[0]));
;
heap = mp_pairheap_pop(pairheap_lt, heap);
}
Expand All @@ -203,7 +203,7 @@ static mp_obj_t extra_coverage(void) {
mp_printf(&mp_plat_print, "# mp_printf\n");
mp_printf(&mp_plat_print, "%d %+d % d\n", -123, 123, 123); // sign
mp_printf(&mp_plat_print, "%05d\n", -123); // negative number with zero padding
mp_printf(&mp_plat_print, "%ld\n", 123); // long
mp_printf(&mp_plat_print, "%ld\n", 123l); // long
mp_printf(&mp_plat_print, "%lx\n", 0x123fl); // long hex
mp_printf(&mp_plat_print, "%lX\n", 0x123fl); // capital long hex
if (sizeof(mp_int_t) == 8) {
Expand All @@ -212,13 +212,13 @@ static mp_obj_t extra_coverage(void) {
mp_printf(&mp_plat_print, "%llu\n", ULLONG_MAX); // unsigned long long
} else {
// fake for platforms without narrower mp_int_t
mp_printf(&mp_plat_print, "7fffffffffffffff\n", LLONG_MAX);
mp_printf(&mp_plat_print, "7FFFFFFFFFFFFFFF\n", LLONG_MAX);
mp_printf(&mp_plat_print, "18446744073709551615\n", ULLONG_MAX);
mp_printf(&mp_plat_print, "7fffffffffffffff\n");
mp_printf(&mp_plat_print, "7FFFFFFFFFFFFFFF\n");
mp_printf(&mp_plat_print, "18446744073709551615\n");
}
mp_printf(&mp_plat_print, "%p\n", (void *)0x789f); // pointer
mp_printf(&mp_plat_print, "%P\n", (void *)0x789f); // pointer uppercase
mp_printf(&mp_plat_print, "%.2s %.3s '%4.4s' '%5.5q' '%.3q'\n", "abc", "abc", "abc", MP_QSTR_True, MP_QSTR_True); // fixed string precision
mp_printf(&mp_plat_print, "%.2s %.3s '%4.4s' '%5.5q' '%.3q'\n", "abc", "abc", "abc", (qstr)MP_QSTR_True, (qstr)MP_QSTR_True); // fixed string precision
mp_printf(&mp_plat_print, "%.*s\n", -1, "abc"); // negative string precision
mp_printf(&mp_plat_print, "%b %b\n", 0, 1); // bools
#ifndef NDEBUG
Expand All @@ -230,7 +230,12 @@ static mp_obj_t extra_coverage(void) {
mp_printf(&mp_plat_print, "%u\n", 0x80000000); // should print unsigned
mp_printf(&mp_plat_print, "%x\n", 0x8000000f); // should print unsigned
mp_printf(&mp_plat_print, "%X\n", 0x8000000f); // should print unsigned
mp_printf(&mp_plat_print, "abc\n%"); // string ends in middle of format specifier
// note: storing the string in a variable is enough to prevent the
// format string checker from checking this format string. Otherwise,
// it would be a compile time diagnostic under the format string
// checker.
const char msg[] = "abc\n%";
mp_printf(&mp_plat_print, msg); // string ends in middle of format specifier
mp_printf(&mp_plat_print, "%%\n"); // literal % character
mp_printf(&mp_plat_print, ".%-3s.\n", "a"); // left adjust

Expand Down Expand Up @@ -269,7 +274,7 @@ static mp_obj_t extra_coverage(void) {
mp_printf(&mp_plat_print, "%p\n", gc_realloc(p, 0, false));

// calling gc_nbytes with a non-heap pointer
mp_printf(&mp_plat_print, "%p\n", gc_nbytes(NULL));
mp_printf(&mp_plat_print, "%d\n", (int)gc_nbytes(NULL));
}

// GC initialisation and allocation stress test, to check the logic behind ALLOC_TABLE_GAP_BYTE
Expand Down Expand Up @@ -330,7 +335,7 @@ static mp_obj_t extra_coverage(void) {
}
ptrs[i][j] = j;
}
mp_printf(&mp_plat_print, "%d %d\n", i, all_zero);
mp_printf(&mp_plat_print, "%d %d\n", (int)i, (int)all_zero);

// hide the pointer from the GC and collect
ptrs[i] = FLIP_POINTER(ptrs[i]);
Expand All @@ -346,7 +351,7 @@ static mp_obj_t extra_coverage(void) {
break;
}
}
mp_printf(&mp_plat_print, "%d %d\n", i, correct_contents);
mp_printf(&mp_plat_print, "%d %d\n", (int)i, (int)correct_contents);
}

// free the memory blocks
Expand Down Expand Up @@ -444,7 +449,7 @@ static mp_obj_t extra_coverage(void) {
// create a bytearray via mp_obj_new_bytearray
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(mp_obj_new_bytearray(4, "data"), &bufinfo, MP_BUFFER_RW);
mp_printf(&mp_plat_print, "%.*s\n", bufinfo.len, bufinfo.buf);
mp_printf(&mp_plat_print, "%.*s\n", (int)bufinfo.len, bufinfo.buf);
}

// mpz
Expand Down Expand Up @@ -511,33 +516,33 @@ static mp_obj_t extra_coverage(void) {

// hash the zero mpz integer
mpz_set_from_int(&mpz, 0);
mp_printf(&mp_plat_print, "%d\n", mpz_hash(&mpz));
mp_printf(&mp_plat_print, "%d\n", (int)mpz_hash(&mpz));

// convert the mpz zero integer to int
mp_printf(&mp_plat_print, "%d\n", mpz_as_int_checked(&mpz, &value_signed));
mp_printf(&mp_plat_print, "%d\n", value_signed);
mp_printf(&mp_plat_print, "%d\n", (int)value_signed);

// mpz_set_from_float with 0 as argument
mpz_set_from_float(&mpz, 0);
mp_printf(&mp_plat_print, "%f\n", mpz_as_float(&mpz));

// convert a large integer value (stored in a mpz) to mp_uint_t and to ll;
mp_obj_t obj_bigint = mp_obj_new_int_from_uint((mp_uint_t)0xdeadbeef);
mp_printf(&mp_plat_print, "%x\n", mp_obj_get_uint(obj_bigint));
mp_printf(&mp_plat_print, "%x\n", (int)mp_obj_get_uint(obj_bigint));
obj_bigint = mp_obj_new_int_from_ll(0xc0ffee777c0ffeell);
long long value_ll = mp_obj_get_ll(obj_bigint);
mp_printf(&mp_plat_print, "%x%08x\n", (uint32_t)(value_ll >> 32), (uint32_t)value_ll);

// convert a large integer value (stored via a struct object) to uint and to ll
// `deadbeef` global is an uctypes.struct defined by extra_coverage.py
obj_bigint = mp_load_global(MP_QSTR_deadbeef);
mp_printf(&mp_plat_print, "%x\n", mp_obj_get_uint(obj_bigint));
mp_printf(&mp_plat_print, "%x\n", (int)mp_obj_get_uint(obj_bigint));
value_ll = mp_obj_get_ll(obj_bigint);
mp_printf(&mp_plat_print, "%x%08x\n", (uint32_t)(value_ll >> 32), (uint32_t)value_ll);

// convert a smaller integer value to mp_uint_t and to ll
obj_bigint = mp_obj_new_int_from_uint(0xc0ffee);
mp_printf(&mp_plat_print, "%x\n", mp_obj_get_uint(obj_bigint));
mp_printf(&mp_plat_print, "%x\n", (int)mp_obj_get_uint(obj_bigint));
value_ll = mp_obj_get_ll(obj_bigint);
mp_printf(&mp_plat_print, "%x%08x\n", (uint32_t)(value_ll >> 32), (uint32_t)value_ll);
}
Expand All @@ -557,7 +562,7 @@ static mp_obj_t extra_coverage(void) {
mp_call_function_2_protected(MP_OBJ_FROM_PTR(&mp_builtin_divmod_obj), mp_obj_new_str_from_cstr("abc"), mp_obj_new_str_from_cstr("abc"));

// mp_obj_int_get_checked with mp_obj_int_t that has a value that is a small integer
mp_printf(&mp_plat_print, "%d\n", mp_obj_int_get_checked(MP_OBJ_FROM_PTR(mp_obj_int_new_mpz())));
mp_printf(&mp_plat_print, "%d\n", (int)mp_obj_int_get_checked(MP_OBJ_FROM_PTR(mp_obj_int_new_mpz())));

// mp_obj_int_get_uint_checked with non-negative small-int
mp_printf(&mp_plat_print, "%d\n", (int)mp_obj_int_get_uint_checked(MP_OBJ_NEW_SMALL_INT(1)));
Expand Down Expand Up @@ -669,7 +674,7 @@ static mp_obj_t extra_coverage(void) {
#endif

mp_vm_return_kind_t ret = mp_execute_bytecode(code_state, MP_OBJ_NULL);
mp_printf(&mp_plat_print, "%d %d\n", ret, mp_obj_get_type(code_state->state[0]) == &mp_type_NotImplementedError);
mp_printf(&mp_plat_print, "%d %d\n", (int)ret, mp_obj_get_type(code_state->state[0]) == &mp_type_NotImplementedError);
}

// scheduler
Expand Down Expand Up @@ -749,36 +754,36 @@ static mp_obj_t extra_coverage(void) {
mp_printf(&mp_plat_print, "# ringbuf\n");

// Single-byte put/get with empty ringbuf.
mp_printf(&mp_plat_print, "%d %d\n", ringbuf_free(&ringbuf), ringbuf_avail(&ringbuf));
mp_printf(&mp_plat_print, "%d %d\n", (int)ringbuf_free(&ringbuf), (int)ringbuf_avail(&ringbuf));
ringbuf_put(&ringbuf, 22);
mp_printf(&mp_plat_print, "%d %d\n", ringbuf_free(&ringbuf), ringbuf_avail(&ringbuf));
mp_printf(&mp_plat_print, "%d %d\n", (int)ringbuf_free(&ringbuf), (int)ringbuf_avail(&ringbuf));
mp_printf(&mp_plat_print, "%d\n", ringbuf_get(&ringbuf));
mp_printf(&mp_plat_print, "%d %d\n", ringbuf_free(&ringbuf), ringbuf_avail(&ringbuf));
mp_printf(&mp_plat_print, "%d %d\n", (int)ringbuf_free(&ringbuf), (int)ringbuf_avail(&ringbuf));

// Two-byte put/get with empty ringbuf.
ringbuf_put16(&ringbuf, 0xaa55);
mp_printf(&mp_plat_print, "%d %d\n", ringbuf_free(&ringbuf), ringbuf_avail(&ringbuf));
mp_printf(&mp_plat_print, "%d %d\n", (int)ringbuf_free(&ringbuf), (int)ringbuf_avail(&ringbuf));
mp_printf(&mp_plat_print, "%04x\n", ringbuf_get16(&ringbuf));
mp_printf(&mp_plat_print, "%d %d\n", ringbuf_free(&ringbuf), ringbuf_avail(&ringbuf));
mp_printf(&mp_plat_print, "%d %d\n", (int)ringbuf_free(&ringbuf), (int)ringbuf_avail(&ringbuf));

// Two-byte put with full ringbuf.
for (int i = 0; i < 99; ++i) {
ringbuf_put(&ringbuf, i);
}
mp_printf(&mp_plat_print, "%d %d\n", ringbuf_free(&ringbuf), ringbuf_avail(&ringbuf));
mp_printf(&mp_plat_print, "%d %d\n", (int)ringbuf_free(&ringbuf), (int)ringbuf_avail(&ringbuf));
mp_printf(&mp_plat_print, "%d\n", ringbuf_put16(&ringbuf, 0x11bb));
// Two-byte put with one byte free.
ringbuf_get(&ringbuf);
mp_printf(&mp_plat_print, "%d %d\n", ringbuf_free(&ringbuf), ringbuf_avail(&ringbuf));
mp_printf(&mp_plat_print, "%d %d\n", (int)ringbuf_free(&ringbuf), (int)ringbuf_avail(&ringbuf));
mp_printf(&mp_plat_print, "%d\n", ringbuf_put16(&ringbuf, 0x3377));
ringbuf_get(&ringbuf);
mp_printf(&mp_plat_print, "%d %d\n", ringbuf_free(&ringbuf), ringbuf_avail(&ringbuf));
mp_printf(&mp_plat_print, "%d %d\n", (int)ringbuf_free(&ringbuf), (int)ringbuf_avail(&ringbuf));
mp_printf(&mp_plat_print, "%d\n", ringbuf_put16(&ringbuf, 0xcc99));
for (int i = 0; i < 97; ++i) {
ringbuf_get(&ringbuf);
}
mp_printf(&mp_plat_print, "%04x\n", ringbuf_get16(&ringbuf));
mp_printf(&mp_plat_print, "%d %d\n", ringbuf_free(&ringbuf), ringbuf_avail(&ringbuf));
mp_printf(&mp_plat_print, "%d %d\n", (int)ringbuf_free(&ringbuf), (int)ringbuf_avail(&ringbuf));

// Two-byte put with wrap around on first byte:
ringbuf.iput = 0;
Expand Down
1 change: 1 addition & 0 deletions ports/unix/variants/nanbox/mpconfigvariant.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@ typedef int64_t mp_int_t;
typedef uint64_t mp_uint_t;
#define UINT_FMT "%llu"
#define INT_FMT "%lld"
#define HEX_FMT "%llx"
Loading
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy