소스 검색

Do not compile debug and trace statements in non-debug build.

scossu 2 주 전
부모
커밋
8d4e2e23c1
16개의 변경된 파일148개의 추가작업 그리고 135개의 파일을 삭제
  1. 7 7
      cpython/py_graph.h
  2. 1 1
      cpython/py_term.h
  3. 1 1
      cpython/py_triple.h
  4. 14 1
      include/core.h
  5. 1 1
      src/buffer.c
  6. 3 3
      src/codec.c
  7. 11 11
      src/codec/grammar_ttl.y
  8. 12 12
      src/codec/lexer_nt.re
  9. 22 22
      src/codec/lexer_ttl.re
  10. 4 4
      src/core.c
  11. 4 4
      src/graph.c
  12. 2 2
      src/namespace.c
  13. 9 9
      src/store_htable.c
  14. 36 36
      src/store_mdb.c
  15. 19 19
      src/term.c
  16. 2 2
      test/test_codec_nt.c

+ 7 - 7
cpython/py_graph.h

@@ -199,8 +199,8 @@ static PyObject *
 Graph_get_uri (GraphObject *self, void *closure)
 {
     LSUP_Term *uri = LSUP_graph_uri (self->ob_struct);
-    log_debug("Graph URI address: %p", uri);
-    log_debug("Graph URI: %s", uri->data);
+    LOG_DEBUG("Graph URI address: %p", uri);
+    LOG_DEBUG("Graph URI: %s", uri->data);
 
     return PyUnicode_FromString (uri->data);
 }
@@ -214,7 +214,7 @@ Graph_set_uri (GraphObject *self, PyObject *value, void *closure)
         return -1;
     }
     LSUP_Term *gr_uri = ((TermObject*)value)->ob_struct;
-    log_debug ("New graph URI: %s", (gr_uri->data));
+    LOG_DEBUG("New graph URI: %s", (gr_uri->data));
 
     LSUP_rc rc = LSUP_graph_set_uri (self->ob_struct, LSUP_term_copy (gr_uri));
 
@@ -294,7 +294,7 @@ Graph_new_from_rdf (PyTypeObject *cls, PyObject *args)
     codec->decode_graph (fh, &res->ob_struct, &ct, &err);
     fclose (fh);
 
-    log_debug ("Decoded %lu triples.", ct);
+    LOG_DEBUG("Decoded %lu triples.", ct);
     if (UNLIKELY (err)) {
         PyErr_SetString (PyExc_IOError, err);
         return NULL;
@@ -404,7 +404,7 @@ Graph_add (PyObject *self, PyObject *triples)
             goto finally;
         }
 
-        log_trace ("Inserting triple #%lu", ct);
+        LOG_TRACE("Inserting triple #%lu", ct);
 
         LSUP_rc db_rc = LSUP_graph_add_iter (
                 it, ((TripleObject *) trp_obj)->ob_struct);
@@ -445,7 +445,7 @@ static PyObject *Graph_remove (PyObject *self, PyObject *args)
         PyErr_SetString (PyExc_SystemError, "Error removing triples.");
         goto finally;
     }
-    log_debug ("Removed %lu triples.", ct);
+    LOG_DEBUG("Removed %lu triples.", ct);
 
 finally:
     if (rc < 0) return NULL;
@@ -472,7 +472,7 @@ static PyObject *Graph_lookup (PyObject *self, PyObject *args)
         rc = -1;
         goto finally;
     }
-    log_debug ("Found %lu triples.", ct);
+    LOG_DEBUG("Found %lu triples.", ct);
 
     // Initialize the generator object.
     it_obj = PyObject_New (

+ 1 - 1
cpython/py_term.h

@@ -438,7 +438,7 @@ Term_richcmp (PyObject *obj1, PyObject *obj2, int op)
 PyObject *
 build_term (LSUP_Term *t)
 {
-    log_trace ("Building term: %s", t->data);
+    LOG_TRACE("Building term: %s", t->data);
     PyTypeObject *term_obj_type;
     PyObject *term_args;
     switch (t->type) {

+ 1 - 1
cpython/py_triple.h

@@ -125,7 +125,7 @@ build_triple (LSUP_Triple *spo)
         *p_obj = build_term (spo->p),
         *o_obj = build_term (spo->o);
 
-    log_trace ("Building triple.");
+    LOG_TRACE("Building triple.");
     PyObject *trp_args = Py_BuildValue ("OOO", s_obj, p_obj, o_obj);
     if (UNLIKELY (!trp_args)) {
         PyErr_SetString (PyExc_SystemError, "Error building triple args.");

+ 14 - 1
include/core.h

@@ -290,6 +290,19 @@ inline int utf8_encode (const uint32_t utf, unsigned char *out)
 }
 
 
+/*
+ * Only compile debug code in debug mode. Parsing variables for debug and
+ * trace messages takes unnecessary cycles for messages that are not displayed
+ * in non-debug mode.
+ */
+#ifdef DEBUG
+#define LOG_DEBUG(...) log_debug(__VA_ARGS__)
+#define LOG_TRACE(...) log_trace(__VA_ARGS__)
+#else
+#define LOG_DEBUG(...)
+#define LOG_TRACE(...)
+#endif
+
 /** @brief Log an error or warning for return codes that are not LSUP_OK.
  *
  * Note that, if used outside of the other macros below, care must be taken
@@ -298,7 +311,7 @@ inline int utf8_encode (const uint32_t utf, unsigned char *out)
  */
 #define LOG_RC(rc) do {                                             \
     if ((rc) < 0) log_error (LSUP_strerror (rc));                   \
-    else if ((rc) > 0) log_debug (LSUP_strerror (rc));               \
+    else if ((rc) > 0) LOG_DEBUG(LSUP_strerror (rc));               \
 } while (0);
 
 /// Error handling via goto.

+ 1 - 1
src/buffer.c

@@ -64,7 +64,7 @@ LSUP_buffer_as_str (const LSUP_Buffer *buf)
         else str_size += 4; // 4 characters for ASCII representation (\xNN).
     }
 
-    log_trace ("Byte buffer str size: %lu", str_size);
+    LOG_TRACE("Byte buffer str size: %lu", str_size);
 
     char *cstr = malloc (str_size);
 

+ 3 - 3
src/codec.c

@@ -41,7 +41,7 @@ uint8_t *unescape_unicode (const uint8_t *esc_str, size_t size)
             tmp_chr[esc_len] = '\0';
 
             uint32_t tmp_val = strtol ((char *) tmp_chr, NULL, 16);
-            //log_debug ("tmp_val: %d", tmp_val);
+            //LOG_DEBUG("tmp_val: %d", tmp_val);
 
             // Reuse tmp_chr to hold the byte values for the code point.
             int cp_len = utf8_encode (tmp_val, tmp_chr);
@@ -55,9 +55,9 @@ uint8_t *unescape_unicode (const uint8_t *esc_str, size_t size)
 #if 0
             // This can generate a LOT of output.
             if (esc_len == 4)
-                log_trace ("UC byte value: %2x %2x", data[len], data[len + 1]);
+                LOG_TRACE("UC byte value: %2x %2x", data[len], data[len + 1]);
             else
-                log_trace (
+                LOG_TRACE(
                     "UC byte value: %2x %2x %2x %2x",
                     data[len], data[len + 1], data[len + 2], data[len + 3]
                 );

+ 11 - 11
src/codec/grammar_ttl.y

@@ -82,7 +82,7 @@ triples 	::= subject(S) ows predObjList(L) PERIOD . {
                 size_t ct = LSUP_graph_add_link_map (state->it, S, L);
                 state->ct += ct;
                 state->rc = LSUP_OK;
-                log_trace ("Added %lu triples.", ct);
+                LOG_TRACE("Added %lu triples.", ct);
 
                 LSUP_term_free (S);
                 LSUP_link_map_free (L);
@@ -91,7 +91,7 @@ triples 	::= subject(S) ows predObjList(L) SEMICOLON PERIOD . [PERIOD] {
                 size_t ct = LSUP_graph_add_link_map (state->it, S, L);
                 state->ct += ct;
                 state->rc = LSUP_OK;
-                log_trace ("Added %lu triples.", ct);
+                LOG_TRACE("Added %lu triples.", ct);
 
                 LSUP_term_free (S);
                 LSUP_link_map_free (L);
@@ -144,18 +144,18 @@ object 	    ::= literal .
 %destructor literal { LSUP_term_free ($$); }
 literal(A)  ::= STRING(D) . {
                 A = LSUP_term_new (LSUP_TERM_LITERAL, D, NULL);
-                log_trace ("Created plain literal: \"%s\"", A->data);
+                LOG_TRACE("Created plain literal: \"%s\"", A->data);
                 free (D);
             }
 literal(A)  ::= STRING(D) LANGTAG(L) . {
                 A = LSUP_term_new (LSUP_TERM_LT_LITERAL, D, L);
-                log_trace ("Created LT-literal: \"%s\"@%s", A->data, A->lang);
+                LOG_TRACE("Created LT-literal: \"%s\"@%s", A->data, A->lang);
                 free (D);
                 free (L);
             }
 literal(A)  ::= STRING(D) DTYPE_MARKER resource(M) . {
                 A = LSUP_term_new (LSUP_TERM_LITERAL, D, M);
-                log_trace (
+                LOG_TRACE(
                         "Created DT-literal: \"%s\"^^%s",
                         A->data, A->datatype);
                 free (D);
@@ -206,18 +206,18 @@ literal(A)  ::= BOOLEAN(D) . {
 %destructor blank { LSUP_term_free ($$); }
 blank(A)    ::= BNODE_ID(D) . {
                 A = LSUP_term_new (LSUP_TERM_BNODE, D, NULL);
-                log_trace ("Created blank node: _:%s", A->data);
+                LOG_TRACE("Created blank node: _:%s", A->data);
 
                 free (D);
             }
 blank(A)    ::= LBRACKET RBRACKET . [BNODE_ID] {
                 A = LSUP_term_new (LSUP_TERM_BNODE, NULL, NULL);
-                log_trace ("Created empty list BN: _:%s", A->data);
+                LOG_TRACE("Created empty list BN: _:%s", A->data);
             }
 blank(A)    ::= LBRACKET predObjList(L) RBRACKET . [BNODE_ID] {
                 A = LSUP_term_new (LSUP_TERM_BNODE, NULL, NULL);
                 state->ct += LSUP_graph_add_link_map (state->it, A, L);
-                log_trace ("Created list BN: _:%s", A->data);
+                LOG_TRACE("Created list BN: _:%s", A->data);
 
                 LSUP_link_map_free (L);
             }
@@ -227,7 +227,7 @@ blank(A)    ::= LPAREN RPAREN . [BNODE_ID] {
                     "rdf:nil",
                     LSUP_graph_namespace (LSUP_graph_iter_graph (state->it))
                 );
-                log_trace ("Created list terminator: %s", A->data);
+                LOG_TRACE("Created list terminator: %s", A->data);
             }
 
 // "collection" is the subject of the first collection item.
@@ -262,13 +262,13 @@ resource(A) ::= IRIREF(D) . {
                 } else {
                     A = rel_iri;
                 }
-                log_trace ("Created IRI: <%s>", A->data);
+                LOG_TRACE("Created IRI: <%s>", A->data);
             }
 resource(A) ::= QNAME(D) . {
                 A = LSUP_iriref_new (
                     D, LSUP_graph_namespace (LSUP_graph_iter_graph (state->it))
                 );
-                log_trace ("Created IRI: %s", A->data);
+                LOG_TRACE("Created IRI: %s", A->data);
                 free (D);
             }
 

+ 12 - 12
src/codec/lexer_nt.re

@@ -36,7 +36,7 @@ static int fill(ParseIterator *it)
     if (shift < 1) {
         return 2;
     }
-    log_debug ("Shifting bytes: %lu", shift);
+    LOG_DEBUG("Shifting bytes: %lu", shift);
     memmove(it->buf, it->tok, it->lim - it->tok);
     it->lim -= shift;
     it->cur -= shift;
@@ -117,19 +117,19 @@ loop:
     EOL {
         it->line ++;
         it->bol = YYCURSOR;
-        log_debug ("New line: #%u.", it->line);
+        LOG_DEBUG("New line: #%u.", it->line);
         return T_EOL;
     }
 
     $ {
-        log_debug ("End of buffer.");
+        LOG_DEBUG("End of buffer.");
         return T_EOF;
     }
 
     IRIREF {
         YYCTYPE *data = unescape_unicode (it->tok + 1, YYCURSOR - it->tok - 2);
 
-        log_debug ("URI data: %s", data);
+        LOG_DEBUG("URI data: %s", data);
 
         *term = LSUP_iriref_new ((char*)data, NULL);
         free (data);
@@ -142,7 +142,7 @@ loop:
         // Only unescape Unicode from data.
         size_t size = lit_data_e - it->tok - 2;
         YYCTYPE *data = unescape_unicode (it->tok + 1, size);
-        log_trace ("Literal data: %s", data);
+        LOG_TRACE("Literal data: %s", data);
 
         char *metadata = NULL;
         const YYCTYPE *md_marker;
@@ -161,7 +161,7 @@ loop:
             metadata = malloc (size);
             memcpy (metadata, md_marker + 1, size);
             metadata [size - 1] = '\0';
-            log_trace ("metadata: %s", metadata);
+            LOG_TRACE("metadata: %s", metadata);
         }
 
         if (type == LSUP_TERM_LITERAL) {
@@ -183,7 +183,7 @@ loop:
     BNODE {
         YYCTYPE *data = unescape_unicode (it->tok + 2, YYCURSOR - it->tok - 2);
 
-        log_debug ("BNode data: %s", data);
+        LOG_DEBUG("BNode data: %s", data);
 
         *term = LSUP_term_new (LSUP_TERM_BNODE, (char*)data, NULL);
         free (data);
@@ -193,14 +193,14 @@ loop:
     }
 
     DOT {
-        log_debug ("End of triple.");
+        LOG_DEBUG("End of triple.");
         it->ct ++;
 
         return T_DOT;
     }
 
     WS {
-        log_debug ("Separator.");
+        LOG_DEBUG("Separator.");
 
         return T_WS;
     }
@@ -210,14 +210,14 @@ loop:
         YYCTYPE *data = malloc (size);
         memcpy (data, it->tok, size);
         data [size - 1] = '\0';
-        log_debug ("Comment: `%s`", data);
+        LOG_DEBUG("Comment: `%s`", data);
         free (data);
 
         goto loop;
     }
 
     * {
-        log_debug (
+        LOG_DEBUG(
             "Invalid token @ %lu: %s (\\x%x)",
             YYCURSOR - it->buf - 1, it->tok, *it->tok);
 
@@ -311,7 +311,7 @@ LSUP_nt_parse_doc (FILE *fh, LSUP_Graph **gr_p, size_t *ct, char **err_p)
     if (ct) *ct = parse_it.ct;
 
     log_info ("Parsed %u triples.", parse_it.ct);
-    log_debug ("Graph size: %lu", LSUP_graph_size (gr));
+    LOG_DEBUG("Graph size: %lu", LSUP_graph_size (gr));
 
     rc = parse_it.ct > 0 ? LSUP_OK : LSUP_NORESULT;
     *gr_p = gr;

+ 22 - 22
src/codec/lexer_ttl.re

@@ -48,7 +48,7 @@ static int fill (ParseIterator *it)
     if (shift < 1) {
         return 2;
     }
-    log_trace ("Shifting bytes: %lu", shift);
+    LOG_TRACE("Shifting bytes: %lu", shift);
     memmove(it->buf, it->tok, it->lim - it->tok);
     it->lim -= shift;
     it->cur -= shift;
@@ -78,7 +78,7 @@ static void parse_init (ParseIterator *it, FILE *fh)
 static inline void newline (ParseIterator *it) {
     it->line ++;
     it->bol = YYCURSOR;
-    log_trace ("New line: #%u.", it->line);
+    LOG_TRACE("New line: #%u.", it->line);
 }
 
 
@@ -153,7 +153,7 @@ loop: // Start new token.
     }
 
     $ {
-        log_trace ("End of document.");
+        LOG_TRACE("End of document.");
         return T_EOF;
     }
 
@@ -168,53 +168,53 @@ loop: // Start new token.
 
     "true" | "false" {
         *token_p = uint8_ndup (it->tok, YYCURSOR - it->tok);
-        log_trace ("Boolean: %s", *token_p);
+        LOG_TRACE("Boolean: %s", *token_p);
 
         return T_BOOLEAN;
     }
 
     '<' UCHAR* '>' {
         *token_p = uint8_ndup (it->tok + 1, YYCURSOR - it->tok - 2);
-        log_trace ("URI data: %s", *token_p);
+        LOG_TRACE("URI data: %s", *token_p);
 
         return T_IRIREF;
     }
 
     '@prefix' WS @pfx (PSTART_CHAR NAME_CHAR*)? ":" {
         *token_p = uint8_ndup (pfx, YYCURSOR - pfx - 1);
-        log_trace ("Prefix declaration: '%s'", *token_p);
+        LOG_TRACE("Prefix declaration: '%s'", *token_p);
 
         return T_PREFIX;
     }
 
     '@base' {
-        log_trace ("'@base' keyword.");
+        LOG_TRACE("'@base' keyword.");
 
         return T_BASE;
     }
 
     (PSTART_CHAR NAME_CHAR*)? ":" (NSTART_CHAR NAME_CHAR*)? {
         *token_p = uint8_ndup (it->tok, YYCURSOR - it->tok);
-        log_trace ("ID name: %s", *token_p);
+        LOG_TRACE("ID name: %s", *token_p);
 
         return T_QNAME;
     }
 
     '_:'  NSTART_CHAR NAME_CHAR* {
         *token_p = uint8_ndup (it->tok + 2, YYCURSOR - it->tok - 2);
-        log_trace ("BNode name: %s", *token_p);
+        LOG_TRACE("BNode name: %s", *token_p);
 
         return T_BNODE_ID;
     }
 
     COMMENT {
-        log_trace ("Comment: `%s`", it->tok);
+        LOG_TRACE("Comment: `%s`", it->tok);
         goto loop;
     }
 
     WS {
         uint8_t *ws = uint8_ndup (it->tok, YYCURSOR - it->tok);
-        log_trace ("Whitespace: '%s'", ws);
+        LOG_TRACE("Whitespace: '%s'", ws);
         // Count newlines in mixed whitespace.
         // That's not great because it scans through the whole whitespace again
         // but it's the simplest and safest.
@@ -227,7 +227,7 @@ loop: // Start new token.
 
     '@' [a-z]+ ('-' [a-zA-Z0-9]+)* {
         *token_p = uint8_ndup (it->tok + 1, YYCURSOR - it->tok - 1);
-        log_trace ("Lang tag: '%s'", *token_p);
+        LOG_TRACE("Lang tag: '%s'", *token_p);
 
         return T_LANGTAG;
     }
@@ -237,7 +237,7 @@ loop: // Start new token.
         size_t offset = *it->tok == '+' ? 1 : 0;
 
         *token_p = uint8_ndup (it->tok + offset, YYCURSOR - it->tok - offset);
-        log_trace ("Integer: %s", *token_p);
+        LOG_TRACE("Integer: %s", *token_p);
 
         return T_INTEGER;
     }
@@ -247,7 +247,7 @@ loop: // Start new token.
         size_t offset = *it->tok == '+' ? 1 : 0;
 
         *token_p = uint8_ndup (it->tok + offset, YYCURSOR - it->tok - offset);
-        log_trace ("Integer: %s", *token_p);
+        LOG_TRACE("Integer: %s", *token_p);
 
         return T_DOUBLE;
     }
@@ -262,7 +262,7 @@ loop: // Start new token.
             for (YYCTYPE *i = YYCURSOR; *i == '0'; i--) size--;
 
         *token_p = uint8_ndup (it->tok + offset, size);
-        log_trace ("Integer: %s", *token_p);
+        LOG_TRACE("Integer: %s", *token_p);
 
         return T_DECIMAL;
     }
@@ -278,7 +278,7 @@ loop: // Start new token.
     ':' { return T_COLON; }
 
     WS? ';' WS? {
-        log_trace ("End of object list.");
+        LOG_TRACE("End of object list.");
 
         return T_SEMICOLON;
     }
@@ -286,7 +286,7 @@ loop: // Start new token.
     WS? ',' WS? { return T_COMMA; }
 
     WS? '.' {
-        log_trace ("End of statement #%u.", it->stmt);
+        LOG_TRACE("End of statement #%u.", it->stmt);
         it->stmt++;
         return T_PERIOD;
     }
@@ -294,7 +294,7 @@ loop: // Start new token.
     '^^' { return T_DTYPE_MARKER; }
 
     "a" {
-        log_trace ("RDF type shorthand 'a'.");
+        LOG_TRACE("RDF type shorthand 'a'.");
         return T_RDF_TYPE;
     }
 
@@ -321,7 +321,7 @@ schar:
 
     [\x22] {
         *token_p = unescape_unicode (it->tok + 1, YYCURSOR - it->tok - 2);
-        log_trace ("String: %s", *token_p);
+        LOG_TRACE("String: %s", *token_p);
 
         return T_STRING;
     }
@@ -341,7 +341,7 @@ lchar:
 
     [\x22]{3} {
         *token_p = unescape_unicode (it->tok + 3, YYCURSOR - it->tok - 6);
-        log_trace ("Long string: %s", it->tok);
+        LOG_TRACE("Long string: %s", it->tok);
 
         return T_STRING;
     }
@@ -424,13 +424,13 @@ LSUP_ttl_parse_doc (FILE *fh, LSUP_Graph **gr_p, size_t *ct, char **err_p)
     if (ct) *ct = state->ct;
 
     log_info ("Parsed %u triples.", state->ct);
-    log_debug ("Graph size: %lu", LSUP_graph_size (gr));
+    LOG_DEBUG("Graph size: %lu", LSUP_graph_size (gr));
 
     *gr_p = gr;
 
 finally: ;
     LSUP_rc rc = state->rc;
-    log_trace ("rc is %d", rc);
+    LOG_TRACE("rc is %d", rc);
 
     TTLParseFree (parser, free);
 

+ 4 - 4
src/core.c

@@ -77,9 +77,9 @@ mkdir_p (const char *_path, mode_t mode)
 
 finally:
 
-    log_trace ("Path: %s", path);
-    log_trace ("errno: %d", errno);
-    log_trace ("rc: %d", rc);
+    LOG_TRACE("Path: %s", path);
+    LOG_TRACE("errno: %d", errno);
+    LOG_TRACE("rc: %d", rc);
     free (path);
 
     return rc;
@@ -91,7 +91,7 @@ unlink_cb(
         const char *fpath, const struct stat *sb, int typeflag,
         struct FTW *ftwbuf)
 {
-    log_debug ("Removing %s", fpath);
+    LOG_DEBUG("Removing %s", fpath);
     int rv = remove(fpath);
 
     if (rv)

+ 4 - 4
src/graph.c

@@ -56,7 +56,7 @@ LSUP_graph_new (LSUP_Store *store, LSUP_Term *uri, LSUP_NSMap *nsm)
     if (gr->store->sif->features & LSUP_STORE_PERM) gr->nsm = NULL;
     else gr->nsm = nsm ? nsm : LSUP_default_nsm;
 
-    log_debug ("Graph created.");
+    LOG_DEBUG("Graph created.");
     return gr;
 }
 
@@ -291,7 +291,7 @@ LSUP_graph_add_init_txn (void *txn, LSUP_Graph *gr)
 LSUP_rc
 LSUP_graph_add_iter (LSUP_GraphIterator *it, const LSUP_Triple *spo)
 {
-    log_trace (
+    LOG_TRACE(
             "Adding triple {%s, %s, %s} to %s",
             spo->s->data, spo->p->data, spo->o->data,
             LSUP_graph_uri(it->graph)->data);
@@ -345,7 +345,7 @@ LSUP_graph_add_txn (
     if (ct) *ct = 0;
     // Serialize and insert RDF triples.
     for (size_t i = 0; trp[i] != NULL; i++) {
-        log_trace ("Inserting triple #%lu", i);
+        LOG_TRACE("Inserting triple #%lu", i);
 
         LSUP_rc db_rc = LSUP_graph_add_iter (it, trp[i]);
 
@@ -504,7 +504,7 @@ LSUP_graph_iter_free (LSUP_GraphIterator *it)
      */
     if (it->graph->store->sif->features & LSUP_STORE_COW) {
         LSUP_btriple_free (it->sspo);
-        log_debug ("Freeing dummy triple @ %p", it->sspo);
+        LOG_DEBUG("Freeing dummy triple @ %p", it->sspo);
     } else {
         // TODO copy-on-retrieval stores. None yet.
     }

+ 2 - 2
src/namespace.c

@@ -87,9 +87,9 @@ LSUP_nsmap_add (NSMap *map, const char *pfx, const char *nsstr)
         entry_s.ns = ns;
         hashmap_set (map, &entry_s);
         if (hashmap_oom (map)) return LSUP_MEM_ERR;
-        log_debug ("Added prefix '%s' to NS map.", entry_s.pfx);
+        LOG_DEBUG("Added prefix '%s' to NS map.", entry_s.pfx);
     } else {
-        log_debug (
+        LOG_DEBUG(
                 "Replacing NS '%s' with '%s' for prefix '%s'.",
                 ret->ns, ns, entry_s.pfx);
         free (ret->ns);

+ 9 - 9
src/store_htable.c

@@ -230,9 +230,9 @@ htstore_add_term (void *h, const LSUP_Buffer *sterm, void *_unused)
     memcpy (entry_s.data, sterm->addr, sterm->size);
     entry_s.size = sterm->size;
 
-    log_trace ("Adding term key: %lx", entry_s.key);
+    LOG_TRACE("Adding term key: %lx", entry_s.key);
     hashmap_set (store->idx, &entry_s);
-    //log_trace ("Term index size: %lu", hashmap_count (store->idx));
+    //LOG_TRACE("Term index size: %lu", hashmap_count (store->idx));
 
     return LSUP_OK;
 }
@@ -336,7 +336,7 @@ htstore_lookup (
     // ? ? ?
     } else it->eq_fn = lookup_none_eq_fn;
 
-    log_trace ("LUK: {%lx, %lx, %lx}", it->luk[0], it->luk[1], it->luk[2]);
+    LOG_TRACE("LUK: {%lx, %lx, %lx}", it->luk[0], it->luk[1], it->luk[2]);
 
     if (ct) {
         // Loop over results to determine count.
@@ -372,7 +372,7 @@ htstore_remove(
     }
 
     while (htiter_next_key (it) == LSUP_OK) {
-        log_trace (
+        LOG_TRACE(
                 "Deleting {%lx, %lx, %lx}.",
                 it->entry[0][0], it->entry[0][1], it->entry[0][2]);
         hashmap_delete (store->keys, it->entry);
@@ -399,9 +399,9 @@ htiter_next_key (HTIterator *it)
     do {
         // Loop through all triples until a match is found, or end is reached.
         if (hashmap_iter (it->store->keys, &it->cur, (void **) &it->entry)) {
-            //log_trace("it->cur: %lu", it->cur);
+            //LOG_TRACE("it->cur: %lu", it->cur);
             if (it->eq_fn (*it->entry, it->luk)) {
-                log_trace (
+                LOG_TRACE(
                     "Found spok: {%lx, %lx, %lx}",
                     it->entry[0][0], it->entry[0][1], it->entry[0][2]
                 );
@@ -478,14 +478,14 @@ static LSUP_rc
 htstore_add_key_iter (HTIterator *it, const LSUP_Key *spok)
 {
     // Add triple.
-    log_trace ("Inserting spok: {%lx, %lx, %lx}", spok[0], spok[1], spok[2]);
+    LOG_TRACE("Inserting spok: {%lx, %lx, %lx}", spok[0], spok[1], spok[2]);
 
     if (hashmap_get (it->store->keys, spok)) {
-        log_trace ("Triple found. Not adding.");
+        LOG_TRACE("Triple found. Not adding.");
         return LSUP_NOACTION;
     }
 
-    log_trace ("Triple not found, inserting.");
+    LOG_TRACE("Triple not found, inserting.");
 
     hashmap_set (it->store->keys, (void *)spok);
     if (hashmap_oom(it->store->keys)) return LSUP_MEM_ERR;

+ 36 - 36
src/store_mdb.c

@@ -366,12 +366,12 @@ mdbstore_setup (const char *id, bool clear)
 
     RCCK (mdb_env_set_maxdbs (env, N_DB));
     RCCK (mdb_env_open (env, path, 0, ENV_FILE_MODE));
-    log_debug ("Environment opened at %s.", path);
+    LOG_DEBUG("Environment opened at %s.", path);
 
     MDB_txn *txn;
     RCCK (mdb_txn_begin (env, NULL, 0, &txn));
     for (int i = 0; i < N_DB; i++) {
-        log_trace ("Creating DB %s", db_labels[i]);
+        LOG_TRACE("Creating DB %s", db_labels[i]);
         MDB_dbi dbi;
         RCCK (
             mdb_dbi_open (txn, db_labels[i], db_flags[i] | MDB_CREATE, &dbi)
@@ -430,7 +430,7 @@ mdbstore_new (const char *id, size_t _unused)
     MDB_stat stat;
     CHECK (mdb_stat (txn, store->dbi[IDX_PFX_NS], &stat), fail);
     if (stat.ms_entries == 0) {
-        log_debug ("Loading initial data into %s", path);
+        LOG_DEBUG("Loading initial data into %s", path);
         // Load initial NS map.
         mdbstore_nsm_put (store, LSUP_default_nsm, txn);
 
@@ -574,7 +574,7 @@ mdbstore_add_init (void *h, const LSUP_Buffer *sc, void *th)
         it->luc = LSUP_buffer_hash (sc);
 
         // Insert t:st for context.
-        //log_debug ("Adding context: %s", sc);
+        //LOG_DEBUG("Adding context: %s", sc);
         it->key.mv_data = &it->luc;
         it->key.mv_size = KLEN;
         it->data.mv_data = sc->addr;
@@ -589,7 +589,7 @@ mdbstore_add_init (void *h, const LSUP_Buffer *sc, void *th)
             return NULL;
         }
     } else {
-        log_debug ("No context passed to iterator, using default.");
+        LOG_DEBUG("No context passed to iterator, using default.");
         it->luc = LSUP_buffer_hash (LSUP_default_ctx_buf);
     }
 
@@ -632,8 +632,8 @@ mdbstore_add_iter (void *h, const LSUP_BufferTriple *sspo)
         }
     }
 
-    log_trace ("Inserting spok: {%lx, %lx, %lx}", spok[0], spok[1], spok[2]);
-    log_trace ("Into context: %lx", it->luc);
+    LOG_TRACE("Inserting spok: {%lx, %lx, %lx}", spok[0], spok[1], spok[2]);
+    LOG_TRACE("Into context: %lx", it->luc);
 
     // Insert spo:c.
     it->key.mv_data = spok;
@@ -756,7 +756,7 @@ mdbstore_lookup (
 
     it->store = h;
     it->luc = LSUP_buffer_hash (sc);
-    log_debug ("Lookup context: %lx", it->luc);
+    LOG_DEBUG("Lookup context: %lx", it->luc);
 
     if (ct) *ct = 0;
 
@@ -857,7 +857,7 @@ mdbiter_next_key (MDBIterator *it)
      * it->rc is set to the result of the next iteration.
      */
     it->iter_op_fn (it);
-    log_trace (
+    LOG_TRACE(
             "Found  spok: {%lx, %lx, %lx}",
             it->spok[0], it->spok[1], it->spok[2]);
 
@@ -872,7 +872,7 @@ mdbiter_next_key (MDBIterator *it)
         rc = LSUP_NORESULT;  // Intermediary value, will never be returned.
 
         while (rc == LSUP_NORESULT) {
-            //log_debug ("begin ctx loop.");
+            //LOG_DEBUG("begin ctx loop.");
             // If ctx is specified, look if the matching triple is associated
             // with it. If not, move on to the next triple.
             // The loop normally exits when a triple with matching ctx is found
@@ -884,10 +884,10 @@ mdbiter_next_key (MDBIterator *it)
 
             if (db_rc == MDB_SUCCESS) {
                 rc = LSUP_OK;
-                log_trace ("Triple found for context.");
+                LOG_TRACE("Triple found for context.");
 
             } else if (db_rc == MDB_NOTFOUND) {
-                log_trace ("No triples found for context.");
+                LOG_TRACE("No triples found for context.");
                 if (it->rc == MDB_NOTFOUND) rc = LSUP_END;
                 else it->iter_op_fn (it);
 
@@ -918,12 +918,12 @@ mdbiter_next_key (MDBIterator *it)
 
     size_t i = 0;
     do {
-        //log_trace("Copying to slot #%lu @%p", i, it->ck + i);
+        //LOG_TRACE("Copying to slot #%lu @%p", i, it->ck + i);
         memcpy (it->ck + i++, data.mv_data, sizeof (*it->ck));
     } while (
             mdb_cursor_get (it->ctx_cur, &key, &data, MDB_NEXT_DUP)
             == MDB_SUCCESS);
-    //log_trace ("setting sentinel @%p", it->ck + i);
+    //LOG_TRACE("setting sentinel @%p", it->ck + i);
     it->ck[i] = NULL_KEY;
 
     return rc;
@@ -952,7 +952,7 @@ mdbiter_next (
             size_t i = 0;
             while (it->ck[i++]); // Include sentinel in count.
             LSUP_Buffer *ctx;
-            log_trace("Allocating %lu context buffers.", i);
+            LOG_TRACE("Allocating %lu context buffers.", i);
             ctx = malloc(i * sizeof (*ctx));
             if (!ctx) return LSUP_MEM_ERR;
 
@@ -1015,7 +1015,7 @@ mdbstore_remove (
     // The lookup operates within the current (bottom) write transaction.
     MDBIterator *it = mdbstore_lookup (store, ss, sp, so, sc, txn, ct);
     if (UNLIKELY (!it)) return LSUP_DB_ERR;
-    if (ct) log_debug ("Found %lu triples to remove.", *ct);
+    if (ct) LOG_DEBUG("Found %lu triples to remove.", *ct);
 
     while (mdbiter_next_key (it) == LSUP_OK) {
         spok_v.mv_data = it->spok;
@@ -1024,7 +1024,7 @@ mdbstore_remove (
         if (db_rc == MDB_NOTFOUND) continue;
         if (UNLIKELY (db_rc != MDB_SUCCESS)) goto fail;
 
-        log_trace (
+        LOG_TRACE(
                 "Removing {%lx, %lx, %lx}",
                 it->spok[0], it->spok[1], it->spok[2]);
 
@@ -1121,7 +1121,7 @@ mdbstore_tkey_exists (MDBStore *store, LSUP_Key tkey)
 static LSUP_rc
 mdbstore_add_term (void *h, const LSUP_Buffer *sterm, void *ith)
 {
-    //log_trace ("Adding term to MDB store: %s", sterm->addr);
+    //LOG_TRACE("Adding term to MDB store: %s", sterm->addr);
     MDBStore *store = h;
     int db_rc;
     MDB_val key, data;
@@ -1153,7 +1153,7 @@ mdbstore_add_term (void *h, const LSUP_Buffer *sterm, void *ith)
 
 fail:
     if (!borrowed_txn) mdb_txn_abort (txn);
-    log_trace ("Aborted txn for adding term.");
+    LOG_TRACE("Aborted txn for adding term.");
     return LSUP_DB_ERR;
 }
 
@@ -1211,11 +1211,11 @@ index_triple(
     LSUP_rc rc = LSUP_NOACTION;
     MDB_val v1, v2;
 
-    log_trace ("Indexing triple: {%lx %lx %lx}", spok[0], spok[1], spok[2]);
+    LOG_TRACE("Indexing triple: {%lx %lx %lx}", spok[0], spok[1], spok[2]);
 
     // Index c:spo.
     if (op == OP_REMOVE) {
-        log_trace ("Indexing op: REMOVE");
+        LOG_TRACE("Indexing op: REMOVE");
         if (ck != NULL_KEY) {
             MDB_cursor *cur;
 
@@ -1236,7 +1236,7 @@ index_triple(
         }
 
     } else if (op == OP_ADD) {
-        log_trace ("Indexing op: ADD");
+        LOG_TRACE("Indexing op: ADD");
         if (ck != NULL_KEY) {
             v1.mv_data = &ck;
             v1.mv_size = KLEN;
@@ -1293,8 +1293,8 @@ index_triple(
 
         } else { // OP_ADD is guaranteed.
             // 1-bound index.
-            log_trace ("Indexing in %s: ", db_labels[lookup_indices[i]]);
-            log_trace (
+            LOG_TRACE("Indexing in %s: ", db_labels[lookup_indices[i]]);
+            LOG_TRACE(
                     "%lx: %lx %lx", *(size_t*)(v1.mv_data),
                     *(size_t*)(v2.mv_data), *(size_t*)(v2.mv_data) + 1);
 
@@ -1304,8 +1304,8 @@ index_triple(
             else if (db_rc != MDB_KEYEXIST) return LSUP_DB_ERR;
 
             // 2-bound index.
-            log_trace ("Indexing in %s: ", db_labels[lookup_indices[i + 3]]);
-            log_trace (
+            LOG_TRACE("Indexing in %s: ", db_labels[lookup_indices[i + 3]]);
+            LOG_TRACE(
                     "%lx %lx: %lx", *(size_t*)(v2.mv_data),
                     *(size_t*)(v2.mv_data) + 1, *(size_t*)(v1.mv_data));
 
@@ -1350,21 +1350,21 @@ it_next_1bound (MDBIterator *it)
     it->spok[it->term_order[1]] = lu_dset[it->i][0];
     it->spok[it->term_order[2]] = lu_dset[it->i][1];
 
-    log_trace (
+    LOG_TRACE(
             "Composed triple: {%lx %lx %lx}",
             it->spok[0], it->spok[1], it->spok[2]);
 
     // Ensure next block within the same page is not beyond the last.
     if (it->i < it->data.mv_size / DBL_KLEN - 1) {
         it->i ++;
-        //log_debug ("Increasing page cursor to %lu.", it->i);
-        //log_debug ("it->rc: %d", it->rc);
+        //LOG_DEBUG("Increasing page cursor to %lu.", it->i);
+        //LOG_DEBUG("it->rc: %d", it->rc);
 
     } else {
         // If the last block in the page is being yielded,
         // move cursor to beginning of next page.
         it->i = 0;
-        //log_debug ("Reset page cursor to %lu.", it->i);
+        //LOG_DEBUG("Reset page cursor to %lu.", it->i);
         it->rc = mdb_cursor_get (
                 it->cur, &it->key, &it->data, MDB_NEXT_MULTIPLE);
     }
@@ -1416,7 +1416,7 @@ it_next_3bound (MDBIterator *it)
 inline static LSUP_rc
 lookup_0bound (MDBIterator *it, size_t *ct)
 {
-    log_debug ("Looking up 0 bound terms.");
+    LOG_DEBUG("Looking up 0 bound terms.");
 
     if (ct) {
         if (it->luc != NULL_KEY) {
@@ -1440,7 +1440,7 @@ lookup_0bound (MDBIterator *it, size_t *ct)
 
             *ct = stat.ms_entries;
         }
-        log_debug ("Found %lu keys.", *ct);
+        LOG_DEBUG("Found %lu keys.", *ct);
     }
 
     it->rc = mdb_cursor_open (it->txn, it->store->dbi[IDX_SPO_C], &it->cur);
@@ -1471,7 +1471,7 @@ lookup_1bound (uint8_t idx0, MDBIterator *it, size_t *ct)
 {
     it->term_order = (const uint8_t*)lookup_ordering_1bound[idx0];
 
-    log_debug ("Looking up 1 bound term: %lx", it->luk[0]);
+    LOG_DEBUG("Looking up 1 bound term: %lx", it->luk[0]);
 
     mdb_cursor_open (it->txn, it->store->dbi[lookup_indices[idx0]], &it->cur);
 
@@ -1482,7 +1482,7 @@ lookup_1bound (uint8_t idx0, MDBIterator *it, size_t *ct)
         // If a context is specified, the only way to count triples matching
         // the context is to loop over them.
         if (it->luc != NULL_KEY) {
-            log_debug ("Counting in context: %lx", it->luc);
+            LOG_DEBUG("Counting in context: %lx", it->luc);
             MDBIterator *ct_it;
             MALLOC_GUARD (ct_it, LSUP_MEM_ERR);
             /*
@@ -1561,7 +1561,7 @@ lookup_2bound(uint8_t idx0, uint8_t idx1, MDBIterator *it, size_t *ct)
                 luk2_offset = 0;
             }
             dbi = it->store->dbi[lookup_indices[i + 3]];
-            log_debug (
+            LOG_DEBUG(
                     "Looking up 2 bound in %s",
                     db_labels[lookup_indices[i + 3]]);
 
@@ -1637,7 +1637,7 @@ lookup_2bound(uint8_t idx0, uint8_t idx1, MDBIterator *it, size_t *ct)
 inline static LSUP_rc
 lookup_3bound (MDBIterator *it, size_t *ct)
 {
-    log_debug (
+    LOG_DEBUG(
             "Looking up 3 bound: {%lx, %lx, %lx}",
             it->luk[0], it->luk[1], it->luk[2]);
 

+ 19 - 19
src/term.c

@@ -346,7 +346,7 @@ LSUP_term_serialize (const LSUP_Term *term)
     LSUP_Buffer *sterm;
     CALLOC_GUARD (sterm, NULL);
 
-    //log_trace ("Effective term being serialized: %s", tmp_term->data);
+    //LOG_TRACE("Effective term being serialized: %s", tmp_term->data);
     int rc = tpl_jot (
             TPL_MEM, &sterm->addr, &sterm->size, TERM_PACK_FMT,
             &tmp_term->type, &tmp_term->data, &metadata);
@@ -581,8 +581,8 @@ const LSUP_Term *
 LSUP_term_set_get (LSUP_TermSet *ts, LSUP_Key key)
 {
     KeyedTerm *entry = hashmap_get (ts, &(KeyedTerm){.key=key});
-    if (entry) log_trace ("ID found for key %lx: %s", key, entry->term->data);
-    else log_trace ("No ID found for key %lx.", key);
+    if (entry) LOG_TRACE("ID found for key %lx: %s", key, entry->term->data);
+    else LOG_TRACE("No ID found for key %lx.", key);
 
     return (entry) ? entry->term : NULL;
 }
@@ -643,13 +643,13 @@ LSUP_link_map_add (
     Link *ex = hashmap_get (cmap->links, &(Link){.term=&entry_s});
     if (ex) {
         // Add terms one by one to the existing term set.
-        log_trace (
+        LOG_TRACE(
                 "Linking term %s exists. Adding individual terms.",
                 ex->term->term->data);
         size_t i = 0;
         KeyedTerm *kt;
         while (hashmap_iter (tset, &i, (void **)&kt)) {
-            log_trace (
+            LOG_TRACE(
                     "Adding term %s to link %s",
                     kt->term->data, ex->term->term->data);
             if (hashmap_get (ex->tset, kt))
@@ -663,7 +663,7 @@ LSUP_link_map_add (
         LSUP_term_free (term);
     } else {
         // Add the new term and the termset wholesale.
-        log_trace ("Adding new linking term %s.", term->data);
+        LOG_TRACE("Adding new linking term %s.", term->data);
         // Allocate inserted member on heap, it will be owned by the map.
         KeyedTerm *ins;
         MALLOC_GUARD (ins, LSUP_MEM_ERR);
@@ -774,7 +774,7 @@ term_init (
                     return LSUP_VALUE_ERR;
                 }
 
-                log_debug ("Fully qualified IRI: %s", fquri);
+                LOG_DEBUG("Fully qualified IRI: %s", fquri);
             } else fquri = (char *) data;
 
             if (strpbrk (fquri, invalid_uri_chars) != NULL) {
@@ -844,7 +844,7 @@ term_init (
             term->type = LSUP_TERM_LITERAL;
         } else {
             char *lang_str = (char *) metadata;
-            log_trace("Lang string: '%s'", lang_str);
+            LOG_TRACE("Lang string: '%s'", lang_str);
             // Lang tags longer than 7 characters will be truncated.
             strncpy(term->lang, lang_str, sizeof (term->lang) - 1);
             if (strlen (term->lang) < 1) {
@@ -858,7 +858,7 @@ term_init (
     if (term->type == LSUP_TERM_LITERAL) {
         term->datatype = metadata;
         if (! term->datatype) term->datatype = LSUP_default_datatype;
-        log_trace ("Storing data type: %s", term->datatype->data);
+        LOG_TRACE("Storing data type: %s", term->datatype->data);
 
         if (! LSUP_IS_IRI (term->datatype)) {
             log_error (
@@ -878,8 +878,8 @@ term_init (
             term->datatype = ex;
         }
 
-        //log_trace ("Datatype address: %p", term->datatype);
-        log_trace ("Datatype hash: %lx", LSUP_term_hash (term->datatype));
+        //LOG_TRACE("Datatype address: %p", term->datatype);
+        LOG_TRACE("Datatype hash: %lx", LSUP_term_hash (term->datatype));
 
     } else if (term->type == LSUP_TERM_BNODE) {
         // TODO This is not usable for global skolemization.
@@ -933,7 +933,7 @@ parse_iri (char *iri_str, MatchCoord coord[]) {
     // Redundant if only called by term_init.
     // memset (coord, 0, sizeof(*coord));
 
-    //log_debug ("Parsing IRI: %s", iri_str);
+    //LOG_DEBUG("Parsing IRI: %s", iri_str);
     // #2: ([^:/?#]+)
     while (
             *cur != ':' && *cur != '/' && *cur != '?'
@@ -948,7 +948,7 @@ parse_iri (char *iri_str, MatchCoord coord[]) {
         coord[2].offset = 0;
         coord[2].size = tmp.size;
         cur++;
-        //log_debug ("Group #2: %lu, %lu", coord[2].offset, coord[2].size);
+        //LOG_DEBUG("Group #2: %lu, %lu", coord[2].offset, coord[2].size);
     } else cur = iri_str;  // Backtrack if no match.
 
     // Non-capturing: (?//([^/?#]*))?
@@ -964,20 +964,20 @@ parse_iri (char *iri_str, MatchCoord coord[]) {
         }
         coord[3].offset = tmp.offset;
         coord[3].size = tmp.size;
-        //log_debug ("Group #3: %lu, %lu", coord[3].offset, coord[3].size);
+        //LOG_DEBUG("Group #3: %lu, %lu", coord[3].offset, coord[3].size);
     }
 
     // Capture group 1.
     coord[1].offset = 0;
     coord[1].size = cur - iri_str;
-    //log_debug ("Group #1: %lu, %lu", coord[1].offset, coord[1].size);
+    //LOG_DEBUG("Group #1: %lu, %lu", coord[1].offset, coord[1].size);
 
     tmp.offset = cur - iri_str;
     tmp.size = 0;
 
     coord[4].offset = tmp.offset;
     coord[4].size = iri_len - tmp.offset;
-    //log_debug ("Group #4: %lu, %lu", coord[4].offset, coord[4].size);
+    //LOG_DEBUG("Group #4: %lu, %lu", coord[4].offset, coord[4].size);
 
     // Non-capturing: (?[^?#]*)
     while (*cur != '?' && *cur != '#' && *cur != '\0') {
@@ -999,7 +999,7 @@ parse_iri (char *iri_str, MatchCoord coord[]) {
             // Got capture group #5.
             coord[5].offset = tmp.offset;
             coord[5].size = tmp.size;
-            //log_debug ("Group #5: %lu, %lu", coord[5].offset, coord[5].size);
+            //LOG_DEBUG("Group #5: %lu, %lu", coord[5].offset, coord[5].size);
         }
     }
 
@@ -1008,12 +1008,12 @@ parse_iri (char *iri_str, MatchCoord coord[]) {
         // #6: (.*)
         coord[6].offset = ++cur - iri_str;
         coord[6].size = iri_str + iri_len - cur;
-        //log_debug ("Group #6: %lu, %lu", coord[6].offset, coord[6].size);
+        //LOG_DEBUG("Group #6: %lu, %lu", coord[6].offset, coord[6].size);
     }
 
     coord[0].offset = 0;
     coord[0].size = iri_len;
-    //log_debug ("Full match: %lu, %lu", coord[0].offset, coord[0].size);
+    //LOG_DEBUG("Full match: %lu, %lu", coord[0].offset, coord[0].size);
 
     return LSUP_OK;
 }

+ 2 - 2
test/test_codec_nt.c

@@ -199,7 +199,7 @@ test_decode_nt_term()
 {
     log_info ("Test decoding terms.");
     for (int i = 0; i < TERM_CT - 2; i++) {
-        log_debug ("Decoding term %d/%d.", i, TERM_CT - 3);
+        LOG_DEBUG("Decoding term %d/%d.", i, TERM_CT - 3);
         LSUP_Term *term;
         EXPECT_PASS (codec.decode_term (start_nt[i], NULL, &term));
         LSUP_term_free (term);
@@ -234,7 +234,7 @@ test_decode_nt_graph()
     }
     codec.encode_graph_done (it);
     free (tmp);
-    log_trace ("Serialized graph: \n%s", out);
+    LOG_TRACE("Serialized graph: \n%s", out);
     free (out);
 
 #endif