@@ -537,8 +537,6 @@ struct zstream {
537
537
} * func ;
538
538
};
539
539
540
- POLYGLOT_DECLARE_STRUCT (zstream );
541
-
542
540
#define ZSTREAM_FLAG_READY 0x1
543
541
#define ZSTREAM_FLAG_IN_STREAM 0x2
544
542
#define ZSTREAM_FLAG_FINISHED 0x4
@@ -597,15 +595,12 @@ zlib_mem_free(voidpf opaque, voidpf address)
597
595
xfree (address );
598
596
}
599
597
600
- POLYGLOT_DECLARE_TYPE (z_stream );
601
-
602
598
static void
603
599
zstream_init (struct zstream * z , const struct zstream_funcs * func )
604
600
{
605
601
z -> flags = 0 ;
606
602
z -> buf = Qnil ;
607
603
z -> input = Qnil ;
608
- polyglot_put_member (z , "stream" , polyglot_from_z_stream (malloc (sizeof (z_stream ))));
609
604
z -> stream .zalloc = zlib_mem_alloc ;
610
605
z -> stream .zfree = zlib_mem_free ;
611
606
z -> stream .opaque = Z_NULL ;
@@ -632,7 +627,7 @@ zstream_expand_buffer(struct zstream *z)
632
627
long buf_filled = ZSTREAM_BUF_FILLED (z );
633
628
if (buf_filled >= ZSTREAM_AVAIL_OUT_STEP_MAX ) {
634
629
int state = 0 ;
635
- VALUE self = (VALUE )rb_tr_managed_from_handle_or_null ( z -> stream .opaque ) ;
630
+ VALUE self = (VALUE )z -> stream .opaque ;
636
631
637
632
rb_obj_reveal (z -> buf , rb_cString );
638
633
OBJ_INFECT (z -> buf , self );
@@ -743,7 +738,7 @@ zstream_append_buffer(struct zstream *z, const Bytef *src, long len)
743
738
static VALUE
744
739
zstream_detach_buffer (struct zstream * z )
745
740
{
746
- VALUE dst , self = (VALUE )rb_tr_managed_from_handle_or_null ( z -> stream .opaque ) ;
741
+ VALUE dst , self = (VALUE )z -> stream .opaque ;
747
742
748
743
if (!ZSTREAM_IS_FINISHED (z ) && !ZSTREAM_IS_GZFILE (z ) &&
749
744
rb_block_given_p ()) {
@@ -935,7 +930,7 @@ zstream_run_func(void *ptr)
935
930
{
936
931
struct zstream_run_args * args = (struct zstream_run_args * )ptr ;
937
932
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 ;
939
934
uInt n ;
940
935
941
936
err = Z_OK ;
@@ -1002,7 +997,7 @@ zstream_run(struct zstream *z, Bytef *src, long len, int flush)
1002
997
int err ;
1003
998
VALUE guard = Qnil ;
1004
999
1005
- args .z = rb_tr_handle_for_managed ( z ) ;
1000
+ args .z = z ;
1006
1001
args .flush = flush ;
1007
1002
args .interrupt = 0 ;
1008
1003
args .jump_state = 0 ;
@@ -1042,7 +1037,7 @@ zstream_run(struct zstream *z, Bytef *src, long len, int flush)
1042
1037
zstream_append_input (z , z -> stream .next_in , z -> stream .avail_in );
1043
1038
}
1044
1039
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 ;
1046
1041
if (self ) {
1047
1042
VALUE dicts = rb_ivar_get (self , id_dictionaries );
1048
1043
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)
1052
1047
}
1053
1048
}
1054
1049
}
1055
- rb_tr_release_handle (args .z );
1056
1050
raise_zlib_error (err , z -> stream .msg );
1057
1051
}
1058
1052
@@ -1061,8 +1055,6 @@ zstream_run(struct zstream *z, Bytef *src, long len, int flush)
1061
1055
RB_GC_GUARD (guard ); /* prevent tail call to make guard effective */
1062
1056
}
1063
1057
1064
- rb_tr_release_handle (args .z );
1065
-
1066
1058
if (args .jump_state )
1067
1059
rb_jump_tag (args .jump_state );
1068
1060
}
@@ -1154,9 +1146,9 @@ zstream_new(VALUE klass, const struct zstream_funcs *funcs)
1154
1146
VALUE obj ;
1155
1147
struct zstream * z ;
1156
1148
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 );
1158
1150
zstream_init (z , funcs );
1159
- z -> stream .opaque = (voidpf )rb_tr_handle_for_managed_leaking ( obj ) ;
1151
+ z -> stream .opaque = (voidpf )obj ;
1160
1152
return obj ;
1161
1153
}
1162
1154
@@ -1595,25 +1587,24 @@ deflate_run(VALUE args)
1595
1587
static VALUE
1596
1588
rb_deflate_s_deflate (int argc , VALUE * argv , VALUE klass )
1597
1589
{
1598
- struct zstream * z ;
1590
+ struct zstream z ;
1599
1591
VALUE src , level , dst , args [2 ];
1600
1592
int err , lev ;
1601
1593
1602
1594
rb_scan_args (argc , argv , "11" , & src , & level );
1603
1595
1604
- z = rb_tr_new_managed_struct (zstream );
1605
1596
lev = ARG_LEVEL (level );
1606
1597
StringValue (src );
1607
- zstream_init_deflate (z );
1608
- err = deflateInit (& z -> stream , lev );
1598
+ zstream_init_deflate (& z );
1599
+ err = deflateInit (& z . stream , lev );
1609
1600
if (err != Z_OK ) {
1610
- raise_zlib_error (err , z -> stream .msg );
1601
+ raise_zlib_error (err , z . stream .msg );
1611
1602
}
1612
- ZSTREAM_READY (z );
1603
+ ZSTREAM_READY (& z );
1613
1604
1614
- args [0 ] = (VALUE )z ;
1605
+ args [0 ] = (VALUE )& z ;
1615
1606
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 );
1617
1608
1618
1609
OBJ_INFECT (dst , src );
1619
1610
return dst ;
@@ -1914,22 +1905,21 @@ inflate_run(VALUE args)
1914
1905
static VALUE
1915
1906
rb_inflate_s_inflate (VALUE obj , VALUE src )
1916
1907
{
1917
- struct zstream * z ;
1908
+ struct zstream z ;
1918
1909
VALUE dst , args [2 ];
1919
1910
int err ;
1920
1911
1921
1912
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 );
1925
1915
if (err != Z_OK ) {
1926
- raise_zlib_error (err , z -> stream .msg );
1916
+ raise_zlib_error (err , z . stream .msg );
1927
1917
}
1928
- ZSTREAM_READY (z );
1918
+ ZSTREAM_READY (& z );
1929
1919
1930
- args [0 ] = (VALUE )z ;
1920
+ args [0 ] = (VALUE )& z ;
1931
1921
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 );
1933
1923
1934
1924
OBJ_INFECT (dst , src );
1935
1925
return dst ;
@@ -1961,9 +1951,7 @@ static VALUE
1961
1951
rb_inflate_add_dictionary (VALUE obj , VALUE dictionary )
1962
1952
{
1963
1953
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 );
1967
1955
1968
1956
rb_hash_aset (dictionaries , checksum , dictionary );
1969
1957
@@ -2217,7 +2205,6 @@ struct gzfile {
2217
2205
2218
2206
#define GZFILE_READ_SIZE 2048
2219
2207
2220
- POLYGLOT_DECLARE_STRUCT (gzfile );
2221
2208
2222
2209
static void
2223
2210
gzfile_mark (void * p )
@@ -2247,7 +2234,7 @@ gzfile_free(void *p)
2247
2234
if (gz -> cbuf ) {
2248
2235
xfree (gz -> cbuf );
2249
2236
}
2250
- // xfree(gz);
2237
+ xfree (gz );
2251
2238
}
2252
2239
2253
2240
static size_t
@@ -2271,7 +2258,6 @@ static const rb_data_type_t gzfile_data_type = {
2271
2258
static void
2272
2259
gzfile_init (struct gzfile * gz , const struct zstream_funcs * funcs , void (* endfunc )(struct gzfile * ))
2273
2260
{
2274
- polyglot_put_member (gz , "z" , rb_tr_new_managed_struct (zstream ));
2275
2261
zstream_init (& gz -> z , funcs );
2276
2262
gz -> z .flags |= ZSTREAM_FLAG_GZFILE ;
2277
2263
gz -> io = Qnil ;
@@ -2299,7 +2285,7 @@ gzfile_new(VALUE klass, const struct zstream_funcs *funcs, void (*endfunc)(struc
2299
2285
VALUE obj ;
2300
2286
struct gzfile * gz ;
2301
2287
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 );
2303
2289
gzfile_init (gz , funcs , endfunc );
2304
2290
return obj ;
2305
2291
}
@@ -3442,15 +3428,10 @@ rb_gzfile_ecopts(struct gzfile *gz, VALUE opts)
3442
3428
rb_io_extract_encoding_option (opts , & gz -> enc , & gz -> enc2 , NULL );
3443
3429
}
3444
3430
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 ;
3454
3435
}
3455
3436
}
3456
3437
@@ -4860,3 +4841,5 @@ Init_zlib(void)
4860
4841
* Raised when the data length recorded in the gzip file footer is not equivalent
4861
4842
* to the length of the actual uncompressed data.
4862
4843
*/
4844
+
4845
+
0 commit comments