From 425b94d663e400b6dee9ed2ebd1c92738970b054 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Sun, 28 Oct 2018 20:16:43 -0400 Subject: js: Introduce annotations for using return values This introduces two annotations to functions. GJS_USE is a macro for GCC and Clang's "warn_unused_result" annotation, meaning that the return value of a function must not be ignored. This allows us to catch some cases where we are neglecting to do error checking. The second annotation is GJS_JSAPI_RETURN_CONVENTION which for now is identical to GJS_USE, but could be made into a custom annotation in the future which a static analyzer plugin could use to enforce further checks at compile time. The "JSAPI return convention" is valid on functions that return bool or a pointer type, and whose first parameter is JSContext*. If false or nullptr is returned, then an exception must be pending at return time on the passed-in JSContext. If true or a non-nullptr value is returned, then no exception must be pending. This commit only has the addition of the attributes, and a few fixes mandated by the autoformatter, so it can be reviewed "lightly". --- gjs/console.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'gjs/console.cpp') diff --git a/gjs/console.cpp b/gjs/console.cpp index c2c9d524..a110bf31 100644 --- a/gjs/console.cpp +++ b/gjs/console.cpp @@ -61,6 +61,7 @@ static GOptionEntry entries[] = { }; // clang-format on +GJS_USE static char ** strndupv(int n, char * const *strv) @@ -75,6 +76,7 @@ strndupv(int n, return retval; } +GJS_USE static char ** strcatv(char **strv1, char **strv2) -- cgit v1.2.1