summaryrefslogtreecommitdiffstats
path: root/depends/pack200/src
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2013-09-29 21:11:30 +0200
committerPetr Mrázek <peterix@gmail.com>2013-09-29 21:11:30 +0200
commit604162acdf5283a9759c1b3ce9e90887a6599ce7 (patch)
tree06dc5f9ce330afb03922f822b9203169e17576e6 /depends/pack200/src
parentd267d86f6e24c4f947c30c1a3642d57b82f8addd (diff)
downloadMultiMC-604162acdf5283a9759c1b3ce9e90887a6599ce7.tar
MultiMC-604162acdf5283a9759c1b3ce9e90887a6599ce7.tar.gz
MultiMC-604162acdf5283a9759c1b3ce9e90887a6599ce7.tar.lz
MultiMC-604162acdf5283a9759c1b3ce9e90887a6599ce7.tar.xz
MultiMC-604162acdf5283a9759c1b3ce9e90887a6599ce7.zip
Turn pack200 into an actual library
Diffstat (limited to 'depends/pack200/src')
-rw-r--r--depends/pack200/src/bands.cpp36
-rw-r--r--depends/pack200/src/bands.h9
-rw-r--r--depends/pack200/src/bytes.cpp4
-rw-r--r--depends/pack200/src/bytes.h2
-rw-r--r--depends/pack200/src/coding.cpp125
-rw-r--r--depends/pack200/src/coding.h29
-rw-r--r--depends/pack200/src/constants.h2
-rw-r--r--depends/pack200/src/defines.h75
-rw-r--r--depends/pack200/src/main.cpp489
-rw-r--r--depends/pack200/src/unpack.cpp670
-rw-r--r--depends/pack200/src/unpack.h114
-rw-r--r--depends/pack200/src/unpack200.cpp172
-rw-r--r--depends/pack200/src/utils.cpp28
-rw-r--r--depends/pack200/src/utils.h9
-rw-r--r--depends/pack200/src/zip.cpp56
-rw-r--r--depends/pack200/src/zip.h28
16 files changed, 507 insertions, 1341 deletions
diff --git a/depends/pack200/src/bands.cpp b/depends/pack200/src/bands.cpp
index 6b4e8971..1c10b35b 100644
--- a/depends/pack200/src/bands.cpp
+++ b/depends/pack200/src/bands.cpp
@@ -34,6 +34,7 @@
#include <stdlib.h>
#include <stdarg.h>
#include <assert.h>
+#include <stdint.h>
#include "defines.h"
#include "bytes.h"
@@ -44,18 +45,8 @@
#include "constants.h"
#include "unpack.h"
-inline void band::abort(const char *msg)
-{
- u->abort(msg);
-}
-inline bool band::aborting()
-{
- return u->aborting();
-}
-
void band::readData(int expectedLength)
{
- CHECK;
assert(expectedLength >= 0);
assert(vs[0].cmk == cmk_ERROR);
if (expectedLength != 0)
@@ -82,7 +73,7 @@ void band::readData(int expectedLength)
// Make a conservatively generous estimate of band size in bytes.
// Assume B == 5 everywhere.
// Assume awkward pop with all {U} values (2*5 per value)
- jlong generous = (jlong)length * (B_MAX * 3 + 1) + C_SLOP;
+ int64_t generous = (int64_t)length * (B_MAX * 3 + 1) + C_SLOP;
u->ensure_input(generous);
}
@@ -102,7 +93,6 @@ void band::readData(int expectedLength)
assert(!valc->isMalloc);
}
xvs.init(u->rp, u->rplimit, valc);
- CHECK;
int X = xvs.getInt();
if (valc->S() != 0)
{
@@ -133,7 +123,6 @@ void band::readData(int expectedLength)
byte XB_byte = (byte)XB;
byte *XB_ptr = &XB_byte;
cm.init(u->rp, u->rplimit, XB_ptr, 0, defc, length, nullptr);
- CHECK;
}
else
{
@@ -162,7 +151,6 @@ void band::setIndexByTag(byte tag)
entry *band::getRefCommon(cpindex *ix_, bool nullOKwithCaller)
{
- CHECK_0;
assert(ix_->ixTag == ixTag ||
(ixTag == CONSTANT_Literal && ix_->ixTag >= CONSTANT_Integer &&
ix_->ixTag <= CONSTANT_String));
@@ -171,27 +159,26 @@ entry *band::getRefCommon(cpindex *ix_, bool nullOKwithCaller)
// But nullOKwithCaller means caller is willing to tolerate a nullptr.
entry *ref = ix_->get(n);
if (ref == nullptr && !(nullOKwithCaller && n == -1))
- abort(n == -1 ? "nullptr ref" : "bad ref");
+ unpack_abort(n == -1 ? "nullptr ref" : "bad ref");
return ref;
}
-jlong band::getLong(band &lo_band, bool have_hi)
+int64_t band::getLong(band &lo_band, bool have_hi)
{
band &hi_band = (*this);
assert(lo_band.bn == hi_band.bn + 1);
- uint lo = lo_band.getInt();
+ uint32_t lo = lo_band.getInt();
if (!have_hi)
{
assert(hi_band.length == 0);
return makeLong(0, lo);
}
- uint hi = hi_band.getInt();
+ uint32_t hi = hi_band.getInt();
return makeLong(hi, lo);
}
int band::getIntTotal()
{
- CHECK_0;
if (length == 0)
return 0;
if (total_memo > 0)
@@ -201,8 +188,7 @@ int band::getIntTotal()
// and that the partial sums never overflow (wrap negative)
if (total < 0)
{
- abort("overflow detected");
- return 0;
+ unpack_abort("overflow detected");
}
for (int k = length - 1; k > 0; k--)
{
@@ -210,8 +196,7 @@ int band::getIntTotal()
total += vs[0].getInt();
if (total < prev_total)
{
- abort("overflow detected");
- return 0;
+ unpack_abort("overflow detected");
}
}
rewind();
@@ -221,7 +206,6 @@ int band::getIntTotal()
int band::getIntCount(int tag)
{
- CHECK_0;
if (length == 0)
return 0;
if (tag >= HIST0_MIN && tag <= HIST0_MAX)
@@ -230,7 +214,6 @@ int band::getIntCount(int tag)
{
// Lazily calculate an approximate histogram.
hist0 = U_NEW(int, (HIST0_MAX - HIST0_MIN) + 1);
- CHECK_0;
for (int k = length; k > 0; k--)
{
int x = vs[0].getInt();
@@ -404,7 +387,6 @@ const band_init all_band_inits[] =
BAND_INIT(file_modtime, DELTA5_spec, 0), BAND_INIT(file_options, UNSIGNED5_spec, 0),
// BAND_INIT(file_bits, BYTE1_spec, 0),
{0, 0}};
-#define NUM_BAND_INITS (sizeof(all_band_inits) / sizeof(all_band_inits[0]))
band *band::makeBands(unpacker *u)
{
@@ -434,7 +416,7 @@ void band::initIndexes(unpacker *u)
for (int i = 0; i < BAND_LIMIT; i++)
{
band *scan = &tmp_all_bands[i];
- uint tag = scan->ixTag; // Cf. #define INDEX(tag) above
+ uint32_t tag = scan->ixTag; // Cf. #define INDEX(tag) above
if (tag != 0 && tag != CONSTANT_Literal && (tag & SUBINDEX_BIT) == 0)
{
scan->setIndex(u->cp.getIndex(tag));
diff --git a/depends/pack200/src/bands.h b/depends/pack200/src/bands.h
index 3f944481..a56cd7d5 100644
--- a/depends/pack200/src/bands.h
+++ b/depends/pack200/src/bands.h
@@ -150,11 +150,11 @@ struct band
return getRefCommon(ix2, true);
}
entry *getRefCommon(cpindex *ix, bool nullOK);
- jlong getLong(band &lo_band, bool have_hi);
+ int64_t getLong(band &lo_band, bool have_hi);
- static jlong makeLong(uint hi, uint lo)
+ static int64_t makeLong(uint32_t hi, uint32_t lo)
{
- return ((julong)hi << 32) + (((julong)lo << 32) >> 32);
+ return ((uint64_t)hi << 32) + (((uint64_t)lo << 32) >> 32);
}
int getIntTotal();
@@ -162,9 +162,6 @@ struct band
static band *makeBands(unpacker *u);
static void initIndexes(unpacker *u);
-
- void abort(const char *msg = nullptr); //{ u->abort(msg); }
- bool aborting(); //{ return u->aborting(); }
};
extern band all_bands[];
diff --git a/depends/pack200/src/bytes.cpp b/depends/pack200/src/bytes.cpp
index b82a987a..d3808afa 100644
--- a/depends/pack200/src/bytes.cpp
+++ b/depends/pack200/src/bytes.cpp
@@ -27,6 +27,7 @@
#include <stdlib.h>
#include <string.h>
#include <assert.h>
+#include <stdint.h>
#include "defines.h"
#include "bytes.h"
#include "utils.h"
@@ -114,7 +115,7 @@ int bytes::compareTo(bytes &other)
void bytes::saveFrom(const void *ptr_, size_t len_)
{
malloc(len_);
- // Save as much as possible. (Helps unpacker::abort.)
+ // Save as much as possible.
if (len_ > len)
{
assert(ptr == dummy); // error recovery
@@ -161,7 +162,6 @@ byte *fillbytes::grow(size_t s)
allocated = b.len;
if (allocated != maxlen)
{
- assert(unpack_aborting());
b.len = nlen - s; // back up
return dummy; // scribble during error recov.
}
diff --git a/depends/pack200/src/bytes.h b/depends/pack200/src/bytes.h
index 3926f9f2..2e4a9daf 100644
--- a/depends/pack200/src/bytes.h
+++ b/depends/pack200/src/bytes.h
@@ -161,7 +161,7 @@ struct fillbytes
b.len = 0;
}
int8_t *grow(size_t s); // grow so that limit() += s
- int getByte(uint i)
+ int getByte(uint32_t i)
{
return *loc(i) & 0xFF;
}
diff --git a/depends/pack200/src/coding.cpp b/depends/pack200/src/coding.cpp
index 32977e05..226ba458 100644
--- a/depends/pack200/src/coding.cpp
+++ b/depends/pack200/src/coding.cpp
@@ -32,6 +32,7 @@
#include <stdlib.h>
#include <stdarg.h>
#include <assert.h>
+#include <stdint.h>
#include "defines.h"
#include "bytes.h"
@@ -53,12 +54,12 @@ extern coding basic_codings[];
#define IS_NEG_CODE(S, codeVal) ((((int)(codeVal) + 1) & ((1 << S) - 1)) == 0)
-#define DECODE_SIGN_S1(ux) (((uint)(ux) >> 1) ^ -((int)(ux) & 1))
+#define DECODE_SIGN_S1(ux) (((uint32_t)(ux) >> 1) ^ -((int)(ux) & 1))
-static int decode_sign(int S, uint ux)
+static int decode_sign(int S, uint32_t ux)
{ // == Coding.decodeSign32
assert(S > 0);
- uint sigbits = (ux >> S);
+ uint32_t sigbits = (ux >> S);
if (IS_NEG_CODE(S, ux))
return (int)(~sigbits);
else
@@ -90,9 +91,9 @@ coding *coding::init()
return nullptr; // no 5-byte fixed-size coding
// first compute the range of the coding, in 64 bits
- jlong range = 0;
+ int64_t range = 0;
{
- jlong H_i = 1;
+ int64_t H_i = 1;
for (int i = 0; i < B; i++)
{
range += H_i;
@@ -106,7 +107,7 @@ coding *coding::init()
int this_umax;
// now, compute min and max
- if (range >= ((jlong)1 << 32))
+ if (range >= ((int64_t)1 << 32))
{
this_umax = INT_MAX_VALUE;
this->umin = INT_MIN_VALUE;
@@ -121,13 +122,13 @@ coding *coding::init()
if (S != 0 && range != 0)
{
int Smask = (1 << S) - 1;
- jlong maxPosCode = range - 1;
- jlong maxNegCode = range - 1;
+ int64_t maxPosCode = range - 1;
+ int64_t maxNegCode = range - 1;
while (IS_NEG_CODE(S, maxPosCode))
--maxPosCode;
while (!IS_NEG_CODE(S, maxNegCode))
--maxNegCode;
- int maxPos = decode_sign(S, (uint)maxPosCode);
+ int maxPos = decode_sign(S, (uint32_t)maxPosCode);
if (maxPos < 0)
this->max = INT_MAX_VALUE; // 32-bit wraparound
else
@@ -135,7 +136,7 @@ coding *coding::init()
if (maxNegCode < 0)
this->min = 0; // No negative codings at all.
else
- this->min = decode_sign(S, (uint)maxNegCode);
+ this->min = decode_sign(S, (uint32_t)maxNegCode);
}
}
@@ -163,7 +164,8 @@ coding *coding::findBySpec(int spec)
break;
}
coding *ptr = NEW(coding, 1);
- CHECK_NULL_0(ptr);
+ if (!ptr)
+ return nullptr;
coding *c = ptr->initFrom(spec);
if (c == nullptr)
{
@@ -207,25 +209,25 @@ void coding_method::reset(value_stream *state)
}
}
-uint coding::parse(byte *&rp, int B, int H)
+uint32_t coding::parse(byte *&rp, int B, int H)
{
int L = 256 - H;
byte *ptr = rp;
// hand peel the i==0 part of the loop:
- uint b_i = *ptr++ & 0xFF;
- if (B == 1 || b_i < (uint)L)
+ uint32_t b_i = *ptr++ & 0xFF;
+ if (B == 1 || b_i < (uint32_t)L)
{
rp = ptr;
return b_i;
}
- uint sum = b_i;
- uint H_i = H;
+ uint32_t sum = b_i;
+ uint32_t H_i = H;
assert(B <= B_MAX);
for (int i = 2; i <= B_MAX; i++)
{ // easy for compilers to unroll if desired
b_i = *ptr++ & 0xFF;
sum += b_i * H_i;
- if (i == B || b_i < (uint)L)
+ if (i == B || b_i < (uint32_t)L)
{
rp = ptr;
return sum;
@@ -236,26 +238,26 @@ uint coding::parse(byte *&rp, int B, int H)
return 0;
}
-uint coding::parse_lgH(byte *&rp, int B, int H, int lgH)
+uint32_t coding::parse_lgH(byte *&rp, int B, int H, int lgH)
{
assert(H == (1 << lgH));
int L = 256 - (1 << lgH);
byte *ptr = rp;
// hand peel the i==0 part of the loop:
- uint b_i = *ptr++ & 0xFF;
- if (B == 1 || b_i < (uint)L)
+ uint32_t b_i = *ptr++ & 0xFF;
+ if (B == 1 || b_i < (uint32_t)L)
{
rp = ptr;
return b_i;
}
- uint sum = b_i;
- uint lg_H_i = lgH;
+ uint32_t sum = b_i;
+ uint32_t lg_H_i = lgH;
assert(B <= B_MAX);
for (int i = 2; i <= B_MAX; i++)
{ // easy for compilers to unroll if desired
b_i = *ptr++ & 0xFF;
sum += b_i << lg_H_i;
- if (i == B || b_i < (uint)L)
+ if (i == B || b_i < (uint32_t)L)
{
rp = ptr;
return sum;
@@ -272,7 +274,7 @@ void coding::parseMultiple(byte *&rp, int N, byte *limit, int B, int H)
{
if (N < 0)
{
- abort("bad value count");
+ unpack_abort("bad value count");
return;
}
byte *ptr = rp;
@@ -281,7 +283,7 @@ void coding::parseMultiple(byte *&rp, int N, byte *limit, int B, int H)
size_t len = (size_t)N * B;
if (len / B != (size_t)N || ptr + len > limit)
{
- abort(ERB);
+ unpack_abort(ERB);
return;
}
rp = ptr + len;
@@ -312,7 +314,7 @@ void coding::parseMultiple(byte *&rp, int N, byte *limit, int B, int H)
// do an error check here
if (ptr > limit)
{
- abort(ERB);
+ unpack_abort(ERB);
return;
}
}
@@ -401,12 +403,12 @@ void value_stream::setCoding(coding *defc)
}
}
-static int getPopValue(value_stream *self, uint uval)
+static int getPopValue(value_stream *self, uint32_t uval)
{
if (uval > 0)
{
// note that the initial parse performed a range check
- assert(uval <= (uint)self->cm->fVlength);
+ assert(uval <= (uint32_t)self->cm->fVlength);
return self->cm->fValues[uval - 1];
}
else
@@ -422,7 +424,7 @@ int coding::sumInUnsignedRange(int x, int y)
int range = (int)(umax + 1);
assert(range > 0);
x += y;
- if (x != (int)((jlong)(x - y) + (jlong)y))
+ if (x != (int)((int64_t)(x - y) + (int64_t)y))
{
// 32-bit overflow interferes with range reduction.
// Back off from the overflow by adding a multiple of range:
@@ -461,9 +463,9 @@ int coding::sumInUnsignedRange(int x, int y)
return x;
}
-static int getDeltaValue(value_stream *self, uint uval, bool isSubrange)
+static int getDeltaValue(value_stream *self, uint32_t uval, bool isSubrange)
{
- assert((uint)(self->c.isSubrange) == (uint)isSubrange);
+ assert((uint32_t)(self->c.isSubrange) == (uint32_t)isSubrange);
assert(self->c.isSubrange | self->c.isFullRange);
if (isSubrange)
return self->sum = self->c.sumInUnsignedRange(self->sum, (int)uval);
@@ -499,7 +501,7 @@ int value_stream::getInt()
}
CODING_PRIVATE(c.spec);
- uint uval;
+ uint32_t uval;
enum
{
B5 = 5,
@@ -546,19 +548,19 @@ int value_stream::getInt()
assert(D == 1);
uval = coding::parse(rp, B, H);
if (S != 0)
- uval = (uint)decode_sign(S, uval);
+ uval = (uint32_t)decode_sign(S, uval);
return getDeltaValue(this, uval, (bool)c.isSubrange);
case cmk_BHS1D1full:
assert(S == 1 && D == 1 && c.isFullRange);
uval = coding::parse(rp, B, H);
- uval = (uint)DECODE_SIGN_S1(uval);
+ uval = (uint32_t)DECODE_SIGN_S1(uval);
return getDeltaValue(this, uval, false);
case cmk_BHS1D1sub:
assert(S == 1 && D == 1 && c.isSubrange);
uval = coding::parse(rp, B, H);
- uval = (uint)DECODE_SIGN_S1(uval);
+ uval = (uint32_t)DECODE_SIGN_S1(uval);
return getDeltaValue(this, uval, true);
case cmk_DELTA5:
@@ -583,7 +585,7 @@ int value_stream::getInt()
uval = coding::parse(rp, B, H);
if (S != 0)
{
- uval = (uint)decode_sign(S, uval);
+ uval = (uint32_t)decode_sign(S, uval);
}
if (D != 0)
{
@@ -592,7 +594,7 @@ int value_stream::getInt()
sum = c.sumInUnsignedRange(sum, (int)uval);
else
sum += (int)uval;
- uval = (uint)sum;
+ uval = (uint32_t)sum;
}
return getPopValue(this, uval);
@@ -616,8 +618,8 @@ int value_stream::getInt()
static int moreCentral(int x, int y)
{ // used to find end of Pop.{F}
// Suggested implementation from the Pack200 specification:
- uint kx = (x >> 31) ^ (x << 1);
- uint ky = (y >> 31) ^ (y << 1);
+ uint32_t kx = (x >> 31) ^ (x << 1);
+ uint32_t ky = (y >> 31) ^ (y << 1);
return (kx < ky ? x : y);
}
// static maybe_inline
@@ -680,7 +682,7 @@ void coding_method::init(byte *&band_rp, byte *band_limit, byte *&meta_rp, int m
to_free = foundc; // findBySpec may dynamically allocate
if (foundc == nullptr)
{
- abort("illegal arb. coding");
+ unpack_abort("illegal arbitrary coding");
return;
}
// and fall through
@@ -699,13 +701,11 @@ void coding_method::init(byte *&band_rp, byte *band_limit, byte *&meta_rp, int m
int N2 = (N >= 0) ? N - K : N;
if (N == 0 || (N2 <= 0 && N2 != N))
{
- abort("illegal run encoding");
- return;
+ unpack_abort("illegal run encoding");
}
if ((mode & DISABLE_RUN) != 0)
{
- abort("illegal nested run encoding");
- return;
+ unpack_abort("illegal nested run encoding");
}
// & Enc{ ACode } if ADef=0 (ABDef != 1)
@@ -719,11 +719,11 @@ void coding_method::init(byte *&band_rp, byte *band_limit, byte *&meta_rp, int m
{
this->init(band_rp, band_limit, meta_rp, disRun, defc, K, valueSink);
}
- CHECK;
// & Enc{ BCode } if BDef=0 (ABDef != 2)
coding_method *tail = U_NEW(coding_method, 1);
- CHECK_NULL(tail);
+ if (!tail)
+ return;
tail->u = u;
// The 'run' codings may be nested indirectly via 'pop' codings.
@@ -764,13 +764,11 @@ void coding_method::init(byte *&band_rp, byte *band_limit, byte *&meta_rp, int m
int TH = (256 - TL);
if (N <= 0)
{
- abort("illegal pop encoding");
- return;
+ unpack_abort("illegal pop encoding");
}
if ((mode & DISABLE_POP) != 0)
{
- abort("illegal nested pop encoding");
- return;
+ unpack_abort("illegal nested pop encoding");
}
// No indirect nesting of 'pop', but 'run' is OK.
@@ -796,7 +794,6 @@ void coding_method::init(byte *&band_rp, byte *band_limit, byte *&meta_rp, int m
fValues = (u->saveTo(fvbuf, fValueSink.b), (int *)fvbuf.ptr);
fVlength = fValueSink.length(); // i.e., the parameter K
fValueSink.free();
- CHECK;
// Skip the first {F} run in all subsequent passes.
// The next call to this->init(...) will set vs0.rp to point after the {F}.
@@ -812,12 +809,12 @@ void coding_method::init(byte *&band_rp, byte *band_limit, byte *&meta_rp, int m
break; // found it
tcode->free();
tcode = coding::findBySpec(B, TH);
- CHECK_NULL(tcode);
+ if (!tcode)
+ return;
}
if (!(fVlength <= tcode->umax))
{
- abort("pop.L value too small");
- return;
+ unpack_abort("pop.L value too small");
}
this->init(band_rp, band_limit, NO_META, disPop, tcode, N, nullptr);
tcode->free();
@@ -826,7 +823,6 @@ void coding_method::init(byte *&band_rp, byte *band_limit, byte *&meta_rp, int m
{
this->init(band_rp, band_limit, meta_rp, disPop, defc, N, nullptr);
}
- CHECK;
// Count the number of zero tokens right now.
// Also verify that they are in bounds.
@@ -834,13 +830,12 @@ void coding_method::init(byte *&band_rp, byte *band_limit, byte *&meta_rp, int m
value_stream vs = vs0;
for (int i = 0; i < N; i++)
{
- uint val = vs.getInt();
+ uint32_t val = vs.getInt();
if (val == 0)
UN += 1;
- if (!(val <= (uint)fVlength))
+ if (!(val <= (uint32_t)fVlength))
{
- abort("pop token out of range");
- return;
+ unpack_abort("pop token out of range");
}
}
vs.done();
@@ -849,7 +844,8 @@ void coding_method::init(byte *&band_rp, byte *band_limit, byte *&meta_rp, int m
if (UN != 0)
{
uValues = U_NEW(coding_method, 1);
- CHECK_NULL(uValues);
+ if (uValues == nullptr)
+ return;
uValues->u = u;
if (UDef != 0)
{
@@ -867,7 +863,7 @@ void coding_method::init(byte *&band_rp, byte *band_limit, byte *&meta_rp, int m
int uop = (*meta_rp++ & 0xFF);
if (uop > _meta_canon_max)
// %%% Spec. requires the more strict (uop != _meta_default).
- abort("bad meta-coding for empty pop/U");
+ unpack_abort("bad meta-coding for empty pop/U");
}
}
@@ -901,8 +897,7 @@ void coding_method::init(byte *&band_rp, byte *band_limit, byte *&meta_rp, int m
}
else
{
- abort("bad meta-coding");
- return;
+ unpack_abort("bad meta-coding");
}
// Common code here skips a series of values with one coding.
@@ -926,7 +921,7 @@ void coding_method::init(byte *&band_rp, byte *band_limit, byte *&meta_rp, int m
coding &c = vs0.c;
CODING_PRIVATE(c.spec);
// assert sane N
- assert((uint)N < INT_MAX_VALUE || N == POP_FAVORED_N);
+ assert((uint32_t)N < INT_MAX_VALUE || N == POP_FAVORED_N);
// Look at the values, or at least skip over them quickly.
if (valueSink == nullptr)
@@ -970,14 +965,12 @@ void coding_method::init(byte *&band_rp, byte *band_limit, byte *&meta_rp, int m
if (valueSink->length() > 0 && (val == last || val == min)) //|| val == min2
break;
valueSink->add(val);
- CHECK;
last = val;
min = moreCentral(min, last);
// min2 = moreCentral2(min2, last, min);
}
band_rp = vs.rp;
}
- CHECK;
// Get an accurate upper limit now.
vs0.rplimit = band_rp;
diff --git a/depends/pack200/src/coding.h b/depends/pack200/src/coding.h
index 5f017b9e..f9bd6ca2 100644
--- a/depends/pack200/src/coding.h
+++ b/depends/pack200/src/coding.h
@@ -84,11 +84,11 @@ struct coding
static coding *findBySpec(int B, int H, int S = 0, int D = 0);
static coding *findByIndex(int irregularCodingIndex);
- static uint parse(byte *&rp, int B, int H);
- static uint parse_lgH(byte *&rp, int B, int H, int lgH);
+ static uint32_t parse(byte *&rp, int B, int H);
+ static uint32_t parse_lgH(byte *&rp, int B, int H, int lgH);
static void parseMultiple(byte *&rp, int N, byte *limit, int B, int H);
- uint parse(byte *&rp)
+ uint32_t parse(byte *&rp)
{
return parse(rp, CODING_B(spec), CODING_H(spec));
}
@@ -116,12 +116,6 @@ struct coding
}
void free(); // free self if isMalloc
-
- // error handling
- static void abort(const char *msg = nullptr)
- {
- unpack_abort(msg);
- }
};
enum coding_method_kind
@@ -224,10 +218,6 @@ struct value_stream
return this + 1;
}
bool hasHelper();
-
- // error handling
- // inline void abort(const char* msg);
- // inline void aborting();
};
struct coding_method
@@ -254,17 +244,4 @@ struct coding_method
// The value sink is used to collect output values, when desired.
void init(byte *&band_rp, byte *band_limit, byte *&meta_rp, int mode, coding *defc, int N,
intlist *valueSink);
-
- // error handling
- void abort(const char *msg)
- {
- unpack_abort(msg, u);
- }
- bool aborting()
- {
- return unpack_aborting(u);
- }
};
-
-// inline void value_stream::abort(const char* msg) { cm->abort(msg); }
-// inline void value_stream::aborting() { cm->aborting(); }
diff --git a/depends/pack200/src/constants.h b/depends/pack200/src/constants.h
index aeb3335d..2cc14b7d 100644
--- a/depends/pack200/src/constants.h
+++ b/depends/pack200/src/constants.h
@@ -51,7 +51,7 @@
// magic number for gzip streams (for processing pack200-gzip data)
#define GZIP_MAGIC 0x1F8B0800
-#define GZIP_MAGIC_MASK 0xFFFFFF00 // last byte is variable "flg" field
+#define GZIP_MAGIC_MASK 0xFFFFFF00 // last \bchar\b is variable "flg" field
enum
{
diff --git a/depends/pack200/src/defines.h b/depends/pack200/src/defines.h
index 63abae0a..cfe5fc28 100644
--- a/depends/pack200/src/defines.h
+++ b/depends/pack200/src/defines.h
@@ -32,39 +32,22 @@
#include <unistd.h>
#endif
-#ifndef FULL
-#define FULL 1 /* Adds <500 bytes to the zipped final product. */
-#endif
-
-#if FULL // define this if you want debugging and/or compile-time attributes
-#define IF_FULL(x) x
-#else
-#define IF_FULL(x) /*x*/
-#endif
-
// Error messages that we have
-#define ERROR_ENOMEM "Native allocation failed"
+#define ERROR_ENOMEM "Memory allocation failed"
#define ERROR_FORMAT "Corrupted pack file"
#define ERROR_RESOURCE "Cannot extract resource file"
#define ERROR_OVERFLOW "Internal buffer overflow"
#define ERROR_INTERNAL "Internal error"
-#define LOGFILE_STDOUT "-"
-#define LOGFILE_STDERR ""
-
#define lengthof(array) (sizeof(array) / sizeof(array[0]))
#define NEW(T, n) (T *) must_malloc((int)(scale_size(n, sizeof(T))))
#define U_NEW(T, n) (T *) u->alloc(scale_size(n, sizeof(T)))
#define T_NEW(T, n) (T *) u->temp_alloc(scale_size(n, sizeof(T)))
-// bytes and byte arrays
-
-typedef unsigned int uint;
+typedef signed char byte;
#ifdef _MSC_VER
-typedef LONGLONG jlong;
-typedef DWORDLONG julong;
#define MKDIR(dir) mkdir(dir)
#define getpid() _getpid()
#define PATH_MAX MAX_PATH
@@ -73,64 +56,10 @@ typedef DWORDLONG julong;
#define tempname _tempname
#define sleep Sleep
#else
-typedef signed char byte;
-#ifdef _LP64
-typedef long jlong;
-typedef long unsigned julong;
-#else
-typedef long long jlong;
-typedef long long unsigned julong;
-#endif
#define MKDIR(dir) mkdir(dir, 0777);
#endif
/* Must cast to void *, then size_t, then int. */
#define ptrlowbits(x) ((int)(size_t)(void *)(x))
-/* Back and forth from jlong to pointer */
-#define ptr2jlong(x) ((jlong)(size_t)(void *)(x))
-#define jlong2ptr(x) ((void *)(size_t)(x))
-
-// Keys used by Java:
-#define UNPACK_DEFLATE_HINT "unpack.deflate.hint"
-
-#define COM_PREFIX "com.sun.java.util.jar.pack."
-#define UNPACK_MODIFICATION_TIME COM_PREFIX "unpack.modification.time"
-#define DEBUG_VERBOSE COM_PREFIX "verbose"
-
-#define ZIP_ARCHIVE_MARKER_COMMENT "PACK200"
-
-// The following are not known to the Java classes:
-#define UNPACK_REMOVE_PACKFILE COM_PREFIX "unpack.remove.packfile"
-
-// Called from unpacker layers
-#define _CHECK_DO(t, x) \
- { \
- if (t) \
- { \
- x; \
- } \
- }
-
-#define CHECK _CHECK_DO(aborting(), return)
-#define CHECK_(y) _CHECK_DO(aborting(), return y)
-#define CHECK_0 _CHECK_DO(aborting(), return 0)
-
-#define CHECK_NULL(p) _CHECK_DO((p) == nullptr, return)
-#define CHECK_NULL_(y, p) _CHECK_DO((p) == nullptr, return y)
-#define CHECK_NULL_0(p) _CHECK_DO((p) == nullptr, return 0)
-
-#define CHECK_COUNT(t) \
- if (t < 0) \
- { \
- abort("bad value count"); \
- } \
- CHECK
-
-#define STR_TRUE "true"
-#define STR_FALSE "false"
-
-#define STR_TF(x) ((x) ? STR_TRUE : STR_FALSE)
-#define BOOL_TF(x) (((x) != nullptr &&strcmp((x), STR_TRUE) == 0) ? true : false)
-
#define DEFAULT_ARCHIVE_MODTIME 1060000000 // Aug 04, 2003 5:26 PM PDT
diff --git a/depends/pack200/src/main.cpp b/depends/pack200/src/main.cpp
deleted file mode 100644
index ad46a2a2..00000000
--- a/depends/pack200/src/main.cpp
+++ /dev/null
@@ -1,489 +0,0 @@
-/*
- * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-#include <sys/types.h>
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <errno.h>
-#include <assert.h>
-
-#include <limits.h>
-#include <time.h>
-
-#include "defines.h"
-#include "bytes.h"
-#include "utils.h"
-#include "coding.h"
-#include "bands.h"
-
-#include "constants.h"
-
-#include "zip.h"
-
-#include "unpack.h"
-
-int main(int argc, char **argv)
-{
- return unpacker::run(argc, argv);
-}
-
-unpacker *unpacker::non_mt_current = nullptr;
-unpacker *unpacker::current()
-{
- return non_mt_current;
-}
-static void set_current_unpacker(unpacker *u)
-{
- unpacker::non_mt_current = u;
-}
-
-// Callback for fetching data, Unix style.
-static jlong read_input_via_stdio(unpacker *u, void *buf, jlong minlen, jlong maxlen)
-{
- assert(minlen <= maxlen); // don't talk nonsense
- jlong numread = 0;
- char *bufptr = (char *)buf;
- while (numread < minlen)
- {
- // read available input, up to buf.length or maxlen
- int readlen = (1 << 16);
- if (readlen > (maxlen - numread))
- readlen = (int)(maxlen - numread);
- int nr = 0;
- if (u->infileptr != nullptr)
- {
- nr = (int)fread(bufptr, 1, readlen, u->infileptr);
- }
- else
- {
-#ifndef WIN32
- // we prefer unbuffered inputs
- nr = (int)read(u->infileno, bufptr, readlen);
-#else
- nr = (int)fread(bufptr, 1, readlen, stdin);
-#endif
- }
- if (nr <= 0)
- {
- if (errno != EINTR)
- break;
- nr = 0;
- }
- numread += nr;
- bufptr += nr;
- assert(numread <= maxlen);
- }
- // fprintf(u->errstrm, "readInputFn(%d,%d) => %d\n",
- // (int)minlen, (int)maxlen, (int)numread);
- return numread;
-}
-
-enum
-{
- EOF_MAGIC = 0,
- BAD_MAGIC = -1
-};
-static int read_magic(unpacker *u, char peek[], int peeklen)
-{
- assert(peeklen == 4); // magic numbers are always 4 bytes
- jlong nr = (u->read_input_fn)(u, peek, peeklen, peeklen);
- if (nr != peeklen)
- {
- return (nr == 0) ? EOF_MAGIC : BAD_MAGIC;
- }
- int magic = 0;
- for (int i = 0; i < peeklen; i++)
- {
- magic <<= 8;
- magic += peek[i] & 0xFF;
- }
- return magic;
-}
-
-static void setup_gzin(unpacker *u)
-{
- gunzip *gzin = NEW(gunzip, 1);
- gzin->init(u);
-}
-
-static const char *nbasename(const char *progname)
-{
- const char *slash = strrchr(progname, '/');
- if (slash != nullptr)
- progname = ++slash;
- return progname;
-}
-
-static const char *usage_lines[] = {
- "Usage: %s [-opt... | --option=value]... x.pack[.gz] y.jar\n", "\n", "Unpacking Options\n",
- " -H{h}, --deflate-hint={h} override transmitted deflate hint: true, false, or keep "
- "(default)\n",
- " -r, --remove-pack-file remove input file after unpacking\n",
- " -v, --verbose increase program verbosity\n",
- " -q, --quiet set verbosity to lowest level\n",
- " -l{F}, --log-file={F} output to the given log file, or '-' for standard output "
- "(default)\n",
- " -?, -h, --help print this message\n",
- " -J{X} Java VM argument (ignored)\n", nullptr};
-
-static void usage(unpacker *u, const char *progname, bool full = false)
-{
- // WinMain does not set argv[0] to the progrname
- progname = (progname != nullptr) ? nbasename(progname) : "unpack200";
- for (int i = 0; usage_lines[i] != nullptr; i++)
- {
- fprintf(stderr, usage_lines[i], progname);
- if (!full)
- {
- fprintf(stderr, "(For more information, run %s --help .)\n", progname);
- break;
- }
- }
-}
-
-// argument parsing
-static char **init_args(int argc, char **argv, int &envargc)
-{
- const char *env = getenv("UNPACK200_FLAGS");
- ptrlist envargs;
- envargs.init();
- if (env != nullptr)
- {
- char *buf = (char *)strdup(env);
- const char *delim = "\n\t ";
- for (char *p = strtok(buf, delim); p != nullptr; p = strtok(nullptr, delim))
- {
- envargs.add(p);
- }
- }
- // allocate extra margin at both head and tail
- char **argp = NEW(char *, envargs.length() + argc + 1);
- char **argp0 = argp;
- int i;
- for (i = 0; i < envargs.length(); i++)
- {
- *argp++ = (char *)envargs.get(i);
- }
- for (i = 1; i < argc; i++)
- {
- // note: skip argv[0] (program name)
- *argp++ = (char *)strdup(argv[i]); // make a scratch copy
- }
- *argp = nullptr; // sentinel
- envargc = envargs.length(); // report this count to next_arg
- envargs.free();
- return argp0;
-}
-
-static int strpcmp(const char *str, const char *pfx)
-{
- return strncmp(str, pfx, strlen(pfx));
-}
-
-static const char flag_opts[] = "vqrVh?";
-static const char string_opts[] = "HlJ";
-
-static int next_arg(char **&argp)
-{
- char *arg = *argp;
- if (arg == nullptr || arg[0] != '-')
- { // end of option list
- return 0;
- }
- // printf("opt: %s\n", arg);
- char ach = arg[1];
- if (ach == '\0')
- {
- // ++argp; // do not pop this arg
- return 0; // bare "-" is stdin/stdout
- }
- else if (arg[1] == '-')
- { // --foo option
- static const char *keys[] = {"Hdeflate-hint=", "vverbose", "qquiet",
- "rremove-pack-file", "llog-file=", "Vversion",
- "hhelp", nullptr};
- if (arg[2] == '\0')
- { // end of option list
- ++argp; // pop the "--"
- return 0;
- }
- for (int i = 0; keys[i] != nullptr; i++)
- {
- const char *key = keys[i];
- char kch = *key++;
- if (strchr(key, '=') == nullptr)
- {
- if (!strcmp(arg + 2, key))
- {
- ++argp; // pop option arg
- return kch;
- }
- }
- else
- {
- if (!strpcmp(arg + 2, key))
- {
- *argp += 2 + strlen(key); // remove "--"+key from arg
- return kch;
- }
- }
- }
- }
- else if (strchr(flag_opts, ach) != nullptr)
- { // plain option
- if (arg[2] == '\0')
- {
- ++argp;
- }
- else
- {
- // in-place edit of "-vxyz" to "-xyz"
- arg += 1; // skip original '-'
- arg[0] = '-';
- *argp = arg;
- }
- // printf(" key => %c\n", ach);
- return ach;
- }
- else if (strchr(string_opts, ach) != nullptr)
- { // argument-bearing option
- if (arg[2] == '\0')
- {
- if (argp[1] == nullptr)
- return -1; // no next arg
- ++argp; // leave the argument in place
- }
- else
- {
- // in-place edit of "-Hxyz" to "xyz"
- arg += 2; // skip original '-H'
- *argp = arg;
- }
- // printf(" key => %c\n", ach);
- return ach;
- }
- return -1; // bad argument
-}
-
-static const char sccsver[] = "1.30, 07/05/05";
-
-// Usage: unpackage input.pack output.jar
-int unpacker::run(int argc, char **argv)
-{
- unpacker u;
- u.init(read_input_via_stdio);
- set_current_unpacker(&u);
-
- jar jarout;
- jarout.init(&u);
-
- int envargc = 0;
- char **argbuf = init_args(argc, argv, envargc);
- char **arg0 = argbuf + envargc;
- char **argp = argbuf;
-
- int verbose = 0;
- char *logfile = nullptr;
-
- for (;;)
- {
- const char *arg = (*argp == nullptr) ? "" : u.saveStr(*argp);
- bool isenvarg = (argp < arg0);
- int ach = next_arg(argp);
- bool hasoptarg = (ach != 0 && strchr(string_opts, ach) != nullptr);
- if (ach == 0 && argp >= arg0)
- break;
- if (isenvarg && argp == arg0 && hasoptarg)
- ach = 0; // don't pull from cmdline
- switch (ach)
- {
- case 'H':
- u.set_option(UNPACK_DEFLATE_HINT, *argp++);
- break;
- case 'v':
- ++verbose;
- break;
- case 'q':
- verbose = 0;
- break;
- case 'r':
- u.set_option(UNPACK_REMOVE_PACKFILE, "1");
- break;
- case 'l':
- logfile = *argp++;
- break;
- case 'J':
- argp += 1;
- break; // skip ignored -Jxxx parameter
-
- case 'h':
- case '?':
- usage(&u, argv[0], true);
- exit(1);
-
- default:
- const char *inenv = isenvarg ? " in ${UNPACK200_FLAGS}" : "";
- if (hasoptarg)
- fprintf(stderr, "Missing option string%s: %s\n", inenv, arg);
- else
- fprintf(stderr, "Unrecognized argument%s: %s\n", inenv, arg);
- usage(&u, argv[0]);
- exit(2);
- }
- }
-
- if (verbose != 0)
- {
- u.set_option(DEBUG_VERBOSE, u.saveIntStr(verbose));
- }
-
- const char *source_file = *argp++;
- const char *destination_file = *argp++;
-
- if (source_file == nullptr || destination_file == nullptr || *argp != nullptr)
- {
- usage(&u, argv[0]);
- exit(2);
- }
-
- if (verbose != 0)
- {
- fprintf(stderr, "Unpacking from %s to %s\n", source_file, destination_file);
- }
- bool &remove_source = u.remove_packfile;
-
- if (strcmp(source_file, "-") == 0)
- {
- remove_source = false;
- u.infileno = fileno(stdin);
- }
- else
- {
- u.infileptr = fopen(source_file, "rb");
- if (u.infileptr == nullptr)
- {
- fprintf(stderr, "Error: Could not open input file: %s\n", source_file);
- exit(3); // Called only from the native standalone unpacker
- }
- }
-
- if (strcmp(destination_file, "-") == 0)
- {
- jarout.jarfp = stdout;
- }
- else
- {
- jarout.openJarFile(destination_file);
- assert(jarout.jarfp != nullptr);
- }
-
- if (verbose != 0)
- u.dump_options();
-
- char peek[4];
- int magic;
-
- // check for GZIP input
- magic = read_magic(&u, peek, (int)sizeof(peek));
- if ((magic & GZIP_MAGIC_MASK) == GZIP_MAGIC)
- {
- // Oops; must slap an input filter on this data.
- setup_gzin(&u);
- u.gzin->start(magic);
- if (!u.aborting())
- {
- u.start();
- }
- }
- else
- {
- u.start(peek, sizeof(peek));
- }
-
- // Note: The checks to u.aborting() are necessary to gracefully
- // terminate processing when the first segment throws an error.
-
- for (;;)
- {
- if (u.aborting())
- break;
-
- // Each trip through this loop unpacks one segment
- // and then resets the unpacker.
- for (unpacker::file *filep; (filep = u.get_next_file()) != nullptr;)
- {
- if (u.aborting())
- break;
- u.write_file_to_jar(filep);
- }
- if (u.aborting())
- break;
-
- // Peek ahead for more data.
- magic = read_magic(&u, peek, (int)sizeof(peek));
- if (magic != (int)JAVA_PACKAGE_MAGIC)
- {
- if (magic != EOF_MAGIC)
- u.abort("garbage after end of pack archive");
- break; // all done
- }
-
- // Release all storage from parsing the old segment.
- u.reset();
-
- // Restart, beginning with the peek-ahead.
- u.start(peek, sizeof(peek));
- }
-
- int status = 0;
- if (u.aborting())
- {
- fprintf(stderr, "Error: %s\n", u.get_abort_message());
- status = 1;
- }
-
- if (u.infileptr != nullptr)
- {
- fclose(u.infileptr);
- u.infileptr = nullptr;
- }
-
- if (!u.aborting() && remove_source)
- remove(source_file);
-
- if (verbose != 0)
- {
- fprintf(stderr, "unpacker completed with status=%d\n", status);
- }
-
- u.finish();
-
- u.free(); // tidy up malloc blocks
- set_current_unpacker(nullptr); // clean up global pointer
-
- return status;
-}
diff --git a/depends/pack200/src/unpack.cpp b/depends/pack200/src/unpack.cpp
index a562d442..8a66d42a 100644
--- a/depends/pack200/src/unpack.cpp
+++ b/depends/pack200/src/unpack.cpp
@@ -51,6 +51,7 @@
#include <assert.h>
#include <limits.h>
#include <time.h>
+#include <stdint.h>
#include "defines.h"
#include "bytes.h"
@@ -79,23 +80,15 @@ enum
REQUESTED_LDC = -1
};
-#define NO_INORD ((uint) - 1)
+#define NO_INORD ((uint32_t) - 1)
struct entry
{
byte tag;
-
-#if 0
- byte bits;
- enum {
- //EB_EXTRA = 1,
- EB_SUPER = 2
- };
-#endif
unsigned short nrefs; // pack w/ tag
int outputIndex;
- uint inord; // &cp.entries[cp.tag_base[this->tag]+this->inord] == this
+ uint32_t inord; // &cp.entries[cp.tag_base[this->tag]+this->inord] == this
entry **refs;
@@ -104,10 +97,10 @@ struct entry
{
bytes b;
int i;
- jlong l;
+ int64_t l;
} value;
- void requestOutputIndex(cpool &cp, int req = REQUESTED);
+ void requestOutputIndex(constant_pool &cp, int req = REQUESTED);
int getOutputIndex()
{
assert(outputIndex > NOT_REQUESTED);
@@ -116,7 +109,7 @@ struct entry
entry *ref(int refnum)
{
- assert((uint)refnum < nrefs);
+ assert((uint32_t)refnum < nrefs);
return refs[refnum];
}
@@ -178,11 +171,15 @@ struct entry
bool tagMatches(byte tag2)
{
- return (tag2 == tag) || (tag2 == CONSTANT_Utf8 && tag == CONSTANT_Signature);
+ return (tag2 == tag) || (tag2 == CONSTANT_Utf8 && tag == CONSTANT_Signature) ||
+ (tag2 == CONSTANT_Literal && tag >= CONSTANT_Integer && tag <= CONSTANT_String &&
+ tag != CONSTANT_Class) ||
+ (tag2 == CONSTANT_Member && tag >= CONSTANT_Fieldref &&
+ tag <= CONSTANT_InterfaceMethodref);
}
};
-entry *cpindex::get(uint i)
+entry *cpindex::get(uint32_t i)
{
if (i >= len)
return nullptr;
@@ -250,16 +247,16 @@ int entry::typeSize()
}
}
-inline cpindex *cpool::getFieldIndex(entry *classRef)
+inline cpindex *constant_pool::getFieldIndex(entry *classRef)
{
assert(classRef->tagMatches(CONSTANT_Class));
- assert((uint)classRef->inord < (uint)tag_count[CONSTANT_Class]);
+ assert((uint32_t)classRef->inord < (uint32_t)tag_count[CONSTANT_Class]);
return &member_indexes[classRef->inord * 2 + 0];
}
-inline cpindex *cpool::getMethodIndex(entry *classRef)
+inline cpindex *constant_pool::getMethodIndex(entry *classRef)
{
assert(classRef->tagMatches(CONSTANT_Class));
- assert((uint)classRef->inord < (uint)tag_count[CONSTANT_Class]);
+ assert((uint32_t)classRef->inord < (uint32_t)tag_count[CONSTANT_Class]);
return &member_indexes[classRef->inord * 2 + 1];
}
@@ -277,7 +274,6 @@ struct inner_class
void unpacker::free()
{
int i;
- assert(infileptr == nullptr); // caller resp.
if (jarout != nullptr)
jarout->reset();
if (gzin != nullptr)
@@ -287,7 +283,9 @@ void unpacker::free()
}
if (free_input)
input.free();
- // free everybody ever allocated with U_NEW or (recently) with T_NEW
+ /*
+ * free everybody ever allocated with U_NEW or (recently) with T_NEW
+ */
assert(smallbuf.base() == nullptr || mallocs.contains(smallbuf.base()));
assert(tsmallbuf.base() == nullptr || tmallocs.contains(tsmallbuf.base()));
mallocs.freeAll();
@@ -318,10 +316,10 @@ void unpacker::free()
// Will eagerly read ahead by larger chunks, if possible.
// Returns false if (rplimit-rp) is not at least 'more',
// unless rplimit hits input.limit().
-bool unpacker::ensure_input(jlong more)
+bool unpacker::ensure_input(int64_t more)
{
- julong want = more - input_remaining();
- if ((jlong)want <= 0)
+ uint64_t want = more - input_remaining();
+ if ((int64_t)want <= 0)
return true; // it's already in the buffer
if (rplimit == input.limit())
return true; // not expecting any more
@@ -333,23 +331,22 @@ bool unpacker::ensure_input(jlong more)
rplimit = input.limit();
return true;
}
- CHECK_0;
- julong remaining = (input.limit() - rplimit); // how much left to read?
+ uint64_t remaining = (input.limit() - rplimit); // how much left to read?
byte *rpgoal = (want >= remaining) ? input.limit() : rplimit + (size_t)want;
enum
{
CHUNK_SIZE = (1 << 14)
};
- julong fetch = want;
+ uint64_t fetch = want;
if (fetch < CHUNK_SIZE)
fetch = CHUNK_SIZE;
if (fetch > remaining * 3 / 4)
fetch = remaining;
// Try to fetch at least "more" bytes.
- while ((jlong)fetch > 0)
+ while ((int64_t)fetch > 0)
{
- jlong nr = (*read_input_fn)(this, rplimit, fetch, remaining);
+ int64_t nr = (*read_input_fn)(this, rplimit, fetch, remaining);
if (nr <= 0)
{
return (rplimit >= rpgoal);
@@ -358,7 +355,7 @@ bool unpacker::ensure_input(jlong more)
rplimit += nr;
fetch -= nr;
bytes_read += nr;
- assert(remaining == (julong)(input.limit() - rplimit));
+ assert(remaining == (uint64_t)(input.limit() - rplimit));
}
return true;
}
@@ -434,10 +431,10 @@ void unpacker::putu4_at(byte *wp, int n)
wp[3] = (n) >> 0;
}
-void unpacker::putu8_at(byte *wp, jlong n)
+void unpacker::putu8_at(byte *wp, int64_t n)
{
- putu4_at(wp + 0, (int)((julong)n >> 32));
- putu4_at(wp + 4, (int)((julong)n >> 0));
+ putu4_at(wp + 0, (int)((uint64_t)n >> 32));
+ putu4_at(wp + 4, (int)((uint64_t)n >> 0));
}
void unpacker::putu2(int n)
@@ -450,7 +447,7 @@ void unpacker::putu4(int n)
putu4_at(put_space(4), n);
}
-void unpacker::putu8(jlong n)
+void unpacker::putu8(int64_t n)
{
putu8_at(put_space(8), n);
}
@@ -521,11 +518,6 @@ void *unpacker::alloc_heap(size_t size, bool smallOK, bool temp)
void unpacker::saveTo(bytes &b, byte *ptr, size_t len)
{
b.ptr = U_NEW(byte, add_size(len, 1));
- if (aborting())
- {
- b.len = 0;
- return;
- }
b.len = len;
b.copyFrom(ptr, len);
}
@@ -591,8 +583,7 @@ void unpacker::read_file_header()
// Therefore, the caller must use only a bare minimum of read-ahead.
if (inbytes.len > FIRST_READ)
{
- abort("too much read-ahead");
- return;
+ unpack_abort("too much read-ahead");
}
input.set(initbuf, sizeof(initbuf));
input.b.clear();
@@ -605,7 +596,7 @@ void unpacker::read_file_header()
// but is certain not to overflow past the archive_header.
input.b.len = FIRST_READ;
if (!ensure_input(FIRST_READ))
- abort("EOF reading archive magic number");
+ unpack_abort("EOF reading archive magic number");
if (rp[0] == 'P' && rp[1] == 'K')
{
@@ -621,7 +612,6 @@ void unpacker::read_file_header()
{
// Get some breathing room.
input.set(U_NEW(byte, (size_t)CHUNK + C_SLOP), (size_t)CHUNK);
- CHECK;
}
rp = rplimit = input.base();
if (!ensure_input(1))
@@ -658,9 +648,8 @@ void unpacker::read_file_header()
magic, majver, minver, JAVA_PACKAGE_MAGIC, JAVA5_PACKAGE_MAJOR_VERSION,
JAVA5_PACKAGE_MINOR_VERSION, JAVA_PACKAGE_MAGIC, JAVA6_PACKAGE_MAJOR_VERSION,
JAVA6_PACKAGE_MINOR_VERSION);
- abort(message);
+ unpack_abort(message);
}
- CHECK;
archive_options = hdr.getInt();
hdrVals += 1;
@@ -672,15 +661,15 @@ void unpacker::read_file_header()
if ((archive_options & ~OPTION_LIMIT) != 0)
{
fprintf(stderr, "Warning: Illegal archive options 0x%x\n", archive_options);
- abort("illegal archive options");
+ unpack_abort("illegal archive options");
return;
}
if ((archive_options & AO_HAVE_FILE_HEADERS) != 0)
{
- uint hi = hdr.getInt();
- uint lo = hdr.getInt();
- julong x = band::makeLong(hi, lo);
+ uint32_t hi = hdr.getInt();
+ uint32_t lo = hdr.getInt();
+ uint64_t x = band::makeLong(hi, lo);
archive_size = (size_t)x;
if (archive_size != x)
{
@@ -701,12 +690,11 @@ void unpacker::read_file_header()
int header_size_1 = (int)(rplimit - rp); // buffered unused initial fragment
int header_size = header_size_0 + header_size_1;
unsized_bytes_read = header_size_0;
- CHECK;
if (foreign_buf)
{
if (archive_size > (size_t)header_size_1)
{
- abort("EOF reading fixed input buffer");
+ unpack_abort("EOF reading fixed input buffer");
return;
}
}
@@ -714,17 +702,16 @@ void unpacker::read_file_header()
{
if (archive_size < ARCHIVE_SIZE_MIN)
{
- abort("impossible archive size"); // bad input data
+ unpack_abort("impossible archive size"); // bad input data
return;
}
if (archive_size < header_size_1)
{
- abort("too much read-ahead"); // somehow we pre-fetched too much?
+ unpack_abort("too much read-ahead"); // somehow we pre-fetched too much?
return;
}
input.set(U_NEW(byte, add_size(header_size_0, archive_size, C_SLOP)),
(size_t)header_size_0 + archive_size);
- CHECK;
assert(input.limit()[0] == 0);
// Move all the bytes we read initially into the real buffer.
input.b.copyFrom(initbuf, header_size);
@@ -736,19 +723,16 @@ void unpacker::read_file_header()
// It's more complicated and painful.
// A zero archive_size means that we must read until EOF.
input.init(CHUNK * 2);
- CHECK;
input.b.len = input.allocated;
rp = rplimit = input.base();
// Set up input buffer as if we already read the header:
input.b.copyFrom(initbuf, header_size);
- CHECK;
rplimit += header_size;
while (ensure_input(input.limit() - rp))
{
size_t dataSoFar = input_remaining();
size_t nextSize = add_size(dataSoFar, CHUNK);
input.ensureSize(nextSize);
- CHECK;
input.b.len = input.allocated;
rp = rplimit = input.base();
rplimit += dataSoFar;
@@ -756,7 +740,6 @@ void unpacker::read_file_header()
size_t dataSize = (rplimit - input.base());
input.b.len = dataSize;
input.grow(C_SLOP);
- CHECK;
free_input = true; // free it later
input.b.len = dataSize;
assert(input.limit()[0] == 0);
@@ -765,25 +748,21 @@ void unpacker::read_file_header()
rp += header_size_0; // already scanned these bytes...
}
live_input = true; // mark as "do not reuse"
- if (aborting())
- {
- abort("cannot allocate large input buffer for package file");
- return;
- }
// read the rest of the header fields
ensure_input((AH_LENGTH - AH_LENGTH_0) * B_MAX);
- CHECK;
hdr.rp = rp;
hdr.rplimit = rplimit;
if ((archive_options & AO_HAVE_FILE_HEADERS) != 0)
{
archive_next_count = hdr.getInt();
- CHECK_COUNT(archive_next_count);
+ if (archive_next_count < 0)
+ unpack_abort("bad archive_next_count");
archive_modtime = hdr.getInt();
file_count = hdr.getInt();
- CHECK_COUNT(file_count);
+ if (file_count < 0)
+ unpack_abort("bad file_count");
hdrVals += 3;
}
else
@@ -794,9 +773,11 @@ void unpacker::read_file_header()
if ((archive_options & AO_HAVE_SPECIAL_FORMATS) != 0)
{
band_headers_size = hdr.getInt();
- CHECK_COUNT(band_headers_size);
+ if (band_headers_size < 0)
+ unpack_abort("bad band_headers_size");
attr_definition_count = hdr.getInt();
- CHECK_COUNT(attr_definition_count);
+ if (attr_definition_count < 0)
+ unpack_abort("bad attr_definition_count");
hdrVals += 2;
}
else
@@ -821,16 +802,22 @@ void unpacker::read_file_header()
}
}
cp_counts[k] = hdr.getInt();
- CHECK_COUNT(cp_counts[k]);
+ if (cp_counts[k] < 0)
+ unpack_abort("bad cp_counts");
hdrVals += 1;
}
ic_count = hdr.getInt();
- CHECK_COUNT(ic_count);
+ if (ic_count < 0)
+ unpack_abort("bad ic_count");
+
default_class_minver = hdr.getInt();
default_class_majver = hdr.getInt();
+
class_count = hdr.getInt();
- CHECK_COUNT(class_count);
+ if (class_count < 0)
+ unpack_abort("bad class_count");
+
hdrVals += 4;
// done with archive_header
@@ -839,11 +826,10 @@ void unpacker::read_file_header()
rp = hdr.rp;
if (rp > rplimit)
- abort("EOF reading archive header");
+ unpack_abort("EOF reading archive header");
// Now size the CP.
cp.init(this, cp_counts);
- CHECK;
default_file_modtime = archive_modtime;
if (default_file_modtime == 0 && !(archive_options & AO_HAVE_FILE_MODTIME))
@@ -856,13 +842,13 @@ void unpacker::read_file_header()
ensure_input(band_headers_size);
if (input_remaining() < (size_t)band_headers_size)
{
- abort("EOF reading band headers");
+ unpack_abort("EOF reading band headers");
return;
}
bytes band_headers;
// The "1+" allows an initial byte to be pushed on the front.
band_headers.set(1 + U_NEW(byte, 1 + band_headers_size + C_SLOP), band_headers_size);
- CHECK;
+
// Start scanning band headers here:
band_headers.copyFrom(rp, band_headers.len);
rp += band_headers.len;
@@ -891,7 +877,7 @@ void unpacker::finish()
}
// Cf. PackageReader.readConstantPoolCounts
-void cpool::init(unpacker *u_, int counts[NUM_COUNTS])
+void constant_pool::init(unpacker *u_, int counts[NUM_COUNTS])
{
this->u = u_;
@@ -915,8 +901,7 @@ void cpool::init(unpacker *u_, int counts[NUM_COUNTS])
};
if (len >= (1 << 29) || len < 0 || next_entry >= CP_SIZE_LIMIT + IMPLICIT_ENTRY_COUNT)
{
- abort("archive too large: constant pool limit exceeded");
- return;
+ unpack_abort("archive too large: constant pool limit exceeded");
}
}
@@ -937,7 +922,6 @@ void cpool::init(unpacker *u_, int counts[NUM_COUNTS])
// the entries are renumbered for classfile output.
entries = U_NEW(entry, maxentries);
- CHECK;
first_extra_entry = &entries[nentries];
@@ -951,8 +935,8 @@ void cpool::init(unpacker *u_, int counts[NUM_COUNTS])
}
// Initialize hashTab to a generous power-of-two size.
- uint pow2 = 1;
- uint target = maxentries + maxentries / 2; // 60% full
+ uint32_t pow2 = 1;
+ uint32_t target = maxentries + maxentries / 2; // 60% full
while (pow2 < target)
pow2 <<= 1;
hashTab = U_NEW(entry *, hashTabLength = pow2);
@@ -1056,7 +1040,6 @@ void unpacker::read_Utf8_values(entry *cpMap, int len)
cp_Utf8_suffix.readData(len - SUFFIX_SKIP_1);
bytes *allsuffixes = T_NEW(bytes, len);
- CHECK;
int nbigsuf = 0;
fillbytes charbuf; // buffer to allocate small strings
@@ -1069,8 +1052,7 @@ void unpacker::read_Utf8_values(entry *cpMap, int len)
int suffix = (i < SUFFIX_SKIP_1) ? 0 : cp_Utf8_suffix.getInt();
if (suffix < 0)
{
- abort("bad utf8 suffix");
- return;
+ unpack_abort("bad utf8 suffix");
}
if (suffix == 0 && i >= SUFFIX_SKIP_1)
{
@@ -1079,7 +1061,7 @@ void unpacker::read_Utf8_values(entry *cpMap, int len)
continue;
}
bytes &chars = allsuffixes[i];
- uint size3 = suffix * 3; // max Utf8 length
+ uint32_t size3 = suffix * 3; // max Utf8 length
bool isMalloc = (suffix > SMALL);
if (isMalloc)
{
@@ -1095,7 +1077,7 @@ void unpacker::read_Utf8_values(entry *cpMap, int len)
}
chars.set(charbuf.grow(size3 + 1), size3);
}
- CHECK;
+
byte *chp = chars.ptr;
for (int j = 0; j < suffix; j++)
{
@@ -1106,7 +1088,6 @@ void unpacker::read_Utf8_values(entry *cpMap, int len)
if (isMalloc)
{
chars.realloc(chp - chars.ptr);
- CHECK;
tmallocs.add(chars.ptr); // free it later
}
else
@@ -1131,8 +1112,7 @@ void unpacker::read_Utf8_values(entry *cpMap, int len)
int prefix = (i < PREFIX_SKIP_2) ? 0 : cp_Utf8_prefix.getInt();
if (prefix < 0 || prefix + suffix < 0)
{
- abort("bad utf8 prefix");
- return;
+ unpack_abort("bad utf8 prefix");
}
bytes &chars = allsuffixes[i];
if (suffix == 0 && i >= SUFFIX_SKIP_1)
@@ -1161,7 +1141,7 @@ void unpacker::read_Utf8_values(entry *cpMap, int len)
if (chars.ptr != nullptr)
continue; // already input
int suffix = (int)chars.len; // pick up the hack
- uint size3 = suffix * 3;
+ uint32_t size3 = suffix * 3;
if (suffix == 0)
continue; // done with empty string
chars.malloc(size3);
@@ -1174,7 +1154,6 @@ void unpacker::read_Utf8_values(entry *cpMap, int len)
chp = store_Utf8_char(chp, ch);
}
chars.realloc(chp - chars.ptr);
- CHECK;
tmallocs.add(chars.ptr); // free it later
// cp_Utf8_big_chars.done();
cp_Utf8_big_chars = saved_band; // reset the band for the next string
@@ -1185,9 +1164,8 @@ void unpacker::read_Utf8_values(entry *cpMap, int len)
// Finally, sew together all the prefixes and suffixes.
bytes bigbuf;
bigbuf.malloc(maxlen * 3 + 1); // max Utf8 length, plus slop for nullptr
- CHECK;
- int prevlen = 0; // previous string length (in chars)
- tmallocs.add(bigbuf.ptr); // free after this block
+ int prevlen = 0; // previous string length (in chars)
+ tmallocs.add(bigbuf.ptr); // free after this block
cp_Utf8_prefix.rewind();
for (i = 0; i < len; i++)
{
@@ -1199,7 +1177,7 @@ void unpacker::read_Utf8_values(entry *cpMap, int len)
// make sure the prefix value is not corrupted, though:
if (prefix > prevlen)
{
- abort("utf8 prefix overflow");
+ unpack_abort("utf8 prefix overflow");
return;
}
fillp = skip_Utf8_chars(bigbuf.ptr, prefix);
@@ -1211,7 +1189,6 @@ void unpacker::read_Utf8_values(entry *cpMap, int len)
bytes &value = cpMap[i].value.b;
value.set(U_NEW(byte, add_size(length, 1)), length);
value.copyFrom(bigbuf.ptr, length);
- CHECK;
// Index all Utf8 strings
entry *&htref = cp.hashTabRef(CONSTANT_Utf8, value);
if (htref == nullptr)
@@ -1256,14 +1233,12 @@ void unpacker::read_single_refs(band &cp_band, byte refTag, entry *cpMap, int le
assert(refTag == CONSTANT_Utf8);
cp_band.setIndexByTag(refTag);
cp_band.readData(len);
- CHECK;
int indexTag = (cp_band.bn == e_cp_Class) ? CONSTANT_Class : 0;
for (int i = 0; i < len; i++)
{
entry &e = cpMap[i];
e.refs = U_NEW(entry *, e.nrefs = 1);
entry *utf = cp_band.getRef();
- CHECK;
e.refs[0] = utf;
e.value.b = utf->value.b; // copy value of Utf8 string to self
if (indexTag != 0)
@@ -1290,14 +1265,12 @@ void unpacker::read_double_refs(band &cp_band, byte ref1Tag, byte ref2Tag, entry
cp_band2.setIndexByTag(ref2Tag);
cp_band1.readData(len);
cp_band2.readData(len);
- CHECK;
for (int i = 0; i < len; i++)
{
entry &e = cpMap[i];
e.refs = U_NEW(entry *, e.nrefs = 2);
e.refs[0] = cp_band1.getRef();
e.refs[1] = cp_band2.getRef();
- CHECK;
}
// cp_band1.done();
// cp_band2.done();
@@ -1308,14 +1281,12 @@ void unpacker::read_signature_values(entry *cpMap, int len)
{
cp_Signature_form.setIndexByTag(CONSTANT_Utf8);
cp_Signature_form.readData(len);
- CHECK;
int ncTotal = 0;
int i;
for (i = 0; i < len; i++)
{
entry &e = cpMap[i];
entry &form = *cp_Signature_form.getRef();
- CHECK;
int nc = 0;
for (const char *ncp = form.utf8String(); *ncp; ncp++)
@@ -1326,7 +1297,6 @@ void unpacker::read_signature_values(entry *cpMap, int len)
ncTotal += nc;
e.refs = U_NEW(entry *, cpMap[i].nrefs = 1 + nc);
- CHECK;
e.refs[0] = &form;
}
// cp_Signature_form.done();
@@ -1338,7 +1308,6 @@ void unpacker::read_signature_values(entry *cpMap, int len)
for (int j = 1; j < e.nrefs; j++)
{
e.refs[j] = cp_Signature_classes.getRef();
- CHECK;
}
}
// cp_Signature_classes.done();
@@ -1410,19 +1379,16 @@ void unpacker::read_cp()
assert(false);
break;
}
- CHECK;
}
cp.expandSignatures();
- CHECK;
cp.initMemberIndexes();
- CHECK;
#define SNAME(n, s) #s "\0"
const char *symNames = (ALL_ATTR_DO(SNAME) "<init>");
#undef SNAME
- for (int sn = 0; sn < cpool::s_LIMIT; sn++)
+ for (int sn = 0; sn < constant_pool::s_LIMIT; sn++)
{
assert(symNames[0] >= '0' && symNames[0] <= 'Z'); // sanity
bytes name;
@@ -1469,7 +1435,6 @@ unpacker::attr_definitions::defineLayout(int idx, entry *nameEntry, const char *
{
const char *name = nameEntry->value.b.strval();
layout_definition *lo = defineLayout(idx, name, layout);
- CHECK_0;
lo->nameEntry = nameEntry;
return lo;
}
@@ -1482,10 +1447,10 @@ unpacker::layout_definition *unpacker::attr_definitions::defineLayout(int idx, c
{
// Fixed attr.
if (idx >= (int)flag_limit)
- abort("attribute index too large");
+ unpack_abort("attribute index too large");
if (isRedefined(idx))
- abort("redefined attribute index");
- redef |= ((julong)1 << idx);
+ unpack_abort("redefined attribute index");
+ redef |= ((uint64_t)1 << idx);
}
else
{
@@ -1493,7 +1458,6 @@ unpacker::layout_definition *unpacker::attr_definitions::defineLayout(int idx, c
overflow_count.add(0); // make a new counter
}
layout_definition *lo = U_NEW(layout_definition, 1);
- CHECK_0;
lo->idx = idx;
lo->name = name;
lo->layout = layout;
@@ -1501,7 +1465,6 @@ unpacker::layout_definition *unpacker::attr_definitions::defineLayout(int idx, c
{
layouts.add(nullptr);
}
- CHECK_0;
layouts.get(idx) = lo;
return lo;
}
@@ -1522,13 +1485,11 @@ band **unpacker::attr_definitions::buildBands(unpacker::layout_definition *lo)
bands_made = 0x10000; // base number for bands made
const char *lp = lo->layout;
lp = parseLayout(lp, lo->elems, -1);
- CHECK_0;
if (lp[0] != '\0' || band_stack.length() > 0)
{
- abort("garbage at end of layout");
+ unpack_abort("garbage at end of layout");
}
band_stack.popTo(0);
- CHECK_0;
// Fix up callables to point at their callees.
band **bands = lo->elems;
@@ -1540,7 +1501,7 @@ band **unpacker::attr_definitions::buildBands(unpacker::layout_definition *lo)
{
if (bands[num_callables]->le_kind != EK_CBLE)
{
- abort("garbage mixed with callables");
+ unpack_abort("garbage mixed with callables");
break;
}
num_callables += 1;
@@ -1554,7 +1515,7 @@ band **unpacker::attr_definitions::buildBands(unpacker::layout_definition *lo)
int call_num = call.le_len;
if (call_num < 0 || call_num >= num_callables)
{
- abort("bad call in layout");
+ unpack_abort("bad call in layout");
break;
}
band &cble = *bands[call_num];
@@ -1636,7 +1597,6 @@ const char *unpacker::attr_definitions::parseIntLayout(const char *lp, band *&re
{
const char *lp0 = lp;
band *b = U_NEW(band, 1);
- CHECK_(lp);
char le = *lp++;
int spec = UNSIGNED5_spec;
if (le == 'S' && can_be_signed)
@@ -1667,7 +1627,7 @@ const char *unpacker::attr_definitions::parseIntLayout(const char *lp, band *&re
le_len = 0;
break;
default:
- abort("bad layout element");
+ unpack_abort("bad layout element");
}
b->le_len = le_len;
band_stack.add(b);
@@ -1704,15 +1664,13 @@ const char *unpacker::attr_definitions::parseNumeral(const char *lp, int &res)
}
if (lp == dp)
{
- abort("missing numeral in layout");
- return "";
+ unpack_abort("missing numeral in layout");
}
lp = dp;
if (con < 0 && !(sgn && con == -con))
{
// (Portability note: Misses the error if int is not 32 bits.)
- abort("numeral overflow");
- return "";
+ unpack_abort("numeral overflow");
}
if (sgn)
con = -con;
@@ -1732,7 +1690,6 @@ band **unpacker::attr_definitions::popBody(int bs_base)
{
int nb = bs_limit - bs_base;
band **res = U_NEW(band *, add_size(nb, 1));
- CHECK_(no_bands);
for (int i = 0; i < nb; i++)
{
band *b = (band *)band_stack.get(bs_base + i);
@@ -1789,12 +1746,11 @@ const char *unpacker::attr_definitions::parseLayout(const char *lp, band **&res,
b->le_bci = EK_BCO;
b->defc = coding::findBySpec(BRANCH5_spec);
break;
- case 'N': // replication: 'N' uint '[' elem ... ']'
+ case 'N': // replication: 'N' uint32_t '[' elem ... ']'
lp = parseIntLayout(lp, b, EK_REPL);
assert(*lp == '[');
++lp;
lp = parseLayout(lp, b->le_body, curCble);
- CHECK_(lp);
break;
case 'T': // union: 'T' any_int union_case* '(' ')' '[' body ']'
lp = parseIntLayout(lp, b, EK_UN, can_be_signed);
@@ -1803,13 +1759,12 @@ const char *unpacker::attr_definitions::parseLayout(const char *lp, band **&res,
for (;;)
{ // for each case
band &k_case = *U_NEW(band, 1);
- CHECK_(lp);
band_stack.add(&k_case);
k_case.le_kind = EK_CASE;
k_case.bn = bands_made++;
if (*lp++ != '(')
{
- abort("bad union case");
+ unpack_abort("bad union case");
return "";
}
if (*lp++ != ')')
@@ -1827,19 +1782,19 @@ const char *unpacker::attr_definitions::parseLayout(const char *lp, band **&res,
// new in version 160, allow (1-5) for (1,2,3,4,5)
if (u->majver < JAVA6_PACKAGE_MAJOR_VERSION)
{
- abort("bad range in union case label (old archive format)");
+ unpack_abort(
+ "bad range in union case label (old archive format)");
return "";
}
int caselimit = caseval;
lp++;
lp = parseNumeral(lp, caselimit);
if (caseval >= caselimit ||
- (uint)(caselimit - caseval) > 0x10000)
+ (uint32_t)(caselimit - caseval) > 0x10000)
{
// Note: 0x10000 is arbitrary implementation restriction.
// We can remove it later if it's important to.
- abort("bad range in union case label");
- return "";
+ unpack_abort("bad range in union case label");
}
for (;;)
{
@@ -1855,13 +1810,11 @@ const char *unpacker::attr_definitions::parseLayout(const char *lp, band **&res,
}
if (*lp++ != ')')
{
- abort("bad case label");
- return "";
+ unpack_abort("bad case label");
}
// save away the case labels
int ntags = band_stack.length() - case_base;
int *tags = U_NEW(int, add_size(ntags, 1));
- CHECK_(lp);
k_case.le_casetags = tags;
*tags++ = ntags;
for (int i = 0; i < ntags; i++)
@@ -1869,13 +1822,11 @@ const char *unpacker::attr_definitions::parseLayout(const char *lp, band **&res,
*tags++ = ptrlowbits(band_stack.get(case_base + i));
}
band_stack.popTo(case_base);
- CHECK_(lp);
}
// Got le_casetags. Now grab the body.
assert(*lp == '[');
++lp;
lp = parseLayout(lp, k_case.le_body, curCble);
- CHECK_(lp);
if (k_case.le_casetags == nullptr)
break; // done
}
@@ -1885,7 +1836,6 @@ const char *unpacker::attr_definitions::parseLayout(const char *lp, band **&res,
case '(': // call: '(' -?NN* ')'
{
band &call = *U_NEW(band, 1);
- CHECK_(lp);
band_stack.add(&call);
call.le_kind = EK_CALL;
call.bn = bands_made++;
@@ -1896,11 +1846,9 @@ const char *unpacker::attr_definitions::parseLayout(const char *lp, band **&res,
call_num += curCble; // numeral is self-relative offset
call.le_len = call_num; // use le_len as scratch
calls_to_link.add(&call);
- CHECK_(lp);
if (*lp++ != ')')
{
- abort("bad call label");
- return "";
+ unpack_abort("bad call label");
}
}
break;
@@ -1964,7 +1912,7 @@ const char *unpacker::attr_definitions::parseLayout(const char *lp, band **&res,
}
if (ixTag == CONSTANT_None)
{
- abort("bad reference layout");
+ unpack_abort("bad reference layout");
break;
}
bool nullOK = false;
@@ -1983,12 +1931,11 @@ const char *unpacker::attr_definitions::parseLayout(const char *lp, band **&res,
// [callable1][callable2]...
if (!top_level)
{
- abort("bad nested callable");
+ unpack_abort("bad nested callable");
break;
}
curCble += 1;
band &cble = *U_NEW(band, 1);
- CHECK_(lp);
band_stack.add(&cble);
cble.le_kind = EK_CBLE;
cble.bn = bands_made++;
@@ -2005,10 +1952,8 @@ const char *unpacker::attr_definitions::parseLayout(const char *lp, band **&res,
done = true;
break;
default:
- abort("bad layout");
- break;
+ unpack_abort("bad layout");
}
- CHECK_(lp);
}
// Return the accumulated bands:
@@ -2095,10 +2040,8 @@ void unpacker::read_attr_defs()
attr_definition_name.readData(attr_definition_count);
attr_definition_layout.readData(attr_definition_count);
- CHECK;
-
// Initialize correct predef bits, to distinguish predefs from new defs.
-#define ORBIT(n, s) | ((julong)1 << n)
+#define ORBIT(n, s) | ((uint64_t)1 << n)
attr_defs[ATTR_CONTEXT_CLASS].predef = (0 X_ATTR_DO(ORBIT) CLASS_ATTR_DO(ORBIT));
attr_defs[ATTR_CONTEXT_FIELD].predef = (0 X_ATTR_DO(ORBIT) FIELD_ATTR_DO(ORBIT));
attr_defs[ATTR_CONTEXT_METHOD].predef = (0 X_ATTR_DO(ORBIT) METHOD_ATTR_DO(ORBIT));
@@ -2120,7 +2063,6 @@ void unpacker::read_attr_defs()
int idx = ADH_BYTE_INDEX(header);
entry *name = attr_definition_name.getRef();
entry *layout = attr_definition_layout.getRef();
- CHECK;
attr_defs[attrc].defineLayout(idx, name, layout->value.b.strval());
}
}
@@ -2160,7 +2102,7 @@ static int lastIndexOf(int chmin, int chmax, bytes &x, int pos)
return -1;
}
-inner_class *cpool::getIC(entry *inner)
+inner_class *constant_pool::getIC(entry *inner)
{
if (inner == nullptr)
return nullptr;
@@ -2172,7 +2114,7 @@ inner_class *cpool::getIC(entry *inner)
return ic;
}
-inner_class *cpool::getFirstChildIC(entry *outer)
+inner_class *constant_pool::getFirstChildIC(entry *outer)
{
if (outer == nullptr)
return nullptr;
@@ -2184,7 +2126,7 @@ inner_class *cpool::getFirstChildIC(entry *outer)
return ic;
}
-inner_class *cpool::getNextChildIC(inner_class *child)
+inner_class *constant_pool::getNextChildIC(inner_class *child)
{
inner_class *ic = child->next_sibling;
assert(ic == nullptr || ic->outer == child->outer);
@@ -2202,7 +2144,6 @@ void unpacker::read_ics()
ics = U_NEW(inner_class, ic_count);
ic_this_class.readData(ic_count);
ic_flags.readData(ic_count);
- CHECK;
// Scan flags to get count of long-form bands.
int long_forms = 0;
for (i = 0; i < ic_count; i++)
@@ -2215,12 +2156,11 @@ void unpacker::read_ics()
}
flags &= ~ACC_IC_LONG_FORM;
entry *inner = ic_this_class.getRef();
- CHECK;
- uint inord = inner->inord;
- assert(inord < (uint)cp.tag_count[CONSTANT_Class]);
+ uint32_t inord = inner->inord;
+ assert(inord < (uint32_t)cp.tag_count[CONSTANT_Class]);
if (ic_index[inord] != nullptr)
{
- abort("identical inner class");
+ unpack_abort("identical inner class");
break;
}
ic_index[inord] = &ics[i];
@@ -2228,7 +2168,6 @@ void unpacker::read_ics()
ics[i].flags = flags;
assert(cp.getIC(inner) == &ics[i]);
}
- CHECK;
// ic_this_class.done();
// ic_flags.done();
ic_outer_class.readData(long_forms);
@@ -2256,8 +2195,7 @@ void unpacker::read_ics()
dollar2 = lastIndexOf(DOLLAR_MIN, DOLLAR_MAX, n, nlen);
if (dollar2 < 0)
{
- abort();
- return;
+ unpack_abort();
}
assert(dollar2 >= pkglen);
if (isDigitString(n, dollar2 + 1, nlen))
@@ -2296,10 +2234,10 @@ void unpacker::read_ics()
// update child/sibling list
if (ics[i].outer != nullptr)
{
- uint outord = ics[i].outer->inord;
+ uint32_t outord = ics[i].outer->inord;
if (outord != NO_INORD)
{
- assert(outord < (uint)cp.tag_count[CONSTANT_Class]);
+ assert(outord < (uint32_t)cp.tag_count[CONSTANT_Class]);
ics[i].next_sibling = ic_child_index[outord];
ic_child_index[outord] = &ics[i];
}
@@ -2316,8 +2254,6 @@ void unpacker::read_classes()
class_interface_count.readData(class_count);
class_interface.readData(class_interface_count.getIntTotal());
- CHECK;
-
#if 0
int i;
// Make a little mark on super-classes.
@@ -2332,27 +2268,18 @@ void unpacker::read_classes()
class_field_count.readData(class_count);
class_method_count.readData(class_count);
- CHECK;
-
int field_count = class_field_count.getIntTotal();
int method_count = class_method_count.getIntTotal();
field_descr.readData(field_count);
read_attrs(ATTR_CONTEXT_FIELD, field_count);
- CHECK;
-
method_descr.readData(method_count);
read_attrs(ATTR_CONTEXT_METHOD, method_count);
-
- CHECK;
-
read_attrs(ATTR_CONTEXT_CLASS, class_count);
- CHECK;
-
read_code_headers();
}
-int unpacker::attr_definitions::predefCount(uint idx)
+int unpacker::attr_definitions::predefCount(uint32_t idx)
{
return isPredefined(idx) ? flag_count[idx] : 0;
}
@@ -2364,27 +2291,23 @@ void unpacker::read_attrs(int attrc, int obj_count)
int i, idx, count;
- CHECK;
-
bool haveLongFlags = ad.haveLongFlags();
band &xxx_flags_hi = ad.xxx_flags_hi();
if (haveLongFlags)
xxx_flags_hi.readData(obj_count);
- CHECK;
band &xxx_flags_lo = ad.xxx_flags_lo();
xxx_flags_lo.readData(obj_count);
- CHECK;
// pre-scan flags, counting occurrences of each index bit
- julong indexMask = ad.flagIndexMask(); // which flag bits are index bits?
+ uint64_t indexMask = ad.flagIndexMask(); // which flag bits are index bits?
for (i = 0; i < obj_count; i++)
{
- julong indexBits = xxx_flags_hi.getLong(xxx_flags_lo, haveLongFlags);
+ uint64_t indexBits = xxx_flags_hi.getLong(xxx_flags_lo, haveLongFlags);
if ((indexBits & ~indexMask) > (ushort) - 1)
{
- abort("undefined attribute flag bit");
+ unpack_abort("undefined attribute flag bit");
return;
}
indexBits &= indexMask; // ignore classfile flag bits
@@ -2400,19 +2323,17 @@ void unpacker::read_attrs(int attrc, int obj_count)
band &xxx_attr_count = ad.xxx_attr_count();
// There is one count element for each 1<<16 bit set in flags:
xxx_attr_count.readData(ad.predefCount(X_ATTR_OVERFLOW));
- CHECK;
band &xxx_attr_indexes = ad.xxx_attr_indexes();
int overflowIndexCount = xxx_attr_count.getIntTotal();
xxx_attr_indexes.readData(overflowIndexCount);
- CHECK;
// pre-scan attr indexes, counting occurrences of each value
for (i = 0; i < overflowIndexCount; i++)
{
idx = xxx_attr_indexes.getInt();
if (!ad.isIndex(idx))
{
- abort("attribute index out of bounds");
+ unpack_abort("attribute index out of bounds");
return;
}
ad.getCount(idx) += 1;
@@ -2428,7 +2349,6 @@ void unpacker::read_attrs(int attrc, int obj_count)
{
// Build the bands lazily, only when they are used.
band **bands = ad.buildBands(lo);
- CHECK;
if (lo->hasCallables())
{
for (i = 0; bands[i] != nullptr; i++)
@@ -2443,7 +2363,6 @@ void unpacker::read_attrs(int attrc, int obj_count)
}
}
ad.xxx_attr_calls().readData(backwardCounts);
- CHECK;
// Read built-in bands.
// Mostly, these are hand-coded equivalents to readBandData().
@@ -2453,53 +2372,44 @@ void unpacker::read_attrs(int attrc, int obj_count)
count = ad.predefCount(CLASS_ATTR_SourceFile);
class_SourceFile_RUN.readData(count);
- CHECK;
count = ad.predefCount(CLASS_ATTR_EnclosingMethod);
class_EnclosingMethod_RC.readData(count);
class_EnclosingMethod_RDN.readData(count);
- CHECK;
count = ad.predefCount(X_ATTR_Signature);
class_Signature_RS.readData(count);
- CHECK;
ad.readBandData(X_ATTR_RuntimeVisibleAnnotations);
ad.readBandData(X_ATTR_RuntimeInvisibleAnnotations);
count = ad.predefCount(CLASS_ATTR_InnerClasses);
class_InnerClasses_N.readData(count);
- CHECK;
count = class_InnerClasses_N.getIntTotal();
class_InnerClasses_RC.readData(count);
class_InnerClasses_F.readData(count);
- CHECK;
+
// Drop remaining columns wherever flags are zero:
count -= class_InnerClasses_F.getIntCount(0);
class_InnerClasses_outer_RCN.readData(count);
class_InnerClasses_name_RUN.readData(count);
- CHECK;
count = ad.predefCount(CLASS_ATTR_ClassFile_version);
class_ClassFile_version_minor_H.readData(count);
class_ClassFile_version_major_H.readData(count);
- CHECK;
break;
case ATTR_CONTEXT_FIELD:
count = ad.predefCount(FIELD_ATTR_ConstantValue);
field_ConstantValue_KQ.readData(count);
- CHECK;
count = ad.predefCount(X_ATTR_Signature);
field_Signature_RS.readData(count);
- CHECK;
ad.readBandData(X_ATTR_RuntimeVisibleAnnotations);
ad.readBandData(X_ATTR_RuntimeInvisibleAnnotations);
- CHECK;
break;
case ATTR_CONTEXT_METHOD:
@@ -2511,18 +2421,15 @@ void unpacker::read_attrs(int attrc, int obj_count)
method_Exceptions_N.readData(count);
count = method_Exceptions_N.getIntTotal();
method_Exceptions_RC.readData(count);
- CHECK;
count = ad.predefCount(X_ATTR_Signature);
method_Signature_RS.readData(count);
- CHECK;
ad.readBandData(X_ATTR_RuntimeVisibleAnnotations);
ad.readBandData(X_ATTR_RuntimeInvisibleAnnotations);
ad.readBandData(METHOD_ATTR_RuntimeVisibleParameterAnnotations);
ad.readBandData(METHOD_ATTR_RuntimeInvisibleParameterAnnotations);
ad.readBandData(METHOD_ATTR_AnnotationDefault);
- CHECK;
break;
case ATTR_CONTEXT_CODE:
@@ -2531,14 +2438,12 @@ void unpacker::read_attrs(int attrc, int obj_count)
// disable this feature in old archives!
if (count != 0 && majver < JAVA6_PACKAGE_MAJOR_VERSION)
{
- abort("undefined StackMapTable attribute (old archive format)");
+ unpack_abort("undefined StackMapTable attribute (old archive format)");
return;
}
code_StackMapTable_N.readData(count);
- CHECK;
count = code_StackMapTable_N.getIntTotal();
code_StackMapTable_frame_T.readData(count);
- CHECK;
// the rest of it depends in a complicated way on frame tags
{
int fat_frame_count = 0;
@@ -2583,23 +2488,18 @@ void unpacker::read_attrs(int attrc, int obj_count)
// deal completely with fat frames:
offset_count += fat_frame_count;
code_StackMapTable_local_N.readData(fat_frame_count);
- CHECK;
type_count += code_StackMapTable_local_N.getIntTotal();
code_StackMapTable_stack_N.readData(fat_frame_count);
type_count += code_StackMapTable_stack_N.getIntTotal();
- CHECK;
// read the rest:
code_StackMapTable_offset.readData(offset_count);
code_StackMapTable_T.readData(type_count);
- CHECK;
// (7) [RCH]
count = code_StackMapTable_T.getIntCount(7);
code_StackMapTable_RC.readData(count);
- CHECK;
// (8) [PH]
count = code_StackMapTable_T.getIntCount(8);
code_StackMapTable_P.readData(count);
- CHECK;
}
count = ad.predefCount(CODE_ATTR_LineNumberTable);
@@ -2644,7 +2544,7 @@ void unpacker::read_attrs(int attrc, int obj_count)
void unpacker::attr_definitions::readBandData(int idx)
{
int j;
- uint count = getCount(idx);
+ uint32_t count = getCount(idx);
if (count == 0)
return;
layout_definition *lo = getLayout(idx);
@@ -2674,12 +2574,12 @@ void unpacker::attr_definitions::readBandData(int idx)
}
}
// Now consult whichever callables have non-zero entry counts.
- readBandData(bands, (uint) - 1);
+ readBandData(bands, (uint32_t) - 1);
}
}
// Recursive helper to the previous function:
-void unpacker::attr_definitions::readBandData(band **body, uint count)
+void unpacker::attr_definitions::readBandData(band **body, uint32_t count)
{
int j, k;
for (j = 0; body[j] != nullptr; j++)
@@ -2778,7 +2678,7 @@ void unpacker::putlayout(band **body)
int prevBCI = -1;
if (body == NULL)
{
- abort("putlayout: unexpected NULL for body");
+ unpack_abort("putlayout: unexpected NULL for body");
return;
}
for (i = 0; body[i] != nullptr; i++)
@@ -2959,7 +2859,6 @@ void unpacker::get_code_header(int &max_stack, int &max_na_locals, int &handler_
void unpacker::read_code_headers()
{
code_headers.readData(code_count);
- CHECK;
int totalHandlerCount = 0;
int totalFlagsCount = 0;
for (int i = 0; i < code_count; i++)
@@ -2983,7 +2882,6 @@ void unpacker::read_code_headers()
code_max_na_locals.readData();
code_handler_count.readData();
totalHandlerCount += code_handler_count.getIntTotal();
- CHECK;
// Read handler specifications.
// Cf. PackageReader.readCodeHandlers.
@@ -2991,13 +2889,11 @@ void unpacker::read_code_headers()
code_handler_end_PO.readData(totalHandlerCount);
code_handler_catch_PO.readData(totalHandlerCount);
code_handler_class_RCN.readData(totalHandlerCount);
- CHECK;
read_attrs(ATTR_CONTEXT_CODE, totalFlagsCount);
- CHECK;
}
-static inline bool is_in_range(uint n, uint min, uint max)
+static inline bool is_in_range(uint32_t n, uint32_t min, uint32_t max)
{
return n - min <= max - min; // unsigned arithmetic!
}
@@ -3095,7 +2991,6 @@ unpacker::read_bcs()
// read from bc_codes and bc_case_count
fillbytes all_switch_ops;
all_switch_ops.init();
- CHECK;
// Read directly from rp/rplimit.
// Do this later: bc_codes.readData(...)
@@ -3121,8 +3016,7 @@ unpacker::read_bcs()
}
if (opptr == oplimit)
{
- abort();
- break;
+ unpack_abort();
}
int bc = *opptr++ & 0xFF;
bool isWide = false;
@@ -3130,8 +3024,7 @@ unpacker::read_bcs()
{
if (opptr == oplimit)
{
- abort();
- break;
+ unpack_abort();
}
bc = *opptr++ & 0xFF;
isWide = true;
@@ -3208,8 +3101,6 @@ unpacker::read_bcs()
doneScanningMethod:
{
}
- if (aborting())
- break;
}
// Go through the formality, so we can use it in a regular fashion later:
@@ -3245,7 +3136,6 @@ void unpacker::read_bands()
byte *rp0 = rp;
read_file_header();
- CHECK;
if (cp.nentries == 0)
{
@@ -3257,32 +3147,27 @@ void unpacker::read_bands()
check_options();
read_cp();
- CHECK;
read_attr_defs();
- CHECK;
read_ics();
- CHECK;
read_classes();
- CHECK;
read_bcs();
- CHECK;
read_files();
}
/// CP routines
-entry *&cpool::hashTabRef(byte tag, bytes &b)
+entry *&constant_pool::hashTabRef(byte tag, bytes &b)
{
- uint hash = tag + (int)b.len;
+ uint32_t hash = tag + (int)b.len;
for (int i = 0; i < (int)b.len; i++)
{
hash = hash * 31 + (0xFF & b.ptr[i]);
}
entry **ht = hashTab;
int hlen = hashTabLength;
- assert((hlen & (hlen - 1)) == 0); // must be power of 2
- uint hash1 = hash & (hlen - 1); // == hash % hlen
- uint hash2 = 0; // lazily computed (requires mod op.)
+ assert((hlen & (hlen - 1)) == 0); // must be power of 2
+ uint32_t hash1 = hash & (hlen - 1); // == hash % hlen
+ uint32_t hash2 = 0; // lazily computed (requires mod op.)
int probes = 0;
while (ht[hash1] != nullptr)
{
@@ -3293,9 +3178,9 @@ entry *&cpool::hashTabRef(byte tag, bytes &b)
// Note: hash2 must be relatively prime to hlen, hence the "|1".
hash2 = (((hash % 499) & (hlen - 1)) | 1);
hash1 += hash2;
- if (hash1 >= (uint)hlen)
+ if (hash1 >= (uint32_t)hlen)
hash1 -= hlen;
- assert(hash1 < (uint)hlen);
+ assert(hash1 < (uint32_t)hlen);
assert(++probes < hlen);
}
return ht[hash1];
@@ -3310,7 +3195,7 @@ static void insert_extra(entry *e, ptrlist &extras)
// Note: We will sort the list (by string-name) later.
}
-entry *cpool::ensureUtf8(bytes &b)
+entry *constant_pool::ensureUtf8(bytes &b)
{
entry *&ix = hashTabRef(CONSTANT_Utf8, b);
if (ix != nullptr)
@@ -3318,7 +3203,7 @@ entry *cpool::ensureUtf8(bytes &b)
// Make one.
if (nentries == maxentries)
{
- abort("cp utf8 overflow");
+ unpack_abort("cp utf8 overflow");
return &entries[tag_base[CONSTANT_Utf8]]; // return something
}
entry &e = entries[nentries++];
@@ -3329,7 +3214,7 @@ entry *cpool::ensureUtf8(bytes &b)
return ix = &e;
}
-entry *cpool::ensureClass(bytes &b)
+entry *constant_pool::ensureClass(bytes &b)
{
entry *&ix = hashTabRef(CONSTANT_Class, b);
if (ix != nullptr)
@@ -3337,7 +3222,7 @@ entry *cpool::ensureClass(bytes &b)
// Make one.
if (nentries == maxentries)
{
- abort("cp class overflow");
+ unpack_abort("cp class overflow");
return &entries[tag_base[CONSTANT_Class]]; // return something
}
entry &e = entries[nentries++];
@@ -3353,7 +3238,7 @@ entry *cpool::ensureClass(bytes &b)
return &e;
}
-void cpool::expandSignatures()
+void constant_pool::expandSignatures()
{
int i;
int nsigs = 0;
@@ -3362,7 +3247,6 @@ void cpool::expandSignatures()
int sig_limit = tag_count[CONSTANT_Signature] + first_sig;
fillbytes buf;
buf.init(1 << 10);
- CHECK;
for (i = first_sig; i < sig_limit; i++)
{
entry &e = entries[i];
@@ -3418,7 +3302,7 @@ void cpool::expandSignatures()
}
}
-void cpool::initMemberIndexes()
+void constant_pool::initMemberIndexes()
{
// This function does NOT refer to any class schema.
// It is totally internal to the cpool.
@@ -3489,7 +3373,7 @@ void cpool::initMemberIndexes()
u->free_temps();
}
-void entry::requestOutputIndex(cpool &cp, int req)
+void entry::requestOutputIndex(constant_pool &cp, int req)
{
assert(outputIndex <= NOT_REQUESTED); // must not have assigned indexes yet
if (tag == CONSTANT_Signature)
@@ -3514,7 +3398,7 @@ void entry::requestOutputIndex(cpool &cp, int req)
}
}
-void cpool::resetOutputIndexes()
+void constant_pool::resetOutputIndexes()
{
int i;
int noes = outputEntries.length();
@@ -3571,7 +3455,7 @@ extern "C" int outputEntry_cmp(const void *e1p, const void *e2p)
return compare_Utf8_chars(e1.value.b, e2.value.b);
}
-void cpool::computeOutputIndexes()
+void constant_pool::computeOutputIndexes()
{
int i;
@@ -3596,114 +3480,9 @@ void cpool::computeOutputIndexes()
}
// Unpacker Start
-
-const char str_tf[] = "true\0false";
-#undef STR_TRUE
-#undef STR_FALSE
-#define STR_TRUE (&str_tf[0])
-#define STR_FALSE (&str_tf[5])
-
-const char *unpacker::get_option(const char *prop)
-{
- if (prop == nullptr)
- return nullptr;
- if (strcmp(prop, UNPACK_DEFLATE_HINT) == 0)
- {
- return deflate_hint_or_zero == 0 ? nullptr : STR_TF(deflate_hint_or_zero > 0);
-#ifdef HAVE_STRIP
- }
- else if (strcmp(prop, UNPACK_STRIP_COMPILE) == 0)
- {
- return STR_TF(strip_compile);
- }
- else if (strcmp(prop, UNPACK_STRIP_DEBUG) == 0)
- {
- return STR_TF(strip_debug);
- }
- else if (strcmp(prop, UNPACK_STRIP_JCOV) == 0)
- {
- return STR_TF(strip_jcov);
-#endif /*HAVE_STRIP*/
- }
- else if (strcmp(prop, UNPACK_REMOVE_PACKFILE) == 0)
- {
- return STR_TF(remove_packfile);
- }
- else if (strcmp(prop, DEBUG_VERBOSE) == 0)
- {
- return saveIntStr(verbose);
- }
- else if (strcmp(prop, UNPACK_MODIFICATION_TIME) == 0)
- {
- return (modification_time_or_zero == 0) ? nullptr
- : saveIntStr(modification_time_or_zero);
- }
- else
- {
- return NULL; // unknown option ignore
- }
-}
-
-bool unpacker::set_option(const char *prop, const char *value)
-{
- if (prop == NULL)
- return false;
- if (strcmp(prop, UNPACK_DEFLATE_HINT) == 0)
- {
- deflate_hint_or_zero =
- ((value == nullptr || strcmp(value, "keep") == 0) ? 0 : BOOL_TF(value) ? +1 : -1);
-#ifdef HAVE_STRIP
- }
- else if (strcmp(prop, UNPACK_STRIP_COMPILE) == 0)
- {
- strip_compile = STR_TF(value);
- }
- else if (strcmp(prop, UNPACK_STRIP_DEBUG) == 0)
- {
- strip_debug = STR_TF(value);
- }
- else if (strcmp(prop, UNPACK_STRIP_JCOV) == 0)
- {
- strip_jcov = STR_TF(value);
-#endif /*HAVE_STRIP*/
- }
- else if (strcmp(prop, UNPACK_REMOVE_PACKFILE) == 0)
- {
- remove_packfile = STR_TF(value);
- }
- else if (strcmp(prop, DEBUG_VERBOSE) == 0)
- {
- verbose = (value == nullptr) ? 0 : atoi(value);
- }
- else if (strcmp(prop, UNPACK_MODIFICATION_TIME) == 0)
- {
- if (value == nullptr || (strcmp(value, "keep") == 0))
- {
- modification_time_or_zero = 0;
- }
- else if (strcmp(value, "now") == 0)
- {
- time_t now;
- time(&now);
- modification_time_or_zero = (int)now;
- }
- else
- {
- modification_time_or_zero = atoi(value);
- if (modification_time_or_zero == 0)
- modification_time_or_zero = 1; // make non-zero
- }
- }
- else
- {
- return false; // unknown option ignore
- }
- return true;
-}
-
// Deallocate all internal storage and reset to a clean state.
// Do not disturb any input or output connections, including
-// infileptr, infileno, inbytes, read_input_fn, jarout, or errstrm.
+// infileptr, inbytes, read_input_fn, jarout, or errstrm.
// Do not reset any unpack options.
void unpacker::reset()
{
@@ -3737,26 +3516,19 @@ void unpacker::reset()
this->free();
this->init(read_input_fn);
-// restore selected interface state:
-#define SAVE(x) this->x = save_u.x
- SAVE(infileptr); // buffered
- SAVE(infileno); // unbuffered
- SAVE(inbytes); // direct
- SAVE(jarout);
- SAVE(gzin);
- SAVE(verbose); // verbose level, 0 means no output
- SAVE(strip_compile);
- SAVE(strip_debug);
- SAVE(strip_jcov);
- SAVE(remove_packfile);
- SAVE(deflate_hint_or_zero); // ==0 means not set, otherwise -1 or 1
- SAVE(modification_time_or_zero);
- SAVE(bytes_read_before_reset);
- SAVE(bytes_written_before_reset);
- SAVE(files_written_before_reset);
- SAVE(classes_written_before_reset);
- SAVE(segments_read_before_reset);
-#undef SAVE
+ // restore selected interface state:
+ infileptr = save_u.infileptr;
+ inbytes = save_u.inbytes;
+ jarout = save_u.jarout;
+ gzin = save_u.gzin;
+ verbose = save_u.verbose;
+ deflate_hint_or_zero = save_u.deflate_hint_or_zero;
+ modification_time_or_zero = save_u.modification_time_or_zero;
+ bytes_read_before_reset = save_u.bytes_read_before_reset;
+ bytes_written_before_reset = save_u.bytes_written_before_reset;
+ files_written_before_reset = save_u.files_written_before_reset;
+ classes_written_before_reset = save_u.classes_written_before_reset;
+ segments_read_before_reset = save_u.segments_read_before_reset;
// Note: If we use strip_names, watch out: They get nuked here.
}
@@ -3774,32 +3546,6 @@ void unpacker::init(read_input_fn_t input_fn)
attr_defs[i].u = u; // set up outer ptr
}
-const char *unpacker::get_abort_message()
-{
- return abort_message;
-}
-
-void unpacker::dump_options()
-{
- static const char *opts[] = {
- UNPACK_DEFLATE_HINT,
-#ifdef HAVE_STRIP
- UNPACK_STRIP_COMPILE, UNPACK_STRIP_DEBUG, UNPACK_STRIP_JCOV,
-#endif /*HAVE_STRIP*/
- UNPACK_REMOVE_PACKFILE, DEBUG_VERBOSE, UNPACK_MODIFICATION_TIME, nullptr};
- for (int i = 0; opts[i] != nullptr; i++)
- {
- const char *str = get_option(opts[i]);
- if (str == nullptr)
- {
- if (verbose == 0)
- continue;
- str = "(not set)";
- }
- fprintf(stderr, "%s=%s\n", opts[i], str);
- }
-}
-
// Usage: unpack a byte buffer
// packptr is a reference to byte buffer containing a
// packed file and len is the length of the buffer.
@@ -3833,7 +3579,6 @@ void unpacker::check_options()
// Turn off per-file modtime by force.
archive_options &= ~AO_HAVE_FILE_MODTIME;
}
- // %%% strip_compile, etc...
}
// classfile writing
@@ -3854,7 +3599,7 @@ void unpacker::reset_cur_classfile()
requested_ics.empty();
}
-cpindex *cpool::getKQIndex()
+cpindex *constant_pool::getKQIndex()
{
char ch = '?';
if (u->cur_descr != nullptr)
@@ -3887,21 +3632,21 @@ cpindex *cpool::getKQIndex()
tag = CONSTANT_Integer;
break;
default:
- abort("bad KQ reference");
+ unpack_abort("bad KQ reference");
break;
}
return getIndex(tag);
}
-uint unpacker::to_bci(uint bii)
+uint32_t unpacker::to_bci(uint32_t bii)
{
- uint len = bcimap.length();
- uint *map = (uint *)bcimap.base();
+ uint32_t len = bcimap.length();
+ uint32_t *map = (uint32_t *)bcimap.base();
assert(len > 0); // must be initialized before using to_bci
if (bii < len)
return map[bii];
// Else it's a fractional or out-of-range BCI.
- uint key = bii - len;
+ uint32_t key = bii - len;
for (int i = len;; i--)
{
if (map[i - 1] - (i - 1) <= key)
@@ -4060,7 +3805,6 @@ unpacker::write_bc_ops()
--wp; // not really part of the code
int size = bc_escrefsize.getInt();
entry *ref = bc_escref.getRefN();
- CHECK;
switch (size)
{
case 1:
@@ -4114,7 +3858,7 @@ unpacker::write_bc_ops()
if (ref == nullptr)
break; // oops, bad input
assert(ref->tag == CONSTANT_Methodref);
- if (ref->memberDescr()->descrName() == cp.sym[cpool::s_lt_init_gt])
+ if (ref->memberDescr()->descrName() == cp.sym[constant_pool::s_lt_init_gt])
{
if (which_init++ == coding)
break;
@@ -4139,7 +3883,6 @@ unpacker::write_bc_ops()
putu1_fast(origBC);
}
entry *ref = bc_which->getRef();
- CHECK;
putref(ref);
continue;
}
@@ -4162,7 +3905,6 @@ unpacker::write_bc_ops()
if (bc_which != nullptr)
{
entry *ref = bc_which->getRefCommon(bc_which->ix, bc_which->nullOK);
- CHECK;
if (ref == nullptr && bc_which == &bc_classref)
{
// Shorthand for class self-references.
@@ -4285,7 +4027,6 @@ unpacker::write_code()
handler_count = code_handler_count.getInt();
int siglen = cur_descr->descrType()->typeSize();
- CHECK;
if ((cur_descr_flags & ACC_STATIC) == 0)
siglen++;
max_locals += siglen;
@@ -4296,7 +4037,6 @@ unpacker::write_code()
// Write the bytecodes themselves.
write_bc_ops();
- CHECK;
byte *bcbasewp = wp_at(bcbase);
putu4_at(bcbasewp, (int)(wp - (bcbasewp + 4))); // size of code attr
@@ -4311,10 +4051,9 @@ unpacker::write_code()
bii += code_handler_catch_PO.getInt();
putu2(to_bci(bii));
putref(code_handler_class_RCN.getRefN());
- CHECK;
}
- julong indexBits = cflags;
+ uint64_t indexBits = cflags;
if (cflags < 0)
{
bool haveLongFlags = attr_defs[ATTR_CONTEXT_CODE].haveLongFlags();
@@ -4323,9 +4062,8 @@ unpacker::write_code()
write_attrs(ATTR_CONTEXT_CODE, indexBits);
}
-int unpacker::write_attrs(int attrc, julong indexBits)
+int unpacker::write_attrs(int attrc, uint64_t indexBits)
{
- CHECK_0;
if (indexBits == 0)
{
// Quick short-circuit.
@@ -4338,9 +4076,9 @@ int unpacker::write_attrs(int attrc, julong indexBits)
int i, j, j2, idx, count;
int oiCount = 0;
- if (ad.isPredefined(X_ATTR_OVERFLOW) && (indexBits & ((julong)1 << X_ATTR_OVERFLOW)) != 0)
+ if (ad.isPredefined(X_ATTR_OVERFLOW) && (indexBits & ((uint64_t)1 << X_ATTR_OVERFLOW)) != 0)
{
- indexBits -= ((julong)1 << X_ATTR_OVERFLOW);
+ indexBits -= ((uint64_t)1 << X_ATTR_OVERFLOW);
oiCount = ad.xxx_attr_count().getInt();
}
@@ -4371,7 +4109,6 @@ int unpacker::write_attrs(int attrc, julong indexBits)
entry *aname = nullptr;
entry *ref; // scratch
size_t abase = put_empty(2 + 4);
- CHECK_0;
if (idx < (int)ad.flag_limit && ad.isPredefined(idx))
{
// Switch on the attrc and idx simultaneously.
@@ -4396,15 +4133,14 @@ int unpacker::write_attrs(int attrc, julong indexBits)
case ADH_BYTE(ATTR_CONTEXT_CLASS, CLASS_ATTR_InnerClasses) :
// note the existence of this attr, but save for later
if (cur_class_has_local_ics)
- abort("too many InnerClasses attrs");
+ unpack_abort("too many InnerClasses attrs");
cur_class_has_local_ics = true;
wp = wp_at(abase);
continue;
case ADH_BYTE(ATTR_CONTEXT_CLASS, CLASS_ATTR_SourceFile) :
- aname = cp.sym[cpool::s_SourceFile];
+ aname = cp.sym[constant_pool::s_SourceFile];
ref = class_SourceFile_RUN.getRefN();
- CHECK_0;
if (ref == nullptr)
{
bytes &n = cur_class->ref(0)->value.b;
@@ -4431,23 +4167,23 @@ int unpacker::write_attrs(int attrc, julong indexBits)
break;
case ADH_BYTE(ATTR_CONTEXT_CLASS, CLASS_ATTR_EnclosingMethod) :
- aname = cp.sym[cpool::s_EnclosingMethod];
+ aname = cp.sym[constant_pool::s_EnclosingMethod];
putref(class_EnclosingMethod_RC.getRefN());
putref(class_EnclosingMethod_RDN.getRefN());
break;
case ADH_BYTE(ATTR_CONTEXT_FIELD, FIELD_ATTR_ConstantValue) :
- aname = cp.sym[cpool::s_ConstantValue];
+ aname = cp.sym[constant_pool::s_ConstantValue];
putref(field_ConstantValue_KQ.getRefUsing(cp.getKQIndex()));
break;
case ADH_BYTE(ATTR_CONTEXT_METHOD, METHOD_ATTR_Code) :
- aname = cp.sym[cpool::s_Code];
+ aname = cp.sym[constant_pool::s_Code];
write_code();
break;
case ADH_BYTE(ATTR_CONTEXT_METHOD, METHOD_ATTR_Exceptions) :
- aname = cp.sym[cpool::s_Exceptions];
+ aname = cp.sym[constant_pool::s_Exceptions];
putu2(count = method_Exceptions_N.getInt());
for (j = 0; j < count; j++)
{
@@ -4456,7 +4192,7 @@ int unpacker::write_attrs(int attrc, julong indexBits)
break;
case ADH_BYTE(ATTR_CONTEXT_CODE, CODE_ATTR_StackMapTable) :
- aname = cp.sym[cpool::s_StackMapTable];
+ aname = cp.sym[constant_pool::s_StackMapTable];
// (keep this code aligned with its brother in unpacker::read_attrs)
putu2(count = code_StackMapTable_N.getInt());
for (j = 0; j < count; j++)
@@ -4504,7 +4240,7 @@ int unpacker::write_attrs(int attrc, julong indexBits)
break;
case ADH_BYTE(ATTR_CONTEXT_CODE, CODE_ATTR_LineNumberTable) :
- aname = cp.sym[cpool::s_LineNumberTable];
+ aname = cp.sym[constant_pool::s_LineNumberTable];
putu2(count = code_LineNumberTable_N.getInt());
for (j = 0; j < count; j++)
{
@@ -4514,7 +4250,7 @@ int unpacker::write_attrs(int attrc, julong indexBits)
break;
case ADH_BYTE(ATTR_CONTEXT_CODE, CODE_ATTR_LocalVariableTable) :
- aname = cp.sym[cpool::s_LocalVariableTable];
+ aname = cp.sym[constant_pool::s_LocalVariableTable];
putu2(count = code_LocalVariableTable_N.getInt());
for (j = 0; j < count; j++)
{
@@ -4530,7 +4266,7 @@ int unpacker::write_attrs(int attrc, julong indexBits)
break;
case ADH_BYTE(ATTR_CONTEXT_CODE, CODE_ATTR_LocalVariableTypeTable) :
- aname = cp.sym[cpool::s_LocalVariableTypeTable];
+ aname = cp.sym[constant_pool::s_LocalVariableTypeTable];
putu2(count = code_LocalVariableTypeTable_N.getInt());
for (j = 0; j < count; j++)
{
@@ -4546,24 +4282,24 @@ int unpacker::write_attrs(int attrc, julong indexBits)
break;
case ADH_BYTE(ATTR_CONTEXT_CLASS, X_ATTR_Signature) :
- aname = cp.sym[cpool::s_Signature];
+ aname = cp.sym[constant_pool::s_Signature];
putref(class_Signature_RS.getRefN());
break;
case ADH_BYTE(ATTR_CONTEXT_FIELD, X_ATTR_Signature) :
- aname = cp.sym[cpool::s_Signature];
+ aname = cp.sym[constant_pool::s_Signature];
putref(field_Signature_RS.getRefN());
break;
case ADH_BYTE(ATTR_CONTEXT_METHOD, X_ATTR_Signature) :
- aname = cp.sym[cpool::s_Signature];
+ aname = cp.sym[constant_pool::s_Signature];
putref(method_Signature_RS.getRefN());
break;
case ADH_BYTE(ATTR_CONTEXT_CLASS, X_ATTR_Deprecated) :
case ADH_BYTE(ATTR_CONTEXT_FIELD, X_ATTR_Deprecated) :
case ADH_BYTE(ATTR_CONTEXT_METHOD, X_ATTR_Deprecated) :
- aname = cp.sym[cpool::s_Deprecated];
+ aname = cp.sym[constant_pool::s_Deprecated];
// no data
break;
}
@@ -4575,7 +4311,7 @@ int unpacker::write_attrs(int attrc, julong indexBits)
layout_definition *lo = ad.getLayout(idx);
if (lo == nullptr)
{
- abort("bad layout index");
+ unpack_abort("bad layout index");
break;
}
assert((int)lo->idx == idx);
@@ -4600,8 +4336,7 @@ int unpacker::write_attrs(int attrc, julong indexBits)
}
if (aname == nullptr)
- abort("bad attribute index");
- CHECK_0;
+ unpack_abort("bad attribute index");
byte *wp1 = wp;
wp = wp_at(abase);
@@ -4628,7 +4363,6 @@ int unpacker::write_attrs(int attrc, julong indexBits)
void unpacker::write_members(int num, int attrc)
{
- CHECK;
attr_definitions &ad = attr_defs[attrc];
band &member_flags_hi = ad.xxx_flags_hi();
band &member_flags_lo = ad.xxx_flags_lo();
@@ -4636,18 +4370,16 @@ void unpacker::write_members(int num, int attrc)
bool haveLongFlags = ad.haveLongFlags();
putu2(num);
- julong indexMask = attr_defs[attrc].flagIndexMask();
+ uint64_t indexMask = attr_defs[attrc].flagIndexMask();
for (int i = 0; i < num; i++)
{
- julong mflags = member_flags_hi.getLong(member_flags_lo, haveLongFlags);
+ uint64_t mflags = member_flags_hi.getLong(member_flags_lo, haveLongFlags);
entry *mdescr = member_descr.getRef();
cur_descr = mdescr;
putu2(cur_descr_flags = (ushort)(mflags & ~indexMask));
- CHECK;
putref(mdescr->descrName());
putref(mdescr->descrType());
write_attrs(attrc, (mflags & indexMask));
- CHECK;
}
cur_descr = nullptr;
}
@@ -4669,14 +4401,12 @@ void unpacker::write_classfile_tail()
attr_definitions &ad = attr_defs[ATTR_CONTEXT_CLASS];
bool haveLongFlags = ad.haveLongFlags();
- julong kflags = class_flags_hi.getLong(class_flags_lo, haveLongFlags);
- julong indexMask = ad.flagIndexMask();
+ uint64_t kflags = class_flags_hi.getLong(class_flags_lo, haveLongFlags);
+ uint64_t indexMask = ad.flagIndexMask();
cur_class = class_this.getRef();
cur_super = class_super.getRef();
- CHECK;
-
if (cur_super == cur_class)
cur_super = nullptr;
// special representation for java/lang/Object
@@ -4693,7 +4423,6 @@ void unpacker::write_classfile_tail()
write_members(class_field_count.getInt(), ATTR_CONTEXT_FIELD);
write_members(class_method_count.getInt(), ATTR_CONTEXT_METHOD);
- CHECK;
cur_class_has_local_ics = false; // may be set true by write_attrs
@@ -4760,7 +4489,6 @@ void unpacker::write_classfile_tail()
{
inner_class &extra_ic = extra_ics[i];
extra_ic.inner = class_InnerClasses_RC.getRef();
- CHECK;
// Find the corresponding equivalent global IC:
inner_class *global_ic = cp.getIC(extra_ic.inner);
int flags = class_InnerClasses_F.getInt();
@@ -4769,7 +4497,7 @@ void unpacker::write_classfile_tail()
// The extra IC is simply a copy of a global IC.
if (global_ic == nullptr)
{
- abort("bad reference to inner class");
+ unpack_abort("bad reference to inner class");
break;
}
extra_ic = (*global_ic); // fill in rest of fields
@@ -4812,7 +4540,7 @@ void unpacker::write_classfile_tail()
if (local_ics > 0)
{
// append the new attribute:
- putref(cp.sym[cpool::s_InnerClasses]);
+ putref(cp.sym[constant_pool::s_InnerClasses]);
putu4(2 + 2 * 4 * local_ics);
putu2(local_ics);
PTRLIST_QSORT(requested_ics, raw_address_cmp);
@@ -4832,7 +4560,6 @@ void unpacker::write_classfile_tail()
putu2(ic->flags);
}
}
- assert(local_ics == 0); // must balance
putu2_at(wp_at(naOffset), ++na); // increment class attr count
}
@@ -4844,7 +4571,6 @@ void unpacker::write_classfile_tail()
}
requested_ics.empty();
- CHECK;
close_output();
// rewrite CP references in the tail
@@ -4868,7 +4594,6 @@ void unpacker::write_classfile_tail()
assert(false); // should not reach here
}
}
- CHECK;
}
void unpacker::write_classfile_head()
@@ -4919,7 +4644,7 @@ void unpacker::write_classfile_head()
putu2(e.refs[1]->getOutputIndex());
break;
default:
- abort(ERROR_INTERNAL);
+ unpack_abort(ERROR_INTERNAL);
}
}
close_output();
@@ -4927,7 +4652,6 @@ void unpacker::write_classfile_head()
unpacker::file *unpacker::get_next_file()
{
- CHECK_0;
free_temps();
if (files_remaining == 0)
{
@@ -4936,9 +4660,9 @@ unpacker::file *unpacker::get_next_file()
cur_file.size = 0;
if (archive_size != 0)
{
- julong predicted_size = unsized_bytes_read + archive_size;
+ uint64_t predicted_size = unsized_bytes_read + archive_size;
if (predicted_size != bytes_read)
- abort("archive header had incorrect size");
+ unpack_abort("archive header had incorrect size");
}
return nullptr;
}
@@ -4953,7 +4677,6 @@ unpacker::file *unpacker::get_next_file()
if (files_written < file_count)
{
entry *e = file_name.getRef();
- CHECK_0;
cur_file.name = e->utf8String();
bool haveLongSize = ((archive_options & AO_HAVE_FILE_SIZE_HI) != 0);
cur_file.size = file_size_hi.getLong(file_size_lo, haveLongSize);
@@ -4973,20 +4696,17 @@ unpacker::file *unpacker::get_next_file()
classes_written += 1;
if (cur_file.size != 0)
{
- abort("class file size transmitted");
- return nullptr;
+ unpack_abort("class file size transmitted");
}
reset_cur_classfile();
// write the meat of the classfile:
write_classfile_tail();
cur_file.data[1] = cur_classfile_tail.b;
- CHECK_0;
// write the CP of the classfile, second:
write_classfile_head();
cur_file.data[0] = cur_classfile_head.b;
- CHECK_0;
cur_file.size += cur_file.data[0].len;
cur_file.size += cur_file.data[1].len;
@@ -5006,8 +4726,7 @@ unpacker::file *unpacker::get_next_file()
if (cur_file.size != (size_t)cur_file.size)
{
// Silly size specified.
- abort("resource file too large");
- return nullptr;
+ unpack_abort("resource file too large");
}
size_t rpleft = input_remaining();
if (rpleft > 0)
@@ -5024,7 +4743,6 @@ unpacker::file *unpacker::get_next_file()
bytes_read += fleft; // Credit it to the overall archive size.
}
}
- CHECK_0;
bytes_written += cur_file.size;
files_written += 1;
return &cur_file;
@@ -5034,7 +4752,7 @@ unpacker::file *unpacker::get_next_file()
void unpacker::write_file_to_jar(unpacker::file *f)
{
size_t htsize = f->data[0].len + f->data[1].len;
- julong fsize = f->size;
+ uint64_t fsize = f->size;
if (htsize == fsize)
{
jarout->addJarEntry(f->name, f->deflate_hint(), f->modtime, f->data[0], f->data[1]);
@@ -5070,10 +4788,9 @@ void unpacker::write_file_to_jar(unpacker::file *f)
input.ensureSize(fleft);
}
rplimit = rp = input.base();
- CHECK;
input.setLimit(rp + fleft);
if (!ensure_input(fleft))
- abort("EOF reading resource file");
+ unpack_abort("EOF reading resource file");
part2.ptr = input_scan();
part2.len = input_remaining();
rplimit = rp = input.base();
@@ -5085,14 +4802,3 @@ void unpacker::write_file_to_jar(unpacker::file *f)
fprintf(stderr, "Wrote " LONG_LONG_FORMAT " bytes to: %s\n", fsize, f->name);
}
}
-
-void unpacker::abort(const char *message)
-{
- if (message == nullptr)
- message = "error unpacking archive";
- if (message[0] == '@')
- ++message;
- fprintf(stderr, "%s\n", message);
- fflush(stderr);
- exit(-1);
-}
diff --git a/depends/pack200/src/unpack.h b/depends/pack200/src/unpack.h
index 11f7bbe1..0100700d 100644
--- a/depends/pack200/src/unpack.h
+++ b/depends/pack200/src/unpack.h
@@ -27,7 +27,7 @@
struct jar;
struct gunzip;
struct band;
-struct cpool;
+struct constant_pool;
struct entry;
struct cpindex;
struct inner_class;
@@ -35,7 +35,7 @@ struct value_stream;
struct cpindex
{
- uint len;
+ uint32_t len;
entry *base1; // base of primary index
entry **base2; // base of secondary index
byte ixTag; // type of entries (!= CONSTANT_None), plus 64 if sub-index
@@ -44,7 +44,7 @@ struct cpindex
SUB_TAG = 64
};
- entry *get(uint i);
+ entry *get(uint32_t i);
void init(int len_, entry *base1_, int ixTag_)
{
@@ -62,12 +62,12 @@ struct cpindex
}
};
-struct cpool
+struct constant_pool
{
- uint nentries;
+ uint32_t nentries;
entry *entries;
entry *first_extra_entry;
- uint maxentries; // total allocated size of entries
+ uint32_t maxentries; // total allocated size of entries
// Position and size of each homogeneous subrange:
int tag_count[CONSTANT_Limit];
@@ -89,7 +89,7 @@ struct cpool
ptrlist outputEntries; // list of entry* needing output idx assigned
entry **hashTab;
- uint hashTabLength;
+ uint32_t hashTabLength;
entry *&hashTabRef(byte tag, bytes &b);
entry *ensureUtf8(bytes &b);
entry *ensureClass(bytes &b);
@@ -117,12 +117,12 @@ struct cpool
int getCount(byte tag)
{
- assert((uint)tag < CONSTANT_Limit);
+ assert((uint32_t)tag < CONSTANT_Limit);
return tag_count[tag];
}
cpindex *getIndex(byte tag)
{
- assert((uint)tag < CONSTANT_Limit);
+ assert((uint32_t)tag < CONSTANT_Limit);
return &tag_index[tag];
}
cpindex *getKQIndex(); // uses cur_descr
@@ -133,10 +133,6 @@ struct cpool
void computeOutputOrder();
void computeOutputIndexes();
void resetOutputIndexes();
-
- // error handling
- inline void abort(const char *msg);
- inline bool aborting();
};
/*
@@ -149,7 +145,7 @@ struct unpacker
struct file
{
const char *name;
- julong size;
+ uint64_t size;
int modtime;
int options;
bytes data[2];
@@ -161,12 +157,8 @@ struct unpacker
}
};
- // global pointer to self, if not running under JNI (not multi-thread safe)
- static unpacker *non_mt_current;
-
// if running Unix-style, here are the inputs and outputs
FILE *infileptr; // buffered
- int infileno; // unbuffered
bytes inbytes; // direct
gunzip *gzin; // gunzip filter, if any
jar *jarout; // output JAR file
@@ -174,19 +166,13 @@ struct unpacker
// pointer to self, for U_NEW macro
unpacker *u;
- // private abort message string, allocated to PATH_MAX*2
- const char *abort_message;
ptrlist mallocs; // list of guys to free when we are all done
ptrlist tmallocs; // list of guys to free on next client request
fillbytes smallbuf; // supplies small alloc requests
fillbytes tsmallbuf; // supplies temporary small alloc requests
// option management members
- int verbose; // verbose level, 0 means no output
- bool strip_compile;
- bool strip_debug;
- bool strip_jcov;
- bool remove_packfile;
+ int verbose; // verbose level, 0 means no output
int deflate_hint_or_zero; // ==0 means not set, otherwise -1 or 1
int modification_time_or_zero;
@@ -196,11 +182,12 @@ struct unpacker
bool free_input; // must the input buffer be freed?
byte *rp; // read pointer (< rplimit <= input.limit())
byte *rplimit; // how much of the input block has been read?
- julong bytes_read;
+ uint64_t bytes_read;
int unsized_bytes_read;
// callback to read at least one byte, up to available input
- typedef jlong (*read_input_fn_t)(unpacker *self, void *buf, jlong minlen, jlong maxlen);
+ typedef int64_t (*read_input_fn_t)(unpacker *self, void *buf, int64_t minlen,
+ int64_t maxlen);
read_input_fn_t read_input_fn;
// archive header fields
@@ -218,7 +205,7 @@ struct unpacker
// engine state
band *all_bands; // indexed by band_number
byte *meta_rp; // read-pointer into (copy of) band_headers
- cpool cp; // all constant pool information
+ constant_pool cp; // all constant pool information
inner_class *ics; // InnerClasses
// output stream
@@ -239,7 +226,7 @@ struct unpacker
fillbytes cur_classfile_tail;
int files_written; // also tells which file we're working on
int classes_written; // also tells which class we're working on
- julong bytes_written;
+ uint64_t bytes_written;
intlist bcimap;
fillbytes class_fixup_type;
intlist class_fixup_offset;
@@ -250,8 +237,8 @@ struct unpacker
ptrlist requested_ics; // which ics need output?
// stats pertaining to multiple segments (updated on reset)
- julong bytes_read_before_reset;
- julong bytes_written_before_reset;
+ uint64_t bytes_read_before_reset;
+ uint64_t bytes_written_before_reset;
int files_written_before_reset;
int classes_written_before_reset;
int segments_read_before_reset;
@@ -259,7 +246,7 @@ struct unpacker
// attribute state
struct layout_definition
{
- uint idx; // index (0..31...) which identifies this layout
+ uint32_t idx; // index (0..31...) which identifies this layout
const char *name; // name of layout
entry *nameEntry;
const char *layout; // string of layout (not yet parsed)
@@ -280,9 +267,9 @@ struct unpacker
unpacker *u; // pointer to self, for U_NEW macro
int xxx_flags_hi_bn; // locator for flags, count, indexes, calls bands
int attrc; // ATTR_CONTEXT_CLASS, etc.
- uint flag_limit; // 32 or 63, depending on archive_options bit
- julong predef; // mask of built-in definitions
- julong redef; // mask of local flag definitions or redefinitions
+ uint32_t flag_limit; // 32 or 63, depending on archive_options bit
+ uint64_t predef; // mask of built-in definitions
+ uint64_t redef; // mask of local flag definitions or redefinitions
ptrlist layouts; // local (compressor-defined) defs, in index order
int flag_count[X_ATTR_LIMIT_FLAGS_HI];
intlist overflow_count;
@@ -321,12 +308,12 @@ struct unpacker
band **popBody(int band_stack_base); // pops a body off band_stack
// Read data into the bands of the idx-th layout.
- void readBandData(int idx); // parse layout, make bands, read data
- void readBandData(band **body, uint count); // recursive helper
+ void readBandData(int idx); // parse layout, make bands, read data
+ void readBandData(band **body, uint32_t count); // recursive helper
- layout_definition *getLayout(uint idx)
+ layout_definition *getLayout(uint32_t idx)
{
- if (idx >= (uint)layouts.length())
+ if (idx >= (uint32_t)layouts.length())
return nullptr;
return (layout_definition *)layouts.get(idx);
}
@@ -344,33 +331,33 @@ struct unpacker
}
// Return flag_count if idx is predef and not redef, else zero.
- int predefCount(uint idx);
+ int predefCount(uint32_t idx);
- bool isRedefined(uint idx)
+ bool isRedefined(uint32_t idx)
{
if (idx >= flag_limit)
return false;
return (bool)((redef >> idx) & 1);
}
- bool isPredefined(uint idx)
+ bool isPredefined(uint32_t idx)
{
if (idx >= flag_limit)
return false;
return (bool)(((predef & ~redef) >> idx) & 1);
}
- julong flagIndexMask()
+ uint64_t flagIndexMask()
{
return (predef | redef);
}
- bool isIndex(uint idx)
+ bool isIndex(uint32_t idx)
{
assert(flag_limit != 0); // must be set up already
if (idx < flag_limit)
return (bool)(((predef | redef) >> idx) & 1);
else
- return (idx - flag_limit < (uint)overflow_count.length());
+ return (idx - flag_limit < (uint32_t)overflow_count.length());
}
- int &getCount(uint idx)
+ int &getCount(uint32_t idx)
{
assert(isIndex(idx));
if (idx < flag_limit)
@@ -378,14 +365,6 @@ struct unpacker
else
return overflow_count.get(idx - flag_limit);
}
- bool aborting()
- {
- return u->aborting();
- }
- void abort(const char *msg)
- {
- u->abort(msg);
- }
};
attr_definitions attr_defs[ATTR_CONTEXT_LIMIT];
@@ -407,10 +386,8 @@ struct unpacker
bool set_option(const char *option, const char *value);
const char *get_option(const char *option);
- void dump_options();
-
// Fetching input.
- bool ensure_input(jlong more);
+ bool ensure_input(int64_t more);
byte *input_scan()
{
return rp;
@@ -473,12 +450,6 @@ struct unpacker
sprintf(buf, "%d", num);
return saveStr(buf);
}
- const char *get_abort_message();
- void abort(const char *s = nullptr);
- bool aborting()
- {
- return abort_message != nullptr;
- }
static unpacker *current(); // find current instance
// Output management
@@ -514,7 +485,7 @@ struct unpacker
}
void putu2(int n); // { putu2_at(put_space(2), n); }
void putu4(int n); // { putu4_at(put_space(4), n); }
- void putu8(jlong n); // { putu8_at(put_space(8), n); }
+ void putu8(int64_t n); // { putu8_at(put_space(8), n); }
void putref(entry *e); // { putu2_at(put_space(2), putref_index(e, 2)); }
void putu1ref(entry *e); // { putu1_at(put_space(1), putref_index(e, 1)); }
int putref_index(entry *e, int size); // size in [1..2]
@@ -530,7 +501,7 @@ struct unpacker
{
return wpbase + offset;
}
- uint to_bci(uint bii);
+ uint32_t to_bci(uint32_t bii);
void get_code_header(int &max_stack, int &max_na_locals, int &handler_count, int &cflags);
band *ref_band_for_self_op(int bc, bool &isAloadVar, int &origBCVar);
band *ref_band_for_op(int bc);
@@ -543,7 +514,7 @@ struct unpacker
}
static void putu2_at(byte *wp, int n);
static void putu4_at(byte *wp, int n);
- static void putu8_at(byte *wp, jlong n);
+ static void putu8_at(byte *wp, int64_t n);
// Private stuff
void reset_cur_classfile();
@@ -552,7 +523,7 @@ struct unpacker
void write_code();
void write_bc_ops();
void write_members(int num, int attrc); // attrc=ATTR_CONTEXT_FIELD/METHOD
- int write_attrs(int attrc, julong indexBits);
+ int write_attrs(int attrc, uint64_t indexBits);
// The readers
void read_bands();
@@ -574,12 +545,3 @@ struct unpacker
void read_double_refs(band &cp_band, byte ref1Tag, byte ref2Tag, entry *cpMap, int len);
void read_signature_values(entry *cpMap, int len);
};
-
-inline void cpool::abort(const char *msg)
-{
- u->abort(msg);
-}
-inline bool cpool::aborting()
-{
- return u->aborting();
-}
diff --git a/depends/pack200/src/unpack200.cpp b/depends/pack200/src/unpack200.cpp
new file mode 100644
index 00000000..c6aa0b02
--- /dev/null
+++ b/depends/pack200/src/unpack200.cpp
@@ -0,0 +1,172 @@
+/*
+ * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+#include <sys/types.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <errno.h>
+#include <assert.h>
+#include <limits.h>
+#include <time.h>
+#include <stdint.h>
+
+#include "constants.h"
+#include "utils.h"
+#include "defines.h"
+#include "bytes.h"
+#include "coding.h"
+#include "unpack200.h"
+#include "unpack.h"
+#include "zip.h"
+
+// Callback for fetching data, Unix style.
+static int64_t read_input_via_stdio(unpacker *u, void *buf, int64_t minlen, int64_t maxlen)
+{
+ assert(u->infileptr != nullptr);
+ assert(minlen <= maxlen); // don't talk nonsense
+ int64_t numread = 0;
+ char *bufptr = (char *)buf;
+ while (numread < minlen)
+ {
+ // read available input, up to buf.length or maxlen
+ int readlen = (1 << 16);
+ if (readlen > (maxlen - numread))
+ readlen = (int)(maxlen - numread);
+ int nr = 0;
+
+ nr = (int)fread(bufptr, 1, readlen, u->infileptr);
+ if (nr <= 0)
+ {
+ if (errno != EINTR)
+ break;
+ nr = 0;
+ }
+ numread += nr;
+ bufptr += nr;
+ assert(numread <= maxlen);
+ }
+ return numread;
+}
+
+enum
+{
+ EOF_MAGIC = 0,
+ BAD_MAGIC = -1
+};
+
+static int read_magic(unpacker *u, char peek[], int peeklen)
+{
+ assert(peeklen == 4); // magic numbers are always 4 bytes
+ int64_t nr = (u->read_input_fn)(u, peek, peeklen, peeklen);
+ if (nr != peeklen)
+ {
+ return (nr == 0) ? EOF_MAGIC : BAD_MAGIC;
+ }
+ int magic = 0;
+ for (int i = 0; i < peeklen; i++)
+ {
+ magic <<= 8;
+ magic += peek[i] & 0xFF;
+ }
+ return magic;
+}
+
+void unpack_200(std::string input_path, std::string output_path)
+{
+ unpacker u;
+ int status = 0;
+
+ FILE *input = fopen(input_path.c_str(), "rb");
+ if (!input)
+ {
+ throw std::runtime_error("Can't open input file" + input_path);
+ }
+ FILE *output = fopen(output_path.c_str(), "wb");
+ if (!output)
+ {
+ fclose(output);
+ throw std::runtime_error("Can't open output file" + output_path);
+ }
+ u.init(read_input_via_stdio);
+
+ // initialize jar output
+ // the output takes ownership of the file handle
+ jar jarout;
+ jarout.init(&u);
+ jarout.jarfp = output;
+
+ // the input doesn't
+ u.infileptr = input;
+
+ // read the magic!
+ char peek[4];
+ int magic;
+ magic = read_magic(&u, peek, (int)sizeof(peek));
+
+ // if it is a gzip encoded file, we need an extra gzip input filter
+ if ((magic & GZIP_MAGIC_MASK) == GZIP_MAGIC)
+ {
+ gunzip *gzin = NEW(gunzip, 1);
+ gzin->init(&u);
+ // FIXME: why the side effects? WHY?
+ u.gzin->start(magic);
+ u.start();
+ }
+ else
+ {
+ // otherwise, feed the bytes to the unpacker directly
+ u.start(peek, sizeof(peek));
+ }
+
+ // Note: The checks to u.aborting() are necessary to gracefully
+ // terminate processing when the first segment throws an error.
+ for (;;)
+ {
+ // Each trip through this loop unpacks one segment
+ // and then resets the unpacker.
+ for (unpacker::file *filep; (filep = u.get_next_file()) != nullptr;)
+ {
+ u.write_file_to_jar(filep);
+ }
+
+ // Peek ahead for more data.
+ magic = read_magic(&u, peek, (int)sizeof(peek));
+ if (magic != (int)JAVA_PACKAGE_MAGIC)
+ {
+ if (magic != EOF_MAGIC)
+ unpack_abort("garbage after end of pack archive");
+ break; // all done
+ }
+
+ // Release all storage from parsing the old segment.
+ u.reset();
+ // Restart, beginning with the peek-ahead.
+ u.start(peek, sizeof(peek));
+ }
+ u.finish();
+ u.free(); // tidy up malloc blocks
+ fclose(input);
+}
diff --git a/depends/pack200/src/utils.cpp b/depends/pack200/src/utils.cpp
index 3ea8c92e..0b7d91ca 100644
--- a/depends/pack200/src/utils.cpp
+++ b/depends/pack200/src/utils.cpp
@@ -29,6 +29,7 @@
#include <string.h>
#include <limits.h>
#include <assert.h>
+#include <stdint.h>
#include <sys/stat.h>
@@ -57,35 +58,14 @@ void *must_malloc(size_t size)
}
else
{
- unpack_abort(ERROR_ENOMEM);
+ throw std::runtime_error(ERROR_ENOMEM);
}
return ptr;
}
-void unpack_abort(const char *msg, unpacker *u)
+void unpack_abort(const char *msg)
{
if (msg == nullptr)
msg = "corrupt pack file or internal error";
- if (u == nullptr)
- u = unpacker::current();
- if (u == nullptr)
- {
- fprintf(stderr, "Error: unpacker: %s\n", msg);
- ::abort();
- return;
- }
- u->abort(msg);
-}
-
-bool unpack_aborting(unpacker *u)
-{
- if (u == nullptr)
- u = unpacker::current();
- if (u == nullptr)
- {
- fprintf(stderr, "Error: unpacker: no current instance\n");
- ::abort();
- return true;
- }
- return u->aborting();
+ throw std::runtime_error(msg);
}
diff --git a/depends/pack200/src/utils.h b/depends/pack200/src/utils.h
index 0ce6b7d8..5a3dc8f6 100644
--- a/depends/pack200/src/utils.h
+++ b/depends/pack200/src/utils.h
@@ -25,6 +25,8 @@
// Definitions of our util functions
+#include <stdexcept>
+
void *must_malloc(size_t size);
// overflow management
@@ -46,9 +48,6 @@ inline size_t add_size(size_t size1, size_t size2, int size3)
return add_size(add_size(size1, size2), size3);
}
-// These may be expensive, because they have to go via Java TSD,
-// if the optional u argument is missing.
struct unpacker;
-extern void unpack_abort(const char *msg, unpacker *u = nullptr);
-extern bool unpack_aborting(unpacker *u = nullptr);
-
+/// This throws an exception!
+extern void unpack_abort(const char *msg = nullptr);
diff --git a/depends/pack200/src/zip.cpp b/depends/pack200/src/zip.cpp
index f1bc25ad..baea2ba7 100644
--- a/depends/pack200/src/zip.cpp
+++ b/depends/pack200/src/zip.cpp
@@ -30,6 +30,7 @@
#include <string.h>
#include <errno.h>
#include <time.h>
+#include <stdint.h>
#include <stdlib.h>
#include <assert.h>
@@ -47,29 +48,14 @@
#include "zip.h"
-#ifdef NO_ZLIB
-
-inline bool jar::deflate_bytes(bytes &head, bytes &tail)
-{
- return false;
-}
-inline uint jar::get_crc32(uint c, uchar *ptr, uint len)
-{
- return 0;
-}
-#define Z_NULL NULL
-
-#else // Have ZLIB
-
#include <zlib.h>
-inline uint jar::get_crc32(uint c, uchar *ptr, uint len)
+inline uint32_t jar::get_crc32(uint32_t c, uchar *ptr, uint32_t len)
{
return crc32(c, ptr, len);
}
-#endif // End of ZLIB
-
+// FIXME: this is bullshit. Do real endianness detection.
#ifdef sparc
#define SWAP_BYTES(a) ((((a) << 8) & 0xff00) | 0x00ff) & (((a) >> 8) | 0xff00)
#else
@@ -107,7 +93,7 @@ void jar::write_data(void *buff, int len)
void jar::add_to_jar_directory(const char *fname, bool store, int modtime, int len, int clen,
uint32_t crc)
{
- uint fname_length = (uint)strlen(fname);
+ uint32_t fname_length = (uint32_t)strlen(fname);
ushort header[23];
if (modtime == 0)
modtime = default_modtime;
@@ -169,9 +155,9 @@ void jar::add_to_jar_directory(const char *fname, bool store, int modtime, int l
}
void jar::write_jar_header(const char *fname, bool store, int modtime, int len, int clen,
- uint crc)
+ uint32_t crc)
{
- uint fname_length = (uint)strlen(fname);
+ uint32_t fname_length = (uint32_t)strlen(fname);
ushort header[15];
if (modtime == 0)
modtime = default_modtime;
@@ -218,12 +204,10 @@ void jar::write_jar_header(const char *fname, bool store, int modtime, int len,
write_data((char *)fname, (int)fname_length);
}
-static const char marker_comment[] = ZIP_ARCHIVE_MARKER_COMMENT;
-
void jar::write_central_directory()
{
bytes mc;
- mc.set(marker_comment);
+ mc.set("PACK200");
ushort header[11];
@@ -278,11 +262,11 @@ void jar::addJarEntry(const char *fname, bool deflate_hint, int modtime, bytes &
int len = (int)(head.len + tail.len);
int clen = 0;
- uint crc = get_crc32(0, Z_NULL, 0);
+ uint32_t crc = get_crc32(0, Z_NULL, 0);
if (head.len != 0)
- crc = get_crc32(crc, (uchar *)head.ptr, (uint)head.len);
+ crc = get_crc32(crc, (uchar *)head.ptr, (uint32_t)head.len);
if (tail.len != 0)
- crc = get_crc32(crc, (uchar *)tail.ptr, (uint)tail.len);
+ crc = get_crc32(crc, (uchar *)tail.ptr, (uint32_t)tail.len);
bool deflate = (deflate_hint && len > 0);
@@ -452,10 +436,10 @@ bool jar::deflate_bytes(bytes &head, bytes &tail)
}
// Callback for fetching data from a GZIP input stream
-static jlong read_input_via_gzip(unpacker *u, void *buf, jlong minlen, jlong maxlen)
+static int64_t read_input_via_gzip(unpacker *u, void *buf, int64_t minlen, int64_t maxlen)
{
assert(minlen <= maxlen); // don't talk nonsense
- jlong numread = 0;
+ int64_t numread = 0;
char *bufptr = (char *)buf;
char *inbuf = u->gzin->inbuf;
size_t inbuflen = sizeof(u->gzin->inbuf);
@@ -476,7 +460,7 @@ static jlong read_input_via_gzip(unpacker *u, void *buf, jlong minlen, jlong max
int error = inflate(&zs, Z_NO_FLUSH);
if (error != Z_OK && error != Z_STREAM_END)
{
- u->abort("error inflating input");
+ unpack_abort("error inflating input");
break;
}
int nr = readlen - zs.avail_out;
@@ -505,7 +489,7 @@ static jlong read_input_via_gzip(unpacker *u, void *buf, jlong minlen, jlong max
// %%% should check final CRC and length here
// %%% should check for concatenated *.gz files here
if (zs.avail_in > 0)
- u->abort("garbage after end of deflated input stream");
+ unpack_abort("garbage after end of deflated input stream");
// pop this filter off:
u->gzin->free();
break;
@@ -577,15 +561,11 @@ void gunzip::start(int magic)
if (gz_flg & FHCRC)
read_fixed_field(gz_hcrc, sizeof(gz_hcrc));
- if (aborting())
- return;
-
// now the input stream is ready to read into the inflater
int error = inflateInit2((z_stream *)zstream, -MAX_WBITS);
if (error != Z_OK)
{
- abort("cannot create input");
- return;
+ unpack_abort("cannot create input");
}
}
@@ -602,9 +582,7 @@ void gunzip::free()
void gunzip::read_fixed_field(char *buf, size_t buflen)
{
- if (aborting())
- return;
- jlong nr = ((unpacker::read_input_fn_t)read_input_fn)(u, buf, buflen, buflen);
+ int64_t nr = ((unpacker::read_input_fn_t)read_input_fn)(u, buf, buflen, buflen);
if ((size_t)nr != buflen)
- u->abort("short stream header");
+ unpack_abort("short stream header");
}
diff --git a/depends/pack200/src/zip.h b/depends/pack200/src/zip.h
index 1b6a8b02..67ec24da 100644
--- a/depends/pack200/src/zip.h
+++ b/depends/pack200/src/zip.h
@@ -24,7 +24,7 @@
*/
#include <stdint.h>
typedef unsigned short ushort;
-typedef unsigned int uint;
+typedef unsigned int uint32_t;
typedef unsigned char uchar;
struct unpacker;
@@ -42,7 +42,7 @@ struct jar
// Private members
fillbytes central_directory;
ushort central_directory_count;
- uint output_file_offset;
+ uint32_t output_file_offset;
fillbytes deflated; // temporary buffer
// pointer to outer unpacker, for error checks etc.
@@ -85,17 +85,7 @@ struct jar
// The definitions of these depend on the NO_ZLIB option:
bool deflate_bytes(bytes &head, bytes &tail);
- static uint get_crc32(uint c, unsigned char *ptr, uint len);
-
- // error handling
- void abort(const char *msg)
- {
- unpack_abort(msg, u);
- }
- bool aborting()
- {
- return unpack_aborting(u);
- }
+ static uint32_t get_crc32(uint32_t c, unsigned char *ptr, uint32_t len);
};
struct gunzip
@@ -105,7 +95,7 @@ struct gunzip
// pointer to outer unpacker, for error checks etc.
unpacker *u;
- void *read_input_fn; // underlying byte stream
+ void *read_input_fn; // underlying \bchar\b stream
void *zstream; // inflater state
char inbuf[1 << 14]; // input buffer
@@ -117,14 +107,4 @@ struct gunzip
// private stuff
void read_fixed_field(char *buf, size_t buflen);
-
- // error handling
- void abort(const char *msg)
- {
- unpack_abort(msg, u);
- }
- bool aborting()
- {
- return unpack_aborting(u);
- }
};