py: For malloc and vstr functions, use size_t exclusively for int type.

It seems most sensible to use size_t for measuring "number of bytes" in
malloc and vstr functions (since that's what size_t is for).  We don't
use mp_uint_t because malloc and vstr are not Micro Python specific.
This commit is contained in:
Damien George
2014-09-23 18:10:17 +01:00
parent ac04a8a56a
commit b0261341d3
5 changed files with 80 additions and 101 deletions

View File

@@ -54,9 +54,9 @@
#include "stackctrl.h"
// Command line options, with their defaults
bool compile_only = false;
uint emit_opt = MP_EMIT_OPT_NONE;
uint mp_verbose_flag;
STATIC bool compile_only = false;
STATIC uint emit_opt = MP_EMIT_OPT_NONE;
mp_uint_t mp_verbose_flag = 0;
#if MICROPY_ENABLE_GC
// Heap size of GC heap (if enabled)
@@ -222,8 +222,9 @@ int usage(char **argv) {
return 1;
}
#if MICROPY_MEM_STATS
STATIC mp_obj_t mem_info(void) {
printf("mem: total=%d, current=%d, peak=%d\n",
printf("mem: total=" UINT_FMT ", current=" UINT_FMT ", peak=" UINT_FMT "\n",
m_get_total_bytes_allocated(), m_get_current_bytes_allocated(), m_get_peak_bytes_allocated());
printf("stack: " UINT_FMT "\n", mp_stack_usage());
#if MICROPY_ENABLE_GC
@@ -232,6 +233,7 @@ STATIC mp_obj_t mem_info(void) {
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mem_info_obj, mem_info);
#endif
STATIC mp_obj_t qstr_info(void) {
uint n_pool, n_qstr, n_str_data_bytes, n_total_bytes;
@@ -325,7 +327,9 @@ int main(int argc, char **argv) {
mp_obj_list_init(mp_sys_argv, 0);
#if MICROPY_MEM_STATS
mp_store_name(qstr_from_str("mem_info"), (mp_obj_t*)&mem_info_obj);
#endif
mp_store_name(qstr_from_str("qstr_info"), (mp_obj_t*)&qstr_info_obj);
// Here is some example code to create a class and instance of that class.