summaryrefslogtreecommitdiff
path: root/devel/ruby-zlib/patches/patch-aa
blob: 60cf1ab1f4701a6d12b8d6b03c1aaabbab05ec79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
$NetBSD: patch-aa,v 1.4 2005/03/06 16:52:40 taca Exp $

--- zlib.c.orig	2004-12-18 16:37:01.000000000 +0900
+++ zlib.c
@@ -55,7 +55,7 @@ static void zstream_reset_input _((struc
 static void zstream_passthrough_input _((struct zstream*));
 static VALUE zstream_detach_input _((struct zstream*));
 static void zstream_reset _((struct zstream*));
-static void zstream_end _((struct zstream*));
+static VALUE zstream_end _((struct zstream*));
 static void zstream_run _((struct zstream*, Bytef*, uInt, int));
 static VALUE zstream_sync _((struct zstream*, Bytef*, uInt));
 static void zstream_mark _((struct zstream*));
@@ -80,7 +80,8 @@ static VALUE rb_zstream_closed_p _((VALU
 
 static VALUE rb_deflate_s_allocate _((VALUE));
 static VALUE rb_deflate_initialize _((int, VALUE*, VALUE));
-static VALUE rb_deflate_clone _((VALUE));
+static VALUE rb_deflate_init_copy _((VALUE, VALUE));
+static VALUE deflate_run _((VALUE));
 static VALUE rb_deflate_s_deflate _((int, VALUE*, VALUE));
 static void do_deflate _((struct zstream*, VALUE, int));
 static VALUE rb_deflate_deflate _((int, VALUE*, VALUE));
@@ -89,6 +90,7 @@ static VALUE rb_deflate_flush _((int, VA
 static VALUE rb_deflate_params _((VALUE, VALUE, VALUE));
 static VALUE rb_deflate_set_dictionary _((VALUE, VALUE));
 
+static VALUE inflate_run _((VALUE));
 static VALUE rb_inflate_s_allocate _((VALUE));
 static VALUE rb_inflate_initialize _((int, VALUE*, VALUE));
 static VALUE rb_inflate_s_inflate _((VALUE, VALUE));
@@ -667,7 +669,7 @@ zstream_reset(z)
     zstream_reset_input(z);
 }
 
-static void
+static VALUE
 zstream_end(z)
     struct zstream *z;
 {
@@ -692,6 +694,7 @@ zstream_end(z)
 	raise_zlib_error(err, z->stream.msg);
     }
     z->flags = 0;
+    return Qnil;
 }
 
 static void
@@ -1152,26 +1155,31 @@ rb_deflate_initialize(argc, argv, obj)
  * Duplicates the deflate stream.
  */
 static VALUE
-rb_deflate_clone(obj)
-    VALUE obj;
+rb_deflate_init_copy(self, orig)
+    VALUE self, orig;
 {
-    struct zstream *z = get_zstream(obj);
-    struct zstream *z2;
-    VALUE clone;
+    struct zstream *z1 = get_zstream(self);
+    struct zstream *z2 = get_zstream(orig);
     int err;
 
-    clone = zstream_deflate_new(rb_class_of(obj));
-    Data_Get_Struct(clone, struct zstream, z2);
-
-    err = deflateCopy(&z2->stream, &z->stream);
+    err = deflateCopy(&z1->stream, &z2->stream);
     if (err != Z_OK) {
 	raise_zlib_error(err, 0);
     }
+    z1->flags = z2->flags;
 
-    z2->flags = z->flags;
-    CLONESETUP(clone, obj);
-    OBJ_INFECT(clone, obj);
-    return clone;
+    return self;
+}
+
+static VALUE
+deflate_run(args)
+    VALUE args;
+{
+    struct zstream *z = (struct zstream *)((VALUE *)args)[0];
+    VALUE src = ((VALUE *)args)[1];
+
+    zstream_run(z, RSTRING(src)->ptr, RSTRING(src)->len, Z_FINISH);
+    return zstream_detach_buffer(z);
 }
 
 /*
@@ -1201,7 +1209,7 @@ rb_deflate_s_deflate(argc, argv, klass)
     VALUE klass;
 {
     struct zstream z;
-    VALUE src, level, dst;
+    VALUE src, level, dst, args[2];
     int err, lev;
 
     rb_scan_args(argc, argv, "11", &src, &level);
@@ -1215,9 +1223,9 @@ rb_deflate_s_deflate(argc, argv, klass)
     }
     ZSTREAM_READY(&z);
 
-    zstream_run(&z, RSTRING(src)->ptr, RSTRING(src)->len, Z_FINISH);
-    dst = zstream_detach_buffer(&z);
-    zstream_end(&z);
+    args[0] = (VALUE)&z;
+    args[1] = src;
+    dst = rb_ensure(deflate_run, (VALUE)args, zstream_end, (VALUE)&z);
 
     OBJ_INFECT(dst, src);
     return dst;
@@ -1239,6 +1247,18 @@ do_deflate(z, src, flush)
     }
 }
 
+static VALUE
+inflate_run(args)
+    VALUE args;
+{
+    struct zstream *z = (struct zstream *)((VALUE *)args)[0];
+    VALUE src = ((VALUE *)args)[1];
+
+    zstream_run(z, RSTRING(src)->ptr, RSTRING(src)->len, Z_SYNC_FLUSH);
+    zstream_run(z, "", 0, Z_FINISH);  /* for checking errors */
+    return zstream_detach_buffer(z);
+}
+
 /*
  * call-seq: deflate(string[, flush])
  *
@@ -1452,7 +1472,7 @@ rb_inflate_s_inflate(obj, src)
     VALUE obj, src;
 {
     struct zstream z;
-    VALUE dst;
+    VALUE dst, args[2];
     int err;
 
     StringValue(src);
@@ -1463,10 +1483,9 @@ rb_inflate_s_inflate(obj, src)
     }
     ZSTREAM_READY(&z);
 
-    zstream_run(&z, RSTRING(src)->ptr, RSTRING(src)->len, Z_SYNC_FLUSH);
-    zstream_run(&z, "", 0, Z_FINISH);  /* for checking errors */
-    dst = zstream_detach_buffer(&z);
-    zstream_end(&z);
+    args[0] = (VALUE)&z;
+    args[1] = src;
+    dst = rb_ensure(inflate_run, (VALUE)args, zstream_end, (VALUE)&z);
 
     OBJ_INFECT(dst, src);
     return dst;
@@ -3333,7 +3352,7 @@ void Init_zlib()
     rb_define_singleton_method(cDeflate, "deflate", rb_deflate_s_deflate, -1);
     rb_define_alloc_func(cDeflate, rb_deflate_s_allocate);
     rb_define_method(cDeflate, "initialize", rb_deflate_initialize, -1);
-    rb_define_method(cDeflate, "clone", rb_deflate_clone, 0);
+    rb_define_method(cDeflate, "initialize_copy", rb_deflate_init_copy, 0);
     rb_define_method(cDeflate, "deflate", rb_deflate_deflate, -1);
     rb_define_method(cDeflate, "<<", rb_deflate_addstr, 1);
     rb_define_method(cDeflate, "flush", rb_deflate_flush, -1);