From 9eee20ada8974e53227fa77e8dc0013ceaca88a3 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 10 Nov 2020 22:58:12 +0100 Subject: Add nonnull and nullable attributes to API This will warn if NULL is passed to any nonnull-annotated parameter, and is also supported by sanitizers which can check for violations at runtime. Unfortunately, it is currently only supported by clang. GCC has a similar feature in the nonnull attribute, but this has a different syntax (it's a function attribute) and is more dangerous since it is used by the optimizer to assume a null pointer is undefined behavior. This one just warns and still allows code to handle the situation gracefully, which I think is more appropriate for a library API. Note that this optimization behavior is not some unlikely edge case: switching these attributes to the GCC one will break release builds. --- src/env.c | 1 + src/writer.c | 1 + 2 files changed, 2 insertions(+) (limited to 'src') diff --git a/src/env.c b/src/env.c index 3813391c..431fef41 100644 --- a/src/env.c +++ b/src/env.c @@ -70,6 +70,7 @@ serd_env_get_base_uri(const SerdEnv* env, return &env->base_uri_node; } +// TODO: Make env nonnull in next major release SerdStatus serd_env_set_base_uri(SerdEnv* env, const SerdNode* uri) diff --git a/src/writer.c b/src/writer.c index 5f312c30..5c84b950 100644 --- a/src/writer.c +++ b/src/writer.c @@ -694,6 +694,7 @@ write_list_obj(SerdWriter* writer, return false; } +// TODO: Make subject, predicate,object nonnull in next major release SerdStatus serd_writer_write_statement(SerdWriter* writer, SerdStatementFlags flags, -- cgit v1.2.1