@@ -8,12 +8,54 @@ static ID intern_source_eql, intern_severity_eql, intern_db_error_number_eql, in
88static ID intern_new , intern_dup , intern_transpose_iconv_encoding , intern_local_offset , intern_gsub , intern_call ;
99VALUE opt_escape_regex , opt_escape_dblquote ;
1010
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+ };
1153
1254// Lib Macros
1355
1456#define GET_CLIENT_WRAPPER (self ) \
1557 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)
1759
1860#define REQUIRE_OPEN_CLIENT (cwrap ) \
1961 if (cwrap->closed || cwrap->userdata->closed) { \
@@ -244,39 +286,11 @@ static void rb_tinytds_client_reset_userdata(tinytds_client_userdata *userdata)
244286 userdata -> nonblocking_errors_size = 0 ;
245287}
246288
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-
275289static VALUE allocate (VALUE klass )
276290{
277291 VALUE obj ;
278292 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 );
280294 cwrap -> closed = 1 ;
281295 cwrap -> charset = Qnil ;
282296 cwrap -> userdata = malloc (sizeof (tinytds_client_userdata ));
0 commit comments