From 62b5999571d145b02516333df1bfa0f539119cb3 Mon Sep 17 00:00:00 2001 From: Kirill Kuzminykh Date: Tue, 12 Nov 2024 22:47:09 +0300 Subject: [PATCH] - Exclude `heif_items.h` from `wrapper.hpp` because this API isn't yet ready and doesn't work as expected. - Added test for testing cases when not all functions from *.h files are really available in libheif. --- CHANGELOG.md | 25 ++------- build.rs | 39 ++++++++++++++ src/bindings.rs | 140 ------------------------------------------------ src/lib.rs | 5 ++ wrapper.hpp | 4 -- 5 files changed, 49 insertions(+), 164 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d164dd3..ff1dfc9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Change Log -## [3.0.0] - 2024-11-07 +## [Unreleased] - ReleaseDate ### Added @@ -40,25 +40,6 @@ - `heif_context_add_compatible_brand` - `heif_context_encode_grid` - `heif_context_add_generic_uri_metadata` - - `heif_context_get_number_of_items` - - `heif_context_get_list_of_item_IDs` - - `heif_item_get_item_type` - - `heif_item_is_item_hidden` - - `heif_item_get_mime_item_content_type` - - `heif_item_get_mime_item_content_encoding` - - `heif_item_get_uri_item_uri_type` - - `heif_item_get_item_name` - - `heif_item_set_item_name` - - `heif_item_get_item_data` - - `heif_release_item_data` - - `heif_context_get_item_references` - - `heif_release_item_references` - - `heif_context_add_item_reference` - - `heif_context_add_item_references` - - `heif_context_add_item` - - `heif_context_add_mime_item` - - `heif_context_add_precompressed_mime_item` - - `heif_context_add_uri_item` - `heif_item_get_properties_of_type` - `heif_item_get_transformation_properties` - `heif_item_get_property_type` @@ -115,6 +96,10 @@ - `heif_decoding_options` - `heif_encoding_options` +## [3.0.0] - 2024-11-07 + +**YANKED** + ## [2.1.1] - 2024-05-08 - Fixed minimal required version of `libheif` specified in `build.rs`. diff --git a/build.rs b/build.rs index 877dfde..02ec8d2 100644 --- a/build.rs +++ b/build.rs @@ -230,4 +230,43 @@ fn run_bindgen(include_dirs: &[String]) { bindings .write_to_file(out_path.join("bindings.rs")) .expect("Couldn't write bindings!"); + + // Create linker_test.ts module for testing cases when not all + // functions from *.h files are really available in libheif. + let code = bindings.to_string(); + let mut func_names = Vec::new(); + for line in code.lines() { + if !line.contains("pub fn ") { + continue; + } + let line = line.trim(); + let res: Vec<&str> = line.split(&[' ', '(']).collect(); + if res.len() > 3 { + if let &["pub", "fn", name] = &res[..3] { + func_names.push(name) + } + } + } + + let mut result = vec![ + "use super::*;\n\n", + "#[test]\n", + "fn is_all_functions_exists_in_libheif() {\n", + " let fn_pointers = [\n", + ]; + for name in func_names { + result.push(" "); + result.push(name); + result.push(" as *const fn(),\n") + } + result.extend(vec![ + " ];\n", + " for pointer in fn_pointers.iter() {\n", + " assert!(!pointer.is_null());\n", + " }\n", + "}\n", + ]); + let test_module = result.join(""); + let test_path = out_path.join("linker_test.rs"); + std::fs::write(&test_path, test_module).expect("Couldn't write test module!"); } diff --git a/src/bindings.rs b/src/bindings.rs index c46a15a..61a0e4e 100644 --- a/src/bindings.rs +++ b/src/bindings.rs @@ -2111,146 +2111,6 @@ extern "C" { arg1: *const heif_encoder_descriptor, ) -> libc::c_int; } -extern "C" { - #[doc = " Gets the number of items.\n\n This is not the same as the number of images, since there can be other types of items,\n such as metadata.\n\n @param ctx the file context\n @return the number of items"] - pub fn heif_context_get_number_of_items(ctx: *const heif_context) -> libc::c_int; -} -extern "C" { - #[doc = " Get the item identifiers.\n\n Fills in the item IDs into the user-supplied array {@code ID_array}, preallocated with {@code count} entries.\n\n @param ctx the file context\n @param ID_array the output array.\n @param count the number of items allocated within {@code ID_array}.\n @return the total number of IDs filled into the array, which may be less than {@code count}."] - pub fn heif_context_get_list_of_item_IDs( - ctx: *const heif_context, - ID_array: *mut heif_item_id, - count: libc::c_int, - ) -> libc::c_int; -} -extern "C" { - #[doc = " Gets the item type.\n\n Usually, this is a four character code (e.g. `mime` or `uri `), but it can theoretically be\n any 4-byte number. Thus, the type is returned as an integer. You can use {@link heif_fourcc} to map\n between the two representations.\n\n @param ctx the file context\n @param item_id the item identifier for the item\n @return the item type"] - pub fn heif_item_get_item_type(ctx: *const heif_context, item_id: heif_item_id) -> u32; -} -extern "C" { - pub fn heif_item_is_item_hidden(ctx: *const heif_context, item_id: heif_item_id) - -> libc::c_int; -} -extern "C" { - #[doc = " Gets the MIME content_type for an item.\n\n Only valid if the item type is `mime`.\n If the item does not exist, or if it is not a `mime` item, NULL is returned.\n\n @param ctx the file context\n @param item_id the item identifier for the item\n @return the item content_type"] - pub fn heif_item_get_mime_item_content_type( - ctx: *const heif_context, - item_id: heif_item_id, - ) -> *const libc::c_char; -} -extern "C" { - #[doc = " Gets the content_encoding for a MIME item.\n\n Only valid if the item type is `mime`.\n If the item does not exist, or if it is not a `mime` item, NULL is returned.\n\n If the item is not encoded, the returned value will be an empty string (not null).\n\n @param ctx the file context\n @param item_id the item identifier for the item\n @return the item content_type"] - pub fn heif_item_get_mime_item_content_encoding( - ctx: *const heif_context, - item_id: heif_item_id, - ) -> *const libc::c_char; -} -extern "C" { - #[doc = " Gets the item_uri_type for an item.\n\n Only valid if the item type is `uri `.\n If the item does not exist, or if it is not a `uri ` item, NULL is returned.\n\n @param ctx the file context\n @param item_id the item identifier for the item\n @return the item item_uri_type"] - pub fn heif_item_get_uri_item_uri_type( - ctx: *const heif_context, - item_id: heif_item_id, - ) -> *const libc::c_char; -} -extern "C" { - pub fn heif_item_get_item_name( - ctx: *const heif_context, - item_id: heif_item_id, - ) -> *const libc::c_char; -} -extern "C" { - pub fn heif_item_set_item_name( - ctx: *mut heif_context, - item: heif_item_id, - item_name: *const libc::c_char, - ) -> heif_error; -} -extern "C" { - #[doc = " Gets the raw metadata, as stored in the HEIF file.\n\n Data in a \"mime\" item with \"content_encoding\" can be compressed.\n When `out_compression_format` is NULL, the decompressed data will be returned.\n Otherwise, the compressed data is returned and `out_compression_format` will be filled with the\n compression format.\n If the compression method is not supported, an error will be returned.\n\n It is valid to set `out_data` to NULL. In that case, only the `out_data_size` is filled.\n Note that it is inefficient to use `out_data=NULL` just to get the size of compressed data.\n In general, this should be avoided.\n\n If there is no data assigned to the item or there is an error, `out_data_size` is set to zero.\n\n @param ctx the file context\n @param item_id the item identifier for the item\n @param out_compression_format how the data is compressed. If the pointer is NULL, the decompressed data will be returned.\n @param out_data the corresponding raw metadata\n @param out_data_size the size of the metadata in bytes\n @return whether the call succeeded, or there was an error"] - pub fn heif_item_get_item_data( - ctx: *const heif_context, - item_id: heif_item_id, - out_compression_format: *mut heif_metadata_compression, - out_data: *mut *mut u8, - out_data_size: *mut usize, - ) -> heif_error; -} -extern "C" { - #[doc = " Free the item data.\n\n This is used to free memory associated with the data returned by\n {@link heif_item_get_item_data} in 'out_data' and set the pointer to NULL.\n\n @param ctx the file context\n @param item_data the data to free"] - pub fn heif_release_item_data(ctx: *const heif_context, item_data: *mut *mut u8); -} -extern "C" { - #[doc = " Get the item ids that reference the given item.\n\n @param ctx the file context.\n @param from_item_id the item identifier for the item.\n @param index the index of the reference to get.\n @param out_reference_type_4cc The 4cc of the reference. (e.g dimg, thmb, cdsc, or auxl)\n @param out_references_to the item references. Use {@link heif_release_item_references} to free the memory.\n @return the number of items that reference the given item. Returns 0 if the index exceeds the number of references."] - pub fn heif_context_get_item_references( - ctx: *const heif_context, - from_item_id: heif_item_id, - index: libc::c_int, - out_reference_type_4cc: *mut u32, - out_references_to: *mut *mut heif_item_id, - ) -> usize; -} -extern "C" { - pub fn heif_release_item_references( - ctx: *const heif_context, - references: *mut *mut heif_item_id, - ); -} -extern "C" { - pub fn heif_context_add_item_reference( - ctx: *mut heif_context, - reference_type: u32, - from_item: heif_item_id, - to_item: heif_item_id, - ) -> heif_error; -} -extern "C" { - pub fn heif_context_add_item_references( - ctx: *mut heif_context, - reference_type: u32, - from_item: heif_item_id, - to_item: *const heif_item_id, - num_to_items: libc::c_int, - ) -> heif_error; -} -extern "C" { - #[doc = " ------------------------- adding new items -------------------------"] - pub fn heif_context_add_item( - ctx: *mut heif_context, - item_type: *const libc::c_char, - data: *const libc::c_void, - size: libc::c_int, - out_item_id: *mut heif_item_id, - ) -> heif_error; -} -extern "C" { - pub fn heif_context_add_mime_item( - ctx: *mut heif_context, - content_type: *const libc::c_char, - content_encoding: heif_metadata_compression, - data: *const libc::c_void, - size: libc::c_int, - out_item_id: *mut heif_item_id, - ) -> heif_error; -} -extern "C" { - pub fn heif_context_add_precompressed_mime_item( - ctx: *mut heif_context, - content_type: *const libc::c_char, - content_encoding: *const libc::c_char, - data: *const libc::c_void, - size: libc::c_int, - out_item_id: *mut heif_item_id, - ) -> heif_error; -} -extern "C" { - pub fn heif_context_add_uri_item( - ctx: *mut heif_context, - item_uri_type: *const libc::c_char, - data: *const libc::c_void, - size: libc::c_int, - out_item_id: *mut heif_item_id, - ) -> heif_error; -} #[doc = " heif_item_property_unknown = -1,"] pub const heif_item_property_type_heif_item_property_type_invalid: heif_item_property_type = 0; #[doc = " heif_item_property_unknown = -1,"] diff --git a/src/lib.rs b/src/lib.rs index 3098649..57ef0fe 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,3 +10,8 @@ include!(concat!(env!("OUT_DIR"), "/bindings.rs")); mod bindings; #[cfg(any(not(feature = "use-bindgen"), docsrs))] pub use bindings::*; + +#[cfg(all(test, feature = "use-bindgen", not(docsrs)))] +mod linker_test { + include!(concat!(env!("OUT_DIR"), "/linker_test.rs")); +} diff --git a/wrapper.hpp b/wrapper.hpp index 8e1be3f..dd68282 100644 --- a/wrapper.hpp +++ b/wrapper.hpp @@ -1,7 +1,3 @@ #include -#if __has_include("libheif/heif_items.h") - // heif_items.h was added in version 1.18 - #include -#endif #include #include