Commit 4b72b3a1 authored by Damien George's avatar Damien George
Browse files

py: Change type signature of builtin funs that take variable or kw args.

With this patch the n_args parameter is changed type from mp_uint_t to
size_t.
parent a0c97814
......@@ -546,12 +546,12 @@ STATIC inline mp_obj_t str_split_internal(mp_uint_t n_args, const mp_obj_t *args
return res;
}
mp_obj_t mp_obj_str_split(mp_uint_t n_args, const mp_obj_t *args) {
mp_obj_t mp_obj_str_split(size_t n_args, const mp_obj_t *args) {
return str_split_internal(n_args, args, SPLIT);
}
#if MICROPY_PY_BUILTINS_STR_SPLITLINES
STATIC mp_obj_t str_splitlines(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
STATIC mp_obj_t str_splitlines(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_keepends, MP_ARG_BOOL, {.u_bool = false} },
};
......@@ -565,7 +565,7 @@ STATIC mp_obj_t str_splitlines(mp_uint_t n_args, const mp_obj_t *pos_args, mp_ma
}
#endif
STATIC mp_obj_t str_rsplit(mp_uint_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t str_rsplit(size_t n_args, const mp_obj_t *args) {
if (n_args < 3) {
// If we don't have split limit, it doesn't matter from which side
// we split.
......@@ -667,24 +667,24 @@ STATIC mp_obj_t str_finder(mp_uint_t n_args, const mp_obj_t *args, mp_int_t dire
}
}
STATIC mp_obj_t str_find(mp_uint_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t str_find(size_t n_args, const mp_obj_t *args) {
return str_finder(n_args, args, 1, false);
}
STATIC mp_obj_t str_rfind(mp_uint_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t str_rfind(size_t n_args, const mp_obj_t *args) {
return str_finder(n_args, args, -1, false);
}
STATIC mp_obj_t str_index(mp_uint_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t str_index(size_t n_args, const mp_obj_t *args) {
return str_finder(n_args, args, 1, true);
}
STATIC mp_obj_t str_rindex(mp_uint_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t str_rindex(size_t n_args, const mp_obj_t *args) {
return str_finder(n_args, args, -1, true);
}
// TODO: (Much) more variety in args
STATIC mp_obj_t str_startswith(mp_uint_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t str_startswith(size_t n_args, const mp_obj_t *args) {
const mp_obj_type_t *self_type = mp_obj_get_type(args[0]);
GET_STR_DATA_LEN(args[0], str, str_len);
GET_STR_DATA_LEN(args[1], prefix, prefix_len);
......@@ -698,7 +698,7 @@ STATIC mp_obj_t str_startswith(mp_uint_t n_args, const mp_obj_t *args) {
return mp_obj_new_bool(memcmp(start, prefix, prefix_len) == 0);
}
STATIC mp_obj_t str_endswith(mp_uint_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t str_endswith(size_t n_args, const mp_obj_t *args) {
GET_STR_DATA_LEN(args[0], str, str_len);
GET_STR_DATA_LEN(args[1], suffix, suffix_len);
if (n_args > 2) {
......@@ -785,15 +785,15 @@ STATIC mp_obj_t str_uni_strip(int type, mp_uint_t n_args, const mp_obj_t *args)
return mp_obj_new_str_of_type(self_type, orig_str + first_good_char_pos, stripped_len);
}
STATIC mp_obj_t str_strip(mp_uint_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t str_strip(size_t n_args, const mp_obj_t *args) {
return str_uni_strip(STRIP, n_args, args);
}
STATIC mp_obj_t str_lstrip(mp_uint_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t str_lstrip(size_t n_args, const mp_obj_t *args) {
return str_uni_strip(LSTRIP, n_args, args);
}
STATIC mp_obj_t str_rstrip(mp_uint_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t str_rstrip(size_t n_args, const mp_obj_t *args) {
return str_uni_strip(RSTRIP, n_args, args);
}
......@@ -845,7 +845,7 @@ STATIC NORETURN void terse_str_format_value_error(void) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "bad format string"));
}
mp_obj_t mp_obj_str_format(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
mp_obj_t mp_obj_str_format(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
assert(MP_OBJ_IS_STR_OR_BYTES(args[0]));
GET_STR_DATA_LEN(args[0], str, len);
......@@ -1486,7 +1486,7 @@ not_enough_args:
// The implementation is optimized, returning the original string if there's
// nothing to replace.
STATIC mp_obj_t str_replace(mp_uint_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t str_replace(size_t n_args, const mp_obj_t *args) {
assert(MP_OBJ_IS_STR_OR_BYTES(args[0]));
mp_int_t max_rep = -1;
......@@ -1591,7 +1591,7 @@ STATIC mp_obj_t str_replace(mp_uint_t n_args, const mp_obj_t *args) {
return mp_obj_new_str_from_vstr(self_type, &vstr);
}
STATIC mp_obj_t str_count(mp_uint_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t str_count(size_t n_args, const mp_obj_t *args) {
const mp_obj_type_t *self_type = mp_obj_get_type(args[0]);
assert(2 <= n_args && n_args <= 4);
assert(MP_OBJ_IS_STR_OR_BYTES(args[0]));
......@@ -1759,7 +1759,7 @@ STATIC mp_obj_t str_islower(mp_obj_t self_in) {
// These methods are superfluous in the presense of str() and bytes()
// constructors.
// TODO: should accept kwargs too
STATIC mp_obj_t bytes_decode(mp_uint_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t bytes_decode(size_t n_args, const mp_obj_t *args) {
mp_obj_t new_args[2];
if (n_args == 1) {
new_args[0] = args[0];
......@@ -1771,7 +1771,7 @@ STATIC mp_obj_t bytes_decode(mp_uint_t n_args, const mp_obj_t *args) {
}
// TODO: should accept kwargs too
STATIC mp_obj_t str_encode(mp_uint_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t str_encode(size_t n_args, const mp_obj_t *args) {
mp_obj_t new_args[2];
if (n_args == 1) {
new_args[0] = args[0];
......
......@@ -62,8 +62,8 @@ const byte *mp_obj_str_get_data_no_check(mp_obj_t self_in, size_t *len);
mp_obj_t mp_obj_str_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args);
void mp_str_print_json(const mp_print_t *print, const byte *str_data, size_t str_len);
mp_obj_t mp_obj_str_format(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kwargs);
mp_obj_t mp_obj_str_split(mp_uint_t n_args, const mp_obj_t *args);
mp_obj_t mp_obj_str_format(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs);
mp_obj_t mp_obj_str_split(size_t n_args, const mp_obj_t *args);
mp_obj_t mp_obj_new_str_of_type(const mp_obj_type_t *type, const byte* data, size_t len);
mp_obj_t mp_obj_str_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in);
......
......@@ -114,7 +114,7 @@ STATIC mp_obj_t stringio_close(mp_obj_t self_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(stringio_close_obj, stringio_close);
STATIC mp_obj_t stringio___exit__(mp_uint_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t stringio___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args;
return stringio_close(args[0]);
}
......
......@@ -208,7 +208,7 @@ STATIC mp_obj_t tuple_count(mp_obj_t self_in, mp_obj_t value) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(tuple_count_obj, tuple_count);
STATIC mp_obj_t tuple_index(mp_uint_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t tuple_index(size_t n_args, const mp_obj_t *args) {
assert(MP_OBJ_IS_TYPE(args[0], &mp_type_tuple));
mp_obj_tuple_t *self = MP_OBJ_TO_PTR(args[0]);
return mp_seq_index_obj(self->items, self->len, n_args, args);
......
......@@ -62,7 +62,7 @@ const mp_stream_p_t *mp_get_stream_raise(mp_obj_t self_in, int flags) {
return stream_p;
}
STATIC mp_obj_t stream_read(mp_uint_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t stream_read(size_t n_args, const mp_obj_t *args) {
const mp_stream_p_t *stream_p = mp_get_stream_raise(args[0], MP_STREAM_OP_READ);
// What to do if sz < -1? Python docs don't specify this case.
......@@ -214,7 +214,7 @@ STATIC mp_obj_t stream_write_method(mp_obj_t self_in, mp_obj_t arg) {
return mp_stream_write(self_in, bufinfo.buf, bufinfo.len);
}
STATIC mp_obj_t stream_readinto(mp_uint_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t stream_readinto(size_t n_args, const mp_obj_t *args) {
const mp_stream_p_t *stream_p = mp_get_stream_raise(args[0], MP_STREAM_OP_READ);
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(args[1], &bufinfo, MP_BUFFER_WRITE);
......@@ -287,7 +287,7 @@ STATIC mp_obj_t stream_readall(mp_obj_t self_in) {
}
// Unbuffered, inefficient implementation of readline() for raw I/O files.
STATIC mp_obj_t stream_unbuffered_readline(mp_uint_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t stream_unbuffered_readline(size_t n_args, const mp_obj_t *args) {
const mp_stream_p_t *stream_p = mp_get_stream_raise(args[0], MP_STREAM_OP_READ);
mp_int_t max_size = -1;
......@@ -365,7 +365,7 @@ mp_obj_t mp_stream_unbuffered_iter(mp_obj_t self) {
return MP_OBJ_STOP_ITERATION;
}
STATIC mp_obj_t stream_seek(mp_uint_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t stream_seek(size_t n_args, const mp_obj_t *args) {
const mp_stream_p_t *stream_p = mp_get_stream_raise(args[0], MP_STREAM_OP_IOCTL);
struct mp_stream_seek_t seek_s;
......
......@@ -52,7 +52,7 @@ mp_import_stat_t mp_import_stat(const char *path) {
return MP_IMPORT_STAT_NO_EXIST;
}
mp_obj_t mp_builtin_open(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);
......
......@@ -82,7 +82,7 @@ mp_import_stat_t mp_import_stat(const char *path) {
return MP_IMPORT_STAT_NO_EXIST;
}
mp_obj_t mp_builtin_open(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);
......
......@@ -130,7 +130,7 @@ STATIC mp_obj_t fdfile_close(mp_obj_t self_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(fdfile_close_obj, fdfile_close);
STATIC mp_obj_t fdfile___exit__(mp_uint_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t fdfile___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args;
return fdfile_close(args[0]);
}
......@@ -264,7 +264,7 @@ const mp_obj_type_t mp_type_textio = {
};
// Factory function for I/O stream classes
mp_obj_t mp_builtin_open(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
// TODO: analyze buffering args and instantiate appropriate type
mp_arg_val_t arg_vals[FILE_OPEN_NUM_ARGS];
mp_arg_parse_all(n_args, args, kwargs, FILE_OPEN_NUM_ARGS, file_open_args, arg_vals);
......
......@@ -158,7 +158,7 @@ void prompt_write_history(void) {
#endif
}
STATIC mp_obj_t mp_builtin_input(mp_uint_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t mp_builtin_input(size_t n_args, const mp_obj_t *args) {
if (n_args == 1) {
mp_obj_print(args[0], PRINT_STR);
}
......
......@@ -208,7 +208,7 @@ STATIC mp_obj_t make_func(mp_obj_t rettype_in, void *func, mp_obj_t argtypes_in)
return MP_OBJ_FROM_PTR(o);
}
STATIC mp_obj_t ffimod_func(mp_uint_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t ffimod_func(size_t n_args, const mp_obj_t *args) {
(void)n_args; // always 4
mp_obj_ffimod_t *self = MP_OBJ_TO_PTR(args[0]);
const char *symname = mp_obj_str_get_str(args[2]);
......@@ -477,7 +477,7 @@ STATIC const mp_obj_type_t opaque_type = {
};
*/
STATIC mp_obj_t mod_ffi_open(mp_uint_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t mod_ffi_open(size_t n_args, const mp_obj_t *args) {
return ffimod_make_new((mp_obj_t)&ffimod_type, n_args, 0, args);
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_ffi_open_obj, 1, 2, mod_ffi_open);
......
......@@ -193,7 +193,7 @@ STATIC mp_obj_t listdir_next(mp_obj_t self_in) {
return MP_OBJ_FROM_PTR(t);
}
STATIC mp_obj_t mod_os_ilistdir(mp_uint_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t mod_os_ilistdir(size_t n_args, const mp_obj_t *args) {
const char *path = ".";
if (n_args > 0) {
path = mp_obj_str_get_str(args[0]);
......@@ -206,7 +206,7 @@ STATIC mp_obj_t mod_os_ilistdir(mp_uint_t n_args, const mp_obj_t *args) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_os_ilistdir_obj, 0, 1, mod_os_ilistdir);
STATIC mp_obj_t mod_os_errno(mp_uint_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t mod_os_errno(size_t n_args, const mp_obj_t *args) {
if (n_args == 0) {
return MP_OBJ_NEW_SMALL_INT(errno);
}
......
......@@ -171,7 +171,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(socket_accept_obj, socket_accept);
// Note: besides flag param, this differs from read() in that
// this does not swallow blocking errors (EAGAIN, EWOULDBLOCK) -
// these would be thrown as exceptions.
STATIC mp_obj_t socket_recv(mp_uint_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t socket_recv(size_t n_args, const mp_obj_t *args) {
mp_obj_socket_t *self = MP_OBJ_TO_PTR(args[0]);
int sz = MP_OBJ_SMALL_INT_VALUE(args[1]);
int flags = 0;
......@@ -190,7 +190,7 @@ STATIC mp_obj_t socket_recv(mp_uint_t n_args, const mp_obj_t *args) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_recv_obj, 2, 3, socket_recv);
STATIC mp_obj_t socket_recvfrom(mp_uint_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t socket_recvfrom(size_t n_args, const mp_obj_t *args) {
mp_obj_socket_t *self = MP_OBJ_TO_PTR(args[0]);
int sz = MP_OBJ_SMALL_INT_VALUE(args[1]);
int flags = 0;
......@@ -220,7 +220,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_recvfrom_obj, 2, 3, socket_rec
// Note: besides flag param, this differs from write() in that
// this does not swallow blocking errors (EAGAIN, EWOULDBLOCK) -
// these would be thrown as exceptions.
STATIC mp_obj_t socket_send(mp_uint_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t socket_send(size_t n_args, const mp_obj_t *args) {
mp_obj_socket_t *self = MP_OBJ_TO_PTR(args[0]);
int flags = 0;
......@@ -237,7 +237,7 @@ STATIC mp_obj_t socket_send(mp_uint_t n_args, const mp_obj_t *args) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_send_obj, 2, 3, socket_send);
STATIC mp_obj_t socket_sendto(mp_uint_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t socket_sendto(size_t n_args, const mp_obj_t *args) {
mp_obj_socket_t *self = MP_OBJ_TO_PTR(args[0]);
int flags = 0;
......@@ -258,7 +258,7 @@ STATIC mp_obj_t socket_sendto(mp_uint_t n_args, const mp_obj_t *args) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_sendto_obj, 3, 4, socket_sendto);
STATIC mp_obj_t socket_setsockopt(mp_uint_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t socket_setsockopt(size_t n_args, const mp_obj_t *args) {
(void)n_args; // always 4
mp_obj_socket_t *self = MP_OBJ_TO_PTR(args[0]);
int level = MP_OBJ_SMALL_INT_VALUE(args[1]);
......@@ -299,7 +299,7 @@ STATIC mp_obj_t socket_setblocking(mp_obj_t self_in, mp_obj_t flag_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_setblocking_obj, socket_setblocking);
STATIC mp_obj_t socket_makefile(mp_uint_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t socket_makefile(size_t n_args, const mp_obj_t *args) {
// TODO: CPython explicitly says that closing returned object doesn't close
// the original socket (Python2 at all says that fd is dup()ed). But we
// save on the bloat.
......@@ -421,7 +421,7 @@ STATIC mp_obj_t mod_socket_inet_pton(mp_obj_t family_in, mp_obj_t addr_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_socket_inet_pton_obj, mod_socket_inet_pton);
STATIC mp_obj_t mod_socket_getaddrinfo(mp_uint_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t mod_socket_getaddrinfo(size_t n_args, const mp_obj_t *args) {
// TODO: Implement all args
assert(n_args >= 2 && n_args <= 4);
assert(MP_OBJ_IS_STR(args[0]));
......
......@@ -154,7 +154,7 @@ STATIC mp_obj_t mod_time_sleep_us(mp_obj_t arg) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_time_sleep_us_obj, mod_time_sleep_us);
STATIC mp_obj_t mod_time_strftime(mp_uint_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t mod_time_strftime(size_t n_args, const mp_obj_t *args) {
time_t t;
if (n_args == 1) {
t = time(NULL);
......
......@@ -52,7 +52,7 @@ typedef struct _mp_obj_poll_t {
} mp_obj_poll_t;
/// \method register(obj[, eventmask])
STATIC mp_obj_t poll_register(mp_uint_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t poll_register(size_t n_args, const mp_obj_t *args) {
mp_obj_poll_t *self = MP_OBJ_TO_PTR(args[0]);
int fd = mp_obj_get_int(args[1]);
mp_uint_t flags;
......@@ -129,7 +129,7 @@ MP_DEFINE_CONST_FUN_OBJ_3(poll_modify_obj, poll_modify);
/// \method poll([timeout])
/// Timeout is in milliseconds.
STATIC mp_obj_t poll_poll(mp_uint_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t poll_poll(size_t n_args, const mp_obj_t *args) {
mp_obj_poll_t *self = MP_OBJ_TO_PTR(args[0]);
// work out timeout (it's given already in ms)
......@@ -186,7 +186,7 @@ STATIC const mp_obj_type_t mp_type_poll = {
.locals_dict = (void*)&poll_locals_dict,
};
STATIC mp_obj_t select_poll(mp_uint_t n_args, const mp_obj_t *args) {
STATIC mp_obj_t select_poll(size_t n_args, const mp_obj_t *args) {
int alloc = 4;
if (n_args > 0) {
alloc = mp_obj_get_int(args[0]);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment