Home | History | Annotate | Download | only in src

Lines Matching refs:blob

66 static bool _try_writable (hb_blob_t *blob);
69 _hb_blob_destroy_user_data (hb_blob_t *blob)
71 if (blob->destroy) {
72 blob->destroy (blob->user_data);
73 blob->user_data = NULL;
74 blob->destroy = NULL;
80 * @data: (array length=length) (closure user_data) (destroy destroy) (scope notified) (transfer none): Pointer to blob data.
86 * Creates a new "blob" object wrapping @data. The @mode parameter is used
89 * Return value: New blob, or the empty blob if something failed or if @length is
101 hb_blob_t *blob;
103 if (!length || !(blob = hb_object_create<hb_blob_t> ())) {
109 blob->data = data;
110 blob->length = length;
111 blob->mode = mode;
113 blob->user_data = user_data;
114 blob->destroy = destroy;
116 if (blob->mode == HB_MEMORY_MODE_DUPLICATE) {
117 blob->mode = HB_MEMORY_MODE_READONLY;
118 if (!_try_writable (blob)) {
119 hb_blob_destroy (blob);
124 return blob;
129 * @parent: Parent blob.
130 * @offset: Start offset of sub-blob within @parent, in bytes.
131 * @length: Length of sub-blob.
133 * Returns a blob that represents a range of bytes in @parent. The new
134 * blob is always created with %HB_MEMORY_MODE_READONLY, meaning that it
135 * will never modify data in the parent blob. The parent data is not
141 * Return value: New blob, or the empty blob if something failed or if
152 hb_blob_t *blob;
159 blob = hb_blob_create (parent->data + offset,
165 return blob;
171 * Returns the singleton empty blob.
175 * Return value: (transfer full): the empty blob.
200 * @blob: a blob.
202 * Increases the reference count on @blob.
206 * Return value: @blob.
211 hb_blob_reference (hb_blob_t *blob)
213 return hb_object_reference (blob);
218 * @blob: a blob.
220 * Descreases the reference count on @blob, and if it reaches zero, destroys
221 * @blob, freeing all memory, possibly calling the destroy-callback the blob
229 hb_blob_destroy (hb_blob_t *blob)
231 if (!hb_object_destroy (blob)) return;
233 _hb_blob_destroy_user_data (blob);
235 free (blob);
240 * @blob: a blob.
251 hb_blob_set_user_data (hb_blob_t *blob,
257 return hb_object_set_user_data (blob, key, data, destroy, replace);
262 * @blob: a blob.
272 hb_blob_get_user_data (hb_blob_t *blob,
275 return hb_object_get_user_data (blob, key);
281 * @blob: a blob.
288 hb_blob_make_immutable (hb_blob_t *blob)
290 if (hb_object_is_inert (blob))
293 blob->immutable = true;
298 * @blob: a blob.
307 hb_blob_is_immutable (hb_blob_t *blob)
309 return blob->immutable;
315 * @blob: a blob.
319 * Return value: the length of blob data in bytes.
324 hb_blob_get_length (hb_blob_t *blob)
326 return blob->length;
331 * @blob: a blob.
341 hb_blob_get_data (hb_blob_t *blob, unsigned int *length)
344 *length = blob->length;
346 return blob->data;
351 * @blob: a blob.
354 * Tries to make blob data writable (possibly copying it) and
357 * Fails if blob has been made immutable, or if memory allocation
360 * Returns: (transfer none) (array length=length): Writable blob data,
366 hb_blob_get_data_writable (hb_blob_t *blob, unsigned int *length)
368 if (!_try_writable (blob)) {
376 *length = blob->length;
378 return const_cast<char *> (blob->data);
383 _try_make_writable_inplace_unix (hb_blob_t *blob)
398 DEBUG_MSG_FUNC (BLOB, blob, "failed to get pagesize: %s", strerror (errno));
401 DEBUG_MSG_FUNC (BLOB, blob, "pagesize is %lu", (unsigned long) pagesize);
404 addr = (const char *) (((uintptr_t) blob->data) & mask);
405 length = (const char *) (((uintptr_t) blob->data + blob->length + pagesize-1) & mask) - addr;
406 DEBUG_MSG_FUNC (BLOB, blob,
410 DEBUG_MSG_FUNC (BLOB, blob, "mprotect failed: %s", strerror (errno));
414 blob->mode = HB_MEMORY_MODE_WRITABLE;
416 DEBUG_MSG_FUNC (BLOB, blob,
426 _try_writable_inplace (hb_blob_t *blob)
428 DEBUG_MSG_FUNC (BLOB, blob, "making writable inplace\n");
430 if (_try_make_writable_inplace_unix (blob))
433 DEBUG_MSG_FUNC (BLOB, blob, "making writable -> FAILED\n");
436 blob->mode = HB_MEMORY_MODE_READONLY;
441 _try_writable (hb_blob_t *blob)
443 if (blob->immutable)
446 if (blob->mode == HB_MEMORY_MODE_WRITABLE)
449 if (blob->mode == HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE && _try_writable_inplace (blob))
452 if (blob->mode == HB_MEMORY_MODE_WRITABLE)
456 DEBUG_MSG_FUNC (BLOB, blob, "current data is -> %p\n", blob->data);
460 new_data = (char *) malloc (blob->length);
464 DEBUG_MSG_FUNC (BLOB, blob, "dupped successfully -> %p\n", blob->data);
466 memcpy (new_data, blob->data, blob->length);
467 _hb_blob_destroy_user_data (blob);
468 blob->mode = HB_MEMORY_MODE_WRITABLE;
469 blob->data = new_data;
470 blob->user_data = new_data;
471 blob->destroy = free;