/**
* @var EINA_VALUE_TYPE_BLOB
* manages blob of bytes type, see @ref Eina_Value_Blob
+ *
+ * eina_value_set() takes an #Eina_Value_Blob
+ * eina_value_pset() takes a pointer to #Eina_Value_Blob.
+ *
+ * eina_value_get() and eina_value_pget() takes a pointer to
+ * #Eina_Value_Blob and it's an exact copy of value, no allocations
+ * are made.
+ *
+ * Memory is untouched unless you provide @c ops (operations) pointer.
+ *
* @since 1.2
*/
EAPI extern const Eina_Value_Type *EINA_VALUE_TYPE_BLOB;
};
/**
+ * @var EINA_VALUE_BLOB_OPERATIONS_MALLOC
+ *
+ * Assumes @c memory was create with malloc() and applies free() to it
+ * during flush (Eina_Value_Blob_Operations::free). Copy is done with
+ * malloc() as well.
+ *
+ * No compare or to_string are provided, defaults will be used.
+ */
+EAPI extern const Eina_Value_Blob_Operations *EINA_VALUE_BLOB_OPERATIONS_MALLOC;
+
+/**
* @typedef Eina_Value_Blob
* @since 1.2
*/
}
}
-static void
-_eina_value_type_blob_converted_ops_free(const Eina_Value_Blob_Operations *ops __UNUSED__, void *memory, size_t size __UNUSED__)
-{
- free(memory);
-}
-
-static void *
-_eina_value_type_blob_converted_ops_copy(const Eina_Value_Blob_Operations *ops __UNUSED__, const void *memory, size_t size)
-{
- void *ret = malloc(size);
- if (!ret)
- {
- eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
- return NULL;
- }
- memcpy(ret, memory, size);
- return ret;
-}
-
-static const Eina_Value_Blob_Operations _eina_value_type_blob_converted_ops = {
- EINA_VALUE_BLOB_OPERATIONS_VERSION,
- _eina_value_type_blob_converted_ops_free,
- _eina_value_type_blob_converted_ops_copy,
- NULL, /* default compare */
- NULL, /* default to_string */
-};
-
static Eina_Bool
_eina_value_type_blob_convert_from(const Eina_Value_Type *type, const Eina_Value_Type *convert, void *type_mem, const void *convert_mem)
{
if (!eina_value_type_pget(convert, convert_mem, buf))
return EINA_FALSE;
- desc.ops = &_eina_value_type_blob_converted_ops;
+ desc.ops = EINA_VALUE_BLOB_OPERATIONS_MALLOC;
desc.memory = buf;
desc.size = convert->value_size;
return eina_value_type_pset(type, type_mem, &desc);
}
};
+static void
+_eina_value_blob_operations_malloc_free(const Eina_Value_Blob_Operations *ops __UNUSED__, void *memory, size_t size __UNUSED__)
+{
+ free(memory);
+}
+
+static void *
+_eina_value_blob_operations_malloc_copy(const Eina_Value_Blob_Operations *ops __UNUSED__, const void *memory, size_t size)
+{
+ void *ret = malloc(size);
+ if (!ret)
+ {
+ eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
+ return NULL;
+ }
+ memcpy(ret, memory, size);
+ return ret;
+}
+
+static const Eina_Value_Blob_Operations _EINA_VALUE_BLOB_OPERATIONS_MALLOC = {
+ EINA_VALUE_BLOB_OPERATIONS_VERSION,
+ _eina_value_blob_operations_malloc_free,
+ _eina_value_blob_operations_malloc_copy,
+ NULL,
+ NULL
+};
+
/**
* @endcond
*/
EINA_VALUE_TYPE_TIMEVAL = &_EINA_VALUE_TYPE_TIMEVAL;
EINA_VALUE_TYPE_BLOB = &_EINA_VALUE_TYPE_BLOB;
+ EINA_VALUE_BLOB_OPERATIONS_MALLOC = &_EINA_VALUE_BLOB_OPERATIONS_MALLOC;
+
return EINA_TRUE;
}
EAPI const Eina_Value_Type *EINA_VALUE_TYPE_TIMEVAL = NULL;
EAPI const Eina_Value_Type *EINA_VALUE_TYPE_BLOB = NULL;
+EAPI const Eina_Value_Blob_Operations *EINA_VALUE_BLOB_OPERATIONS_MALLOC = NULL;
+
EAPI Eina_Error EINA_ERROR_VALUE_FAILED = 0;
EAPI const unsigned int eina_prime_table[] =