Skip to content

Commit 3582d56

Browse files
committed
Remove zlib patches.
1 parent f2be431 commit 3582d56

File tree

4 files changed

+31
-81
lines changed

4 files changed

+31
-81
lines changed

lib/cext/patches/zlib_patches.rb

Lines changed: 0 additions & 31 deletions
This file was deleted.

lib/cext/preprocess.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
require_relative 'patches/puma_patches'
1616
require_relative 'patches/sqlite3_patches'
1717
require_relative 'patches/racc_patches'
18-
require_relative 'patches/zlib_patches'
1918

2019
class Preprocessor
2120

@@ -46,7 +45,6 @@ def self.add_gem_patches(patch_hash, gem_patches)
4645
add_gem_patches(PATCHED_FILES, ::PumaPatches::PATCHES)
4746
add_gem_patches(PATCHED_FILES, ::SQLite3Patches::PATCHES)
4847
add_gem_patches(PATCHED_FILES, ::RaccPatches::PATCHES)
49-
add_gem_patches(PATCHED_FILES, ::ZLibPatches::PATCHES)
5048

5149
LOCAL = /\w+\s*(\[\s*\d+\s*\])?/
5250
VALUE_LOCALS = /^(?<before>\s+)VALUE\s+(?<locals>#{LOCAL}(\s*,\s*#{LOCAL})*);(?<after>\s*(\/\/.+)?)$/

src/main/c/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ $(CEXTS_DIR)/openssl.su: openssl/openssl.su
110110
cp $< $@
111111

112112
# zlib.su
113-
zlib/Makefile: zlib/extconf.rb $(EXTCONF_DEPS) $(ROOT)/lib/cext/patches/zlib_patches.rb
113+
zlib/Makefile: zlib/extconf.rb $(EXTCONF_DEPS)
114114
cd zlib && $(RUBY) extconf.rb || $(IF_EXTCONF_FAIL)
115115

116116
zlib/zlib.su: zlib/Makefile zlib/zlib.c

src/main/c/zlib/zlib.c

Lines changed: 30 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -537,8 +537,6 @@ struct zstream {
537537
} *func;
538538
};
539539

540-
POLYGLOT_DECLARE_STRUCT(zstream);
541-
542540
#define ZSTREAM_FLAG_READY 0x1
543541
#define ZSTREAM_FLAG_IN_STREAM 0x2
544542
#define ZSTREAM_FLAG_FINISHED 0x4
@@ -597,15 +595,12 @@ zlib_mem_free(voidpf opaque, voidpf address)
597595
xfree(address);
598596
}
599597

600-
POLYGLOT_DECLARE_TYPE(z_stream);
601-
602598
static void
603599
zstream_init(struct zstream *z, const struct zstream_funcs *func)
604600
{
605601
z->flags = 0;
606602
z->buf = Qnil;
607603
z->input = Qnil;
608-
polyglot_put_member(z, "stream", polyglot_from_z_stream(malloc(sizeof(z_stream))));
609604
z->stream.zalloc = zlib_mem_alloc;
610605
z->stream.zfree = zlib_mem_free;
611606
z->stream.opaque = Z_NULL;
@@ -632,7 +627,7 @@ zstream_expand_buffer(struct zstream *z)
632627
long buf_filled = ZSTREAM_BUF_FILLED(z);
633628
if (buf_filled >= ZSTREAM_AVAIL_OUT_STEP_MAX) {
634629
int state = 0;
635-
VALUE self = (VALUE)rb_tr_managed_from_handle_or_null(z->stream.opaque);
630+
VALUE self = (VALUE)z->stream.opaque;
636631

637632
rb_obj_reveal(z->buf, rb_cString);
638633
OBJ_INFECT(z->buf, self);
@@ -743,7 +738,7 @@ zstream_append_buffer(struct zstream *z, const Bytef *src, long len)
743738
static VALUE
744739
zstream_detach_buffer(struct zstream *z)
745740
{
746-
VALUE dst, self = (VALUE)rb_tr_managed_from_handle_or_null(z->stream.opaque);
741+
VALUE dst, self = (VALUE)z->stream.opaque;
747742

748743
if (!ZSTREAM_IS_FINISHED(z) && !ZSTREAM_IS_GZFILE(z) &&
749744
rb_block_given_p()) {
@@ -935,7 +930,7 @@ zstream_run_func(void *ptr)
935930
{
936931
struct zstream_run_args *args = (struct zstream_run_args *)ptr;
937932
int err, state, flush = args->flush;
938-
struct zstream *z = polyglot_as_zstream(rb_tr_managed_from_handle(args->z));
933+
struct zstream *z = args->z;
939934
uInt n;
940935

941936
err = Z_OK;
@@ -1002,7 +997,7 @@ zstream_run(struct zstream *z, Bytef *src, long len, int flush)
1002997
int err;
1003998
VALUE guard = Qnil;
1004999

1005-
args.z = rb_tr_handle_for_managed(z);
1000+
args.z = z;
10061001
args.flush = flush;
10071002
args.interrupt = 0;
10081003
args.jump_state = 0;
@@ -1042,7 +1037,7 @@ zstream_run(struct zstream *z, Bytef *src, long len, int flush)
10421037
zstream_append_input(z, z->stream.next_in, z->stream.avail_in);
10431038
}
10441039
if (err == Z_NEED_DICT) {
1045-
VALUE self = (VALUE)rb_tr_managed_from_handle_or_null(z->stream.opaque);
1040+
VALUE self = (VALUE)z->stream.opaque;
10461041
if (self) {
10471042
VALUE dicts = rb_ivar_get(self, id_dictionaries);
10481043
VALUE dict = rb_hash_aref(dicts, rb_uint2inum(z->stream.adler));
@@ -1052,7 +1047,6 @@ zstream_run(struct zstream *z, Bytef *src, long len, int flush)
10521047
}
10531048
}
10541049
}
1055-
rb_tr_release_handle(args.z);
10561050
raise_zlib_error(err, z->stream.msg);
10571051
}
10581052

@@ -1061,8 +1055,6 @@ zstream_run(struct zstream *z, Bytef *src, long len, int flush)
10611055
RB_GC_GUARD(guard); /* prevent tail call to make guard effective */
10621056
}
10631057

1064-
rb_tr_release_handle(args.z);
1065-
10661058
if (args.jump_state)
10671059
rb_jump_tag(args.jump_state);
10681060
}
@@ -1154,9 +1146,9 @@ zstream_new(VALUE klass, const struct zstream_funcs *funcs)
11541146
VALUE obj;
11551147
struct zstream *z;
11561148

1157-
obj = TypedData_Make_Managed_Struct(klass, struct zstream, &zstream_data_type, z, zstream);
1149+
obj = TypedData_Make_Struct(klass, struct zstream, &zstream_data_type, z);
11581150
zstream_init(z, funcs);
1159-
z->stream.opaque = (voidpf)rb_tr_handle_for_managed_leaking(obj);
1151+
z->stream.opaque = (voidpf)obj;
11601152
return obj;
11611153
}
11621154

@@ -1595,25 +1587,24 @@ deflate_run(VALUE args)
15951587
static VALUE
15961588
rb_deflate_s_deflate(int argc, VALUE *argv, VALUE klass)
15971589
{
1598-
struct zstream *z;
1590+
struct zstream z;
15991591
VALUE src, level, dst, args[2];
16001592
int err, lev;
16011593

16021594
rb_scan_args(argc, argv, "11", &src, &level);
16031595

1604-
z = rb_tr_new_managed_struct(zstream);
16051596
lev = ARG_LEVEL(level);
16061597
StringValue(src);
1607-
zstream_init_deflate(z);
1608-
err = deflateInit(&z->stream, lev);
1598+
zstream_init_deflate(&z);
1599+
err = deflateInit(&z.stream, lev);
16091600
if (err != Z_OK) {
1610-
raise_zlib_error(err, z->stream.msg);
1601+
raise_zlib_error(err, z.stream.msg);
16111602
}
1612-
ZSTREAM_READY(z);
1603+
ZSTREAM_READY(&z);
16131604

1614-
args[0] = (VALUE)z;
1605+
args[0] = (VALUE)&z;
16151606
args[1] = src;
1616-
dst = rb_ensure(deflate_run, (VALUE)args, zstream_end, (VALUE)z);
1607+
dst = rb_ensure(deflate_run, (VALUE)args, zstream_end, (VALUE)&z);
16171608

16181609
OBJ_INFECT(dst, src);
16191610
return dst;
@@ -1914,22 +1905,21 @@ inflate_run(VALUE args)
19141905
static VALUE
19151906
rb_inflate_s_inflate(VALUE obj, VALUE src)
19161907
{
1917-
struct zstream *z;
1908+
struct zstream z;
19181909
VALUE dst, args[2];
19191910
int err;
19201911

19211912
StringValue(src);
1922-
z = rb_tr_new_managed_struct(zstream);
1923-
zstream_init_inflate(z);
1924-
err = inflateInit(&z->stream);
1913+
zstream_init_inflate(&z);
1914+
err = inflateInit(&z.stream);
19251915
if (err != Z_OK) {
1926-
raise_zlib_error(err, z->stream.msg);
1916+
raise_zlib_error(err, z.stream.msg);
19271917
}
1928-
ZSTREAM_READY(z);
1918+
ZSTREAM_READY(&z);
19291919

1930-
args[0] = (VALUE)z;
1920+
args[0] = (VALUE)&z;
19311921
args[1] = src;
1932-
dst = rb_ensure(inflate_run, (VALUE)args, zstream_end, (VALUE)z);
1922+
dst = rb_ensure(inflate_run, (VALUE)args, zstream_end, (VALUE)&z);
19331923

19341924
OBJ_INFECT(dst, src);
19351925
return dst;
@@ -1961,9 +1951,7 @@ static VALUE
19611951
rb_inflate_add_dictionary(VALUE obj, VALUE dictionary)
19621952
{
19631953
VALUE dictionaries = rb_ivar_get(obj, id_dictionaries);
1964-
VALUE argv[1];
1965-
argv[0] = dictionary;
1966-
VALUE checksum = do_checksum(1, argv, adler32);
1954+
VALUE checksum = do_checksum(1, &dictionary, adler32);
19671955

19681956
rb_hash_aset(dictionaries, checksum, dictionary);
19691957

@@ -2217,7 +2205,6 @@ struct gzfile {
22172205

22182206
#define GZFILE_READ_SIZE 2048
22192207

2220-
POLYGLOT_DECLARE_STRUCT(gzfile);
22212208

22222209
static void
22232210
gzfile_mark(void *p)
@@ -2247,7 +2234,7 @@ gzfile_free(void *p)
22472234
if (gz->cbuf) {
22482235
xfree(gz->cbuf);
22492236
}
2250-
// xfree(gz);
2237+
xfree(gz);
22512238
}
22522239

22532240
static size_t
@@ -2271,7 +2258,6 @@ static const rb_data_type_t gzfile_data_type = {
22712258
static void
22722259
gzfile_init(struct gzfile *gz, const struct zstream_funcs *funcs, void (*endfunc)(struct gzfile *))
22732260
{
2274-
polyglot_put_member(gz, "z", rb_tr_new_managed_struct(zstream));
22752261
zstream_init(&gz->z, funcs);
22762262
gz->z.flags |= ZSTREAM_FLAG_GZFILE;
22772263
gz->io = Qnil;
@@ -2299,7 +2285,7 @@ gzfile_new(VALUE klass, const struct zstream_funcs *funcs, void (*endfunc)(struc
22992285
VALUE obj;
23002286
struct gzfile *gz;
23012287

2302-
obj = TypedData_Make_Managed_Struct(klass, struct gzfile, &gzfile_data_type, gz, gzfile);
2288+
obj = TypedData_Make_Struct(klass, struct gzfile, &gzfile_data_type, gz);
23032289
gzfile_init(gz, funcs, endfunc);
23042290
return obj;
23052291
}
@@ -3442,15 +3428,10 @@ rb_gzfile_ecopts(struct gzfile *gz, VALUE opts)
34423428
rb_io_extract_encoding_option(opts, &gz->enc, &gz->enc2, NULL);
34433429
}
34443430
if (gz->enc2) {
3445-
// TODO TruffleRuby: not supported, when uncommented the method fails to
3446-
// execute as it tries to convert opts to native because of &opts
3447-
// gz->ecflags = rb_econv_prepare_opts(opts, &opts);
3448-
// rb_encoding *enc = gz->enc;
3449-
// rb_encoding *enc2 = gz->enc2;
3450-
// gz->ec = rb_econv_open_opts(enc2->name, enc->name,
3451-
// gz->ecflags, opts);
3452-
// gz->ecopts = opts;
3453-
rb_tr_error("external encoding not supported");
3431+
gz->ecflags = rb_econv_prepare_opts(opts, &opts);
3432+
gz->ec = rb_econv_open_opts(gz->enc2->name, gz->enc->name,
3433+
gz->ecflags, opts);
3434+
gz->ecopts = opts;
34543435
}
34553436
}
34563437

@@ -4860,3 +4841,5 @@ Init_zlib(void)
48604841
* Raised when the data length recorded in the gzip file footer is not equivalent
48614842
* to the length of the actual uncompressed data.
48624843
*/
4844+
4845+

0 commit comments

Comments
 (0)