|
@@ -9,6 +9,27 @@
|
|
*/
|
|
*/
|
|
#define NULL_KEY 0
|
|
#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.
|
|
/** @brief General-purpose data buffer.
|
|
*
|
|
*
|
|
* The structure is transparently exposed so that the related API only defines
|
|
* The structure is transparently exposed so that the related API only defines
|
|
@@ -21,6 +42,7 @@
|
|
typedef struct LSUP_Buffer {
|
|
typedef struct LSUP_Buffer {
|
|
/*@null@*/ unsigned char *addr;
|
|
/*@null@*/ unsigned char *addr;
|
|
size_t size;
|
|
size_t size;
|
|
|
|
+ LSUP_BufferFlag flags;
|
|
} LSUP_Buffer;
|
|
} LSUP_Buffer;
|
|
|
|
|
|
|
|
|
|
@@ -37,12 +59,9 @@ typedef struct buffer_triple_t {
|
|
} LSUP_BufferTriple;
|
|
} 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.
|
|
/** @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
|
|
* @param[in] data Optional data to initially populate the object with. If
|
|
* NULL, the buffer data are garbage.
|
|
* 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.
|
|
* on error.
|
|
*/
|
|
*/
|
|
inline LSUP_Buffer *
|
|
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.
|
|
/** @brief Dummy buffer to be used with #LSUP_buffer_init.
|
|
*/
|
|
*/
|
|
#define BUF_DUMMY LSUP_buffer_new (NULL, 0)
|
|
#define BUF_DUMMY LSUP_buffer_new (NULL, 0)
|
|
@@ -226,17 +271,6 @@ void
|
|
LSUP_btriple_free (LSUP_BufferTriple *sspo);
|
|
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.
|
|
/** @brief Get serialized triple by term position.
|
|
*
|
|
*
|
|
* Useful for looping over all terms.
|
|
* 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
|
|
* Triple of dummy buffer, with #LSUP_Buffer size space allocated, but no
|
|
* contents.
|
|
* contents.
|
|
*
|
|
*
|
|
- * Free with #LSUP_btriple_free_shallow().
|
|
|
|
|
|
+ * Free with #LSUP_btriple_free().
|
|
*/
|
|
*/
|
|
#define BTRP_DUMMY LSUP_btriple_new (BUF_DUMMY, BUF_DUMMY, BUF_DUMMY)
|
|
#define BTRP_DUMMY LSUP_btriple_new (BUF_DUMMY, BUF_DUMMY, BUF_DUMMY)
|
|
|
|
|