Lines Matching refs:blob
68 static bool _try_writable (hb_blob_t *blob);
71 _hb_blob_destroy_user_data (hb_blob_t *blob)
73 if (blob->destroy) {
74 blob->destroy (blob->user_data);
75 blob->user_data = NULL;
76 blob->destroy = NULL;
82 * @data: (array length=length) (closure user_data) (destroy destroy) (scope notified) (transfer none): Pointer to blob data.
88 * Creates a new "blob" object wrapping @data. The @mode parameter is used
91 * Return value: New blob, or the empty blob if something failed or if @length is
103 hb_blob_t *blob;
105 if (!length || !(blob = hb_object_create<hb_blob_t> ())) {
111 blob->data = data;
112 blob->length = length;
113 blob->mode = mode;
115 blob->user_data = user_data;
116 blob->destroy = destroy;
118 if (blob->mode == HB_MEMORY_MODE_DUPLICATE) {
119 blob->mode = HB_MEMORY_MODE_READONLY;
120 if (!_try_writable (blob)) {
121 hb_blob_destroy (blob);
126 return blob;
131 * @parent: Parent blob.
132 * @offset: Start offset of sub-blob within @parent, in bytes.
133 * @length: Length of sub-blob.
135 * Returns a blob that represents a range of bytes in @parent. The new
136 * blob is always created with %HB_MEMORY_MODE_READONLY, meaning that it
137 * will never modify data in the parent blob. The parent data is not
143 * Return value: New blob, or the empty blob if something failed or if
154 hb_blob_t *blob;
161 blob = hb_blob_create (parent->data + offset,
167 return blob;
173 * Returns the singleton empty blob.
177 * Return value: (transfer full): the empty blob.
202 * @blob: a blob.
204 * Increases the reference count on @blob.
208 * Return value: @blob.
213 hb_blob_reference (hb_blob_t *blob)
215 return hb_object_reference (blob);
220 * @blob: a blob.
222 * Descreases the reference count on @blob, and if it reaches zero, destroys
223 * @blob, freeing all memory, possibly calling the destroy-callback the blob
231 hb_blob_destroy (hb_blob_t *blob)
233 if (!hb_object_destroy (blob)) return;
235 _hb_blob_destroy_user_data (blob);
237 free (blob);
242 * @blob: a blob.
253 hb_blob_set_user_data (hb_blob_t *blob,
259 return hb_object_set_user_data (blob, key, data, destroy, replace);
264 * @blob: a blob.
274 hb_blob_get_user_data (hb_blob_t *blob,
277 return hb_object_get_user_data (blob, key);
283 * @blob: a blob.
290 hb_blob_make_immutable (hb_blob_t *blob)
292 if (hb_object_is_inert (blob))
295 blob->immutable = true;
300 * @blob: a blob.
309 hb_blob_is_immutable (hb_blob_t *blob)
311 return blob->immutable;
317 * @blob: a blob.
321 * Return value: the length of blob data in bytes.
326 hb_blob_get_length (hb_blob_t *blob)
328 return blob->length;
333 * @blob: a blob.
343 hb_blob_get_data (hb_blob_t *blob, unsigned int *length)
346 *length = blob->length;
348 return blob->data;
353 * @blob: a blob.
356 * Tries to make blob data writable (possibly copying it) and
359 * Fails if blob has been made immutable, or if memory allocation
362 * Returns: (transfer none) (array length=length): Writable blob data,
368 hb_blob_get_data_writable (hb_blob_t *blob, unsigned int *length)
370 if (!_try_writable (blob)) {
378 *length = blob->length;
380 return const_cast<char *> (blob->data);
385 _try_make_writable_inplace_unix (hb_blob_t *blob)
400 DEBUG_MSG_FUNC (BLOB, blob, "failed to get pagesize: %s", strerror (errno));
403 DEBUG_MSG_FUNC (BLOB, blob, "pagesize is %lu", (unsigned long) pagesize);
406 addr = (const char *) (((uintptr_t) blob->data) & mask);
407 length = (const char *) (((uintptr_t) blob->data + blob->length + pagesize-1) & mask) - addr;
408 DEBUG_MSG_FUNC (BLOB, blob,
412 DEBUG_MSG_FUNC (BLOB, blob, "mprotect failed: %s", strerror (errno));
416 blob->mode = HB_MEMORY_MODE_WRITABLE;
418 DEBUG_MSG_FUNC (BLOB, blob,
428 _try_writable_inplace (hb_blob_t *blob)
430 DEBUG_MSG_FUNC (BLOB, blob, "making writable inplace\n");
432 if (_try_make_writable_inplace_unix (blob))
435 DEBUG_MSG_FUNC (BLOB, blob, "making writable -> FAILED\n");
438 blob->mode = HB_MEMORY_MODE_READONLY;
443 _try_writable (hb_blob_t *blob)
445 if (blob->immutable)
448 if (blob->mode == HB_MEMORY_MODE_WRITABLE)
451 if (blob->mode == HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE && _try_writable_inplace (blob))
454 if (blob->mode == HB_MEMORY_MODE_WRITABLE)
458 DEBUG_MSG_FUNC (BLOB, blob, "current data is -> %p\n", blob->data);
462 new_data = (char *) malloc (blob->length);
466 DEBUG_MSG_FUNC (BLOB, blob, "dupped successfully -> %p\n", blob->data);
468 memcpy (new_data, blob->data, blob->length);
469 _hb_blob_destroy_user_data (blob);
470 blob->mode = HB_MEMORY_MODE_WRITABLE;
471 blob->data = new_data;
472 blob->user_data = new_data;
473 blob->destroy = free;