@@ -89,16 +89,23 @@ STATIC mp_obj_t btree_put(size_t n_args, const mp_obj_t *args) {
89
89
(void )n_args ;
90
90
mp_obj_btree_t * self = MP_OBJ_TO_PTR (args [0 ]);
91
91
DBT key , val ;
92
- key .data = (void * )mp_obj_str_get_data (args [1 ], & key .size );
93
- val .data = (void * )mp_obj_str_get_data (args [2 ], & val .size );
92
+ // Different ports may have different type sizes
93
+ mp_uint_t v ;
94
+ key .data = (void * )mp_obj_str_get_data (args [1 ], & v );
95
+ key .size = v ;
96
+ val .data = (void * )mp_obj_str_get_data (args [2 ], & v );
97
+ val .size = v ;
94
98
return MP_OBJ_NEW_SMALL_INT (__bt_put (self -> db , & key , & val , 0 ));
95
99
}
96
100
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (btree_put_obj , 3 , 4 , btree_put );
97
101
98
102
STATIC mp_obj_t btree_get (size_t n_args , const mp_obj_t * args ) {
99
103
mp_obj_btree_t * self = MP_OBJ_TO_PTR (args [0 ]);
100
104
DBT key , val ;
101
- key .data = (void * )mp_obj_str_get_data (args [1 ], & key .size );
105
+ // Different ports may have different type sizes
106
+ mp_uint_t v ;
107
+ key .data = (void * )mp_obj_str_get_data (args [1 ], & v );
108
+ key .size = v ;
102
109
int res = __bt_get (self -> db , & key , & val , 0 );
103
110
if (res == RET_SPECIAL ) {
104
111
if (n_args > 2 ) {
@@ -117,18 +124,22 @@ STATIC mp_obj_t btree_seq(size_t n_args, const mp_obj_t *args) {
117
124
int flags = MP_OBJ_SMALL_INT_VALUE (args [1 ]);
118
125
DBT key , val ;
119
126
if (n_args > 2 ) {
120
- key .data = (void * )mp_obj_str_get_data (args [2 ], & key .size );
127
+ // Different ports may have different type sizes
128
+ mp_uint_t v ;
129
+ key .data = (void * )mp_obj_str_get_data (args [2 ], & v );
130
+ key .size = v ;
121
131
}
122
132
123
133
int res = __bt_seq (self -> db , & key , & val , flags );
124
134
if (res == RET_SPECIAL ) {
125
135
return mp_const_none ;
126
136
}
127
137
128
- mp_obj_tuple_t * pair = mp_obj_new_tuple (2 , NULL );
138
+ mp_obj_t pair_o = mp_obj_new_tuple (2 , NULL );
139
+ mp_obj_tuple_t * pair = MP_OBJ_TO_PTR (pair_o );
129
140
pair -> items [0 ] = mp_obj_new_bytes (key .data , key .size );
130
141
pair -> items [1 ] = mp_obj_new_bytes (val .data , val .size );
131
- return pair ;
142
+ return pair_o ;
132
143
}
133
144
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (btree_seq_obj , 2 , 4 , btree_seq );
134
145
@@ -185,11 +196,14 @@ STATIC mp_obj_t btree_iternext(mp_obj_t self_in) {
185
196
mp_obj_btree_t * self = MP_OBJ_TO_PTR (self_in );
186
197
DBT key , val ;
187
198
int res ;
199
+ // Different ports may have different type sizes
200
+ mp_uint_t v ;
188
201
bool desc = self -> flags & FLAG_DESC ;
189
202
if (self -> start_key != MP_OBJ_NULL ) {
190
203
int flags = R_FIRST ;
191
204
if (self -> start_key != mp_const_none ) {
192
- key .data = (void * )mp_obj_str_get_data (self -> start_key , & key .size );
205
+ key .data = (void * )mp_obj_str_get_data (self -> start_key , & v );
206
+ key .size = v ;
193
207
flags = R_CURSOR ;
194
208
} else if (desc ) {
195
209
flags = R_LAST ;
@@ -207,7 +221,8 @@ STATIC mp_obj_t btree_iternext(mp_obj_t self_in) {
207
221
208
222
if (self -> end_key != mp_const_none ) {
209
223
DBT end_key ;
210
- end_key .data = (void * )mp_obj_str_get_data (self -> end_key , & end_key .size );
224
+ end_key .data = (void * )mp_obj_str_get_data (self -> end_key , & v );
225
+ end_key .size = v ;
211
226
BTREE * t = self -> db -> internal ;
212
227
int cmp = t -> bt_cmp (& key , & end_key );
213
228
if (desc ) {
@@ -228,20 +243,24 @@ STATIC mp_obj_t btree_iternext(mp_obj_t self_in) {
228
243
case FLAG_ITER_VALUES :
229
244
return mp_obj_new_bytes (val .data , val .size );
230
245
default : {
231
- mp_obj_tuple_t * pair = mp_obj_new_tuple (2 , NULL );
246
+ mp_obj_t pair_o = mp_obj_new_tuple (2 , NULL );
247
+ mp_obj_tuple_t * pair = MP_OBJ_TO_PTR (pair_o );
232
248
pair -> items [0 ] = mp_obj_new_bytes (key .data , key .size );
233
249
pair -> items [1 ] = mp_obj_new_bytes (val .data , val .size );
234
- return pair ;
250
+ return pair_o ;
235
251
}
236
252
}
237
253
}
238
254
239
255
STATIC mp_obj_t btree_subscr (mp_obj_t self_in , mp_obj_t index , mp_obj_t value ) {
240
256
mp_obj_btree_t * self = MP_OBJ_TO_PTR (self_in );
257
+ // Different ports may have different type sizes
258
+ mp_uint_t v ;
241
259
if (value == MP_OBJ_NULL ) {
242
260
// delete
243
261
DBT key ;
244
- key .data = (void * )mp_obj_str_get_data (index , & key .size );
262
+ key .data = (void * )mp_obj_str_get_data (index , & v );
263
+ key .size = v ;
245
264
int res = __bt_delete (self -> db , & key , 0 );
246
265
if (res == RET_SPECIAL ) {
247
266
nlr_raise (mp_obj_new_exception (& mp_type_KeyError ));
@@ -251,7 +270,8 @@ STATIC mp_obj_t btree_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
251
270
} else if (value == MP_OBJ_SENTINEL ) {
252
271
// load
253
272
DBT key , val ;
254
- key .data = (void * )mp_obj_str_get_data (index , & key .size );
273
+ key .data = (void * )mp_obj_str_get_data (index , & v );
274
+ key .size = v ;
255
275
int res = __bt_get (self -> db , & key , & val , 0 );
256
276
if (res == RET_SPECIAL ) {
257
277
nlr_raise (mp_obj_new_exception (& mp_type_KeyError ));
@@ -261,8 +281,10 @@ STATIC mp_obj_t btree_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
261
281
} else {
262
282
// store
263
283
DBT key , val ;
264
- key .data = (void * )mp_obj_str_get_data (index , & key .size );
265
- val .data = (void * )mp_obj_str_get_data (value , & val .size );
284
+ key .data = (void * )mp_obj_str_get_data (index , & v );
285
+ key .size = v ;
286
+ val .data = (void * )mp_obj_str_get_data (value , & v );
287
+ val .size = v ;
266
288
int res = __bt_put (self -> db , & key , & val , 0 );
267
289
CHECK_ERROR (res );
268
290
return mp_const_none ;
@@ -316,8 +338,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_btree_open_obj, 1, mod_btree_open);
316
338
STATIC const mp_rom_map_elem_t mp_module_btree_globals_table [] = {
317
339
{ MP_ROM_QSTR (MP_QSTR___name__ ), MP_ROM_QSTR (MP_QSTR_btree ) },
318
340
{ MP_ROM_QSTR (MP_QSTR_open ), MP_ROM_PTR (& mod_btree_open_obj ) },
319
- { MP_ROM_QSTR (MP_QSTR_INCL ), MP_OBJ_NEW_SMALL_INT (FLAG_END_KEY_INCL ) },
320
- { MP_ROM_QSTR (MP_QSTR_DESC ), MP_OBJ_NEW_SMALL_INT (FLAG_DESC ) },
341
+ { MP_ROM_QSTR (MP_QSTR_INCL ), MP_ROM_INT (FLAG_END_KEY_INCL ) },
342
+ { MP_ROM_QSTR (MP_QSTR_DESC ), MP_ROM_INT (FLAG_DESC ) },
321
343
};
322
344
323
345
STATIC MP_DEFINE_CONST_DICT (mp_module_btree_globals , mp_module_btree_globals_table );
0 commit comments