From a989f3edec5864d5de8b217aa595c962d8fc4b0a Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 13 Feb 2018 22:12:36 -0800 Subject: [PATCH] Add hb_blob_copy_writable_or_fail() New API: - hb_blob_copy_writable_or_fail() --- docs/harfbuzz-sections.txt | 1 + src/hb-blob.cc | 25 +++++++++++++++++++++++++ src/hb-blob.h | 3 +++ 3 files changed, 29 insertions(+) diff --git a/docs/harfbuzz-sections.txt b/docs/harfbuzz-sections.txt index a9b4d53eb..5df33a816 100644 --- a/docs/harfbuzz-sections.txt +++ b/docs/harfbuzz-sections.txt @@ -9,6 +9,7 @@ HB_EXTERN hb-blob hb_blob_create hb_blob_create_sub_blob +hb_blob_copy_writable_or_fail hb_blob_destroy hb_blob_get_data hb_blob_get_data_writable diff --git a/src/hb-blob.cc b/src/hb-blob.cc index 804601258..b5291f650 100644 --- a/src/hb-blob.cc +++ b/src/hb-blob.cc @@ -170,6 +170,31 @@ hb_blob_create_sub_blob (hb_blob_t *parent, return blob; } +/** + * hb_blob_copy_writable_or_fail: + * @blob: A blob. + * + * Makes a writable copy of @blob. + * + * Return value: New blob, or nullptr if allocation failed. + * + * Since: 1.8.0 + **/ +hb_blob_t * +hb_blob_copy_writable_or_fail (hb_blob_t *blob) +{ + blob = hb_blob_create (blob->data, + blob->length, + HB_MEMORY_MODE_DUPLICATE, + nullptr, + nullptr); + + if (unlikely (blob == hb_blob_get_empty ())) + blob = nullptr; + + return blob; +} + /** * hb_blob_get_empty: * diff --git a/src/hb-blob.h b/src/hb-blob.h index 53682d3eb..fd561f738 100644 --- a/src/hb-blob.h +++ b/src/hb-blob.h @@ -82,6 +82,9 @@ hb_blob_create_sub_blob (hb_blob_t *parent, unsigned int offset, unsigned int length); +HB_EXTERN hb_blob_t * +hb_blob_copy_writable_or_fail (hb_blob_t *blob); + HB_EXTERN hb_blob_t * hb_blob_get_empty (void);