@@ -66,18 +66,20 @@ typedef unsigned int uint;
6666#define m_del_obj (type , ptr ) (m_del(type, ptr, 1))
6767#define m_del_var (obj_type , var_type , var_num , ptr ) (m_free(ptr, sizeof(obj_type) + sizeof(var_type) * (var_num)))
6868
69- void * m_malloc (int num_bytes );
70- void * m_malloc_maybe (int num_bytes );
71- void * m_malloc_with_finaliser (int num_bytes );
72- void * m_malloc0 (int num_bytes );
73- void * m_realloc (void * ptr , int old_num_bytes , int new_num_bytes );
74- void * m_realloc_maybe (void * ptr , int old_num_bytes , int new_num_bytes );
75- void m_free (void * ptr , int num_bytes );
76- void * m_malloc_fail (int num_bytes );
77-
78- int m_get_total_bytes_allocated (void );
79- int m_get_current_bytes_allocated (void );
80- int m_get_peak_bytes_allocated (void );
69+ void * m_malloc (size_t num_bytes );
70+ void * m_malloc_maybe (size_t num_bytes );
71+ void * m_malloc_with_finaliser (size_t num_bytes );
72+ void * m_malloc0 (size_t num_bytes );
73+ void * m_realloc (void * ptr , size_t old_num_bytes , size_t new_num_bytes );
74+ void * m_realloc_maybe (void * ptr , size_t old_num_bytes , size_t new_num_bytes );
75+ void m_free (void * ptr , size_t num_bytes );
76+ void * m_malloc_fail (size_t num_bytes );
77+
78+ #if MICROPY_MEM_STATS
79+ size_t m_get_total_bytes_allocated (void );
80+ size_t m_get_current_bytes_allocated (void );
81+ size_t m_get_peak_bytes_allocated (void );
82+ #endif
8183
8284/** array helpers ***********************************************/
8385
@@ -110,8 +112,8 @@ mp_uint_t unichar_charlen(const char *str, mp_uint_t len);
110112/** variable string *********************************************/
111113
112114typedef struct _vstr_t {
113- uint alloc ;
114- uint len ;
115+ size_t alloc ;
116+ size_t len ;
115117 char * buf ;
116118 bool had_error : 1 ;
117119 bool fixed_buf : 1 ;
@@ -120,40 +122,38 @@ typedef struct _vstr_t {
120122// convenience macro to declare a vstr with a fixed size buffer on the stack
121123#define VSTR_FIXED (vstr , alloc ) vstr_t vstr; char vstr##_buf[(alloc)]; vstr_init_fixed_buf(&vstr, (alloc), vstr##_buf);
122124
123- void vstr_init (vstr_t * vstr , int alloc );
124- void vstr_init_fixed_buf (vstr_t * vstr , int alloc , char * buf );
125+ void vstr_init (vstr_t * vstr , size_t alloc );
126+ void vstr_init_fixed_buf (vstr_t * vstr , size_t alloc , char * buf );
125127void vstr_clear (vstr_t * vstr );
126128vstr_t * vstr_new (void );
127- vstr_t * vstr_new_size (int alloc );
129+ vstr_t * vstr_new_size (size_t alloc );
128130void vstr_free (vstr_t * vstr );
129131void vstr_reset (vstr_t * vstr );
130132bool vstr_had_error (vstr_t * vstr );
131133char * vstr_str (vstr_t * vstr );
132- int vstr_len (vstr_t * vstr );
133- void vstr_hint_size (vstr_t * vstr , int size );
134- char * vstr_extend (vstr_t * vstr , int size );
135- bool vstr_set_size (vstr_t * vstr , int size );
134+ size_t vstr_len (vstr_t * vstr );
135+ void vstr_hint_size (vstr_t * vstr , size_t size );
136+ char * vstr_extend (vstr_t * vstr , size_t size );
137+ bool vstr_set_size (vstr_t * vstr , size_t size );
136138bool vstr_shrink (vstr_t * vstr );
137- char * vstr_add_len (vstr_t * vstr , int len );
139+ char * vstr_add_len (vstr_t * vstr , size_t len );
138140void vstr_add_byte (vstr_t * vstr , byte v );
139141void vstr_add_char (vstr_t * vstr , unichar chr );
140142void vstr_add_str (vstr_t * vstr , const char * str );
141- void vstr_add_strn (vstr_t * vstr , const char * str , int len );
142- //void vstr_add_le16(vstr_t *vstr, unsigned short v);
143- //void vstr_add_le32(vstr_t *vstr, unsigned int v);
144- void vstr_ins_byte (vstr_t * vstr , uint byte_pos , byte b );
145- void vstr_ins_char (vstr_t * vstr , uint char_pos , unichar chr );
146- void vstr_cut_head_bytes (vstr_t * vstr , uint bytes_to_cut );
147- void vstr_cut_tail_bytes (vstr_t * vstr , uint bytes_to_cut );
148- void vstr_cut_out_bytes (vstr_t * vstr , uint byte_pos , uint bytes_to_cut );
143+ void vstr_add_strn (vstr_t * vstr , const char * str , size_t len );
144+ void vstr_ins_byte (vstr_t * vstr , size_t byte_pos , byte b );
145+ void vstr_ins_char (vstr_t * vstr , size_t char_pos , unichar chr );
146+ void vstr_cut_head_bytes (vstr_t * vstr , size_t bytes_to_cut );
147+ void vstr_cut_tail_bytes (vstr_t * vstr , size_t bytes_to_cut );
148+ void vstr_cut_out_bytes (vstr_t * vstr , size_t byte_pos , size_t bytes_to_cut );
149149void vstr_printf (vstr_t * vstr , const char * fmt , ...);
150150
151151/** non-dynamic size-bounded variable buffer/string *************/
152152
153- #define CHECKBUF (buf , max_size ) char buf[max_size + 1]; uint buf##_len = max_size; char *buf##_p = buf;
153+ #define CHECKBUF (buf , max_size ) char buf[max_size + 1]; size_t buf##_len = max_size; char *buf##_p = buf;
154154#define CHECKBUF_RESET (buf , max_size ) buf##_len = max_size; buf##_p = buf;
155155#define CHECKBUF_APPEND (buf , src , src_len ) \
156- { int l = MIN(src_len, buf##_len); \
156+ { size_t l = MIN(src_len, buf##_len); \
157157 memcpy(buf##_p, src, l); \
158158 buf##_len -= l; \
159159 buf##_p += l; }
@@ -167,15 +167,15 @@ void vstr_vprintf(vstr_t *vstr, const char *fmt, va_list ap);
167167// Debugging helpers
168168int DEBUG_printf (const char * fmt , ...);
169169
170- extern uint mp_verbose_flag ;
170+ extern mp_uint_t mp_verbose_flag ;
171171
172172// This is useful for unicode handling. Some CPU archs has
173173// special instructions for efficient implentation of this
174174// function (e.g. CLZ on ARM).
175175// NOTE: this function is unused at the moment
176176#ifndef count_lead_ones
177- static inline uint count_lead_ones (byte val ) {
178- uint c = 0 ;
177+ static inline mp_uint_t count_lead_ones (byte val ) {
178+ mp_uint_t c = 0 ;
179179 for (byte mask = 0x80 ; val & mask ; mask >>= 1 ) {
180180 c ++ ;
181181 }
0 commit comments