diff options
| author | Paul Eggert | 2015-11-19 15:01:26 -0800 |
|---|---|---|
| committer | Paul Eggert | 2015-11-19 15:01:49 -0800 |
| commit | 92949781eb0963fd1b25f1eec4e2d72d2c8ae32e (patch) | |
| tree | 17f16cb6afb54afcbf6abc0ae2c54fe844454cb8 /modules | |
| parent | d9b300af5c7b07bd870046e73df53e19e860fdb9 (diff) | |
| download | emacs-92949781eb0963fd1b25f1eec4e2d72d2c8ae32e.tar.gz emacs-92949781eb0963fd1b25f1eec4e2d72d2c8ae32e.zip | |
Prefer signed integer types in module code
Generally speaking, at the C level the Emacs source code prefers
signed types like ‘ptrdiff_t’ to unsigned types like ‘size_t’,
partly to avoid the usual signedness confusion when comparing values.
Change the module API to follow this convention.
Use ‘int’ for small values that can’t exceed INT_MAX.
* modules/mod-test/mod-test.c (Fmod_test_globref_make)
(Fmod_test_string_a_to_b, Fmod_test_vector_fill)
(Fmod_test_vector_eq):
* src/emacs-module.c (struct emacs_value_frame)
(module_make_global_ref, module_free_global_ref)
(module_copy_string_contents, module_make_string)
(module_vec_set, module_vec_get, module_vec_size):
* src/emacs-module.h (struct emacs_runtime, struct emacs_env_25):
* src/lread.c (suffix_p):
Prefer signed to unsigned integer types.
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/mod-test/mod-test.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/modules/mod-test/mod-test.c b/modules/mod-test/mod-test.c index d1a4ce0d6fa..0160da69d0f 100644 --- a/modules/mod-test/mod-test.c +++ b/modules/mod-test/mod-test.c | |||
| @@ -117,7 +117,7 @@ Fmod_test_globref_make (emacs_env *env, int nargs, emacs_value args[], | |||
| 117 | { | 117 | { |
| 118 | /* Make a big string and make it global. */ | 118 | /* Make a big string and make it global. */ |
| 119 | char str[26 * 100]; | 119 | char str[26 * 100]; |
| 120 | for (size_t i = 0; i < sizeof str; i++) | 120 | for (int i = 0; i < sizeof str; i++) |
| 121 | str[i] = 'a' + (i % 26); | 121 | str[i] = 'a' + (i % 26); |
| 122 | 122 | ||
| 123 | /* We don't need to null-terminate str. */ | 123 | /* We don't need to null-terminate str. */ |
| @@ -133,14 +133,14 @@ Fmod_test_string_a_to_b (emacs_env *env, int nargs, emacs_value args[], | |||
| 133 | void *data) | 133 | void *data) |
| 134 | { | 134 | { |
| 135 | emacs_value lisp_str = args[0]; | 135 | emacs_value lisp_str = args[0]; |
| 136 | size_t size = 0; | 136 | ptrdiff_t size = 0; |
| 137 | char * buf = NULL; | 137 | char * buf = NULL; |
| 138 | 138 | ||
| 139 | env->copy_string_contents (env, lisp_str, buf, &size); | 139 | env->copy_string_contents (env, lisp_str, buf, &size); |
| 140 | buf = malloc (size); | 140 | buf = malloc (size); |
| 141 | env->copy_string_contents (env, lisp_str, buf, &size); | 141 | env->copy_string_contents (env, lisp_str, buf, &size); |
| 142 | 142 | ||
| 143 | for (size_t i = 0; i + 1 < size; i++) | 143 | for (ptrdiff_t i = 0; i + 1 < size; i++) |
| 144 | if (buf[i] == 'a') | 144 | if (buf[i] == 'a') |
| 145 | buf[i] = 'b'; | 145 | buf[i] = 'b'; |
| 146 | 146 | ||
| @@ -191,8 +191,8 @@ Fmod_test_vector_fill (emacs_env *env, int nargs, emacs_value args[], void *data | |||
| 191 | { | 191 | { |
| 192 | emacs_value vec = args[0]; | 192 | emacs_value vec = args[0]; |
| 193 | emacs_value val = args[1]; | 193 | emacs_value val = args[1]; |
| 194 | size_t size = env->vec_size (env, vec); | 194 | ptrdiff_t size = env->vec_size (env, vec); |
| 195 | for (size_t i = 0; i < size; i++) | 195 | for (ptrdiff_t i = 0; i < size; i++) |
| 196 | env->vec_set (env, vec, i, val); | 196 | env->vec_set (env, vec, i, val); |
| 197 | return env->intern (env, "t"); | 197 | return env->intern (env, "t"); |
| 198 | } | 198 | } |
| @@ -205,8 +205,8 @@ Fmod_test_vector_eq (emacs_env *env, int nargs, emacs_value args[], void *data) | |||
| 205 | { | 205 | { |
| 206 | emacs_value vec = args[0]; | 206 | emacs_value vec = args[0]; |
| 207 | emacs_value val = args[1]; | 207 | emacs_value val = args[1]; |
| 208 | size_t size = env->vec_size (env, vec); | 208 | ptrdiff_t size = env->vec_size (env, vec); |
| 209 | for (size_t i = 0; i < size; i++) | 209 | for (ptrdiff_t i = 0; i < size; i++) |
| 210 | if (!env->eq (env, env->vec_get (env, vec, i), val)) | 210 | if (!env->eq (env, env->vec_get (env, vec, i), val)) |
| 211 | return env->intern (env, "nil"); | 211 | return env->intern (env, "nil"); |
| 212 | return env->intern (env, "t"); | 212 | return env->intern (env, "t"); |