@@ -88,9 +88,9 @@ struct hashmap *basic_get_map_by_handle(struct basic_ctx *ctx, int64_t handle)
8888 return found -> map ;
8989}
9090
91- map_value_t * basic_get_map_value (struct hashmap * map , const char * key )
91+ static map_value_t * basic_get_map_value (struct hashmap * map , const char * key , size_t key_len )
9292{
93- return hashmap_get (map , & (map_value_t ){ .name = key , .name_length = strlen ( key ) });
93+ return hashmap_get (map , & (map_value_t ){ .name = key , .name_length = key_len });
9494}
9595
9696void basic_free_map_up_value (struct basic_ctx * ctx , up_value * value )
@@ -161,7 +161,7 @@ int64_t basic_maphas(struct basic_ctx *ctx)
161161 return 0 ;
162162 }
163163
164- return basic_get_map_value (map , key ) ? 1 : 0 ;
164+ return basic_get_map_value (map , key , strlength ) ? 1 : 0 ;
165165}
166166
167167int64_t basic_mapget (struct basic_ctx * ctx )
@@ -181,7 +181,7 @@ int64_t basic_mapget(struct basic_ctx *ctx)
181181 return 0 ;
182182 }
183183
184- entry = basic_get_map_value (map , key );
184+ entry = basic_get_map_value (map , key , strlength );
185185 if (!entry ) {
186186 tokenizer_error_printf (ctx , "No such MAP key '%s'" , key );
187187 return 0 ;
@@ -213,7 +213,7 @@ void basic_mapgetr(struct basic_ctx *ctx, double* rv)
213213 return ;
214214 }
215215
216- entry = basic_get_map_value (map , key );
216+ entry = basic_get_map_value (map , key , strlength );
217217 if (!entry ) {
218218 tokenizer_error_printf (ctx , "No such MAP key '%s'" , key );
219219 * rv = 0 ;
@@ -250,7 +250,7 @@ char *basic_mapgets(struct basic_ctx *ctx, size_t* out_len)
250250 return "" ;
251251 }
252252
253- map_value_t * entry = basic_get_map_value (map , key );
253+ map_value_t * entry = basic_get_map_value (map , key , strlength );
254254 if (!entry ) {
255255 tokenizer_error_printf (ctx , "No such MAP key '%s'" , key );
256256 return "" ;
@@ -267,23 +267,19 @@ char *basic_mapgets(struct basic_ctx *ctx, size_t* out_len)
267267
268268void mapset_statement (struct basic_ctx * ctx )
269269{
270- int64_t handle ;
271- const char * key ;
272- struct hashmap * map ;
273- map_value_t * found ;
274270 map_value_t new_entry ;
275271 up_value value ;
276272
277273 accept_or_return (MAPSET , ctx );
278- handle = expr (ctx );
274+ int64_t handle = expr (ctx );
279275 accept_or_return (COMMA , ctx );
280276 size_t elen ;
281- key = str_expr (ctx , & elen );
277+ const char * key = str_expr (ctx , & elen );
282278 accept_or_return (COMMA , ctx );
283279 up_eval_value (ctx , & value );
284280 accept_or_return (NEWLINE , ctx );
285281
286- map = basic_get_map_by_handle (ctx , handle );
282+ struct hashmap * map = basic_get_map_by_handle (ctx , handle );
287283 if (!map ) {
288284 tokenizer_error_print (ctx , "Invalid MAP" );
289285 return ;
@@ -298,7 +294,7 @@ void mapset_statement(struct basic_ctx *ctx)
298294 value .v .s .ptr = dup ;
299295 }
300296
301- found = basic_get_map_value (map , key );
297+ map_value_t * found = basic_get_map_value (map , key , elen );
302298 if (found ) {
303299 if (found -> value .kind != value .kind ) {
304300 if (!(found -> value .kind == UP_INT && value .kind == UP_REAL )) {
@@ -330,7 +326,7 @@ void mapset_statement(struct basic_ctx *ctx)
330326
331327 memset (& new_entry , 0 , sizeof (new_entry ));
332328 new_entry .name = buddy_strdup (ctx -> allocator , key );
333- new_entry .name_length = strlen ( key ) ;
329+ new_entry .name_length = elen ;
334330 if (!new_entry .name ) {
335331 basic_free_map_up_value (ctx , & value );
336332 tokenizer_error_print (ctx , "Out of memory" );
@@ -356,7 +352,6 @@ void mapset_statement(struct basic_ctx *ctx)
356352
357353void mapfree_statement (struct basic_ctx * ctx )
358354{
359- basic_map_handle_entry * found ;
360355
361356 accept_or_return (MAPFREE , ctx );
362357 int64_t handle = expr (ctx );
@@ -367,7 +362,7 @@ void mapfree_statement(struct basic_ctx *ctx)
367362 return ;
368363 }
369364
370- found = hashmap_delete (ctx -> maps , & (basic_map_handle_entry ){ .id = handle });
365+ basic_map_handle_entry * found = hashmap_delete (ctx -> maps , & (basic_map_handle_entry ){.id = handle });
371366 if (!found ) {
372367 tokenizer_error_print (ctx , "Invalid MAP" );
373368 return ;
0 commit comments