From: Philipp Stephani Date: Mon, 12 Jun 2017 08:57:39 +0000 (+0200) Subject: emacs-module: Use __attribute__((nonnull)) X-Git-Tag: emacs-26.0.90~521^2~116 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=b49dd3b047bf07994d9577e08daba55f143a8bb1;p=emacs.git emacs-module: Use __attribute__((nonnull)) Annotate all parameters with __attribute__((nonnull)) that may not be NULL. --- diff --git a/src/emacs-module.h b/src/emacs-module.h index 26b519a39cf..88cc38191b1 100644 --- a/src/emacs-module.h +++ b/src/emacs-module.h @@ -35,6 +35,12 @@ along with GNU Emacs. If not, see . */ # define EMACS_NOEXCEPT #endif +#if defined __has_attribute && __has_attribute(__nonnull__) +# define EMACS_ATTRIBUTE_NONNULL(...) __attribute__((__nonnull__(__VA_ARGS__))) +#else +# define EMACS_ATTRIBUTE_NONNULL(...) +#endif + #ifdef __cplusplus extern "C" { #endif @@ -58,7 +64,8 @@ struct emacs_runtime struct emacs_runtime_private *private_members; /* Return an environment pointer. */ - emacs_env *(*get_environment) (struct emacs_runtime *ert); + emacs_env *(*get_environment) (struct emacs_runtime *ert) + EMACS_ATTRIBUTE_NONNULL(1); }; @@ -86,29 +93,36 @@ struct emacs_env_25 /* Memory management. */ emacs_value (*make_global_ref) (emacs_env *env, - emacs_value any_reference); + emacs_value any_reference) + EMACS_ATTRIBUTE_NONNULL(1); void (*free_global_ref) (emacs_env *env, - emacs_value global_reference); + emacs_value global_reference) + EMACS_ATTRIBUTE_NONNULL(1); /* Non-local exit handling. */ - enum emacs_funcall_exit (*non_local_exit_check) (emacs_env *env); + enum emacs_funcall_exit (*non_local_exit_check) (emacs_env *env) + EMACS_ATTRIBUTE_NONNULL(1); - void (*non_local_exit_clear) (emacs_env *env); + void (*non_local_exit_clear) (emacs_env *env) + EMACS_ATTRIBUTE_NONNULL(1); enum emacs_funcall_exit (*non_local_exit_get) (emacs_env *env, emacs_value *non_local_exit_symbol_out, - emacs_value *non_local_exit_data_out); + emacs_value *non_local_exit_data_out) + EMACS_ATTRIBUTE_NONNULL(1, 2, 3); void (*non_local_exit_signal) (emacs_env *env, emacs_value non_local_exit_symbol, - emacs_value non_local_exit_data); + emacs_value non_local_exit_data) + EMACS_ATTRIBUTE_NONNULL(1); void (*non_local_exit_throw) (emacs_env *env, emacs_value tag, - emacs_value value); + emacs_value value) + EMACS_ATTRIBUTE_NONNULL(1); /* Function registration. */ @@ -119,34 +133,45 @@ struct emacs_env_25 ptrdiff_t nargs, emacs_value args[], void *) - EMACS_NOEXCEPT, + EMACS_NOEXCEPT + EMACS_ATTRIBUTE_NONNULL(1), const char *documentation, - void *data); + void *data) + EMACS_ATTRIBUTE_NONNULL(1, 4); emacs_value (*funcall) (emacs_env *env, emacs_value function, ptrdiff_t nargs, - emacs_value args[]); + emacs_value args[]) + EMACS_ATTRIBUTE_NONNULL(1); emacs_value (*intern) (emacs_env *env, - const char *symbol_name); + const char *symbol_name) + EMACS_ATTRIBUTE_NONNULL(1, 2); /* Type conversion. */ emacs_value (*type_of) (emacs_env *env, - emacs_value value); + emacs_value value) + EMACS_ATTRIBUTE_NONNULL(1); - bool (*is_not_nil) (emacs_env *env, emacs_value value); + bool (*is_not_nil) (emacs_env *env, emacs_value value) + EMACS_ATTRIBUTE_NONNULL(1); - bool (*eq) (emacs_env *env, emacs_value a, emacs_value b); + bool (*eq) (emacs_env *env, emacs_value a, emacs_value b) + EMACS_ATTRIBUTE_NONNULL(1); - intmax_t (*extract_integer) (emacs_env *env, emacs_value value); + intmax_t (*extract_integer) (emacs_env *env, emacs_value value) + EMACS_ATTRIBUTE_NONNULL(1); - emacs_value (*make_integer) (emacs_env *env, intmax_t value); + emacs_value (*make_integer) (emacs_env *env, intmax_t value) + EMACS_ATTRIBUTE_NONNULL(1); - double (*extract_float) (emacs_env *env, emacs_value value); + double (*extract_float) (emacs_env *env, emacs_value value) + EMACS_ATTRIBUTE_NONNULL(1); - emacs_value (*make_float) (emacs_env *env, double value); + emacs_value (*make_float) (emacs_env *env, double value) + EMACS_ATTRIBUTE_NONNULL(1); /* Copy the content of the Lisp string VALUE to BUFFER as an utf8 null-terminated string. @@ -163,40 +188,51 @@ struct emacs_env_25 bool (*copy_string_contents) (emacs_env *env, emacs_value value, char *buffer, - ptrdiff_t *size_inout); + ptrdiff_t *size_inout) + EMACS_ATTRIBUTE_NONNULL(1, 4); /* Create a Lisp string from a utf8 encoded string. */ emacs_value (*make_string) (emacs_env *env, - const char *contents, ptrdiff_t length); + const char *contents, ptrdiff_t length) + EMACS_ATTRIBUTE_NONNULL(1, 2); /* Embedded pointer type. */ emacs_value (*make_user_ptr) (emacs_env *env, void (*fin) (void *) EMACS_NOEXCEPT, - void *ptr); + void *ptr) + EMACS_ATTRIBUTE_NONNULL(1); - void *(*get_user_ptr) (emacs_env *env, emacs_value uptr); - void (*set_user_ptr) (emacs_env *env, emacs_value uptr, void *ptr); + void *(*get_user_ptr) (emacs_env *env, emacs_value uptr) + EMACS_ATTRIBUTE_NONNULL(1); + void (*set_user_ptr) (emacs_env *env, emacs_value uptr, void *ptr) + EMACS_ATTRIBUTE_NONNULL(1); void (*(*get_user_finalizer) (emacs_env *env, emacs_value uptr)) - (void *) EMACS_NOEXCEPT; + (void *) EMACS_NOEXCEPT EMACS_ATTRIBUTE_NONNULL(1); void (*set_user_finalizer) (emacs_env *env, emacs_value uptr, - void (*fin) (void *) EMACS_NOEXCEPT); + void (*fin) (void *) EMACS_NOEXCEPT) + EMACS_ATTRIBUTE_NONNULL(1); /* Vector functions. */ - emacs_value (*vec_get) (emacs_env *env, emacs_value vec, ptrdiff_t i); + emacs_value (*vec_get) (emacs_env *env, emacs_value vec, ptrdiff_t i) + EMACS_ATTRIBUTE_NONNULL(1); void (*vec_set) (emacs_env *env, emacs_value vec, ptrdiff_t i, - emacs_value val); + emacs_value val) + EMACS_ATTRIBUTE_NONNULL(1); - ptrdiff_t (*vec_size) (emacs_env *env, emacs_value vec); + ptrdiff_t (*vec_size) (emacs_env *env, emacs_value vec) + EMACS_ATTRIBUTE_NONNULL(1); /* Returns whether a quit is pending. */ - bool (*should_quit) (emacs_env *env); + bool (*should_quit) (emacs_env *env) + EMACS_ATTRIBUTE_NONNULL(1); }; /* Every module should define a function as follows. */ -extern int emacs_module_init (struct emacs_runtime *ert); +extern int emacs_module_init (struct emacs_runtime *ert) + EMACS_ATTRIBUTE_NONNULL(1); #ifdef __cplusplus }