Mercurial > vim
comparison src/dict.c @ 19102:ba9f50bfda83 v8.2.0111
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Commit: https://github.com/vim/vim/commit/9b4a15d5dba354d2e1e02871470bad103f34769a
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jan 11 16:05:23 2020 +0100
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Problem: VAR_SPECIAL is also used for booleans.
Solution: Add VAR_BOOL for better type checking.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 11 Jan 2020 16:15:04 +0100 |
parents | c6248ef5b41b |
children | 94eda51ba9ba |
comparison
equal
deleted
inserted
replaced
19101:7c682fab000b | 19102:ba9f50bfda83 |
---|---|
343 /* | 343 /* |
344 * Add a number or special entry to dictionary "d". | 344 * Add a number or special entry to dictionary "d". |
345 * Returns FAIL when out of memory and when key already exists. | 345 * Returns FAIL when out of memory and when key already exists. |
346 */ | 346 */ |
347 static int | 347 static int |
348 dict_add_number_special(dict_T *d, char *key, varnumber_T nr, int special) | 348 dict_add_number_special(dict_T *d, char *key, varnumber_T nr, vartype_T vartype) |
349 { | 349 { |
350 dictitem_T *item; | 350 dictitem_T *item; |
351 | 351 |
352 item = dictitem_alloc((char_u *)key); | 352 item = dictitem_alloc((char_u *)key); |
353 if (item == NULL) | 353 if (item == NULL) |
354 return FAIL; | 354 return FAIL; |
355 item->di_tv.v_type = special ? VAR_SPECIAL : VAR_NUMBER; | 355 item->di_tv.v_type = vartype; |
356 item->di_tv.vval.v_number = nr; | 356 item->di_tv.vval.v_number = nr; |
357 if (dict_add(d, item) == FAIL) | 357 if (dict_add(d, item) == FAIL) |
358 { | 358 { |
359 dictitem_free(item); | 359 dictitem_free(item); |
360 return FAIL; | 360 return FAIL; |
367 * Returns FAIL when out of memory and when key already exists. | 367 * Returns FAIL when out of memory and when key already exists. |
368 */ | 368 */ |
369 int | 369 int |
370 dict_add_number(dict_T *d, char *key, varnumber_T nr) | 370 dict_add_number(dict_T *d, char *key, varnumber_T nr) |
371 { | 371 { |
372 return dict_add_number_special(d, key, nr, FALSE); | 372 return dict_add_number_special(d, key, nr, VAR_NUMBER); |
373 } | 373 } |
374 | 374 |
375 /* | 375 /* |
376 * Add a special entry to dictionary "d". | 376 * Add a special entry to dictionary "d". |
377 * Returns FAIL when out of memory and when key already exists. | 377 * Returns FAIL when out of memory and when key already exists. |
378 */ | 378 */ |
379 int | 379 int |
380 dict_add_special(dict_T *d, char *key, varnumber_T nr) | 380 dict_add_bool(dict_T *d, char *key, varnumber_T nr) |
381 { | 381 { |
382 return dict_add_number_special(d, key, nr, TRUE); | 382 return dict_add_number_special(d, key, nr, VAR_BOOL); |
383 } | 383 } |
384 | 384 |
385 /* | 385 /* |
386 * Add a string entry to dictionary "d". | 386 * Add a string entry to dictionary "d". |
387 * Returns FAIL when out of memory and when key already exists. | 387 * Returns FAIL when out of memory and when key already exists. |