@@ -8,12 +8,54 @@ static ID intern_source_eql, intern_severity_eql, intern_db_error_number_eql, in
8
8
static ID intern_new , intern_dup , intern_transpose_iconv_encoding , intern_local_offset , intern_gsub , intern_call ;
9
9
VALUE opt_escape_regex , opt_escape_dblquote ;
10
10
11
+ static void rb_tinytds_client_mark (void * ptr )
12
+ {
13
+ tinytds_client_wrapper * cwrap = (tinytds_client_wrapper * )ptr ;
14
+
15
+ if (cwrap ) {
16
+ rb_gc_mark (cwrap -> charset );
17
+ }
18
+ }
19
+
20
+ static void rb_tinytds_client_free (void * ptr )
21
+ {
22
+ tinytds_client_wrapper * cwrap = (tinytds_client_wrapper * )ptr ;
23
+
24
+ if (cwrap -> login ) {
25
+ dbloginfree (cwrap -> login );
26
+ }
27
+
28
+ if (cwrap -> client && !cwrap -> closed ) {
29
+ dbclose (cwrap -> client );
30
+ cwrap -> client = NULL ;
31
+ cwrap -> closed = 1 ;
32
+ cwrap -> userdata -> closed = 1 ;
33
+ }
34
+
35
+ xfree (cwrap -> userdata );
36
+ xfree (ptr );
37
+ }
38
+
39
+ static size_t tinytds_client_wrapper_size (const void * data )
40
+ {
41
+ return sizeof (tinytds_client_wrapper );
42
+ }
43
+
44
+ static const rb_data_type_t tinytds_client_wrapper_type = {
45
+ .wrap_struct_name = "tinytds_client_wrapper" ,
46
+ .function = {
47
+ .dmark = rb_tinytds_client_mark ,
48
+ .dfree = rb_tinytds_client_free ,
49
+ .dsize = tinytds_client_wrapper_size ,
50
+ },
51
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY ,
52
+ };
11
53
12
54
// Lib Macros
13
55
14
56
#define GET_CLIENT_WRAPPER (self ) \
15
57
tinytds_client_wrapper *cwrap; \
16
- Data_Get_Struct (self, tinytds_client_wrapper, cwrap)
58
+ TypedData_Get_Struct (self, tinytds_client_wrapper, &tinytds_client_wrapper_type , cwrap)
17
59
18
60
#define REQUIRE_OPEN_CLIENT (cwrap ) \
19
61
if (cwrap->closed || cwrap->userdata->closed) { \
@@ -244,39 +286,11 @@ static void rb_tinytds_client_reset_userdata(tinytds_client_userdata *userdata)
244
286
userdata -> nonblocking_errors_size = 0 ;
245
287
}
246
288
247
- static void rb_tinytds_client_mark (void * ptr )
248
- {
249
- tinytds_client_wrapper * cwrap = (tinytds_client_wrapper * )ptr ;
250
-
251
- if (cwrap ) {
252
- rb_gc_mark (cwrap -> charset );
253
- }
254
- }
255
-
256
- static void rb_tinytds_client_free (void * ptr )
257
- {
258
- tinytds_client_wrapper * cwrap = (tinytds_client_wrapper * )ptr ;
259
-
260
- if (cwrap -> login ) {
261
- dbloginfree (cwrap -> login );
262
- }
263
-
264
- if (cwrap -> client && !cwrap -> closed ) {
265
- dbclose (cwrap -> client );
266
- cwrap -> client = NULL ;
267
- cwrap -> closed = 1 ;
268
- cwrap -> userdata -> closed = 1 ;
269
- }
270
-
271
- xfree (cwrap -> userdata );
272
- xfree (ptr );
273
- }
274
-
275
289
static VALUE allocate (VALUE klass )
276
290
{
277
291
VALUE obj ;
278
292
tinytds_client_wrapper * cwrap ;
279
- obj = Data_Make_Struct (klass , tinytds_client_wrapper , rb_tinytds_client_mark , rb_tinytds_client_free , cwrap );
293
+ obj = TypedData_Make_Struct (klass , tinytds_client_wrapper , & tinytds_client_wrapper_type , cwrap );
280
294
cwrap -> closed = 1 ;
281
295
cwrap -> charset = Qnil ;
282
296
cwrap -> userdata = malloc (sizeof (tinytds_client_userdata ));
0 commit comments