Lines Matching full:blob

29 #include "hb-blob.hh"
40 * SECTION: hb-blob
41 * @title: hb-blob
54 * @data: Pointer to blob data.
60 * Creates a new "blob" object wrapping @data. The @mode parameter is used
63 * Return value: New blob, or the empty blob if something failed or if @length is
82 hb_blob_t *blob = hb_blob_create_or_fail (data, length, mode, in hb_blob_create() local
84 return likely (blob) ? blob : hb_blob_get_empty (); in hb_blob_create()
89 * @data: Pointer to blob data.
95 * Creates a new "blob" object wrapping @data. The @mode parameter is used
98 * Note that this function returns a freshly-allocated empty blob even if @length
100 * empty blob (as returned by hb_blob_get_empty()) if @length is zero.
102 * Return value: New blob, or `NULL` if failed. Destroy with hb_blob_destroy().
113 hb_blob_t *blob; in hb_blob_create_or_fail() local
116 !(blob = hb_object_create<hb_blob_t> ())) in hb_blob_create_or_fail()
123 blob->data = data; in hb_blob_create_or_fail()
124 blob->length = length; in hb_blob_create_or_fail()
125 blob->mode = mode; in hb_blob_create_or_fail()
127 blob->user_data = user_data; in hb_blob_create_or_fail()
128 blob->destroy = destroy; in hb_blob_create_or_fail()
130 if (blob->mode == HB_MEMORY_MODE_DUPLICATE) { in hb_blob_create_or_fail()
131 blob->mode = HB_MEMORY_MODE_READONLY; in hb_blob_create_or_fail()
132 if (!blob->try_make_writable ()) in hb_blob_create_or_fail()
134 hb_blob_destroy (blob); in hb_blob_create_or_fail()
139 return blob; in hb_blob_create_or_fail()
150 * @parent: Parent blob.
151 * @offset: Start offset of sub-blob within @parent, in bytes.
152 * @length: Length of sub-blob.
154 * Returns a blob that represents a range of bytes in @parent. The new
155 * blob is always created with #HB_MEMORY_MODE_READONLY, meaning that it
156 * will never modify data in the parent blob. The parent data is not
162 * Return value: New blob, or the empty blob if something failed or if
173 hb_blob_t *blob; in hb_blob_create_sub_blob() local
180 blob = hb_blob_create (parent->data + offset, in hb_blob_create_sub_blob()
186 return blob; in hb_blob_create_sub_blob()
191 * @blob: A blob.
193 * Makes a writable copy of @blob.
195 * Return value: The new blob, or nullptr if allocation failed
200 hb_blob_copy_writable_or_fail (hb_blob_t *blob) in hb_blob_copy_writable_or_fail() argument
202 blob = hb_blob_create (blob->data, in hb_blob_copy_writable_or_fail()
203 blob->length, in hb_blob_copy_writable_or_fail()
208 if (unlikely (blob == hb_blob_get_empty ())) in hb_blob_copy_writable_or_fail()
209 blob = nullptr; in hb_blob_copy_writable_or_fail()
211 return blob; in hb_blob_copy_writable_or_fail()
217 * Returns the singleton empty blob.
221 * Return value: (transfer full): The empty blob.
233 * @blob: a blob.
235 * Increases the reference count on @blob.
239 * Return value: @blob.
244 hb_blob_reference (hb_blob_t *blob) in hb_blob_reference() argument
246 return hb_object_reference (blob); in hb_blob_reference()
251 * @blob: a blob.
253 * Decreases the reference count on @blob, and if it reaches zero, destroys
254 * @blob, freeing all memory, possibly calling the destroy-callback the blob
262 hb_blob_destroy (hb_blob_t *blob) in hb_blob_destroy() argument
264 if (!hb_object_destroy (blob)) return; in hb_blob_destroy()
266 hb_free (blob); in hb_blob_destroy()
271 * @blob: An #hb_blob_t
277 * Attaches a user-data key/data pair to the specified blob.
284 hb_blob_set_user_data (hb_blob_t *blob, in hb_blob_set_user_data() argument
290 return hb_object_set_user_data (blob, key, data, destroy, replace); in hb_blob_set_user_data()
295 * @blob: a blob
306 hb_blob_get_user_data (const hb_blob_t *blob, in hb_blob_get_user_data() argument
309 return hb_object_get_user_data (blob, key); in hb_blob_get_user_data()
315 * @blob: a blob
317 * Makes a blob immutable.
322 hb_blob_make_immutable (hb_blob_t *blob) in hb_blob_make_immutable() argument
324 if (hb_object_is_immutable (blob)) in hb_blob_make_immutable()
327 hb_object_make_immutable (blob); in hb_blob_make_immutable()
332 * @blob: a blob.
334 * Tests whether a blob is immutable.
336 * Return value: `true` if @blob is immutable, `false` otherwise
341 hb_blob_is_immutable (hb_blob_t *blob) in hb_blob_is_immutable() argument
343 return hb_object_is_immutable (blob); in hb_blob_is_immutable()
349 * @blob: a blob.
351 * Fetches the length of a blob's data.
353 * Return value: the length of @blob data in bytes.
358 hb_blob_get_length (hb_blob_t *blob) in hb_blob_get_length() argument
360 return blob->length; in hb_blob_get_length()
365 * @blob: a blob.
368 * Fetches the data from a blob.
370 * Returns: (nullable) (transfer none) (array length=length): the byte data of @blob.
375 hb_blob_get_data (hb_blob_t *blob, unsigned int *length) in hb_blob_get_data() argument
378 *length = blob->length; in hb_blob_get_data()
380 return blob->data; in hb_blob_get_data()
385 * @blob: a blob.
388 * Tries to make blob data writable (possibly copying it) and
391 * Fails if blob has been made immutable, or if memory allocation
394 * Returns: (transfer none) (array length=length): Writable blob data,
400 hb_blob_get_data_writable (hb_blob_t *blob, unsigned int *length) in hb_blob_get_data_writable() argument
402 if (hb_object_is_immutable (blob) || in hb_blob_get_data_writable()
403 !blob->try_make_writable ()) in hb_blob_get_data_writable()
409 if (length) *length = blob->length; in hb_blob_get_data_writable()
410 return const_cast<char *> (blob->data); in hb_blob_get_data_writable()
430 DEBUG_MSG_FUNC (BLOB, this, "failed to get pagesize: %s", strerror (errno)); in try_make_writable_inplace_unix()
433 DEBUG_MSG_FUNC (BLOB, this, "pagesize is %lu", (unsigned long) pagesize); in try_make_writable_inplace_unix()
438 DEBUG_MSG_FUNC (BLOB, this, in try_make_writable_inplace_unix()
442 DEBUG_MSG_FUNC (BLOB, this, "mprotect failed: %s", strerror (errno)); in try_make_writable_inplace_unix()
448 DEBUG_MSG_FUNC (BLOB, this, in try_make_writable_inplace_unix()
460 DEBUG_MSG_FUNC (BLOB, this, "making writable inplace\n"); in try_make_writable_inplace()
465 DEBUG_MSG_FUNC (BLOB, this, "making writable -> FAILED\n"); in try_make_writable_inplace()
488 DEBUG_MSG_FUNC (BLOB, this, "current data is -> %p\n", this->data); in try_make_writable()
496 DEBUG_MSG_FUNC (BLOB, this, "dupped successfully -> %p\n", this->data); in try_make_writable()
598 * Creates a new blob containing the data from the
614 hb_blob_t *blob = hb_blob_create_from_file_or_fail (file_name); in hb_blob_create_from_file() local
615 return likely (blob) ? blob : hb_blob_get_empty (); in hb_blob_create_from_file()
622 * Creates a new blob containing the data from the specified file.