diff options
| author | Paul Eggert | 2011-06-14 11:57:19 -0700 |
|---|---|---|
| committer | Paul Eggert | 2011-06-14 11:57:19 -0700 |
| commit | f66c7cf8f794d6f7fd9ccb8794ffc519e4e89795 (patch) | |
| tree | 0de26b21c827049c7fa2485204ecf0e2d632b849 /src/fns.c | |
| parent | a1759b76246a21c7c07dc2ee00b8db792715104c (diff) | |
| download | emacs-f66c7cf8f794d6f7fd9ccb8794ffc519e4e89795.tar.gz emacs-f66c7cf8f794d6f7fd9ccb8794ffc519e4e89795.zip | |
Variadic C functions now count arguments with ptrdiff_t.
This partly undoes my 2011-03-30 change, which replaced int with size_t.
Back then I didn't know that the Emacs coding style prefers signed int.
Also, in the meantime I found a few more instances where arguments
were being counted with int, which may truncate counts on 64-bit
machines, or EMACS_INT, which may be unnecessarily wide.
* lisp.h (struct Lisp_Subr.function.aMANY)
(DEFUN_ARGS_MANY, internal_condition_case_n, safe_call):
Arg counts are now ptrdiff_t, not size_t.
All variadic functions and their callers changed accordingly.
(struct gcpro.nvars): Now size_t, not size_t. All uses changed.
* bytecode.c (exec_byte_code): Check maxdepth for overflow,
to avoid potential buffer overrun. Don't assume arg counts fit in 'int'.
* callint.c (Fcall_interactively): Check arg count for overflow,
to avoid potential buffer overrun. Use signed char, not 'int',
for 'varies' array, so that we needn't bother to check its size
calculation for overflow.
* editfns.c (Fformat): Use ptrdiff_t, not EMACS_INT, to count args.
* eval.c (apply_lambda):
* fns.c (Fmapconcat): Use XFASTINT, not XINT, to get args length.
(struct textprop_rec.argnum): Now ptrdiff_t, not int. All uses changed.
(mapconcat): Use ptrdiff_t, not int and EMACS_INT, to count args.
Diffstat (limited to 'src/fns.c')
| -rw-r--r-- | src/fns.c | 37 |
1 files changed, 18 insertions, 19 deletions
| @@ -344,7 +344,7 @@ Symbols are also allowed; their print names are used instead. */) | |||
| 344 | return i1 < SCHARS (s2) ? Qt : Qnil; | 344 | return i1 < SCHARS (s2) ? Qt : Qnil; |
| 345 | } | 345 | } |
| 346 | 346 | ||
| 347 | static Lisp_Object concat (size_t nargs, Lisp_Object *args, | 347 | static Lisp_Object concat (ptrdiff_t nargs, Lisp_Object *args, |
| 348 | enum Lisp_Type target_type, int last_special); | 348 | enum Lisp_Type target_type, int last_special); |
| 349 | 349 | ||
| 350 | /* ARGSUSED */ | 350 | /* ARGSUSED */ |
| @@ -374,7 +374,7 @@ The result is a list whose elements are the elements of all the arguments. | |||
| 374 | Each argument may be a list, vector or string. | 374 | Each argument may be a list, vector or string. |
| 375 | The last argument is not copied, just used as the tail of the new list. | 375 | The last argument is not copied, just used as the tail of the new list. |
| 376 | usage: (append &rest SEQUENCES) */) | 376 | usage: (append &rest SEQUENCES) */) |
| 377 | (size_t nargs, Lisp_Object *args) | 377 | (ptrdiff_t nargs, Lisp_Object *args) |
| 378 | { | 378 | { |
| 379 | return concat (nargs, args, Lisp_Cons, 1); | 379 | return concat (nargs, args, Lisp_Cons, 1); |
| 380 | } | 380 | } |
| @@ -384,7 +384,7 @@ DEFUN ("concat", Fconcat, Sconcat, 0, MANY, 0, | |||
| 384 | The result is a string whose elements are the elements of all the arguments. | 384 | The result is a string whose elements are the elements of all the arguments. |
| 385 | Each argument may be a string or a list or vector of characters (integers). | 385 | Each argument may be a string or a list or vector of characters (integers). |
| 386 | usage: (concat &rest SEQUENCES) */) | 386 | usage: (concat &rest SEQUENCES) */) |
| 387 | (size_t nargs, Lisp_Object *args) | 387 | (ptrdiff_t nargs, Lisp_Object *args) |
| 388 | { | 388 | { |
| 389 | return concat (nargs, args, Lisp_String, 0); | 389 | return concat (nargs, args, Lisp_String, 0); |
| 390 | } | 390 | } |
| @@ -394,7 +394,7 @@ DEFUN ("vconcat", Fvconcat, Svconcat, 0, MANY, 0, | |||
| 394 | The result is a vector whose elements are the elements of all the arguments. | 394 | The result is a vector whose elements are the elements of all the arguments. |
| 395 | Each argument may be a list, vector or string. | 395 | Each argument may be a list, vector or string. |
| 396 | usage: (vconcat &rest SEQUENCES) */) | 396 | usage: (vconcat &rest SEQUENCES) */) |
| 397 | (size_t nargs, Lisp_Object *args) | 397 | (ptrdiff_t nargs, Lisp_Object *args) |
| 398 | { | 398 | { |
| 399 | return concat (nargs, args, Lisp_Vectorlike, 0); | 399 | return concat (nargs, args, Lisp_Vectorlike, 0); |
| 400 | } | 400 | } |
| @@ -436,13 +436,13 @@ with the original. */) | |||
| 436 | a string and has text properties to be copied. */ | 436 | a string and has text properties to be copied. */ |
| 437 | struct textprop_rec | 437 | struct textprop_rec |
| 438 | { | 438 | { |
| 439 | int argnum; /* refer to ARGS (arguments of `concat') */ | 439 | ptrdiff_t argnum; /* refer to ARGS (arguments of `concat') */ |
| 440 | EMACS_INT from; /* refer to ARGS[argnum] (argument string) */ | 440 | EMACS_INT from; /* refer to ARGS[argnum] (argument string) */ |
| 441 | EMACS_INT to; /* refer to VAL (the target string) */ | 441 | EMACS_INT to; /* refer to VAL (the target string) */ |
| 442 | }; | 442 | }; |
| 443 | 443 | ||
| 444 | static Lisp_Object | 444 | static Lisp_Object |
| 445 | concat (size_t nargs, Lisp_Object *args, | 445 | concat (ptrdiff_t nargs, Lisp_Object *args, |
| 446 | enum Lisp_Type target_type, int last_special) | 446 | enum Lisp_Type target_type, int last_special) |
| 447 | { | 447 | { |
| 448 | Lisp_Object val; | 448 | Lisp_Object val; |
| @@ -452,7 +452,7 @@ concat (size_t nargs, Lisp_Object *args, | |||
| 452 | EMACS_INT toindex_byte = 0; | 452 | EMACS_INT toindex_byte = 0; |
| 453 | register EMACS_INT result_len; | 453 | register EMACS_INT result_len; |
| 454 | register EMACS_INT result_len_byte; | 454 | register EMACS_INT result_len_byte; |
| 455 | register size_t argnum; | 455 | ptrdiff_t argnum; |
| 456 | Lisp_Object last_tail; | 456 | Lisp_Object last_tail; |
| 457 | Lisp_Object prev; | 457 | Lisp_Object prev; |
| 458 | int some_multibyte; | 458 | int some_multibyte; |
| @@ -463,7 +463,7 @@ concat (size_t nargs, Lisp_Object *args, | |||
| 463 | here, and copy the text properties after the concatenation. */ | 463 | here, and copy the text properties after the concatenation. */ |
| 464 | struct textprop_rec *textprops = NULL; | 464 | struct textprop_rec *textprops = NULL; |
| 465 | /* Number of elements in textprops. */ | 465 | /* Number of elements in textprops. */ |
| 466 | int num_textprops = 0; | 466 | ptrdiff_t num_textprops = 0; |
| 467 | USE_SAFE_ALLOCA; | 467 | USE_SAFE_ALLOCA; |
| 468 | 468 | ||
| 469 | tail = Qnil; | 469 | tail = Qnil; |
| @@ -2217,9 +2217,9 @@ DEFUN ("nconc", Fnconc, Snconc, 0, MANY, 0, | |||
| 2217 | doc: /* Concatenate any number of lists by altering them. | 2217 | doc: /* Concatenate any number of lists by altering them. |
| 2218 | Only the last argument is not altered, and need not be a list. | 2218 | Only the last argument is not altered, and need not be a list. |
| 2219 | usage: (nconc &rest LISTS) */) | 2219 | usage: (nconc &rest LISTS) */) |
| 2220 | (size_t nargs, Lisp_Object *args) | 2220 | (ptrdiff_t nargs, Lisp_Object *args) |
| 2221 | { | 2221 | { |
| 2222 | register size_t argnum; | 2222 | ptrdiff_t argnum; |
| 2223 | register Lisp_Object tail, tem, val; | 2223 | register Lisp_Object tail, tem, val; |
| 2224 | 2224 | ||
| 2225 | val = tail = Qnil; | 2225 | val = tail = Qnil; |
| @@ -2342,9 +2342,8 @@ SEQUENCE may be a list, a vector, a bool-vector, or a string. */) | |||
| 2342 | { | 2342 | { |
| 2343 | Lisp_Object len; | 2343 | Lisp_Object len; |
| 2344 | register EMACS_INT leni; | 2344 | register EMACS_INT leni; |
| 2345 | int nargs; | 2345 | ptrdiff_t i, nargs; |
| 2346 | register Lisp_Object *args; | 2346 | register Lisp_Object *args; |
| 2347 | register EMACS_INT i; | ||
| 2348 | struct gcpro gcpro1; | 2347 | struct gcpro gcpro1; |
| 2349 | Lisp_Object ret; | 2348 | Lisp_Object ret; |
| 2350 | USE_SAFE_ALLOCA; | 2349 | USE_SAFE_ALLOCA; |
| @@ -2748,7 +2747,7 @@ DEFUN ("widget-apply", Fwidget_apply, Swidget_apply, 2, MANY, 0, | |||
| 2748 | doc: /* Apply the value of WIDGET's PROPERTY to the widget itself. | 2747 | doc: /* Apply the value of WIDGET's PROPERTY to the widget itself. |
| 2749 | ARGS are passed as extra arguments to the function. | 2748 | ARGS are passed as extra arguments to the function. |
| 2750 | usage: (widget-apply WIDGET PROPERTY &rest ARGS) */) | 2749 | usage: (widget-apply WIDGET PROPERTY &rest ARGS) */) |
| 2751 | (size_t nargs, Lisp_Object *args) | 2750 | (ptrdiff_t nargs, Lisp_Object *args) |
| 2752 | { | 2751 | { |
| 2753 | /* This function can GC. */ | 2752 | /* This function can GC. */ |
| 2754 | Lisp_Object newargs[3]; | 2753 | Lisp_Object newargs[3]; |
| @@ -3353,7 +3352,7 @@ static Lisp_Object Qhash_table_test, Qkey_or_value, Qkey_and_value; | |||
| 3353 | /* Function prototypes. */ | 3352 | /* Function prototypes. */ |
| 3354 | 3353 | ||
| 3355 | static struct Lisp_Hash_Table *check_hash_table (Lisp_Object); | 3354 | static struct Lisp_Hash_Table *check_hash_table (Lisp_Object); |
| 3356 | static size_t get_key_arg (Lisp_Object, size_t, Lisp_Object *, char *); | 3355 | static ptrdiff_t get_key_arg (Lisp_Object, ptrdiff_t, Lisp_Object *, char *); |
| 3357 | static void maybe_resize_hash_table (struct Lisp_Hash_Table *); | 3356 | static void maybe_resize_hash_table (struct Lisp_Hash_Table *); |
| 3358 | static int sweep_weak_table (struct Lisp_Hash_Table *, int); | 3357 | static int sweep_weak_table (struct Lisp_Hash_Table *, int); |
| 3359 | 3358 | ||
| @@ -3396,10 +3395,10 @@ next_almost_prime (EMACS_INT n) | |||
| 3396 | 0. This function is used to extract a keyword/argument pair from | 3395 | 0. This function is used to extract a keyword/argument pair from |
| 3397 | a DEFUN parameter list. */ | 3396 | a DEFUN parameter list. */ |
| 3398 | 3397 | ||
| 3399 | static size_t | 3398 | static ptrdiff_t |
| 3400 | get_key_arg (Lisp_Object key, size_t nargs, Lisp_Object *args, char *used) | 3399 | get_key_arg (Lisp_Object key, ptrdiff_t nargs, Lisp_Object *args, char *used) |
| 3401 | { | 3400 | { |
| 3402 | size_t i; | 3401 | ptrdiff_t i; |
| 3403 | 3402 | ||
| 3404 | for (i = 1; i < nargs; i++) | 3403 | for (i = 1; i < nargs; i++) |
| 3405 | if (!used[i - 1] && EQ (args[i - 1], key)) | 3404 | if (!used[i - 1] && EQ (args[i - 1], key)) |
| @@ -4297,12 +4296,12 @@ WEAK. WEAK t is equivalent to `key-and-value'. Default value of WEAK | |||
| 4297 | is nil. | 4296 | is nil. |
| 4298 | 4297 | ||
| 4299 | usage: (make-hash-table &rest KEYWORD-ARGS) */) | 4298 | usage: (make-hash-table &rest KEYWORD-ARGS) */) |
| 4300 | (size_t nargs, Lisp_Object *args) | 4299 | (ptrdiff_t nargs, Lisp_Object *args) |
| 4301 | { | 4300 | { |
| 4302 | Lisp_Object test, size, rehash_size, rehash_threshold, weak; | 4301 | Lisp_Object test, size, rehash_size, rehash_threshold, weak; |
| 4303 | Lisp_Object user_test, user_hash; | 4302 | Lisp_Object user_test, user_hash; |
| 4304 | char *used; | 4303 | char *used; |
| 4305 | size_t i; | 4304 | ptrdiff_t i; |
| 4306 | 4305 | ||
| 4307 | /* The vector `used' is used to keep track of arguments that | 4306 | /* The vector `used' is used to keep track of arguments that |
| 4308 | have been consumed. */ | 4307 | have been consumed. */ |