aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-05-29 17:12:02 -0400
committerDavid Robillard <d@drobilla.net>2021-05-31 11:37:53 -0400
commit9aa0c922b503f9b1f7f22add0afe19638bba7e9b (patch)
tree73e639bee2fd1cb9d06a1bd5770803ecf6ca5e7e
parent624accde94a105213dc3562606c638d9620e7a72 (diff)
downloadserd-9aa0c922b503f9b1f7f22add0afe19638bba7e9b.tar.gz
serd-9aa0c922b503f9b1f7f22add0afe19638bba7e9b.tar.bz2
serd-9aa0c922b503f9b1f7f22add0afe19638bba7e9b.zip
Make most function parameters const
More const never hurts in general, but in particular this allows the compiler to make better nullability deductions, which reduces the amount of manual nullability casting required.
-rw-r--r--src/base64.c6
-rw-r--r--src/byte_source.c21
-rw-r--r--src/env.c48
-rw-r--r--src/n3.c171
-rw-r--r--src/node.c58
-rw-r--r--src/reader.c124
-rw-r--r--src/reader.h2
-rw-r--r--src/serdi.c12
-rw-r--r--src/string.c12
-rw-r--r--src/system.c2
-rw-r--r--src/uri.c39
11 files changed, 283 insertions, 212 deletions
diff --git a/src/base64.c b/src/base64.c
index 4a9b4dac..8569577b 100644
--- a/src/base64.c
+++ b/src/base64.c
@@ -49,7 +49,7 @@ static const char b64_unmap[] =
/** Encode 3 raw bytes to 4 base64 characters. */
static void
-encode_chunk(uint8_t out[4], const uint8_t in[3], size_t n_in)
+encode_chunk(uint8_t out[4], const uint8_t in[3], const size_t n_in)
{
out[0] = b64_map[in[0] >> 2];
out[1] = b64_map[((in[0] & 0x03) << 4) | ((in[1] & 0xF0) >> 4)];
@@ -107,7 +107,9 @@ decode_chunk(const uint8_t in[4], uint8_t out[3])
}
void*
-serd_base64_decode(const uint8_t* str, size_t len, size_t* size)
+serd_base64_decode(const uint8_t* const str,
+ const size_t len,
+ size_t* const size)
{
void* buf = malloc((len * 3) / 4 + 2);
diff --git a/src/byte_source.c b/src/byte_source.c
index 9f7e4e59..4790a4b2 100644
--- a/src/byte_source.c
+++ b/src/byte_source.c
@@ -25,7 +25,7 @@
#include <string.h>
SerdStatus
-serd_byte_source_page(SerdByteSource* source)
+serd_byte_source_page(SerdByteSource* const source)
{
source->read_head = 0;
const size_t n_read =
@@ -47,12 +47,12 @@ serd_byte_source_page(SerdByteSource* source)
}
SerdStatus
-serd_byte_source_open_source(SerdByteSource* source,
- SerdSource read_func,
- SerdStreamErrorFunc error_func,
- void* stream,
- const uint8_t* name,
- size_t page_size)
+serd_byte_source_open_source(SerdByteSource* const source,
+ const SerdSource read_func,
+ const SerdStreamErrorFunc error_func,
+ void* const stream,
+ const uint8_t* const name,
+ const size_t page_size)
{
const Cursor cur = {name, 1, 1};
@@ -77,7 +77,7 @@ serd_byte_source_open_source(SerdByteSource* source,
}
SerdStatus
-serd_byte_source_prepare(SerdByteSource* source)
+serd_byte_source_prepare(SerdByteSource* const source)
{
source->prepared = true;
@@ -90,7 +90,8 @@ serd_byte_source_prepare(SerdByteSource* source)
}
SerdStatus
-serd_byte_source_open_string(SerdByteSource* source, const uint8_t* utf8)
+serd_byte_source_open_string(SerdByteSource* const source,
+ const uint8_t* const utf8)
{
const Cursor cur = {(const uint8_t*)"(string)", 1, 1};
@@ -101,7 +102,7 @@ serd_byte_source_open_string(SerdByteSource* source, const uint8_t* utf8)
}
SerdStatus
-serd_byte_source_close(SerdByteSource* source)
+serd_byte_source_close(SerdByteSource* const source)
{
if (source->page_size > 1) {
serd_free_aligned(source->file_buf);
diff --git a/src/env.c b/src/env.c
index 942f47f3..ad0252fb 100644
--- a/src/env.c
+++ b/src/env.c
@@ -35,7 +35,7 @@ struct SerdEnvImpl {
};
SerdEnv*
-serd_env_new(const SerdNode* base_uri)
+serd_env_new(const SerdNode* const base_uri)
{
SerdEnv* env = (SerdEnv*)calloc(1, sizeof(struct SerdEnvImpl));
if (env && base_uri) {
@@ -46,7 +46,7 @@ serd_env_new(const SerdNode* base_uri)
}
void
-serd_env_free(SerdEnv* env)
+serd_env_free(SerdEnv* const env)
{
if (!env) {
return;
@@ -63,7 +63,7 @@ serd_env_free(SerdEnv* env)
}
const SerdNode*
-serd_env_get_base_uri(const SerdEnv* env, SerdURI* out)
+serd_env_get_base_uri(const SerdEnv* const env, SerdURI* const out)
{
if (out) {
*out = env->base_uri;
@@ -73,7 +73,7 @@ serd_env_get_base_uri(const SerdEnv* env, SerdURI* out)
}
SerdStatus
-serd_env_set_base_uri(SerdEnv* env, const SerdNode* uri)
+serd_env_set_base_uri(SerdEnv* const env, const SerdNode* const uri)
{
if (!env || (uri && uri->type != SERD_URI)) {
return SERD_ERR_BAD_ARG;
@@ -100,7 +100,9 @@ serd_env_set_base_uri(SerdEnv* env, const SerdNode* uri)
}
SERD_PURE_FUNC static SerdPrefix*
-serd_env_find(const SerdEnv* env, const uint8_t* name, size_t name_len)
+serd_env_find(const SerdEnv* const env,
+ const uint8_t* const name,
+ const size_t name_len)
{
for (size_t i = 0; i < env->n_prefixes; ++i) {
const SerdNode* const prefix_name = &env->prefixes[i].name;
@@ -115,7 +117,9 @@ serd_env_find(const SerdEnv* env, const uint8_t* name, size_t name_len)
}
static void
-serd_env_add(SerdEnv* env, const SerdNode* name, const SerdNode* uri)
+serd_env_add(SerdEnv* const env,
+ const SerdNode* const name,
+ const SerdNode* const uri)
{
SerdPrefix* const prefix = serd_env_find(env, name->buf, name->n_bytes);
if (prefix) {
@@ -133,7 +137,9 @@ serd_env_add(SerdEnv* env, const SerdNode* name, const SerdNode* uri)
}
SerdStatus
-serd_env_set_prefix(SerdEnv* env, const SerdNode* name, const SerdNode* uri)
+serd_env_set_prefix(SerdEnv* const env,
+ const SerdNode* const name,
+ const SerdNode* const uri)
{
if (!name->buf || uri->type != SERD_URI) {
return SERD_ERR_BAD_ARG;
@@ -157,9 +163,9 @@ serd_env_set_prefix(SerdEnv* env, const SerdNode* name, const SerdNode* uri)
}
SerdStatus
-serd_env_set_prefix_from_strings(SerdEnv* env,
- const uint8_t* name,
- const uint8_t* uri)
+serd_env_set_prefix_from_strings(SerdEnv* const env,
+ const uint8_t* const name,
+ const uint8_t* const uri)
{
const SerdNode name_node = serd_node_from_string(SERD_LITERAL, name);
const SerdNode uri_node = serd_node_from_string(SERD_URI, uri);
@@ -168,10 +174,10 @@ serd_env_set_prefix_from_strings(SerdEnv* env,
}
bool
-serd_env_qualify(const SerdEnv* env,
- const SerdNode* uri,
- SerdNode* prefix,
- SerdChunk* suffix)
+serd_env_qualify(const SerdEnv* const env,
+ const SerdNode* const uri,
+ SerdNode* const prefix,
+ SerdChunk* const suffix)
{
for (size_t i = 0; i < env->n_prefixes; ++i) {
const SerdNode* const prefix_uri = &env->prefixes[i].uri;
@@ -190,10 +196,10 @@ serd_env_qualify(const SerdEnv* env,
}
SerdStatus
-serd_env_expand(const SerdEnv* env,
- const SerdNode* curie,
- SerdChunk* uri_prefix,
- SerdChunk* uri_suffix)
+serd_env_expand(const SerdEnv* const env,
+ const SerdNode* const curie,
+ SerdChunk* const uri_prefix,
+ SerdChunk* const uri_suffix)
{
const uint8_t* const colon =
(const uint8_t*)memchr(curie->buf, ':', curie->n_bytes + 1);
@@ -214,7 +220,7 @@ serd_env_expand(const SerdEnv* env,
}
SerdNode
-serd_env_expand_node(const SerdEnv* env, const SerdNode* node)
+serd_env_expand_node(const SerdEnv* const env, const SerdNode* const node)
{
switch (node->type) {
case SERD_NOTHING:
@@ -248,7 +254,9 @@ serd_env_expand_node(const SerdEnv* env, const SerdNode* node)
}
void
-serd_env_foreach(const SerdEnv* env, SerdPrefixSink func, void* handle)
+serd_env_foreach(const SerdEnv* const env,
+ const SerdPrefixSink func,
+ void* const handle)
{
for (size_t i = 0; i < env->n_prefixes; ++i) {
func(handle, &env->prefixes[i].name, &env->prefixes[i].uri);
diff --git a/src/n3.c b/src/n3.c
index c2ada42c..33828258 100644
--- a/src/n3.c
+++ b/src/n3.c
@@ -48,7 +48,7 @@ _Pragma("clang diagnostic ignored \"-Wmissing-declarations\"")
} while (0)
static bool
-fancy_syntax(const SerdReader* reader)
+fancy_syntax(const SerdReader* const reader)
{
return reader->syntax == SERD_TURTLE || reader->syntax == SERD_TRIG;
}
@@ -60,7 +60,7 @@ static SerdStatus
read_predicateObjectList(SerdReader* reader, ReadContext ctx, bool* ate_dot);
static uint8_t
-read_HEX(SerdReader* reader)
+read_HEX(SerdReader* const reader)
{
const int c = peek_byte(reader);
if (is_xdigit(c)) {
@@ -73,7 +73,7 @@ read_HEX(SerdReader* reader)
// Read UCHAR escape, initial \ is already eaten by caller
static SerdStatus
-read_UCHAR(SerdReader* reader, Ref dest, uint32_t* char_code)
+read_UCHAR(SerdReader* const reader, const Ref dest, uint32_t* const char_code)
{
const int b = peek_byte(reader);
unsigned length = 0;
@@ -153,7 +153,7 @@ read_UCHAR(SerdReader* reader, Ref dest, uint32_t* char_code)
// Read ECHAR escape, initial \ is already eaten by caller
static SerdStatus
-read_ECHAR(SerdReader* reader, Ref dest, SerdNodeFlags* flags)
+read_ECHAR(SerdReader* const reader, const Ref dest, SerdNodeFlags* const flags)
{
const int c = peek_byte(reader);
switch (c) {
@@ -190,7 +190,7 @@ read_ECHAR(SerdReader* reader, Ref dest, SerdNodeFlags* flags)
}
static SerdStatus
-bad_char(SerdReader* reader, const char* fmt, uint8_t c)
+bad_char(SerdReader* const reader, const char* const fmt, const uint8_t c)
{
// Skip bytes until the next start byte
for (int b = peek_byte(reader); b != EOF && ((uint8_t)b & 0x80);) {
@@ -203,7 +203,10 @@ bad_char(SerdReader* reader, const char* fmt, uint8_t c)
}
static SerdStatus
-read_utf8_bytes(SerdReader* reader, uint8_t bytes[4], uint32_t* size, uint8_t c)
+read_utf8_bytes(SerdReader* const reader,
+ uint8_t bytes[4],
+ uint32_t* const size,
+ const uint8_t c)
{
*size = utf8_num_bytes(c);
if (*size <= 1 || *size > 4) {
@@ -225,7 +228,7 @@ read_utf8_bytes(SerdReader* reader, uint8_t bytes[4], uint32_t* size, uint8_t c)
}
static SerdStatus
-read_utf8_character(SerdReader* reader, Ref dest, uint8_t c)
+read_utf8_character(SerdReader* const reader, const Ref dest, const uint8_t c)
{
uint32_t size = 0;
uint8_t bytes[4] = {0, 0, 0, 0};
@@ -240,7 +243,10 @@ read_utf8_character(SerdReader* reader, Ref dest, uint8_t c)
}
static SerdStatus
-read_utf8_code(SerdReader* reader, Ref dest, uint32_t* code, uint8_t c)
+read_utf8_code(SerdReader* const reader,
+ const Ref dest,
+ uint32_t* const code,
+ const uint8_t c)
{
uint32_t size = 0;
uint8_t bytes[4] = {0, 0, 0, 0};
@@ -258,7 +264,10 @@ read_utf8_code(SerdReader* reader, Ref dest, uint32_t* code, uint8_t c)
// Read one character (possibly multi-byte)
// The first byte, c, has already been eaten by caller
static SerdStatus
-read_character(SerdReader* reader, Ref dest, SerdNodeFlags* flags, uint8_t c)
+read_character(SerdReader* const reader,
+ const Ref dest,
+ SerdNodeFlags* const flags,
+ const uint8_t c)
{
if (!(c & 0x80)) {
switch (c) {
@@ -281,7 +290,7 @@ read_character(SerdReader* reader, Ref dest, SerdNodeFlags* flags, uint8_t c)
// [10] comment ::= '#' ( [^#xA #xD] )*
static void
-read_comment(SerdReader* reader)
+read_comment(SerdReader* const reader)
{
eat_byte_safe(reader, '#');
int c = 0;
@@ -292,7 +301,7 @@ read_comment(SerdReader* reader)
// [24] ws ::= #x9 | #xA | #xD | #x20 | comment
static bool
-read_ws(SerdReader* reader)
+read_ws(SerdReader* const reader)
{
const int c = peek_byte(reader);
switch (c) {
@@ -311,7 +320,7 @@ read_ws(SerdReader* reader)
}
static bool
-read_ws_star(SerdReader* reader)
+read_ws_star(SerdReader* const reader)
{
while (read_ws(reader)) {
}
@@ -320,14 +329,14 @@ read_ws_star(SerdReader* reader)
}
static bool
-peek_delim(SerdReader* reader, const uint8_t delim)
+peek_delim(SerdReader* const reader, const uint8_t delim)
{
read_ws_star(reader);
return peek_byte(reader) == delim;
}
static bool
-eat_delim(SerdReader* reader, const uint8_t delim)
+eat_delim(SerdReader* const reader, const uint8_t delim)
{
if (peek_delim(reader, delim)) {
eat_byte_safe(reader, delim);
@@ -340,10 +349,10 @@ eat_delim(SerdReader* reader, const uint8_t delim)
// STRING_LITERAL_LONG_QUOTE and STRING_LITERAL_LONG_SINGLE_QUOTE
// Initial triple quotes are already eaten by caller
static SerdStatus
-read_STRING_LITERAL_LONG(SerdReader* reader,
- Ref ref,
- SerdNodeFlags* flags,
- uint8_t q)
+read_STRING_LITERAL_LONG(SerdReader* const reader,
+ const Ref ref,
+ SerdNodeFlags* const flags,
+ const uint8_t q)
{
SerdStatus st = SERD_SUCCESS;
@@ -381,10 +390,10 @@ read_STRING_LITERAL_LONG(SerdReader* reader,
// STRING_LITERAL_QUOTE and STRING_LITERAL_SINGLE_QUOTE
// Initial quote is already eaten by caller
static SerdStatus
-read_STRING_LITERAL(SerdReader* reader,
- Ref ref,
- SerdNodeFlags* flags,
- uint8_t q)
+read_STRING_LITERAL(SerdReader* const reader,
+ const Ref ref,
+ SerdNodeFlags* const flags,
+ const uint8_t q)
{
SerdStatus st = SERD_SUCCESS;
@@ -421,7 +430,9 @@ read_STRING_LITERAL(SerdReader* reader,
}
static SerdStatus
-read_String(SerdReader* reader, Ref node, SerdNodeFlags* flags)
+read_String(SerdReader* const reader,
+ const Ref node,
+ SerdNodeFlags* const flags)
{
const int q1 = peek_byte(reader);
eat_byte_safe(reader, q1);
@@ -466,7 +477,7 @@ is_PN_CHARS_BASE(const uint32_t c)
}
static SerdStatus
-read_PN_CHARS_BASE(SerdReader* reader, Ref dest)
+read_PN_CHARS_BASE(SerdReader* const reader, const Ref dest)
{
uint32_t code = 0;
const int c = peek_byte(reader);
@@ -496,7 +507,7 @@ is_PN_CHARS(const uint32_t c)
}
static SerdStatus
-read_PN_CHARS(SerdReader* reader, Ref dest)
+read_PN_CHARS(SerdReader* const reader, const Ref dest)
{
uint32_t code = 0;
const int c = peek_byte(reader);
@@ -516,7 +527,7 @@ read_PN_CHARS(SerdReader* reader, Ref dest)
}
static SerdStatus
-read_PERCENT(SerdReader* reader, Ref dest)
+read_PERCENT(SerdReader* const reader, const Ref dest)
{
push_byte(reader, dest, eat_byte_safe(reader, '%'));
const uint8_t h1 = read_HEX(reader);
@@ -530,7 +541,7 @@ read_PERCENT(SerdReader* reader, Ref dest)
}
static SerdStatus
-read_PN_LOCAL_ESC(SerdReader* reader, Ref dest)
+read_PN_LOCAL_ESC(SerdReader* const reader, const Ref dest)
{
eat_byte_safe(reader, '\\');
@@ -566,7 +577,7 @@ read_PN_LOCAL_ESC(SerdReader* reader, Ref dest)
}
static SerdStatus
-read_PLX(SerdReader* reader, Ref dest)
+read_PLX(SerdReader* const reader, const Ref dest)
{
const int c = peek_byte(reader);
switch (c) {
@@ -580,7 +591,7 @@ read_PLX(SerdReader* reader, Ref dest)
}
static SerdStatus
-read_PN_LOCAL(SerdReader* reader, Ref dest, bool* ate_dot)
+read_PN_LOCAL(SerdReader* const reader, const Ref dest, bool* const ate_dot)
{
int c = peek_byte(reader);
SerdStatus st = SERD_SUCCESS;
@@ -632,7 +643,7 @@ read_PN_LOCAL(SerdReader* reader, Ref dest, bool* ate_dot)
// Read the remainder of a PN_PREFIX after some initial characters
static SerdStatus
-read_PN_PREFIX_tail(SerdReader* reader, Ref dest)
+read_PN_PREFIX_tail(SerdReader* const reader, const Ref dest)
{
int c = 0;
while ((c = peek_byte(reader))) { // Middle: (PN_CHARS | '.')*
@@ -652,7 +663,7 @@ read_PN_PREFIX_tail(SerdReader* reader, Ref dest)
}
static SerdStatus
-read_PN_PREFIX(SerdReader* reader, Ref dest)
+read_PN_PREFIX(SerdReader* const reader, const Ref dest)
{
if (!read_PN_CHARS_BASE(reader, dest)) {
return read_PN_PREFIX_tail(reader, dest);
@@ -662,7 +673,7 @@ read_PN_PREFIX(SerdReader* reader, Ref dest)
}
static SerdStatus
-read_LANGTAG(SerdReader* reader, Ref* dest)
+read_LANGTAG(SerdReader* const reader, Ref* const dest)
{
int c = peek_byte(reader);
if (!is_alpha(c)) {
@@ -688,7 +699,7 @@ read_LANGTAG(SerdReader* reader, Ref* dest)
}
static SerdStatus
-read_IRIREF_scheme(SerdReader* reader, Ref dest)
+read_IRIREF_scheme(SerdReader* const reader, const Ref dest)
{
int c = peek_byte(reader);
if (!is_alpha(c)) {
@@ -718,7 +729,7 @@ read_IRIREF_scheme(SerdReader* reader, Ref dest)
}
static SerdStatus
-read_IRIREF(SerdReader* reader, Ref* dest)
+read_IRIREF(SerdReader* const reader, Ref* const dest)
{
if (!eat_byte_check(reader, '<')) {
return SERD_ERR_BAD_SYNTAX;
@@ -803,7 +814,10 @@ read_IRIREF(SerdReader* reader, Ref* dest)
}
static SerdStatus
-read_PrefixedName(SerdReader* reader, Ref dest, bool read_prefix, bool* ate_dot)
+read_PrefixedName(SerdReader* const reader,
+ const Ref dest,
+ const bool read_prefix,
+ bool* const ate_dot)
{
SerdStatus st = SERD_SUCCESS;
if (read_prefix && ((st = read_PN_PREFIX(reader, dest)) > SERD_FAILURE)) {
@@ -822,7 +836,7 @@ read_PrefixedName(SerdReader* reader, Ref dest, bool read_prefix, bool* ate_dot)
}
static SerdStatus
-read_0_9(SerdReader* reader, Ref str, bool at_least_one)
+read_0_9(SerdReader* const reader, const Ref str, const bool at_least_one)
{
unsigned count = 0;
SerdStatus st = SERD_SUCCESS;
@@ -838,7 +852,10 @@ read_0_9(SerdReader* reader, Ref str, bool at_least_one)
}
static SerdStatus
-read_number(SerdReader* reader, Ref* dest, Ref* datatype, bool* ate_dot)
+read_number(SerdReader* const reader,
+ Ref* const dest,
+ Ref* const datatype,
+ bool* const ate_dot)
{
#define XSD_DECIMAL NS_XSD "decimal"
#define XSD_DOUBLE NS_XSD "double"
@@ -901,7 +918,7 @@ read_number(SerdReader* reader, Ref* dest, Ref* datatype, bool* ate_dot)
}
static SerdStatus
-read_iri(SerdReader* reader, Ref* dest, bool* ate_dot)
+read_iri(SerdReader* const reader, Ref* const dest, bool* const ate_dot)
{
switch (peek_byte(reader)) {
case '<':
@@ -913,12 +930,12 @@ read_iri(SerdReader* reader, Ref* dest, bool* ate_dot)
}
static SerdStatus
-read_literal(SerdReader* reader,
- Ref* dest,
- Ref* datatype,
- Ref* lang,
- SerdNodeFlags* flags,
- bool* ate_dot)
+read_literal(SerdReader* const reader,
+ Ref* const dest,
+ Ref* const datatype,
+ Ref* const lang,
+ SerdNodeFlags* const flags,
+ bool* const ate_dot)
{
*dest = push_node(reader, SERD_LITERAL, "", 0);
@@ -954,7 +971,7 @@ read_literal(SerdReader* reader,
}
static SerdStatus
-read_verb(SerdReader* reader, Ref* dest)
+read_verb(SerdReader* const reader, Ref* const dest)
{
if (peek_byte(reader) == '<') {
return read_IRIREF(reader, dest);
@@ -986,7 +1003,9 @@ read_verb(SerdReader* reader, Ref* dest)
}
static SerdStatus
-read_BLANK_NODE_LABEL(SerdReader* reader, Ref* dest, bool* ate_dot)
+read_BLANK_NODE_LABEL(SerdReader* const reader,
+ Ref* const dest,
+ bool* const ate_dot)
{
eat_byte_safe(reader, '_');
eat_byte_check(reader, ':');
@@ -1039,7 +1058,7 @@ read_BLANK_NODE_LABEL(SerdReader* reader, Ref* dest, bool* ate_dot)
}
static Ref
-read_blankName(SerdReader* reader)
+read_blankName(SerdReader* const reader)
{
eat_byte_safe(reader, '=');
if (eat_byte_check(reader, '=') != '=') {
@@ -1055,7 +1074,10 @@ read_blankName(SerdReader* reader)
}
static SerdStatus
-read_anon(SerdReader* reader, ReadContext ctx, bool subject, Ref* dest)
+read_anon(SerdReader* const reader,
+ ReadContext ctx,
+ const bool subject,
+ Ref* const dest)
{
const SerdStatementFlags old_flags = *ctx.flags;
bool empty = false;
@@ -1109,7 +1131,10 @@ read_anon(SerdReader* reader, ReadContext ctx, bool subject, Ref* dest)
encountered, and leaves stack in original calling state (i.e. pops
everything it pushes). */
static SerdStatus
-read_object(SerdReader* reader, ReadContext* ctx, bool emit, bool* ate_dot)
+read_object(SerdReader* const reader,
+ ReadContext* const ctx,
+ const bool emit,
+ bool* const ate_dot)
{
static const char* const XSD_BOOLEAN = NS_XSD "boolean";
static const size_t XSD_BOOLEAN_LEN = 40;
@@ -1223,7 +1248,7 @@ read_object(SerdReader* reader, ReadContext* ctx, bool emit, bool* ate_dot)
}
static SerdStatus
-read_objectList(SerdReader* reader, ReadContext ctx, bool* ate_dot)
+read_objectList(SerdReader* const reader, ReadContext ctx, bool* const ate_dot)
{
SerdStatus st = SERD_SUCCESS;
TRY(st, read_object(reader, &ctx, true, ate_dot));
@@ -1240,7 +1265,9 @@ read_objectList(SerdReader* reader, ReadContext ctx, bool* ate_dot)
}
static SerdStatus
-read_predicateObjectList(SerdReader* reader, ReadContext ctx, bool* ate_dot)
+read_predicateObjectList(SerdReader* const reader,
+ ReadContext ctx,
+ bool* const ate_dot)
{
SerdStatus st = SERD_SUCCESS;
while (!(st = read_verb(reader, &ctx.predicate)) && read_ws_star(reader) &&
@@ -1277,11 +1304,11 @@ read_predicateObjectList(SerdReader* reader, ReadContext ctx, bool* ate_dot)
}
static SerdStatus
-end_collection(SerdReader* reader,
- ReadContext ctx,
- Ref n1,
- Ref n2,
- SerdStatus st)
+end_collection(SerdReader* const reader,
+ const ReadContext ctx,
+ const Ref n1,
+ const Ref n2,
+ const SerdStatus st)
{
pop_node(reader, n2);
pop_node(reader, n1);
@@ -1295,7 +1322,7 @@ end_collection(SerdReader* reader,
}
static SerdStatus
-read_collection(SerdReader* reader, ReadContext ctx, Ref* dest)
+read_collection(SerdReader* const reader, ReadContext ctx, Ref* const dest)
{
SerdStatus st = SERD_SUCCESS;
eat_byte_safe(reader, '(');
@@ -1356,7 +1383,10 @@ read_collection(SerdReader* reader, ReadContext ctx, Ref* dest)
}
static SerdStatus
-read_subject(SerdReader* reader, ReadContext ctx, Ref* dest, int* s_type)
+read_subject(SerdReader* const reader,
+ const ReadContext ctx,
+ Ref* const dest,
+ int* const s_type)
{
SerdStatus st = SERD_SUCCESS;
bool ate_dot = false;
@@ -1383,7 +1413,7 @@ read_subject(SerdReader* reader, ReadContext ctx, Ref* dest, int* s_type)
}
static SerdStatus
-read_labelOrSubject(SerdReader* reader, Ref* dest)
+read_labelOrSubject(SerdReader* const reader, Ref* const dest)
{
bool ate_dot = false;
switch (peek_byte(reader)) {
@@ -1407,7 +1437,7 @@ read_labelOrSubject(SerdReader* reader, Ref* dest)
}
static SerdStatus
-read_triples(SerdReader* reader, ReadContext ctx, bool* ate_dot)
+read_triples(SerdReader* const reader, ReadContext ctx, bool* const ate_dot)
{
SerdStatus st = SERD_FAILURE;
if (ctx.subject) {
@@ -1427,7 +1457,7 @@ read_triples(SerdReader* reader, ReadContext ctx, bool* ate_dot)
}
static SerdStatus
-read_base(SerdReader* reader, bool sparql, bool token)
+read_base(SerdReader* const reader, const bool sparql, const bool token)
{
SerdStatus st = SERD_SUCCESS;
if (token) {
@@ -1456,7 +1486,7 @@ read_base(SerdReader* reader, bool sparql, bool token)
}
static SerdStatus
-read_prefixID(SerdReader* reader, bool sparql, bool token)
+read_prefixID(SerdReader* const reader, const bool sparql, const bool token)
{
SerdStatus st = SERD_SUCCESS;
if (token) {
@@ -1494,7 +1524,7 @@ read_prefixID(SerdReader* reader, bool sparql, bool token)
}
static SerdStatus
-read_directive(SerdReader* reader)
+read_directive(SerdReader* const reader)
{
const bool sparql = peek_byte(reader) != '@';
if (!sparql) {
@@ -1521,7 +1551,7 @@ read_directive(SerdReader* reader)
}
static SerdStatus
-read_wrappedGraph(SerdReader* reader, ReadContext* ctx)
+read_wrappedGraph(SerdReader* const reader, ReadContext* const ctx)
{
if (!eat_byte_check(reader, '{')) {
return SERD_ERR_BAD_SYNTAX;
@@ -1560,7 +1590,10 @@ read_wrappedGraph(SerdReader* reader, ReadContext* ctx)
}
static int
-tokcmp(SerdReader* reader, Ref ref, const char* tok, size_t n)
+tokcmp(SerdReader* const reader,
+ const Ref ref,
+ const char* const tok,
+ const size_t n)
{
SerdNode* node = deref(reader, ref);
if (!node || node->n_bytes != n) {
@@ -1571,7 +1604,7 @@ tokcmp(SerdReader* reader, Ref ref, const char* tok, size_t n)
}
SerdStatus
-read_n3_statement(SerdReader* reader)
+read_n3_statement(SerdReader* const reader)
{
SerdStatementFlags flags = 0;
ReadContext ctx = {0, 0, 0, 0, 0, 0, &flags};
@@ -1651,7 +1684,7 @@ read_n3_statement(SerdReader* reader)
}
static void
-skip_until(SerdReader* reader, uint8_t byte)
+skip_until(SerdReader* const reader, const uint8_t byte)
{
for (int c = 0; (c = peek_byte(reader)) && c != byte;) {
eat_byte_safe(reader, c);
@@ -1659,7 +1692,7 @@ skip_until(SerdReader* reader, uint8_t byte)
}
SerdStatus
-read_turtleTrigDoc(SerdReader* reader)
+read_turtleTrigDoc(SerdReader* const reader)
{
while (!reader->source.eof) {
const SerdStatus st = read_n3_statement(reader);
@@ -1675,7 +1708,7 @@ read_turtleTrigDoc(SerdReader* reader)
}
SerdStatus
-read_nquadsDoc(SerdReader* reader)
+read_nquadsDoc(SerdReader* const reader)
{
SerdStatus st = SERD_SUCCESS;
while (!reader->source.eof) {
diff --git a/src/node.c b/src/node.c
index 6b4c11ec..5629565a 100644
--- a/src/node.c
+++ b/src/node.c
@@ -40,7 +40,7 @@
#endif
SerdNode
-serd_node_from_string(SerdType type, const uint8_t* str)
+serd_node_from_string(const SerdType type, const uint8_t* const str)
{
if (!str) {
return SERD_NODE_NULL;
@@ -54,7 +54,9 @@ serd_node_from_string(SerdType type, const uint8_t* str)
}
SerdNode
-serd_node_from_substring(SerdType type, const uint8_t* str, const size_t len)
+serd_node_from_substring(const SerdType type,
+ const uint8_t* const str,
+ const size_t len)
{
if (!str) {
return SERD_NODE_NULL;
@@ -69,7 +71,7 @@ serd_node_from_substring(SerdType type, const uint8_t* str, const size_t len)
}
SerdNode
-serd_node_copy(const SerdNode* node)
+serd_node_copy(const SerdNode* const node)
{
if (!node || !node->buf) {
return SERD_NODE_NULL;
@@ -83,7 +85,7 @@ serd_node_copy(const SerdNode* node)
}
bool
-serd_node_equals(const SerdNode* a, const SerdNode* b)
+serd_node_equals(const SerdNode* const a, const SerdNode* const b)
{
return (a == b) ||
(a->type == b->type && a->n_bytes == b->n_bytes &&
@@ -93,7 +95,7 @@ serd_node_equals(const SerdNode* a, const SerdNode* b)
}
static size_t
-serd_uri_string_length(const SerdURI* uri)
+serd_uri_string_length(const SerdURI* const uri)
{
size_t len = uri->path_base.len;
@@ -112,7 +114,7 @@ serd_uri_string_length(const SerdURI* uri)
}
static size_t
-string_sink(const void* buf, size_t len, void* stream)
+string_sink(const void* const buf, const size_t len, void* const stream)
{
uint8_t** ptr = (uint8_t**)stream;
memcpy(*ptr, buf, len);
@@ -121,9 +123,9 @@ string_sink(const void* buf, size_t len, void* stream)
}
SerdNode
-serd_node_new_uri_from_node(const SerdNode* uri_node,
- const SerdURI* base,
- SerdURI* out)
+serd_node_new_uri_from_node(const SerdNode* const uri_node,
+ const SerdURI* const base,
+ SerdURI* const out)
{
return (uri_node->type == SERD_URI && uri_node->buf)
? serd_node_new_uri_from_string(uri_node->buf, base, out)
@@ -131,9 +133,9 @@ serd_node_new_uri_from_node(const SerdNode* uri_node,
}
SerdNode
-serd_node_new_uri_from_string(const uint8_t* str,
- const SerdURI* base,
- SerdURI* out)
+serd_node_new_uri_from_string(const uint8_t* const str,
+ const SerdURI* const base,
+ SerdURI* const out)
{
if (!str || str[0] == '\0') {
// Empty URI => Base URI, or nothing if no base is given
@@ -182,10 +184,10 @@ is_uri_path_char(const uint8_t c)
}
SerdNode
-serd_node_new_file_uri(const uint8_t* path,
- const uint8_t* hostname,
- SerdURI* out,
- bool escape)
+serd_node_new_file_uri(const uint8_t* const path,
+ const uint8_t* const hostname,
+ SerdURI* const out,
+ const bool escape)
{
const size_t path_len = strlen((const char*)path);
const size_t hostname_len = hostname ? strlen((const char*)hostname) : 0;
@@ -233,7 +235,9 @@ serd_node_new_file_uri(const uint8_t* path,
}
SerdNode
-serd_node_new_uri(const SerdURI* uri, const SerdURI* base, SerdURI* out)
+serd_node_new_uri(const SerdURI* const uri,
+ const SerdURI* const base,
+ SerdURI* const out)
{
SerdURI abs_uri = *uri;
if (base) {
@@ -258,10 +262,10 @@ serd_node_new_uri(const SerdURI* uri, const SerdURI* base, SerdURI* out)
}
SerdNode
-serd_node_new_relative_uri(const SerdURI* uri,
- const SerdURI* base,
- const SerdURI* root,
- SerdURI* out)
+serd_node_new_relative_uri(const SerdURI* const uri,
+ const SerdURI* const base,
+ const SerdURI* const root,
+ SerdURI* const out)
{
const size_t uri_len = serd_uri_string_length(uri);
const size_t base_len = serd_uri_string_length(base);
@@ -283,14 +287,14 @@ serd_node_new_relative_uri(const SerdURI* uri,
}
static unsigned
-serd_digits(double abs)
+serd_digits(const double abs)
{
const double lg = ceil(log10(floor(abs) + 1.0));
return lg < 1.0 ? 1U : (unsigned)lg;
}
SerdNode
-serd_node_new_decimal(double d, unsigned frac_digits)
+serd_node_new_decimal(const double d, const unsigned frac_digits)
{
if (isnan(d) || isinf(d)) {
return SERD_NODE_NULL;
@@ -345,7 +349,7 @@ serd_node_new_decimal(double d, unsigned frac_digits)
}
SerdNode
-serd_node_new_integer(int64_t i)
+serd_node_new_integer(const int64_t i)
{
uint64_t abs_i = (i < 0) ? -i : i;
const unsigned digits = serd_digits((double)abs_i);
@@ -370,7 +374,9 @@ serd_node_new_integer(int64_t i)
}
SerdNode
-serd_node_new_blob(const void* buf, size_t size, bool wrap_lines)
+serd_node_new_blob(const void* const buf,
+ const size_t size,
+ const bool wrap_lines)
{
const size_t len = serd_base64_get_length(size, wrap_lines);
uint8_t* str = (uint8_t*)calloc(len + 2, 1);
@@ -384,7 +390,7 @@ serd_node_new_blob(const void* buf, size_t size, bool wrap_lines)
}
void
-serd_node_free(SerdNode* node)
+serd_node_free(SerdNode* const node)
{
if (node && node->buf) {
free((uint8_t*)node->buf);
diff --git a/src/reader.c b/src/reader.c
index a728f016..9a5e4ba2 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -30,7 +30,7 @@
#include <string.h>
SerdStatus
-r_err(SerdReader* reader, SerdStatus st, const char* fmt, ...)
+r_err(SerdReader* const reader, const SerdStatus st, const char* const fmt, ...)
{
va_list args;
va_start(args, fmt);
@@ -42,7 +42,7 @@ r_err(SerdReader* reader, SerdStatus st, const char* fmt, ...)
}
void
-set_blank_id(SerdReader* reader, Ref ref, size_t buf_size)
+set_blank_id(SerdReader* const reader, const Ref ref, const size_t buf_size)
{
SerdNode* node = deref(reader, ref);
const char* prefix = reader->bprefix ? (const char*)reader->bprefix : "";
@@ -51,13 +51,13 @@ set_blank_id(SerdReader* reader, Ref ref, size_t buf_size)
}
size_t
-genid_size(SerdReader* reader)
+genid_size(const SerdReader* const reader)
{
return reader->bprefix_len + 1 + 10 + 1; // + "b" + UINT32_MAX + \0
}
Ref
-blank_id(SerdReader* reader)
+blank_id(SerdReader* const reader)
{
Ref ref = push_node_padded(reader, genid_size(reader), SERD_BLANK, "", 0);
set_blank_id(reader, ref, genid_size(reader));
@@ -66,7 +66,10 @@ blank_id(SerdReader* reader)
/** fread-like wrapper for getc (which is faster). */
static size_t
-serd_file_read_byte(void* buf, size_t size, size_t nmemb, void* stream)
+serd_file_read_byte(void* const buf,
+ const size_t size,
+ const size_t nmemb,
+ void* const stream)
{
(void)size;
(void)nmemb;
@@ -81,11 +84,11 @@ serd_file_read_byte(void* buf, size_t size, size_t nmemb, void* stream)
}
Ref
-push_node_padded(SerdReader* reader,
- size_t maxlen,
- SerdType type,
- const char* str,
- size_t n_bytes)
+push_node_padded(SerdReader* const reader,
+ const size_t maxlen,
+ const SerdType type,
+ const char* const str,
+ const size_t n_bytes)
{
void* mem = serd_stack_push_aligned(
&reader->stack, sizeof(SerdNode) + maxlen + 1, sizeof(SerdNode));
@@ -108,13 +111,16 @@ push_node_padded(SerdReader* reader,
}
Ref
-push_node(SerdReader* reader, SerdType type, const char* str, size_t n_bytes)
+push_node(SerdReader* const reader,
+ const SerdType type,
+ const char* const str,
+ const size_t n_bytes)
{
return push_node_padded(reader, n_bytes, type, str, n_bytes);
}
SerdNode*
-deref(SerdReader* reader, const Ref ref)
+deref(SerdReader* const reader, const Ref ref)
{
if (ref) {
SerdNode* node = (SerdNode*)(reader->stack.buf + ref);
@@ -125,7 +131,7 @@ deref(SerdReader* reader, const Ref ref)
}
Ref
-pop_node(SerdReader* reader, Ref ref)
+pop_node(SerdReader* const reader, const Ref ref)
{
if (ref && ref != reader->rdf_first && ref != reader->rdf_rest &&
ref != reader->rdf_nil) {
@@ -141,7 +147,11 @@ pop_node(SerdReader* reader, Ref ref)
}
SerdStatus
-emit_statement(SerdReader* reader, ReadContext ctx, Ref o, Ref d, Ref l)
+emit_statement(SerdReader* const reader,
+ const ReadContext ctx,
+ const Ref o,
+ const Ref d,
+ const Ref l)
{
SerdNode* graph = deref(reader, ctx.graph);
if (!graph && reader->default_graph.buf) {
@@ -164,26 +174,26 @@ emit_statement(SerdReader* reader, ReadContext ctx, Ref o, Ref d, Ref l)
}
static SerdStatus
-read_statement(SerdReader* reader)
+read_statement(SerdReader* const reader)
{
return read_n3_statement(reader);
}
static SerdStatus
-read_doc(SerdReader* reader)
+read_doc(SerdReader* const reader)
{
return ((reader->syntax == SERD_NQUADS) ? read_nquadsDoc(reader)
: read_turtleTrigDoc(reader));
}
SerdReader*
-serd_reader_new(SerdSyntax syntax,
- void* handle,
- void (*free_handle)(void*),
- SerdBaseSink base_sink,
- SerdPrefixSink prefix_sink,
- SerdStatementSink statement_sink,
- SerdEndSink end_sink)
+serd_reader_new(const SerdSyntax syntax,
+ void* const handle,
+ void (*const free_handle)(void*),
+ const SerdBaseSink base_sink,
+ const SerdPrefixSink prefix_sink,
+ const SerdStatementSink statement_sink,
+ const SerdEndSink end_sink)
{
SerdReader* me = (SerdReader*)calloc(1, sizeof(SerdReader));
me->handle = handle;
@@ -206,22 +216,22 @@ serd_reader_new(SerdSyntax syntax,
}
void
-serd_reader_set_strict(SerdReader* reader, bool strict)
+serd_reader_set_strict(SerdReader* const reader, const bool strict)
{
reader->strict = strict;
}
void
-serd_reader_set_error_sink(SerdReader* reader,
- SerdErrorSink error_sink,
- void* error_handle)
+serd_reader_set_error_sink(SerdReader* const reader,
+ const SerdErrorSink error_sink,
+ void* const error_handle)
{
reader->error_sink = error_sink;
reader->error_handle = error_handle;
}
void
-serd_reader_free(SerdReader* reader)
+serd_reader_free(SerdReader* const reader)
{
if (!reader) {
return;
@@ -244,13 +254,14 @@ serd_reader_free(SerdReader* reader)
}
void*
-serd_reader_get_handle(const SerdReader* reader)
+serd_reader_get_handle(const SerdReader* const reader)
{
return reader->handle;
}
void
-serd_reader_add_blank_prefix(SerdReader* reader, const uint8_t* prefix)
+serd_reader_add_blank_prefix(SerdReader* const reader,
+ const uint8_t* const prefix)
{
free(reader->bprefix);
reader->bprefix_len = 0;
@@ -265,14 +276,15 @@ serd_reader_add_blank_prefix(SerdReader* reader, const uint8_t* prefix)
}
void
-serd_reader_set_default_graph(SerdReader* reader, const SerdNode* graph)
+serd_reader_set_default_graph(SerdReader* const reader,
+ const SerdNode* const graph)
{
serd_node_free(&reader->default_graph);
reader->default_graph = serd_node_copy(graph);
}
SerdStatus
-serd_reader_read_file(SerdReader* reader, const uint8_t* uri)
+serd_reader_read_file(SerdReader* const reader, const uint8_t* const uri)
{
uint8_t* const path = serd_file_uri_parse(uri, NULL);
if (!path) {
@@ -292,7 +304,7 @@ serd_reader_read_file(SerdReader* reader, const uint8_t* uri)
}
static SerdStatus
-skip_bom(SerdReader* me)
+skip_bom(SerdReader* const me)
{
if (serd_byte_source_peek(&me->source) == 0xEF) {
serd_byte_source_advance(&me->source);
@@ -309,10 +321,10 @@ skip_bom(SerdReader* me)
}
SerdStatus
-serd_reader_start_stream(SerdReader* reader,
- FILE* file,
- const uint8_t* name,
- bool bulk)
+serd_reader_start_stream(SerdReader* const reader,
+ FILE* const file,
+ const uint8_t* const name,
+ const bool bulk)
{
return serd_reader_start_source_stream(reader,
bulk ? (SerdSource)fread
@@ -324,19 +336,19 @@ serd_reader_start_stream(SerdReader* reader,
}
SerdStatus
-serd_reader_start_source_stream(SerdReader* reader,
- SerdSource read_func,
- SerdStreamErrorFunc error_func,
- void* stream,
- const uint8_t* name,
- size_t page_size)
+serd_reader_start_source_stream(SerdReader* const reader,
+ const SerdSource read_func,
+ const SerdStreamErrorFunc error_func,
+ void* const stream,
+ const uint8_t* const name,
+ const size_t page_size)
{
return serd_byte_source_open_source(
&reader->source, read_func, error_func, stream, name, page_size);
}
static SerdStatus
-serd_reader_prepare(SerdReader* reader)
+serd_reader_prepare(SerdReader* const reader)
{
SerdStatus st = serd_byte_source_prepare(&reader->source);
if (st == SERD_SUCCESS) {
@@ -350,7 +362,7 @@ serd_reader_prepare(SerdReader* reader)
}
SerdStatus
-serd_reader_read_chunk(SerdReader* reader)
+serd_reader_read_chunk(SerdReader* const reader)
{
SerdStatus st = SERD_SUCCESS;
if (!reader->source.prepared) {
@@ -368,15 +380,15 @@ serd_reader_read_chunk(SerdReader* reader)
}
SerdStatus
-serd_reader_end_stream(SerdReader* reader)
+serd_reader_end_stream(SerdReader* const reader)
{
return serd_byte_source_close(&reader->source);
}
SerdStatus
-serd_reader_read_file_handle(SerdReader* reader,
- FILE* file,
- const uint8_t* name)
+serd_reader_read_file_handle(SerdReader* const reader,
+ FILE* const file,
+ const uint8_t* const name)
{
return serd_reader_read_source(reader,
(SerdSource)fread,
@@ -387,12 +399,12 @@ serd_reader_read_file_handle(SerdReader* reader,
}
SerdStatus
-serd_reader_read_source(SerdReader* reader,
- SerdSource source,
- SerdStreamErrorFunc error,
- void* stream,
- const uint8_t* name,
- size_t page_size)
+serd_reader_read_source(SerdReader* const reader,
+ const SerdSource source,
+ const SerdStreamErrorFunc error,
+ void* const stream,
+ const uint8_t* const name,
+ const size_t page_size)
{
SerdStatus st = serd_reader_start_source_stream(
reader, source, error, stream, name, page_size);
@@ -411,7 +423,7 @@ serd_reader_read_source(SerdReader* reader,
}
SerdStatus
-serd_reader_read_string(SerdReader* reader, const uint8_t* utf8)
+serd_reader_read_string(SerdReader* const reader, const uint8_t* const utf8)
{
serd_byte_source_open_string(&reader->source, utf8);
diff --git a/src/reader.h b/src/reader.h
index 3a8991f4..e67f8cc2 100644
--- a/src/reader.h
+++ b/src/reader.h
@@ -98,7 +98,7 @@ Ref
push_node(SerdReader* reader, SerdType type, const char* str, size_t n_bytes);
SERD_PURE_FUNC size_t
-genid_size(SerdReader* reader);
+genid_size(const SerdReader* reader);
Ref
blank_id(SerdReader* reader);
diff --git a/src/serdi.c b/src/serdi.c
index a1d8097e..4e06ac95 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -56,7 +56,7 @@ static const Syntax syntaxes[] = {{SERD_TURTLE, "turtle", ".ttl"},
{(SerdSyntax)0, NULL, NULL}};
static SerdSyntax
-get_syntax(const char* name)
+get_syntax(const char* const name)
{
for (const Syntax* s = syntaxes; s->name; ++s) {
if (!serd_strncasecmp(s->name, name, strlen(name))) {
@@ -69,7 +69,7 @@ get_syntax(const char* name)
}
static SERD_PURE_FUNC SerdSyntax
-guess_syntax(const char* filename)
+guess_syntax(const char* const filename)
{
const char* ext = strrchr(filename, '.');
if (ext) {
@@ -95,7 +95,7 @@ print_version(void)
}
static int
-print_usage(const char* name, bool error)
+print_usage(const char* const name, const bool error)
{
FILE* const os = error ? stderr : stdout;
fprintf(os, "%s", error ? "\n" : "");
@@ -120,14 +120,14 @@ print_usage(const char* name, bool error)
}
static int
-missing_arg(const char* name, char opt)
+missing_arg(const char* const name, const char opt)
{
SERDI_ERRORF("option requires an argument -- '%c'\n", opt);
return print_usage(name, true);
}
static SerdStatus
-quiet_error_sink(void* handle, const SerdError* e)
+quiet_error_sink(void* const handle, const SerdError* const e)
{
(void)handle;
(void)e;
@@ -135,7 +135,7 @@ quiet_error_sink(void* handle, const SerdError* e)
}
static FILE*
-serd_fopen(const char* path, const char* mode)
+serd_fopen(const char* const path, const char* const mode)
{
FILE* fd = fopen(path, mode);
if (!fd) {
diff --git a/src/string.c b/src/string.c
index baf01042..6e7cecf2 100644
--- a/src/string.c
+++ b/src/string.c
@@ -23,13 +23,13 @@
#include <stdlib.h>
void
-serd_free(void* ptr)
+serd_free(void* const ptr)
{
free(ptr);
}
const uint8_t*
-serd_strerror(SerdStatus status)
+serd_strerror(const SerdStatus status)
{
switch (status) {
case SERD_SUCCESS:
@@ -95,7 +95,9 @@ serd_substrlen(const uint8_t* const str,
}
size_t
-serd_strlen(const uint8_t* str, size_t* n_bytes, SerdNodeFlags* flags)
+serd_strlen(const uint8_t* const str,
+ size_t* const n_bytes,
+ SerdNodeFlags* const flags)
{
size_t n_chars = 0;
size_t i = 0;
@@ -116,7 +118,7 @@ serd_strlen(const uint8_t* str, size_t* n_bytes, SerdNodeFlags* flags)
}
static double
-read_sign(const char** sptr)
+read_sign(const char** const sptr)
{
double sign = 1.0;
@@ -136,7 +138,7 @@ read_sign(const char** sptr)
}
double
-serd_strtod(const char* str, char** endptr)
+serd_strtod(const char* const str, char** const endptr)
{
double result = 0.0;
diff --git a/src/system.c b/src/system.c
index 6bc93ca6..f706902d 100644
--- a/src/system.c
+++ b/src/system.c
@@ -35,7 +35,7 @@
#include <string.h>
FILE*
-serd_fopen(const char* path, const char* mode)
+serd_fopen(const char* const path, const char* const mode)
{
FILE* fd = fopen(path, mode);
if (!fd) {
diff --git a/src/uri.c b/src/uri.c
index b70992ff..2a906d44 100644
--- a/src/uri.c
+++ b/src/uri.c
@@ -52,7 +52,7 @@ serd_uri_to_path(const uint8_t* uri)
}
uint8_t*
-serd_file_uri_parse(const uint8_t* uri, uint8_t** hostname)
+serd_file_uri_parse(const uint8_t* const uri, uint8_t** const hostname)
{
const uint8_t* path = uri;
if (hostname) {
@@ -122,7 +122,7 @@ serd_uri_string_has_scheme(const uint8_t* utf8)
}
SerdStatus
-serd_uri_parse(const uint8_t* utf8, SerdURI* out)
+serd_uri_parse(const uint8_t* const utf8, SerdURI* const out)
{
*out = SERD_URI_NULL;
@@ -245,7 +245,9 @@ end:
@return A pointer to the new start of `path`
*/
static const uint8_t*
-remove_dot_segments(const uint8_t* path, size_t len, size_t* up)
+remove_dot_segments(const uint8_t* const path,
+ const size_t len,
+ size_t* const up)
{
const uint8_t* begin = path;
const uint8_t* const end = path + len;
@@ -309,7 +311,7 @@ remove_dot_segments(const uint8_t* path, size_t len, size_t* up)
/// Merge `base` and `path` in-place
static void
-merge(SerdChunk* base, SerdChunk* path)
+merge(SerdChunk* const base, SerdChunk* const path)
{
size_t up = 0;
const uint8_t* begin = remove_dot_segments(path->buf, path->len, &up);
@@ -336,7 +338,9 @@ merge(SerdChunk* base, SerdChunk* path)
/// See http://tools.ietf.org/html/rfc3986#section-5.2.2
void
-serd_uri_resolve(const SerdURI* r, const SerdURI* base, SerdURI* t)
+serd_uri_resolve(const SerdURI* const r,
+ const SerdURI* const base,
+ SerdURI* const t)
{
if (!base->scheme.len) {
*t = *r; // Don't resolve against non-absolute URIs
@@ -377,7 +381,10 @@ serd_uri_resolve(const SerdURI* r, const SerdURI* base, SerdURI* t)
/** Write the path of `uri` starting at index `i` */
static size_t
-write_path_tail(SerdSink sink, void* stream, const SerdURI* uri, size_t i)
+write_path_tail(SerdSink sink,
+ void* const stream,
+ const SerdURI* const uri,
+ const size_t i)
{
size_t len = 0;
if (i < uri->path_base.len) {
@@ -398,10 +405,10 @@ write_path_tail(SerdSink sink, void* stream, const SerdURI* uri, size_t i)
/** Write the path of `uri` relative to the path of `base`. */
static size_t
-write_rel_path(SerdSink sink,
- void* stream,
- const SerdURI* uri,
- const SerdURI* base)
+write_rel_path(SerdSink sink,
+ void* const stream,
+ const SerdURI* const uri,
+ const SerdURI* const base)
{
const size_t path_len = uri_path_len(uri);
const size_t base_len = uri_path_len(base);
@@ -452,11 +459,11 @@ serd_uri_path_starts_without_slash(const SerdURI* uri)
/// See http://tools.ietf.org/html/rfc3986#section-5.3
size_t
-serd_uri_serialise_relative(const SerdURI* uri,
- const SerdURI* base,
- const SerdURI* root,
- SerdSink sink,
- void* stream)
+serd_uri_serialise_relative(const SerdURI* const uri,
+ const SerdURI* const base,
+ const SerdURI* const root,
+ SerdSink sink,
+ void* const stream)
{
size_t len = 0;
const bool relative =
@@ -500,7 +507,7 @@ serd_uri_serialise_relative(const SerdURI* uri,
/// See http://tools.ietf.org/html/rfc3986#section-5.3
size_t
-serd_uri_serialise(const SerdURI* uri, SerdSink sink, void* stream)
+serd_uri_serialise(const SerdURI* const uri, SerdSink sink, void* const stream)
{
return serd_uri_serialise_relative(uri, NULL, NULL, sink, stream);
}