Skip to content

Commit f2f6d29

Browse files
committed
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)
1 parent ad4d8a1 commit f2f6d29

File tree

2 files changed

+97
-11
lines changed

2 files changed

+97
-11
lines changed

src/if_ruby.c

Lines changed: 95 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@
103103
#endif
104104
#if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 22
105105
# define rb_gc_writebarrier_unprotect rb_gc_writebarrier_unprotect_stub
106-
# define rb_check_type rb_check_type_stub
107106
#endif
108107

109108
#include <ruby.h>
@@ -122,6 +121,15 @@
122121
# define __OPENTRANSPORTPROVIDERS__
123122
#endif
124123

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
131+
#endif
132+
125133
/*
126134
* Backward compatibility for Ruby 1.8 and earlier.
127135
* Ruby 1.9 does not provide STR2CSTR, instead StringValuePtr is provided.
@@ -184,11 +192,20 @@ static void ruby_vim_init(void);
184192
*/
185193
# define rb_assoc_new dll_rb_assoc_new
186194
# define rb_cObject (*dll_rb_cObject)
187-
# if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER < 22
188-
# define rb_check_type dll_rb_check_type
195+
# define rb_check_type dll_rb_check_type
196+
# ifdef USE_TYPEDDATA
197+
# define rb_check_typeddata dll_rb_check_typeddata
189198
# endif
190199
# 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
192209
# define rb_define_class_under dll_rb_define_class_under
193210
# define rb_define_const dll_rb_define_const
194211
# define rb_define_global_function dll_rb_define_global_function
@@ -297,8 +314,19 @@ static VALUE *dll_rb_cObject;
297314
VALUE *dll_rb_cSymbol;
298315
VALUE *dll_rb_cTrueClass;
299316
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
300320
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
301328
static VALUE (*dll_rb_data_object_alloc) (VALUE, void*, RUBY_DATA_FUNC, RUBY_DATA_FUNC);
329+
# endif
302330
static VALUE (*dll_rb_define_class_under) (VALUE, const char*, VALUE);
303331
static void (*dll_rb_define_const) (VALUE,const char*,VALUE);
304332
static void (*dll_rb_define_global_function) (const char*,VALUE(*)(),int);
@@ -451,13 +479,6 @@ void rb_gc_writebarrier_unprotect_stub(VALUE obj)
451479
# endif
452480
# endif
453481

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-
461482
static HINSTANCE hinstRuby = NULL; /* Instance of ruby.dll */
462483

463484
/*
@@ -480,8 +501,19 @@ static struct
480501
{"rb_cSymbol", (RUBY_PROC*)&dll_rb_cSymbol},
481502
{"rb_cTrueClass", (RUBY_PROC*)&dll_rb_cTrueClass},
482503
{"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
483507
{"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
484515
{"rb_data_object_alloc", (RUBY_PROC*)&dll_rb_data_object_alloc},
516+
# endif
485517
{"rb_define_class_under", (RUBY_PROC*)&dll_rb_define_class_under},
486518
{"rb_define_const", (RUBY_PROC*)&dll_rb_define_const},
487519
{"rb_define_global_function", (RUBY_PROC*)&dll_rb_define_global_function},
@@ -1026,6 +1058,24 @@ static VALUE vim_evaluate(VALUE self UNUSED, VALUE str)
10261058
#endif
10271059
}
10281060

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+
10291079
static VALUE buffer_new(buf_T *buf)
10301080
{
10311081
if (buf->b_ruby_ref)
@@ -1034,7 +1084,11 @@ static VALUE buffer_new(buf_T *buf)
10341084
}
10351085
else
10361086
{
1087+
#ifdef USE_TYPEDDATA
1088+
VALUE obj = TypedData_Wrap_Struct(cBuffer, &buffer_type, buf);
1089+
#else
10371090
VALUE obj = Data_Wrap_Struct(cBuffer, 0, 0, buf);
1091+
#endif
10381092
buf->b_ruby_ref = (void *) obj;
10391093
rb_hash_aset(objtbl, rb_obj_id(obj), obj);
10401094
return obj;
@@ -1045,7 +1099,11 @@ static buf_T *get_buf(VALUE obj)
10451099
{
10461100
buf_T *buf;
10471101

1102+
#ifdef USE_TYPEDDATA
1103+
TypedData_Get_Struct(obj, buf_T, &buffer_type, buf);
1104+
#else
10481105
Data_Get_Struct(obj, buf_T, buf);
1106+
#endif
10491107
if (buf == NULL)
10501108
rb_raise(eDeletedBufferError, "attempt to refer to deleted buffer");
10511109
return buf;
@@ -1242,6 +1300,24 @@ static VALUE buffer_append(VALUE self, VALUE num, VALUE str)
12421300
return str;
12431301
}
12441302

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+
12451321
static VALUE window_new(win_T *win)
12461322
{
12471323
if (win->w_ruby_ref)
@@ -1250,7 +1326,11 @@ static VALUE window_new(win_T *win)
12501326
}
12511327
else
12521328
{
1329+
#ifdef USE_TYPEDDATA
1330+
VALUE obj = TypedData_Wrap_Struct(cVimWindow, &window_type, win);
1331+
#else
12531332
VALUE obj = Data_Wrap_Struct(cVimWindow, 0, 0, win);
1333+
#endif
12541334
win->w_ruby_ref = (void *) obj;
12551335
rb_hash_aset(objtbl, rb_obj_id(obj), obj);
12561336
return obj;
@@ -1261,7 +1341,11 @@ static win_T *get_win(VALUE obj)
12611341
{
12621342
win_T *win;
12631343

1344+
#ifdef USE_TYPEDDATA
1345+
TypedData_Get_Struct(obj, win_T, &window_type, win);
1346+
#else
12641347
Data_Get_Struct(obj, win_T, win);
1348+
#endif
12651349
if (win == NULL)
12661350
rb_raise(eDeletedWindowError, "attempt to refer to deleted window");
12671351
return win;

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,8 @@ static char *(features[]) =
741741

742742
static int included_patches[] =
743743
{ /* Add new patch number below this line */
744+
/**/
745+
985,
744746
/**/
745747
984,
746748
/**/

0 commit comments

Comments
 (0)