diff options
author | David Robillard <d@drobilla.net> | 2020-11-10 15:44:37 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-11-10 18:29:45 +0100 |
commit | bafa091fada7b3fdc663567abc0a7455bc3a77c9 (patch) | |
tree | 68c73bbdec5d0fa83cc2913c7a13f48e84a3bdff /src | |
parent | f820212f2ac92400cf277686e4f79e740b95688c (diff) | |
download | serd-bafa091fada7b3fdc663567abc0a7455bc3a77c9.tar.gz serd-bafa091fada7b3fdc663567abc0a7455bc3a77c9.tar.bz2 serd-bafa091fada7b3fdc663567abc0a7455bc3a77c9.zip |
Add const, pure, and malloc function attributes
Diffstat (limited to 'src')
-rw-r--r-- | src/attributes.h | 26 | ||||
-rw-r--r-- | src/base64.h | 4 | ||||
-rw-r--r-- | src/env.c | 2 | ||||
-rw-r--r-- | src/reader.h | 6 | ||||
-rw-r--r-- | src/serdi.c | 2 | ||||
-rw-r--r-- | src/system.h | 4 | ||||
-rw-r--r-- | src/uri_utils.h | 6 |
7 files changed, 40 insertions, 10 deletions
diff --git a/src/attributes.h b/src/attributes.h new file mode 100644 index 00000000..3ca797a4 --- /dev/null +++ b/src/attributes.h @@ -0,0 +1,26 @@ +/* + Copyright 2019-2020 David Robillard <http://drobilla.net> + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#ifndef SERD_ATTRIBUTES_H +#define SERD_ATTRIBUTES_H + +#ifdef __GNUC__ +# define SERD_MALLOC_FUNC __attribute__((malloc)) +#else +# define SERD_MALLOC_FUNC +#endif + +#endif // SERD_ATTRIBUTES_H diff --git a/src/base64.h b/src/base64.h index 11eb9db9..7fd29fef 100644 --- a/src/base64.h +++ b/src/base64.h @@ -17,6 +17,8 @@ #ifndef SERD_BASE64_H #define SERD_BASE64_H +#include "serd/serd.h" + #include <stdbool.h> #include <stddef.h> #include <stdint.h> @@ -28,7 +30,7 @@ @param wrap_lines Wrap lines at 76 characters to conform to RFC 2045. @return The length of the base64 encoding, excluding null terminator. */ -size_t +SERD_CONST_FUNC size_t serd_base64_get_length(size_t size, bool wrap_lines); /** @@ -93,7 +93,7 @@ serd_env_set_base_uri(SerdEnv* env, return SERD_ERR_BAD_ARG; } -static inline SerdPrefix* +static inline SERD_PURE_FUNC SerdPrefix* serd_env_find(const SerdEnv* env, const uint8_t* name, size_t name_len) diff --git a/src/reader.h b/src/reader.h index 9de37f4c..166e2137 100644 --- a/src/reader.h +++ b/src/reader.h @@ -98,9 +98,9 @@ Ref push_node(SerdReader* reader, const char* str, size_t n_bytes); -size_t genid_size(SerdReader* reader); -Ref blank_id(SerdReader* reader); -void set_blank_id(SerdReader* reader, Ref ref, size_t buf_size); +SERD_PURE_FUNC size_t genid_size(SerdReader* reader); +Ref blank_id(SerdReader* reader); +void set_blank_id(SerdReader* reader, Ref ref, size_t buf_size); SerdNode* deref(SerdReader* reader, Ref ref); diff --git a/src/serdi.c b/src/serdi.c index 5b3d4bbb..033a8c75 100644 --- a/src/serdi.c +++ b/src/serdi.c @@ -66,7 +66,7 @@ get_syntax(const char* name) return (SerdSyntax)0; } -static SerdSyntax +static SERD_PURE_FUNC SerdSyntax guess_syntax(const char* filename) { const char* ext = strrchr(filename, '.'); diff --git a/src/system.h b/src/system.h index b1b84925..0f6a0e0b 100644 --- a/src/system.h +++ b/src/system.h @@ -17,12 +17,14 @@ #ifndef SERD_SYSTEM_H #define SERD_SYSTEM_H +#include "attributes.h" + #include <stdio.h> FILE* serd_fopen(const char* path, const char* mode); -void* +SERD_MALLOC_FUNC void* serd_bufalloc(size_t size); #endif // SERD_SYSTEM_H diff --git a/src/uri_utils.h b/src/uri_utils.h index 4dbcdba5..896d9d8b 100644 --- a/src/uri_utils.h +++ b/src/uri_utils.h @@ -48,7 +48,7 @@ uri_path_at(const SerdURI* uri, size_t i) Return the index of the first differing character after the last root slash, or zero if `uri` is not under `root`. */ -static inline size_t +static inline SERD_PURE_FUNC size_t uri_rooted_index(const SerdURI* uri, const SerdURI* root) { if (!root || !root->scheme.len || @@ -78,14 +78,14 @@ uri_rooted_index(const SerdURI* uri, const SerdURI* root) } /** Return true iff `uri` shares path components with `root` */ -static inline bool +static inline SERD_PURE_FUNC bool uri_is_related(const SerdURI* uri, const SerdURI* root) { return uri_rooted_index(uri, root) > 0; } /** Return true iff `uri` is within the base of `root` */ -static inline bool +static inline SERD_PURE_FUNC bool uri_is_under(const SerdURI* uri, const SerdURI* root) { const size_t index = uri_rooted_index(uri, root); |