Lines Matching defs: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: 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;
108 !(blob = hb_object_create<hb_blob_t> ())) {
114 blob->data = data;
115 blob->length = length;
116 blob->mode = mode;
118 blob->user_data = user_data;
119 blob->destroy = destroy;
121 if (blob->mode == HB_MEMORY_MODE_DUPLICATE) {
122 blob->mode = HB_MEMORY_MODE_READONLY;
123 if (!_try_writable (blob)) {
124 hb_blob_destroy (blob);
129 return blob;
134 * @parent: Parent blob.
135 * @offset: Start offset of sub-blob within @parent, in bytes.
136 * @length: Length of sub-blob.
138 * Returns a blob that represents a range of bytes in @parent. The new
139 * blob is always created with %HB_MEMORY_MODE_READONLY, meaning that it
140 * will never modify data in the parent blob. The parent data is not
146 * Return value: New blob, or the empty blob if something failed or if
157 hb_blob_t *blob;
164 blob = hb_blob_create (parent->data + offset,
170 return blob;
176 * Returns the singleton empty blob.
180 * Return value: (transfer full): the empty blob.
205 * @blob: a blob.
207 * Increases the reference count on @blob.
211 * Return value: @blob.
216 hb_blob_reference (hb_blob_t *blob)
218 return hb_object_reference (blob);
223 * @blob: a blob.
225 * Descreases the reference count on @blob, and if it reaches zero, destroys
226 * @blob, freeing all memory, possibly calling the destroy-callback the blob
234 hb_blob_destroy (hb_blob_t *blob)
236 if (!hb_object_destroy (blob)) return;
238 _hb_blob_destroy_user_data (blob);
240 free (blob);
245 * @blob: a blob.
256 hb_blob_set_user_data (hb_blob_t *blob,
262 return hb_object_set_user_data (blob, key, data, destroy, replace);
267 * @blob: a blob.
277 hb_blob_get_user_data (hb_blob_t *blob,
280 return hb_object_get_user_data (blob, key);
286 * @blob: a blob.
293 hb_blob_make_immutable (hb_blob_t *blob)
295 if (hb_object_is_inert (blob))
298 blob->immutable = true;
303 * @blob: a blob.
312 hb_blob_is_immutable (hb_blob_t *blob)
314 return blob->immutable;
320 * @blob: a blob.
324 * Return value: the length of blob data in bytes.
329 hb_blob_get_length (hb_blob_t *blob)
331 return blob->length;
336 * @blob: a blob.
346 hb_blob_get_data (hb_blob_t *blob, unsigned int *length)
349 *length = blob->length;
351 return blob->data;
356 * @blob: a blob.
359 * Tries to make blob data writable (possibly copying it) and
362 * Fails if blob has been made immutable, or if memory allocation
365 * Returns: (transfer none) (array length=length): Writable blob data,
371 hb_blob_get_data_writable (hb_blob_t *blob, unsigned int *length)
373 if (!_try_writable (blob)) {
381 *length = blob->length;
383 return const_cast<char *> (blob->data);
388 _try_make_writable_inplace_unix (hb_blob_t *blob)
403 DEBUG_MSG_FUNC (BLOB, blob, "failed to get pagesize: %s", strerror (errno));
406 DEBUG_MSG_FUNC (BLOB, blob, "pagesize is %lu", (unsigned long) pagesize);
409 addr = (const char *) (((uintptr_t) blob->data) & mask);
410 length = (const char *) (((uintptr_t) blob->data + blob->length + pagesize-1) & mask) - addr;
411 DEBUG_MSG_FUNC (BLOB, blob,
415 DEBUG_MSG_FUNC (BLOB, blob, "mprotect failed: %s", strerror (errno));
419 blob->mode = HB_MEMORY_MODE_WRITABLE;
421 DEBUG_MSG_FUNC (BLOB, blob,
431 _try_writable_inplace (hb_blob_t *blob)
433 DEBUG_MSG_FUNC (BLOB, blob, "making writable inplace\n");
435 if (_try_make_writable_inplace_unix (blob))
438 DEBUG_MSG_FUNC (BLOB, blob, "making writable -> FAILED\n");
441 blob->mode = HB_MEMORY_MODE_READONLY;
446 _try_writable (hb_blob_t *blob)
448 if (blob->immutable)
451 if (blob->mode == HB_MEMORY_MODE_WRITABLE)
454 if (blob->mode == HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE && _try_writable_inplace (blob))
457 if (blob->mode == HB_MEMORY_MODE_WRITABLE)
461 DEBUG_MSG_FUNC (BLOB, blob, "current data is -> %p\n", blob->data);
465 new_data = (char *) malloc (blob->length);
469 DEBUG_MSG_FUNC (BLOB, blob, "dupped successfully -> %p\n", blob->data);
471 memcpy (new_data, blob->data, blob->length);
472 _hb_blob_destroy_user_data (blob);
473 blob->mode = HB_MEMORY_MODE_WRITABLE;
474 blob->data = new_data;
475 blob->user_data = new_data;
476 blob->destroy = free;