Mercurial > vim
comparison src/if_ruby.c @ 7360:b20095ba6fc2 v7.4.985
commit https://github.com/vim/vim/commit/f2f6d297966ec0e357640b71a238e51afcaba6cc
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Dec 28 20:57:10 2015 +0100
patch 7.4.985
Problem: Can't build with Ruby 2.3.0.
Solution: Use the new TypedData_XXX macro family instead of Data_XXX. Use
TypedData. (Ken Takata)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Mon, 28 Dec 2015 21:00:05 +0100 |
parents | 2a95fa0a07b5 |
children | fe2f6b92d806 |
comparison
equal
deleted
inserted
replaced
7359:127381f2dcb8 | 7360:b20095ba6fc2 |
---|---|
101 * rb_gc_writebarrier_unprotect_promoted if USE_RGENGC */ | 101 * rb_gc_writebarrier_unprotect_promoted if USE_RGENGC */ |
102 # define rb_gc_writebarrier_unprotect_promoted rb_gc_writebarrier_unprotect_promoted_stub | 102 # define rb_gc_writebarrier_unprotect_promoted rb_gc_writebarrier_unprotect_promoted_stub |
103 #endif | 103 #endif |
104 #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 22 | 104 #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 22 |
105 # define rb_gc_writebarrier_unprotect rb_gc_writebarrier_unprotect_stub | 105 # define rb_gc_writebarrier_unprotect rb_gc_writebarrier_unprotect_stub |
106 # define rb_check_type rb_check_type_stub | |
107 #endif | 106 #endif |
108 | 107 |
109 #include <ruby.h> | 108 #include <ruby.h> |
110 #ifdef RUBY19_OR_LATER | 109 #ifdef RUBY19_OR_LATER |
111 # include <ruby/encoding.h> | 110 # include <ruby/encoding.h> |
118 /* T_DATA defined both by Ruby and Mac header files, hack around it... */ | 117 /* T_DATA defined both by Ruby and Mac header files, hack around it... */ |
119 #if defined(MACOS_X_UNIX) || defined(macintosh) | 118 #if defined(MACOS_X_UNIX) || defined(macintosh) |
120 # define __OPENTRANSPORT__ | 119 # define __OPENTRANSPORT__ |
121 # define __OPENTRANSPORTPROTOCOL__ | 120 # define __OPENTRANSPORTPROTOCOL__ |
122 # define __OPENTRANSPORTPROVIDERS__ | 121 # define __OPENTRANSPORTPROVIDERS__ |
122 #endif | |
123 | |
124 /* | |
125 * The TypedData_XXX macro family can be used since Ruby 1.9.2, and | |
126 * the old Data_XXX macro family was deprecated on Ruby 2.2. | |
127 * Use TypedData_XXX if available. | |
128 */ | |
129 #ifdef TypedData_Wrap_Struct | |
130 # define USE_TYPEDDATA 1 | |
123 #endif | 131 #endif |
124 | 132 |
125 /* | 133 /* |
126 * Backward compatibility for Ruby 1.8 and earlier. | 134 * Backward compatibility for Ruby 1.8 and earlier. |
127 * Ruby 1.9 does not provide STR2CSTR, instead StringValuePtr is provided. | 135 * Ruby 1.9 does not provide STR2CSTR, instead StringValuePtr is provided. |
182 /* | 190 /* |
183 * Wrapper defines | 191 * Wrapper defines |
184 */ | 192 */ |
185 # define rb_assoc_new dll_rb_assoc_new | 193 # define rb_assoc_new dll_rb_assoc_new |
186 # define rb_cObject (*dll_rb_cObject) | 194 # define rb_cObject (*dll_rb_cObject) |
187 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER < 22 | 195 # define rb_check_type dll_rb_check_type |
188 # define rb_check_type dll_rb_check_type | 196 # ifdef USE_TYPEDDATA |
197 # define rb_check_typeddata dll_rb_check_typeddata | |
189 # endif | 198 # endif |
190 # define rb_class_path dll_rb_class_path | 199 # define rb_class_path dll_rb_class_path |
191 # define rb_data_object_alloc dll_rb_data_object_alloc | 200 # ifdef USE_TYPEDDATA |
201 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 23 | |
202 # define rb_data_typed_object_wrap dll_rb_data_typed_object_wrap | |
203 # else | |
204 # define rb_data_typed_object_alloc dll_rb_data_typed_object_alloc | |
205 # endif | |
206 # else | |
207 # define rb_data_object_alloc dll_rb_data_object_alloc | |
208 # endif | |
192 # define rb_define_class_under dll_rb_define_class_under | 209 # define rb_define_class_under dll_rb_define_class_under |
193 # define rb_define_const dll_rb_define_const | 210 # define rb_define_const dll_rb_define_const |
194 # define rb_define_global_function dll_rb_define_global_function | 211 # define rb_define_global_function dll_rb_define_global_function |
195 # define rb_define_method dll_rb_define_method | 212 # define rb_define_method dll_rb_define_method |
196 # define rb_define_module dll_rb_define_module | 213 # define rb_define_module dll_rb_define_module |
295 VALUE *dll_rb_cNilClass; | 312 VALUE *dll_rb_cNilClass; |
296 static VALUE *dll_rb_cObject; | 313 static VALUE *dll_rb_cObject; |
297 VALUE *dll_rb_cSymbol; | 314 VALUE *dll_rb_cSymbol; |
298 VALUE *dll_rb_cTrueClass; | 315 VALUE *dll_rb_cTrueClass; |
299 static void (*dll_rb_check_type) (VALUE,int); | 316 static void (*dll_rb_check_type) (VALUE,int); |
317 # ifdef USE_TYPEDDATA | |
318 static void *(*dll_rb_check_typeddata) (VALUE,const rb_data_type_t *); | |
319 # endif | |
300 static VALUE (*dll_rb_class_path) (VALUE); | 320 static VALUE (*dll_rb_class_path) (VALUE); |
321 # ifdef USE_TYPEDDATA | |
322 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 23 | |
323 static VALUE (*dll_rb_data_typed_object_wrap) (VALUE, void*, const rb_data_type_t *); | |
324 # else | |
325 static VALUE (*dll_rb_data_typed_object_alloc) (VALUE, void*, const rb_data_type_t *); | |
326 # endif | |
327 # else | |
301 static VALUE (*dll_rb_data_object_alloc) (VALUE, void*, RUBY_DATA_FUNC, RUBY_DATA_FUNC); | 328 static VALUE (*dll_rb_data_object_alloc) (VALUE, void*, RUBY_DATA_FUNC, RUBY_DATA_FUNC); |
329 # endif | |
302 static VALUE (*dll_rb_define_class_under) (VALUE, const char*, VALUE); | 330 static VALUE (*dll_rb_define_class_under) (VALUE, const char*, VALUE); |
303 static void (*dll_rb_define_const) (VALUE,const char*,VALUE); | 331 static void (*dll_rb_define_const) (VALUE,const char*,VALUE); |
304 static void (*dll_rb_define_global_function) (const char*,VALUE(*)(),int); | 332 static void (*dll_rb_define_global_function) (const char*,VALUE(*)(),int); |
305 static void (*dll_rb_define_method) (VALUE,const char*,VALUE(*)(),int); | 333 static void (*dll_rb_define_method) (VALUE,const char*,VALUE(*)(),int); |
306 static VALUE (*dll_rb_define_module) (const char*); | 334 static VALUE (*dll_rb_define_module) (const char*); |
449 dll_rb_gc_writebarrier_unprotect(obj); | 477 dll_rb_gc_writebarrier_unprotect(obj); |
450 } | 478 } |
451 # endif | 479 # endif |
452 # endif | 480 # endif |
453 | 481 |
454 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 22 | |
455 void rb_check_type_stub(VALUE v, int i) | |
456 { | |
457 dll_rb_check_type(v, i); | |
458 } | |
459 # endif | |
460 | |
461 static HINSTANCE hinstRuby = NULL; /* Instance of ruby.dll */ | 482 static HINSTANCE hinstRuby = NULL; /* Instance of ruby.dll */ |
462 | 483 |
463 /* | 484 /* |
464 * Table of name to function pointer of ruby. | 485 * Table of name to function pointer of ruby. |
465 */ | 486 */ |
478 {"rb_cNilClass", (RUBY_PROC*)&dll_rb_cNilClass}, | 499 {"rb_cNilClass", (RUBY_PROC*)&dll_rb_cNilClass}, |
479 {"rb_cObject", (RUBY_PROC*)&dll_rb_cObject}, | 500 {"rb_cObject", (RUBY_PROC*)&dll_rb_cObject}, |
480 {"rb_cSymbol", (RUBY_PROC*)&dll_rb_cSymbol}, | 501 {"rb_cSymbol", (RUBY_PROC*)&dll_rb_cSymbol}, |
481 {"rb_cTrueClass", (RUBY_PROC*)&dll_rb_cTrueClass}, | 502 {"rb_cTrueClass", (RUBY_PROC*)&dll_rb_cTrueClass}, |
482 {"rb_check_type", (RUBY_PROC*)&dll_rb_check_type}, | 503 {"rb_check_type", (RUBY_PROC*)&dll_rb_check_type}, |
504 # ifdef USE_TYPEDDATA | |
505 {"rb_check_typeddata", (RUBY_PROC*)&dll_rb_check_typeddata}, | |
506 # endif | |
483 {"rb_class_path", (RUBY_PROC*)&dll_rb_class_path}, | 507 {"rb_class_path", (RUBY_PROC*)&dll_rb_class_path}, |
508 # ifdef USE_TYPEDDATA | |
509 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 23 | |
510 {"rb_data_typed_object_wrap", (RUBY_PROC*)&dll_rb_data_typed_object_wrap}, | |
511 # else | |
512 {"rb_data_typed_object_alloc", (RUBY_PROC*)&dll_rb_data_typed_object_alloc}, | |
513 # endif | |
514 # else | |
484 {"rb_data_object_alloc", (RUBY_PROC*)&dll_rb_data_object_alloc}, | 515 {"rb_data_object_alloc", (RUBY_PROC*)&dll_rb_data_object_alloc}, |
516 # endif | |
485 {"rb_define_class_under", (RUBY_PROC*)&dll_rb_define_class_under}, | 517 {"rb_define_class_under", (RUBY_PROC*)&dll_rb_define_class_under}, |
486 {"rb_define_const", (RUBY_PROC*)&dll_rb_define_const}, | 518 {"rb_define_const", (RUBY_PROC*)&dll_rb_define_const}, |
487 {"rb_define_global_function", (RUBY_PROC*)&dll_rb_define_global_function}, | 519 {"rb_define_global_function", (RUBY_PROC*)&dll_rb_define_global_function}, |
488 {"rb_define_method", (RUBY_PROC*)&dll_rb_define_method}, | 520 {"rb_define_method", (RUBY_PROC*)&dll_rb_define_method}, |
489 {"rb_define_module", (RUBY_PROC*)&dll_rb_define_module}, | 521 {"rb_define_module", (RUBY_PROC*)&dll_rb_define_module}, |
1024 #else | 1056 #else |
1025 return Qnil; | 1057 return Qnil; |
1026 #endif | 1058 #endif |
1027 } | 1059 } |
1028 | 1060 |
1061 #ifdef USE_TYPEDDATA | |
1062 static size_t buffer_dsize(const void *buf); | |
1063 | |
1064 static const rb_data_type_t buffer_type = { | |
1065 "vim_buffer", | |
1066 {0, 0, buffer_dsize, {0, 0}}, | |
1067 0, 0, | |
1068 # ifdef RUBY_TYPED_FREE_IMMEDIATELY | |
1069 0, | |
1070 # endif | |
1071 }; | |
1072 | |
1073 static size_t buffer_dsize(const void *buf UNUSED) | |
1074 { | |
1075 return sizeof(buf_T); | |
1076 } | |
1077 #endif | |
1078 | |
1029 static VALUE buffer_new(buf_T *buf) | 1079 static VALUE buffer_new(buf_T *buf) |
1030 { | 1080 { |
1031 if (buf->b_ruby_ref) | 1081 if (buf->b_ruby_ref) |
1032 { | 1082 { |
1033 return (VALUE) buf->b_ruby_ref; | 1083 return (VALUE) buf->b_ruby_ref; |
1034 } | 1084 } |
1035 else | 1085 else |
1036 { | 1086 { |
1087 #ifdef USE_TYPEDDATA | |
1088 VALUE obj = TypedData_Wrap_Struct(cBuffer, &buffer_type, buf); | |
1089 #else | |
1037 VALUE obj = Data_Wrap_Struct(cBuffer, 0, 0, buf); | 1090 VALUE obj = Data_Wrap_Struct(cBuffer, 0, 0, buf); |
1091 #endif | |
1038 buf->b_ruby_ref = (void *) obj; | 1092 buf->b_ruby_ref = (void *) obj; |
1039 rb_hash_aset(objtbl, rb_obj_id(obj), obj); | 1093 rb_hash_aset(objtbl, rb_obj_id(obj), obj); |
1040 return obj; | 1094 return obj; |
1041 } | 1095 } |
1042 } | 1096 } |
1043 | 1097 |
1044 static buf_T *get_buf(VALUE obj) | 1098 static buf_T *get_buf(VALUE obj) |
1045 { | 1099 { |
1046 buf_T *buf; | 1100 buf_T *buf; |
1047 | 1101 |
1102 #ifdef USE_TYPEDDATA | |
1103 TypedData_Get_Struct(obj, buf_T, &buffer_type, buf); | |
1104 #else | |
1048 Data_Get_Struct(obj, buf_T, buf); | 1105 Data_Get_Struct(obj, buf_T, buf); |
1106 #endif | |
1049 if (buf == NULL) | 1107 if (buf == NULL) |
1050 rb_raise(eDeletedBufferError, "attempt to refer to deleted buffer"); | 1108 rb_raise(eDeletedBufferError, "attempt to refer to deleted buffer"); |
1051 return buf; | 1109 return buf; |
1052 } | 1110 } |
1053 | 1111 |
1240 rb_raise(rb_eIndexError, "line number %ld out of range", n); | 1298 rb_raise(rb_eIndexError, "line number %ld out of range", n); |
1241 } | 1299 } |
1242 return str; | 1300 return str; |
1243 } | 1301 } |
1244 | 1302 |
1303 #ifdef USE_TYPEDDATA | |
1304 static size_t window_dsize(const void *buf); | |
1305 | |
1306 static const rb_data_type_t window_type = { | |
1307 "vim_window", | |
1308 {0, 0, window_dsize, {0, 0}}, | |
1309 0, 0, | |
1310 # ifdef RUBY_TYPED_FREE_IMMEDIATELY | |
1311 0, | |
1312 # endif | |
1313 }; | |
1314 | |
1315 static size_t window_dsize(const void *win UNUSED) | |
1316 { | |
1317 return sizeof(win_T); | |
1318 } | |
1319 #endif | |
1320 | |
1245 static VALUE window_new(win_T *win) | 1321 static VALUE window_new(win_T *win) |
1246 { | 1322 { |
1247 if (win->w_ruby_ref) | 1323 if (win->w_ruby_ref) |
1248 { | 1324 { |
1249 return (VALUE) win->w_ruby_ref; | 1325 return (VALUE) win->w_ruby_ref; |
1250 } | 1326 } |
1251 else | 1327 else |
1252 { | 1328 { |
1329 #ifdef USE_TYPEDDATA | |
1330 VALUE obj = TypedData_Wrap_Struct(cVimWindow, &window_type, win); | |
1331 #else | |
1253 VALUE obj = Data_Wrap_Struct(cVimWindow, 0, 0, win); | 1332 VALUE obj = Data_Wrap_Struct(cVimWindow, 0, 0, win); |
1333 #endif | |
1254 win->w_ruby_ref = (void *) obj; | 1334 win->w_ruby_ref = (void *) obj; |
1255 rb_hash_aset(objtbl, rb_obj_id(obj), obj); | 1335 rb_hash_aset(objtbl, rb_obj_id(obj), obj); |
1256 return obj; | 1336 return obj; |
1257 } | 1337 } |
1258 } | 1338 } |
1259 | 1339 |
1260 static win_T *get_win(VALUE obj) | 1340 static win_T *get_win(VALUE obj) |
1261 { | 1341 { |
1262 win_T *win; | 1342 win_T *win; |
1263 | 1343 |
1344 #ifdef USE_TYPEDDATA | |
1345 TypedData_Get_Struct(obj, win_T, &window_type, win); | |
1346 #else | |
1264 Data_Get_Struct(obj, win_T, win); | 1347 Data_Get_Struct(obj, win_T, win); |
1348 #endif | |
1265 if (win == NULL) | 1349 if (win == NULL) |
1266 rb_raise(eDeletedWindowError, "attempt to refer to deleted window"); | 1350 rb_raise(eDeletedWindowError, "attempt to refer to deleted window"); |
1267 return win; | 1351 return win; |
1268 } | 1352 } |
1269 | 1353 |