1
0

2 Commits 4b203e5de1 ... 31515de248

Autor SHA1 Mensagem Data
  scossu 31515de248 Update Doxyfile. há 9 meses atrás
  scossu 0cae6f611d Introduce borrowed buffers. há 9 meses atrás
6 ficheiros alterados com 71 adições e 44 exclusões
  1. 9 9
      Doxyfile
  2. 53 19
      include/buffer.h
  3. 1 11
      src/buffer.c
  4. 6 4
      src/graph.c
  5. 1 0
      src/store_mdb.c
  6. 1 1
      src/term.c

+ 9 - 9
Doxyfile

@@ -437,7 +437,7 @@ INLINE_SIMPLE_STRUCTS  = NO
 # types are typedef'ed and only the typedef is referenced, never the tag name.
 # The default value is: NO.
 
-TYPEDEF_HIDES_STRUCT   = NO
+TYPEDEF_HIDES_STRUCT   = YES
 
 # The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This
 # cache is used to resolve symbols given their name and scope. Since this can be
@@ -477,7 +477,7 @@ NUM_PROC_THREADS       = 1
 # normally produced when WARNINGS is set to YES.
 # The default value is: NO.
 
-EXTRACT_ALL            = YES
+EXTRACT_ALL            = NO
 
 # If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will
 # be included in the documentation.
@@ -593,7 +593,7 @@ CASE_SENSE_NAMES       = YES
 # scope will be hidden.
 # The default value is: NO.
 
-HIDE_SCOPE_NAMES       = YES
+HIDE_SCOPE_NAMES       = NO
 
 # If the HIDE_COMPOUND_REFERENCE tag is set to NO (default) then doxygen will
 # append additional text to a page's title, such as Class Reference. If set to
@@ -638,7 +638,7 @@ INLINE_INFO            = YES
 # name. If set to NO, the members will appear in declaration order.
 # The default value is: YES.
 
-SORT_MEMBER_DOCS       = YES
+SORT_MEMBER_DOCS       = NO
 
 # If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief
 # descriptions of file, namespace and class members alphabetically by member
@@ -748,7 +748,7 @@ SHOW_FILES             = YES
 # Folder Tree View (if specified).
 # The default value is: YES.
 
-SHOW_NAMESPACES        = NO
+SHOW_NAMESPACES        = YES
 
 # The FILE_VERSION_FILTER tag can be used to specify a program or script that
 # doxygen should invoke to get the current version for each file (typically from
@@ -1172,7 +1172,7 @@ VERBATIM_HEADERS       = YES
 # classes, structs, unions or interfaces.
 # The default value is: YES.
 
-ALPHABETICAL_INDEX     = NO
+ALPHABETICAL_INDEX     = YES
 
 # In case all classes in a project start with a common prefix, all classes will
 # be put under the same header in the alphabetical index. The IGNORE_PREFIX tag
@@ -1552,7 +1552,7 @@ ECLIPSE_DOC_ID         = org.doxygen.Project
 # The default value is: NO.
 # This tag requires that the tag GENERATE_HTML is set to YES.
 
-DISABLE_INDEX          = YES
+DISABLE_INDEX          = NO
 
 # The GENERATE_TREEVIEW tag is used to specify whether a tree-like index
 # structure should be generated to display hierarchical information. If the tag
@@ -2211,7 +2211,7 @@ PERLMOD_MAKEVAR_PREFIX =
 # C-preprocessor directives found in the sources and include files.
 # The default value is: YES.
 
-ENABLE_PREPROCESSING   = NO
+ENABLE_PREPROCESSING   = YES
 
 # If the MACRO_EXPANSION tag is set to YES, doxygen will expand all macro names
 # in the source code. If set to NO, only conditional compilation will be
@@ -2396,7 +2396,7 @@ DOT_FONTPATH           =
 # Possible values are: NO, YES, TEXT and GRAPH.
 # The default value is: YES.
 
-CLASS_GRAPH            = NO
+CLASS_GRAPH            = YES
 
 # If the COLLABORATION_GRAPH tag is set to YES then doxygen will generate a
 # graph for each documented class showing the direct and indirect implementation

+ 53 - 19
include/buffer.h

@@ -9,6 +9,27 @@
  */
 #define NULL_KEY 0
 
+
+/// Triple position of s, p, o.
+typedef enum {
+    TRP_POS_S = 0,
+    TRP_POS_P = 1,
+    TRP_POS_O = 2,
+} LSUP_TriplePos;
+
+
+/// Buffer flags, stored in buffer structure.
+typedef enum {
+    LSUP_BUF_BORROWED = 1<<0,       /**< Borrowed buffer. This indicates that
+                                      *  the memory block pointed to by the
+                                      *  buffer is owned by another function,
+                                      *  and instructs #LSUP_buffer_free() to
+                                      *  only free the buffer handle, but not
+                                      *  the underlying data.
+                                      */
+} LSUP_BufferFlag;
+
+
 /** @brief General-purpose data buffer.
  *
  * The structure is transparently exposed so that the related API only defines
@@ -21,6 +42,7 @@
 typedef struct LSUP_Buffer {
     /*@null@*/ unsigned char *addr;
     size_t size;
+    LSUP_BufferFlag flags;
 } LSUP_Buffer;
 
 
@@ -37,12 +59,9 @@ typedef struct buffer_triple_t {
 } LSUP_BufferTriple;
 
 
-typedef enum {
-    TRP_POS_S = 0,
-    TRP_POS_P = 1,
-    TRP_POS_O = 2,
-} LSUP_TriplePos;
-
+/*
+ * Function prototypes.
+ */
 
 /** @brief Initialize or reuse a buffer handle.
  *
@@ -76,7 +95,7 @@ LSUP_buffer_init (
  * @param[in] data Optional data to initially populate the object with. If
  *  NULL, the buffer data are garbage.
  *
- * @return LSUP_Buffer pointer. It must be freed with #LSUP_buffer_free. NULL
+ * @return LSUP_Buffer handle. It must be freed with #LSUP_buffer_free. NULL
  *  on error.
  */
 inline LSUP_Buffer *
@@ -95,6 +114,32 @@ LSUP_buffer_new (const unsigned char *data, const size_t size)
 }
 
 
+/** @brief Create a borrowed buffer (memory view).
+ *
+ * A borrowed buffer does not own the memory block pointed to and should not
+ * be freed. It can be identified by the LSUP_BUF_BORROWED flag.
+ *
+ * @param[in] data Address of data handled by the buffer.
+ *
+ * @param[in] size Length of the data.
+ *
+ * @return LSUP_Buffer handle. It must be freed with #LSUP_buffer_free, which
+ * will correctly leave the underlying data alone. NULL on error.
+ */
+inline LSUP_Buffer *
+LSUP_buffer_new_borrowed (unsigned char *data, const size_t size)
+{
+    LSUP_Buffer *buf;
+    MALLOC_GUARD (buf, NULL);
+
+    buf->addr = data;
+    buf->size = size;
+    buf->flags = LSUP_BUF_BORROWED;
+
+    return buf;
+}
+
+
 /** @brief Dummy buffer to be used with #LSUP_buffer_init.
  */
 #define BUF_DUMMY LSUP_buffer_new (NULL, 0)
@@ -226,17 +271,6 @@ void
 LSUP_btriple_free (LSUP_BufferTriple *sspo);
 
 
-/** @brief Free a buffer triple and its buffer handles but not the buffer data.
- *
- * This is useful when freeing a dummy triple (#LSUP_BTRP_DUMMY) or a triple
- * whose buffers are owned by the caller but the data the terms point to are
- * owned by the store.
- *
- */
-void
-LSUP_btriple_free_shallow (LSUP_BufferTriple *sspo);
-
-
 /** @brief Get serialized triple by term position.
  *
  * Useful for looping over all terms.
@@ -285,7 +319,7 @@ LSUP_btriple_hash (const LSUP_BufferTriple *strp)
  * Triple of dummy buffer, with #LSUP_Buffer size space allocated, but no
  * contents.
  *
- * Free with #LSUP_btriple_free_shallow().
+ * Free with #LSUP_btriple_free().
  */
 #define BTRP_DUMMY LSUP_btriple_new (BUF_DUMMY, BUF_DUMMY, BUF_DUMMY)
 

+ 1 - 11
src/buffer.c

@@ -89,7 +89,7 @@ LSUP_buffer_as_str (const LSUP_Buffer *buf)
 
 void LSUP_buffer_done (LSUP_Buffer *buf)
 {
-    if (LIKELY (buf)) free (buf->addr);
+    if (LIKELY (buf) && !(buf->flags & LSUP_BUF_BORROWED)) free (buf->addr);
 }
 
 void LSUP_buffer_free (LSUP_Buffer *buf)
@@ -154,16 +154,6 @@ LSUP_btriple_free (LSUP_BufferTriple *sspo)
 }
 
 
-void
-LSUP_btriple_free_shallow (LSUP_BufferTriple *sspo)
-{
-    if (UNLIKELY (!sspo)) return;
-
-    sspo->s->addr = sspo->p->addr = sspo->o->addr = NULL;
-    LSUP_btriple_free (sspo);
-}
-
-
 /*
  * Statics.
  */

+ 6 - 4
src/graph.c

@@ -84,7 +84,7 @@ LSUP_graph_get_txn (void *txn, LSUP_Store *store, LSUP_Term *uri, size_t *ct)
     LSUP_graph_add_done (add_it);
     store->sif->lu_free_fn(it);
     LSUP_buffer_free (sc);
-    LSUP_btriple_free_shallow (sspo);
+    LSUP_btriple_free (sspo);
 
     // Do not create a new graph if no results were found.
     if (_ct == 0) {
@@ -168,7 +168,7 @@ LSUP_graph_bool_op_txn (
     gr1->store->sif->lu_free_fn (lu1_it);
 
     res->store->sif->add_done_fn (add_it);
-    LSUP_btriple_free_shallow (sspo);
+    LSUP_btriple_free (sspo);
     LSUP_buffer_free (res_sc);
     LSUP_buffer_free (gr1_sc);
     LSUP_buffer_free (gr2_sc);
@@ -457,8 +457,10 @@ LSUP_graph_lookup_txn (
     if (it->graph->store->sif->features & LSUP_STORE_COW) {
         // Copy-on-wite store.
         it->sspo = BTRP_DUMMY;
-
         if (UNLIKELY (it->sspo == NULL)) return NULL;
+        it->sspo->s->flags |= LSUP_BUF_BORROWED;
+        it->sspo->p->flags |= LSUP_BUF_BORROWED;
+        it->sspo->o->flags |= LSUP_BUF_BORROWED;
     } else {
         // TODO copy-on-retrieval store. No implementations yet.
     }
@@ -501,7 +503,7 @@ LSUP_graph_iter_free (LSUP_GraphIterator *it)
      * the store in case of LSUP_STORE_COW stores.
      */
     if (it->graph->store->sif->features & LSUP_STORE_COW) {
-        LSUP_btriple_free_shallow (it->sspo);
+        LSUP_btriple_free (it->sspo);
         log_debug ("Freeing dummy triple @ %p", it->sspo);
     } else {
         // TODO copy-on-retrieval stores. None yet.

+ 1 - 0
src/store_mdb.c

@@ -726,6 +726,7 @@ key_to_sterm (MDBIterator *it, const LSUP_Key key, LSUP_Buffer *sterm)
 
     db_rc = mdb_get (it->txn, it->store->dbi[IDX_T_ST], &key_v, &data_v);
 
+    sterm->flags |= LSUP_BUF_BORROWED;
     if (db_rc == MDB_SUCCESS) {
         sterm->addr = data_v.mv_data;
         sterm->size = data_v.mv_size;

+ 1 - 1
src/term.c

@@ -344,7 +344,7 @@ LSUP_term_serialize (const LSUP_Term *term)
         memcpy (&metadata, tmp_term->lang, sizeof (metadata));
 
     LSUP_Buffer *sterm;
-    MALLOC_GUARD (sterm, NULL);
+    CALLOC_GUARD (sterm, NULL);
 
     //log_trace ("Effective term being serialized: %s", tmp_term->data);
     int rc = tpl_jot (