Add hb_blob_copy_writable_or_fail() New API: - hb_blob_copy_writable_or_fail()
diff --git a/docs/harfbuzz-sections.txt b/docs/harfbuzz-sections.txt index a9b4d53..5df33a8 100644 --- a/docs/harfbuzz-sections.txt +++ b/docs/harfbuzz-sections.txt
@@ -9,6 +9,7 @@ <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 8046012..b5291f6 100644 --- a/src/hb-blob.cc +++ b/src/hb-blob.cc
@@ -171,6 +171,31 @@ } /** + * 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 53682d3..fd561f7 100644 --- a/src/hb-blob.h +++ b/src/hb-blob.h
@@ -83,6 +83,9 @@ 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 *