xref: /OK3568_Linux_fs/buildroot/package/assimp/0003-closes-2954-upgrade-to-latest-greatest.patch (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1From bb3db0ebaffc6b76de256e597ec1d1e4d2a6663f Mon Sep 17 00:00:00 2001
2From: kimkulling <kim.kulling@googlemail.com>
3Date: Mon, 9 Mar 2020 10:51:26 +0100
4Subject: [PATCH] closes https://github.com/assimp/assimp/issues/2954: upgrade
5 to latest greatest.
6
7[Retrieved from:
8https://github.com/assimp/assimp/commit/bb3db0ebaffc6b76de256e597ec1d1e4d2a6663f]
9Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
10---
11 contrib/zip/CMakeLists.txt      |  8 ++----
12 contrib/zip/README.md           | 51 +++++++++++++++++++++++++++++++--
13 contrib/zip/src/zip.c           | 17 ++++++++++-
14 contrib/zip/src/zip.h           | 13 ++++++++-
15 contrib/zip/test/CMakeLists.txt |  5 ----
16 contrib/zip/test/test.c         |  4 ++-
17 6 files changed, 81 insertions(+), 17 deletions(-)
18
19diff --git a/contrib/zip/CMakeLists.txt b/contrib/zip/CMakeLists.txt
20index 77916d2e14..f194649ede 100644
21--- a/contrib/zip/CMakeLists.txt
22+++ b/contrib/zip/CMakeLists.txt
23@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.0)
24
25 project(zip
26   LANGUAGES C
27-  VERSION "0.1.15")
28+  VERSION "0.1.18")
29 set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
30
31 option(CMAKE_DISABLE_TESTING "Disable test creation" OFF)
32@@ -16,10 +16,6 @@ elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR
33         "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR
34         "${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang")
35   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -Wall -Wextra -Werror -pedantic")
36-  if(ENABLE_COVERAGE)
37-    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage")
38-    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
39-  endif()
40 endif (MSVC)
41
42 # zip
43@@ -35,7 +31,7 @@ if (NOT CMAKE_DISABLE_TESTING)
44   enable_testing()
45   add_subdirectory(test)
46   find_package(Sanitizers)
47-  add_sanitizers(${PROJECT_NAME} ${test_out} ${test_miniz_out})
48+  add_sanitizers(${PROJECT_NAME} ${test_out})
49 endif()
50
51 ####
52diff --git a/contrib/zip/README.md b/contrib/zip/README.md
53index 14eb9a34c8..bdd0822b67 100644
54--- a/contrib/zip/README.md
55+++ b/contrib/zip/README.md
56@@ -1,10 +1,8 @@
57 ### A portable (OSX/Linux/Windows), simple zip library written in C
58 This is done by hacking awesome [miniz](https://code.google.com/p/miniz) library and layering functions on top of the miniz v1.15 API.
59
60-[![Windows](https://ci.appveyor.com/api/projects/status/bph8dr3jacgmjv32/branch/master?svg=true&label=windows)](https://ci.appveyor.com/project/kuba--/zip)
61-[![Linux](https://travis-ci.org/kuba--/zip.svg?branch=master&label=linux%2fosx)](https://travis-ci.org/kuba--/zip)
62+[![Build](https://github.com/kuba--/zip/workflows/build/badge.svg)](https://github.com/kuba--/zip/actions?query=workflow%3Abuild)
63 [![Version](https://badge.fury.io/gh/kuba--%2Fzip.svg)](https://github.com/kuba--/zip/releases)
64-[![Codecov](https://codecov.io/gh/kuba--/zip/branch/master/graph/badge.svg)](https://codecov.io/gh/kuba--/zip)
65
66
67 # The Idea
68@@ -213,6 +211,53 @@ func main() {
69 }
70 ```
71
72+### Rust (ffi)
73+```rust
74+extern crate libc;
75+use std::ffi::CString;
76+
77+#[repr(C)]
78+pub struct Zip {
79+    _private: [u8; 0],
80+}
81+
82+#[link(name = "zip")]
83+extern "C" {
84+    fn zip_open(path: *const libc::c_char, level: libc::c_int, mode: libc::c_char) -> *mut Zip;
85+    fn zip_close(zip: *mut Zip) -> libc::c_void;
86+
87+    fn zip_entry_open(zip: *mut Zip, entryname: *const libc::c_char) -> libc::c_int;
88+    fn zip_entry_close(zip: *mut Zip) -> libc::c_int;
89+    fn zip_entry_write(
90+        zip: *mut Zip,
91+        buf: *const libc::c_void,
92+        bufsize: libc::size_t,
93+    ) -> libc::c_int;
94+}
95+
96+fn main() {
97+    let path = CString::new("/tmp/test.zip").unwrap();
98+    let mode: libc::c_char = 'w' as libc::c_char;
99+
100+    let entryname = CString::new("test.txt").unwrap();
101+    let content = "test content\0";
102+
103+    unsafe {
104+        let zip: *mut Zip = zip_open(path.as_ptr(), 5, mode);
105+        {
106+            zip_entry_open(zip, entryname.as_ptr());
107+            {
108+                let buf = content.as_ptr() as *const libc::c_void;
109+                let bufsize = content.len() as libc::size_t;
110+                zip_entry_write(zip, buf, bufsize);
111+            }
112+            zip_entry_close(zip);
113+        }
114+        zip_close(zip);
115+    }
116+}
117+```
118+
119 ### Ruby (ffi)
120 Install _ffi_ gem.
121 ```shell
122diff --git a/contrib/zip/src/zip.c b/contrib/zip/src/zip.c
123index 1abcfd8fd1..3b2821e6a3 100644
124--- a/contrib/zip/src/zip.c
125+++ b/contrib/zip/src/zip.c
126@@ -222,6 +222,20 @@ void zip_close(struct zip_t *zip) {
127   }
128 }
129
130+int zip_is64(struct zip_t *zip) {
131+  if (!zip) {
132+    // zip_t handler is not initialized
133+    return -1;
134+  }
135+
136+  if (!zip->archive.m_pState) {
137+    // zip state is not initialized
138+    return -1;
139+  }
140+
141+  return (int)zip->archive.m_pState->m_zip64;
142+}
143+
144 int zip_entry_open(struct zip_t *zip, const char *entryname) {
145   size_t entrylen = 0;
146   mz_zip_archive *pzip = NULL;
147@@ -794,7 +808,8 @@ int zip_create(const char *zipname, const char *filenames[], size_t len) {
148
149     if (MZ_FILE_STAT(name, &file_stat) != 0) {
150       // problem getting information - check errno
151-      return -1;
152+      status = -1;
153+      break;
154     }
155
156     if ((file_stat.st_mode & 0200) == 0) {
157diff --git a/contrib/zip/src/zip.h b/contrib/zip/src/zip.h
158index a48d64d6de..cd3ab5cd00 100644
159--- a/contrib/zip/src/zip.h
160+++ b/contrib/zip/src/zip.h
161@@ -21,7 +21,7 @@ extern "C" {
162
163 #if !defined(_SSIZE_T_DEFINED) && !defined(_SSIZE_T_DEFINED_) &&               \
164     !defined(__DEFINED_ssize_t) && !defined(__ssize_t_defined) &&              \
165-    !defined(_SSIZE_T) && !defined(_SSIZE_T_)
166+    !defined(_SSIZE_T) && !defined(_SSIZE_T_) && !defined(_SSIZE_T_DECLARED)
167
168 // 64-bit Windows is the only mainstream platform
169 // where sizeof(long) != sizeof(void*)
170@@ -37,6 +37,7 @@ typedef long ssize_t; /* byte count or error */
171 #define __ssize_t_defined
172 #define _SSIZE_T
173 #define _SSIZE_T_
174+#define _SSIZE_T_DECLARED
175
176 #endif
177
178@@ -90,6 +91,16 @@ extern struct zip_t *zip_open(const char *zipname, int level, char mode);
179  */
180 extern void zip_close(struct zip_t *zip);
181
182+/**
183+ * Determines if the archive has a zip64 end of central directory headers.
184+ *
185+ * @param zip zip archive handler.
186+ *
187+ * @return the return code - 1 (true), 0 (false), negative number (< 0) on
188+ *         error.
189+ */
190+extern int zip_is64(struct zip_t *zip);
191+
192 /**
193  * Opens an entry by name in the zip archive.
194  *
195diff --git a/contrib/zip/test/CMakeLists.txt b/contrib/zip/test/CMakeLists.txt
196index cc060b00fe..1224115858 100644
197--- a/contrib/zip/test/CMakeLists.txt
198+++ b/contrib/zip/test/CMakeLists.txt
199@@ -2,15 +2,10 @@ cmake_minimum_required(VERSION 2.8)
200
201 # test
202 set(test_out test.out)
203-set(test_miniz_out test_miniz.out)
204
205 add_executable(${test_out} test.c)
206 target_link_libraries(${test_out} zip)
207-add_executable(${test_miniz_out} test_miniz.c)
208-target_link_libraries(${test_miniz_out} zip)
209
210 add_test(NAME ${test_out} COMMAND ${test_out})
211-add_test(NAME ${test_miniz_out} COMMAND ${test_miniz_out})
212
213 set(test_out ${test_out} PARENT_SCOPE)
214-set(test_miniz_out ${test_miniz_out} PARENT_SCOPE)
215diff --git a/contrib/zip/test/test.c b/contrib/zip/test/test.c
216index a9b2ddab1e..9cc2248ac0 100644
217--- a/contrib/zip/test/test.c
218+++ b/contrib/zip/test/test.c
219@@ -47,7 +47,7 @@ static void test_write(void) {
220   assert(CRC32DATA1 == zip_entry_crc32(zip));
221   ++total_entries;
222   assert(0 == zip_entry_close(zip));
223-
224+  assert(0 == zip_is64(zip));
225   zip_close(zip);
226 }
227
228@@ -92,6 +92,7 @@ static void test_read(void) {
229   size_t buftmp;
230   struct zip_t *zip = zip_open(ZIPNAME, 0, 'r');
231   assert(zip != NULL);
232+  assert(0 == zip_is64(zip));
233
234   assert(0 == zip_entry_open(zip, "test\\test-1.txt"));
235   assert(strlen(TESTDATA1) == zip_entry_size(zip));
236@@ -310,6 +311,7 @@ static void test_fwrite(void) {
237   assert(0 == zip_entry_open(zip, WFILE));
238   assert(0 == zip_entry_fwrite(zip, WFILE));
239   assert(0 == zip_entry_close(zip));
240+  assert(0 == zip_is64(zip));
241
242   zip_close(zip);
243   remove(WFILE);
244