Skip to content

Commit 0b59d98

Browse files
Aidan63Aidan Lee
andauthored
Typed zip (#1277)
* Updated zlib implementation * header faff to make gcc pch happy * Support haxe 4 with new implementation * no longer throwing on multiple close calls * Give different file names to avoid cache issues * Fix old string value * Another old string * static cast to int to avoid dynamic conversion of unsupported type * true instead of 1 for asLibrary value * some build xml tweaks * Make sure this_dir is used before Zip.cpp * case sensitive * Fix case sensitivity in include * flip around files order --------- Co-authored-by: Aidan Lee <[email protected]>
1 parent 4b2991f commit 0b59d98

File tree

17 files changed

+628
-346
lines changed

17 files changed

+628
-346
lines changed

include/hx/zip/Compress.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#pragma once
2+
3+
#include "Zip.hpp"
4+
5+
HX_DECLARE_CLASS2(hx, zip, Compress)
6+
7+
namespace hx
8+
{
9+
namespace zip
10+
{
11+
struct Compress_obj : Zip_obj
12+
{
13+
static Compress create(int level);
14+
static Array<uint8_t> run(cpp::marshal::View<uint8_t> src, int level);
15+
16+
virtual int getBounds(int length) = 0;
17+
};
18+
}
19+
}

include/hx/zip/Uncompress.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma once
2+
3+
#include "Zip.hpp"
4+
5+
HX_DECLARE_CLASS2(hx, zip, Uncompress)
6+
7+
namespace hx
8+
{
9+
namespace zip
10+
{
11+
struct Uncompress_obj : Zip_obj
12+
{
13+
static Uncompress create(int windowSize);
14+
static Array<uint8_t> run(cpp::marshal::View<uint8_t> src, int bufferSize);
15+
};
16+
}
17+
}

include/hx/zip/Zip.hpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#pragma once
2+
3+
#ifndef HXCPP_H
4+
#include <hxcpp.h>
5+
#endif
6+
7+
HX_DECLARE_CLASS2(hx, zip, Zip)
8+
9+
namespace hx
10+
{
11+
namespace zip
12+
{
13+
enum Flush {
14+
None,
15+
Sync,
16+
Full,
17+
Finish,
18+
Block
19+
};
20+
21+
struct Result final {
22+
const bool done;
23+
const int read;
24+
const int write;
25+
26+
Result(int inDone, int inRead, int inWrite);
27+
};
28+
29+
struct Zip_obj : hx::Object
30+
{
31+
virtual Result execute(cpp::marshal::View<uint8_t> src, cpp::marshal::View<uint8_t> dst) = 0;
32+
virtual void setFlushMode(Flush mode) = 0;
33+
virtual void close() = 0;
34+
};
35+
}
36+
}

include/hxString.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,8 @@ class HXCPP_EXTERN_CLASS_ATTRIBUTES String
4646
static String create(const char16_t *inPtr,int inLen=-1);
4747
static String create(const char *inPtr,int inLen=-1);
4848

49-
#if (HXCPP_API_LEVEL>=500)
5049
static String create(const ::cpp::marshal::View<char>& buffer);
5150
static String create(const ::cpp::marshal::View<char16_t>& buffer);
52-
#endif
5351

5452
// Uses non-gc memory and wont ever be collected
5553
static ::String createPermanent(const char *inUtf8, int inLen);
@@ -173,10 +171,8 @@ class HXCPP_EXTERN_CLASS_ATTRIBUTES String
173171
const wchar_t *wchar_str(hx::IStringAlloc *inBuffer = 0) const;
174172
const char16_t *wc_str(hx::IStringAlloc *inBuffer = 0, int *outCharLength = 0) const;
175173

176-
#if (HXCPP_API_LEVEL >= 500)
177174
bool wc_str(::cpp::marshal::View<char16_t> buffer, int* outCharLength = nullptr) const;
178175
bool utf8_str(::cpp::marshal::View<char> buffer, int* outByteLength = nullptr) const;
179-
#endif
180176

181177
const char *__CStr() const { return utf8_str(); };
182178
const wchar_t *__WCStr() const { return wchar_str(0); }

include/hxcpp.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -351,15 +351,13 @@ typedef PropertyAccessMode PropertyAccess;
351351
#endif
352352
#include <hx/StdLibs.h>
353353
#include <cpp/Pointer.h>
354-
#if (HXCPP_API_LEVEL>=500)
355-
#include <cpp/marshal/Boxed.hpp>
356-
#include <cpp/marshal/ValueType.hpp>
357-
#include <cpp/marshal/PointerType.hpp>
358-
#include <cpp/marshal/ValueReference.hpp>
359-
#include <cpp/marshal/PointerReference.hpp>
360-
#include <cpp/marshal/View.hpp>
361-
#include <cpp/marshal/Marshal.hpp>
362-
#endif
354+
#include <cpp/marshal/Boxed.hpp>
355+
#include <cpp/marshal/ValueType.hpp>
356+
#include <cpp/marshal/PointerType.hpp>
357+
#include <cpp/marshal/ValueReference.hpp>
358+
#include <cpp/marshal/PointerReference.hpp>
359+
#include <cpp/marshal/View.hpp>
360+
#include <cpp/marshal/Marshal.hpp>
363361
#include <hx/Native.h>
364362
#include <hx/Operators.h>
365363
#include <hx/Functions.h>

src/String.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,6 @@ String String::create(const char *inString,int inLength)
788788
return String(s,len);
789789
}
790790

791-
#if (HXCPP_API_LEVEL>=500)
792791
String String::create(const::cpp::marshal::View<char>& buffer)
793792
{
794793
auto start = buffer.ptr.ptr;
@@ -824,7 +823,6 @@ String String::create(const cpp::marshal::View<char16_t>& buffer)
824823

825824
return String::create(buffer.ptr.ptr, buffer.length - (end - start) - extra);
826825
}
827-
#endif
828826

829827
String::String(const Dynamic &inRHS)
830828
{
@@ -1794,8 +1792,6 @@ const char16_t * String::wc_str(hx::IStringAlloc *inBuffer, int *outCharLength)
17941792
return str;
17951793
}
17961794

1797-
#if (HXCPP_API_LEVEL >= 500)
1798-
17991795
bool String::wc_str(::cpp::marshal::View<char16_t> buffer, int* outCharLength) const
18001796
{
18011797
#ifdef HX_SMART_STRINGS
@@ -1918,8 +1914,6 @@ bool String::utf8_str(::cpp::marshal::View<char> buffer, int* outByteLength) con
19181914
return true;
19191915
}
19201916

1921-
#endif
1922-
19231917
const wchar_t * String::wchar_str(hx::IStringAlloc *inBuffer) const
19241918
{
19251919
if (!__s)

src/hx/libs/zlib/Build.xml

Lines changed: 7 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,7 @@
1-
<xml>
2-
3-
<pragma once="true" />
4-
5-
<set name="ZLIB_DIR" value="${HXCPP}/project/thirdparty/zlib-1.3.1"/>
6-
7-
<files id="hxcpp_zlib" dir="${this_dir}" >
8-
<depend files="hxcpp-depends"/>
9-
<depend name="${this_dir}/Build.xml" dateOnly="true" />
10-
<cache value="true" asLibrary="1" />
11-
12-
<compilerflag value="-I${ZLIB_DIR}"/>
13-
<compilerflag value="-DSTDC" unless="windows" />
14-
<compilerflag value="-DHAVE_UNISTD_H" unless="windows" />
15-
16-
<file name="ZLib.cpp"/>
17-
18-
<!-- HXCPP_LINK_NO_ZLIB may be set too late, so use filterout as well. -->
19-
<section unless="HXCPP_LINK_NO_ZLIB" >
20-
<file name="${ZLIB_DIR}/adler32.c" filterout="HXCPP_LINK_NO_ZLIB" tags="" />
21-
<file name="${ZLIB_DIR}/compress.c" filterout="HXCPP_LINK_NO_ZLIB" tags="" />
22-
<file name="${ZLIB_DIR}/crc32.c" filterout="HXCPP_LINK_NO_ZLIB" tags="" />
23-
<file name="${ZLIB_DIR}/deflate.c" filterout="HXCPP_LINK_NO_ZLIB" tags="" />
24-
<file name="${ZLIB_DIR}/gzclose.c" filterout="HXCPP_LINK_NO_ZLIB" tags="" />
25-
<file name="${ZLIB_DIR}/gzlib.c" filterout="HXCPP_LINK_NO_ZLIB" tags="" />
26-
<file name="${ZLIB_DIR}/gzread.c" filterout="HXCPP_LINK_NO_ZLIB" tags="" />
27-
<file name="${ZLIB_DIR}/gzwrite.c" filterout="HXCPP_LINK_NO_ZLIB" tags="" />
28-
<file name="${ZLIB_DIR}/infback.c" filterout="HXCPP_LINK_NO_ZLIB" tags="" />
29-
<file name="${ZLIB_DIR}/inffast.c" filterout="HXCPP_LINK_NO_ZLIB" tags="" />
30-
<file name="${ZLIB_DIR}/inflate.c" filterout="HXCPP_LINK_NO_ZLIB" tags="" />
31-
<file name="${ZLIB_DIR}/inftrees.c" filterout="HXCPP_LINK_NO_ZLIB" tags="" />
32-
<file name="${ZLIB_DIR}/trees.c" filterout="HXCPP_LINK_NO_ZLIB" tags="" />
33-
<file name="${ZLIB_DIR}/uncompr.c" filterout="HXCPP_LINK_NO_ZLIB" tags="" />
34-
<file name="${ZLIB_DIR}/zutil.c" filterout="HXCPP_LINK_NO_ZLIB" tags="" />
35-
</section>
36-
</files>
37-
38-
<target id="haxe">
39-
<files id="hxcpp_zlib" />
40-
</target>
41-
42-
</xml>
1+
<xml>
2+
3+
<pragma once="true" />
4+
5+
<import name="${this_dir}/../../zip/Build.xml"/>
6+
7+
</xml>

0 commit comments

Comments
 (0)