@@ -172,6 +172,30 @@ Statics
172
172
173
173
VALUE Intern_http_conn;
174
174
175
+ /* *******************
176
+ t_get_http_connection
177
+ ********************/
178
+
179
+ static RubyHttpConnection_t *t_get_http_connection (VALUE self)
180
+ {
181
+ RubyHttpConnection_t *hc;
182
+ VALUE ivar = rb_ivar_get (self, Intern_http_conn);
183
+ if (ivar != Qnil)
184
+ Data_Get_Struct (ivar, RubyHttpConnection_t, hc);
185
+ else
186
+ hc = NULL ;
187
+ return hc;
188
+ }
189
+
190
+ /* *******************
191
+ t_delete_http_connection
192
+ ********************/
193
+
194
+ void t_delete_http_connection (RubyHttpConnection_t *hc)
195
+ {
196
+ delete hc;
197
+ }
198
+
175
199
/* **********
176
200
t_post_init
177
201
***********/
@@ -182,7 +206,12 @@ static VALUE t_post_init (VALUE self)
182
206
if (!hc)
183
207
throw std::runtime_error (" no http-connection object" );
184
208
185
- rb_ivar_set (self, Intern_http_conn, LONG2NUM ((long )hc));
209
+ /*
210
+ HACK: http_connection should be given an actual type. No one should
211
+ be touching it from inside ruby, but still
212
+ */
213
+ VALUE http_connection = Data_Wrap_Struct (CLASS_OF (self), 0 , t_delete_http_connection, hc);
214
+ rb_ivar_set (self, Intern_http_conn, http_connection);
186
215
return Qnil;
187
216
}
188
217
@@ -194,7 +223,7 @@ t_receive_data
194
223
static VALUE t_receive_data (VALUE self, VALUE data)
195
224
{
196
225
int length = NUM2INT (rb_funcall (data, rb_intern (" length" ), 0 ));
197
- RubyHttpConnection_t *hc = (RubyHttpConnection_t*)( NUM2LONG ( rb_ivar_get ( self, Intern_http_conn)) );
226
+ RubyHttpConnection_t *hc = t_get_http_connection ( self);
198
227
if (hc)
199
228
hc->ConsumeData (StringValuePtr (data), length);
200
229
return Qnil;
@@ -216,9 +245,6 @@ t_unbind
216
245
217
246
static VALUE t_unbind (VALUE self)
218
247
{
219
- RubyHttpConnection_t *hc = (RubyHttpConnection_t*)(NUM2LONG (rb_ivar_get (self, Intern_http_conn)));
220
- if (hc)
221
- delete hc;
222
248
return Qnil;
223
249
}
224
250
@@ -240,7 +266,7 @@ t_no_environment_strings
240
266
241
267
static VALUE t_no_environment_strings (VALUE self)
242
268
{
243
- RubyHttpConnection_t *hc = (RubyHttpConnection_t*)( NUM2LONG ( rb_ivar_get ( self, Intern_http_conn)) );
269
+ RubyHttpConnection_t *hc = t_get_http_connection ( self);
244
270
if (hc)
245
271
hc->SetNoEnvironmentStrings ();
246
272
return Qnil;
@@ -252,7 +278,7 @@ t_dont_accumulate_post
252
278
253
279
static VALUE t_dont_accumulate_post (VALUE self)
254
280
{
255
- RubyHttpConnection_t *hc = (RubyHttpConnection_t*)( NUM2LONG ( rb_ivar_get ( self, Intern_http_conn)) );
281
+ RubyHttpConnection_t *hc = t_get_http_connection ( self);
256
282
if (hc)
257
283
hc->SetDontAccumulatePost ();
258
284
return Qnil;
0 commit comments