8000 py/runtime: Use size_t/ssize_t instead of uint/int. · micropython/micropython@2e3f204 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2e3f204

Browse files
dlechdpgeorge
authored andcommitted
py/runtime: Use size_t/ssize_t instead of uint/int.
This replaces instances of uint with size_t and int with ssize_t in the mp_call_prepare_args_n_kw_var() function since all of the variables are used as array offsets. Also sort headers while we are touching this. Signed-off-by: David Lechner <david@pybricks.com>
1 parent 4768518 commit 2e3f204

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

py/runtime.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@
2525
* THE SOFTWARE.
2626
*/
2727

28+
#include <assert.h>
2829
#include <stdarg.h>
2930
#include <stdio.h>
3031
#include <string.h>
31-
#include <assert.h>
32+
#include <unistd.h>
3233

3334
#include "py/parsenum.h"
3435
#include "py/compile.h"
@@ -699,8 +700,8 @@ void mp_call_prepare_args_n_kw_var(bool have_self, size_t n_args_n_kw, const mp_
699700
if (have_self) {
700701
self = *args++; // may be MP_OBJ_NULL
701702
}
702-
uint n_args = n_args_n_kw & 0xff;
703-
uint n_kw = (n_args_n_kw >> 8) & 0xff;
703+
size_t n_args = n_args_n_kw & 0xff;
704+
size_t n_kw = (n_args_n_kw >> 8) & 0xff;
704705
mp_uint_t star_args = mp_obj_get_int_truncated(args[n_args + 2 * n_kw]);
705706

706707
DEBUG_OP_printf("call method var (fun=%p, self=%p, n_args=%u, n_kw=%u, args=%p, map=%u)\n", fun, self, n_args, n_kw, args, star_args);
@@ -711,14 +712,14 @@ void mp_call_prepare_args_n_kw_var(bool have_self, size_t n_args_n_kw, const mp_
711712

712713
// The new args array
713714
mp_obj_t *args2;
714-
uint args2_alloc;
715-
uint args2_len = 0;
715+
size_t args2_alloc;
716+
size_t args2_len = 0;
716717

717718
// Try to get a hint for unpacked * args length
718-
int list_len = 0;
719+
ssize_t list_len = 0;
719720

720721
if (star_args != 0) {
721-
for (uint i = 0; i < n_args; i++) {
722+
for (size_t i = 0; i < n_args; i++) {
722723
if (star_args & (1 << i)) {
723724
mp_obj_t len = mp_obj_len_maybe(args[i]);
724725
if (len != MP_OBJ_NULL) {
@@ -730,9 +731,9 @@ void mp_call_prepare_args_n_kw_var(bool have_self, size_t n_args_n_kw, const mp_
730731
}
731732

732733
// Try to get a hint for the size of the kw_dict
733-
int kw_dict_len = 0;
734+
ssize_t kw_dict_len = 0;
734735

735-
for (uint i = 0; i < n_kw; i++) {
736+
for (size_t i = 0; i < n_kw; i++) {
736737
mp_obj_t key = args[n_args + i * 2];
737738
mp_obj_t value = args[n_args + i * 2 + 1];
738739
if (key == MP_OBJ_NULL && value != MP_OBJ_NULL && mp_obj_is_type(value, &mp_type_dict)) {
@@ -770,7 +771,7 @@ void mp_call_prepare_args_n_kw_var(bool have_self, size_t n_args_n_kw, const mp_
770771
args2[args2_len++] = self;
771772
}
772773

773-
for (uint i = 0; i < n_args; i++) {
774+
for (size_t i = 0; i < n_args; i++) {
774775
mp_obj_t arg = args[i];
775776
if (star_args & (1 << i)) {
776777
// star arg
@@ -811,18 +812,18 @@ void mp_call_prepare_args_n_kw_var(bool have_self, size_t n_args_n_kw, const mp_
811812
}
812813

813814
// The size of the args2 array now is the number of positional args.
814-
uint pos_args_len = args2_len;
815+
size_t pos_args_len = args2_len;
815816

816817
// ensure there is still enough room for kw args
817818
if (args2_len + 2 * (n_kw + kw_dict_len) > args2_alloc) {
818-
uint new_alloc = args2_len + 2 * (n_kw + kw_dict_len);
819+
size_t new_alloc = args2_len + 2 * (n_kw + kw_dict_len);
819820
args2 = mp_nonlocal_realloc(args2, args2_alloc * sizeof(mp_obj_t),
820821
new_alloc * sizeof(mp_obj_t));
821822
args2_alloc = new_alloc;
822823
}
823824

824825
// Copy the kw args.
825-
for (uint i = 0; i < n_kw; i++) {
826+
for (size_t i = 0; i < n_kw; i++) {
826827
mp_obj_t kw_key = args[n_args + i * 2];
827828
mp_obj_t kw_value = args[n_args + i * 2 + 1];
828829
if (kw_key == MP_OBJ_NULL) {
@@ -859,7 +860,7 @@ void mp_call_prepare_args_n_kw_var(bool have_self, size_t n_args_n_kw, const mp_
859860
while ((key = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) {
860861
// expand size of args array if needed
861862
if (args2_len + 1 >= args2_alloc) {
862-
uint new_alloc = args2_alloc * 2;
863+
size_t new_alloc = args2_alloc * 2;
863864
args2 = mp_nonlocal_realloc(args2, args2_alloc * sizeof(mp_obj_t), new_alloc * sizeof(mp_obj_t));
864865
args2_alloc = new_alloc;
865866
}

0 commit comments

Comments
 (0)
0