Home | History | Annotate | Download | only in src

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: 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;
107 !(blob = hb_object_create<hb_blob_t> ())) {
113 blob->data = data;
114 blob->length = length;
115 blob->mode = mode;
117 blob->user_data = user_data;
118 blob->destroy = destroy;
120 if (blob->mode == HB_MEMORY_MODE_DUPLICATE) {
121 blob->mode = HB_MEMORY_MODE_READONLY;
122 if (!_try_writable (blob)) {
123 hb_blob_destroy (blob);
128 return blob;
133 * @parent: Parent blob.
134 * @offset: Start offset of sub-blob within @parent, in bytes.
135 * @length: Length of sub-blob.
137 * Returns a blob that represents a range of bytes in @parent. The new
138 * blob is always created with %HB_MEMORY_MODE_READONLY, meaning that it
139 * will never modify data in the parent blob. The parent data is not
145 * Return value: New blob, or the empty blob if something failed or if
156 hb_blob_t *blob;
163 blob = hb_blob_create (parent->data + offset,
169 return blob;
175 * Returns the singleton empty blob.
179 * Return value: (transfer full): the empty blob.
204 * @blob: a blob.
206 * Increases the reference count on @blob.
210 * Return value: @blob.
215 hb_blob_reference (hb_blob_t *blob)
217 return hb_object_reference (blob);
222 * @blob: a blob.
224 * Descreases the reference count on @blob, and if it reaches zero, destroys
225 * @blob, freeing all memory, possibly calling the destroy-callback the blob
233 hb_blob_destroy (hb_blob_t *blob)
235 if (!hb_object_destroy (blob)) return;
237 _hb_blob_destroy_user_data (blob);
239 free (blob);
244 * @blob: a blob.
255 hb_blob_set_user_data (hb_blob_t *blob,
261 return hb_object_set_user_data (blob, key, data, destroy, replace);
266 * @blob: a blob.
276 hb_blob_get_user_data (hb_blob_t *blob,
279 return hb_object_get_user_data (blob, key);
285 * @blob: a blob.
292 hb_blob_make_immutable (hb_blob_t *blob)
294 if (hb_object_is_inert (blob))
297 blob->immutable = true;
302 * @blob: a blob.
311 hb_blob_is_immutable (hb_blob_t *blob)
313 return blob->immutable;
319 * @blob: a blob.
323 * Return value: the length of blob data in bytes.
328 hb_blob_get_length (hb_blob_t *blob)
330 return blob->length;
335 * @blob: a blob.
345 hb_blob_get_data (hb_blob_t *blob, unsigned int *length)
348 *length = blob->length;
350 return blob->data;
355 * @blob: a blob.
358 * Tries to make blob data writable (possibly copying it) and
361 * Fails if blob has been made immutable, or if memory allocation
364 * Returns: (transfer none) (array length=length): Writable blob data,
370 hb_blob_get_data_writable (hb_blob_t *blob, unsigned int *length)
372 if (!_try_writable (blob)) {
380 *length = blob->length;
382 return const_cast<char *> (blob->data);
387 _try_make_writable_inplace_unix (hb_blob_t *blob)
402 DEBUG_MSG_FUNC (BLOB, blob, "failed to get pagesize: %s", strerror (errno));
405 DEBUG_MSG_FUNC (BLOB, blob, "pagesize is %lu", (unsigned long) pagesize);
408 addr = (const char *) (((uintptr_t) blob->data) & mask);
409 length = (const char *) (((uintptr_t) blob->data + blob->length + pagesize-1) & mask) - addr;
410 DEBUG_MSG_FUNC (BLOB, blob,
414 DEBUG_MSG_FUNC (BLOB, blob, "mprotect failed: %s", strerror (errno));
418 blob->mode = HB_MEMORY_MODE_WRITABLE;
420 DEBUG_MSG_FUNC (BLOB, blob,
430 _try_writable_inplace (hb_blob_t *blob)
432 DEBUG_MSG_FUNC (BLOB, blob, "making writable inplace\n");
434 if (_try_make_writable_inplace_unix (blob))
437 DEBUG_MSG_FUNC (BLOB, blob, "making writable -> FAILED\n");
440 blob->mode = HB_MEMORY_MODE_READONLY;
445 _try_writable (hb_blob_t *blob)
447 if (blob->immutable)
450 if (blob->mode == HB_MEMORY_MODE_WRITABLE)
453 if (blob->mode == HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE && _try_writable_inplace (blob))
456 if (blob->mode == HB_MEMORY_MODE_WRITABLE)
460 DEBUG_MSG_FUNC (BLOB, blob, "current data is -> %p\n", blob->data);
464 new_data = (char *) malloc (blob->length);
468 DEBUG_MSG_FUNC (BLOB, blob, "dupped successfully -> %p\n", blob->data);
470 memcpy (new_data, blob->data, blob->length);
471 _hb_blob_destroy_user_data (blob);
472 blob->mode = HB_MEMORY_MODE_WRITABLE;
473 blob->data = new_data;
474 blob->user_data = new_data;
475 blob->destroy = free;