diff options
author | Behdad Esfahbod <behdad@behdad.org> | 2018-02-13 22:12:36 -0800 |
---|---|---|
committer | Behdad Esfahbod <behdad@behdad.org> | 2018-02-13 22:12:36 -0800 |
commit | a989f3edec5864d5de8b217aa595c962d8fc4b0a (patch) | |
tree | da1158fb042ac7f8093d4a6188d74ee2aca08c14 | |
parent | 9046e924421869bf167b52cd394e868796091f62 (diff) |
Add hb_blob_copy_writable_or_fail()
New API:
- hb_blob_copy_writable_or_fail()
-rw-r--r-- | docs/harfbuzz-sections.txt | 1 | ||||
-rw-r--r-- | src/hb-blob.cc | 25 | ||||
-rw-r--r-- | src/hb-blob.h | 3 |
3 files changed, 29 insertions, 0 deletions
diff --git a/docs/harfbuzz-sections.txt b/docs/harfbuzz-sections.txt index a9b4d53e..5df33a81 100644 --- a/docs/harfbuzz-sections.txt +++ b/docs/harfbuzz-sections.txt @@ -9,6 +9,7 @@ HB_EXTERN <FILE>hb-blob</FILE> 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 80460125..b5291f65 100644 --- a/src/hb-blob.cc +++ b/src/hb-blob.cc @@ -171,6 +171,31 @@ hb_blob_create_sub_blob (hb_blob_t *parent, } /** + * 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: * * Returns the singleton empty blob. diff --git a/src/hb-blob.h b/src/hb-blob.h index 53682d3e..fd561f73 100644 --- a/src/hb-blob.h +++ b/src/hb-blob.h @@ -83,6 +83,9 @@ hb_blob_create_sub_blob (hb_blob_t *parent, 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); HB_EXTERN hb_blob_t * |