Mercurial > vim
comparison src/if_ruby.c @ 15454:1d2b5c016f17 v8.1.0735
patch 8.1.0735: cannot handle binary data
commit https://github.com/vim/vim/commit/6e5ea8d2a995b32bbc5972edc4f827b959f2702f
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jan 12 22:47:31 2019 +0100
patch 8.1.0735: cannot handle binary data
Problem: Cannot handle binary data.
Solution: Add the Blob type. (Yasuhiro Matsumoto, closes https://github.com/vim/vim/issues/3638)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 12 Jan 2019 23:00:06 +0100 |
parents | 0807e2dbbab6 |
children | 55ccc2d353bd |
comparison
equal
deleted
inserted
replaced
15453:cdee6e827112 | 15454:1d2b5c016f17 |
---|---|
49 # endif | 49 # endif |
50 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 20 | 50 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 20 |
51 # define rb_cFloat (*dll_rb_cFloat) | 51 # define rb_cFloat (*dll_rb_cFloat) |
52 # endif | 52 # endif |
53 # define rb_cNilClass (*dll_rb_cNilClass) | 53 # define rb_cNilClass (*dll_rb_cNilClass) |
54 # define rb_cString (*dll_rb_cString) | |
54 # define rb_cSymbol (*dll_rb_cSymbol) | 55 # define rb_cSymbol (*dll_rb_cSymbol) |
55 # define rb_cTrueClass (*dll_rb_cTrueClass) | 56 # define rb_cTrueClass (*dll_rb_cTrueClass) |
56 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18 | 57 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18 |
57 /* | 58 /* |
58 * On ver 1.8, all Ruby functions are exported with "__declspec(dllimport)" | 59 * On ver 1.8, all Ruby functions are exported with "__declspec(dllimport)" |
217 /* | 218 /* |
218 * Wrapper defines | 219 * Wrapper defines |
219 */ | 220 */ |
220 # define rb_assoc_new dll_rb_assoc_new | 221 # define rb_assoc_new dll_rb_assoc_new |
221 # define rb_cObject (*dll_rb_cObject) | 222 # define rb_cObject (*dll_rb_cObject) |
223 # define rb_class_new_instance dll_rb_class_new_instance | |
222 # define rb_check_type dll_rb_check_type | 224 # define rb_check_type dll_rb_check_type |
223 # ifdef USE_TYPEDDATA | 225 # ifdef USE_TYPEDDATA |
224 # define rb_check_typeddata dll_rb_check_typeddata | 226 # define rb_check_typeddata dll_rb_check_typeddata |
225 # endif | 227 # endif |
226 # define rb_class_path dll_rb_class_path | 228 # define rb_class_path dll_rb_class_path |
363 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 20 | 365 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 20 |
364 VALUE *dll_rb_cFloat; | 366 VALUE *dll_rb_cFloat; |
365 # endif | 367 # endif |
366 VALUE *dll_rb_cNilClass; | 368 VALUE *dll_rb_cNilClass; |
367 static VALUE *dll_rb_cObject; | 369 static VALUE *dll_rb_cObject; |
370 VALUE *dll_rb_cString; | |
368 VALUE *dll_rb_cSymbol; | 371 VALUE *dll_rb_cSymbol; |
369 VALUE *dll_rb_cTrueClass; | 372 VALUE *dll_rb_cTrueClass; |
373 static VALUE (*dll_rb_class_new_instance) (int,VALUE*,VALUE); | |
370 static void (*dll_rb_check_type) (VALUE,int); | 374 static void (*dll_rb_check_type) (VALUE,int); |
371 # ifdef USE_TYPEDDATA | 375 # ifdef USE_TYPEDDATA |
372 static void *(*dll_rb_check_typeddata) (VALUE,const rb_data_type_t *); | 376 static void *(*dll_rb_check_typeddata) (VALUE,const rb_data_type_t *); |
373 # endif | 377 # endif |
374 static VALUE (*dll_rb_class_path) (VALUE); | 378 static VALUE (*dll_rb_class_path) (VALUE); |
577 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 20 | 581 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 20 |
578 {"rb_cFloat", (RUBY_PROC*)&dll_rb_cFloat}, | 582 {"rb_cFloat", (RUBY_PROC*)&dll_rb_cFloat}, |
579 # endif | 583 # endif |
580 {"rb_cNilClass", (RUBY_PROC*)&dll_rb_cNilClass}, | 584 {"rb_cNilClass", (RUBY_PROC*)&dll_rb_cNilClass}, |
581 {"rb_cObject", (RUBY_PROC*)&dll_rb_cObject}, | 585 {"rb_cObject", (RUBY_PROC*)&dll_rb_cObject}, |
586 {"rb_cString", (RUBY_PROC*)&dll_rb_cString}, | |
582 {"rb_cSymbol", (RUBY_PROC*)&dll_rb_cSymbol}, | 587 {"rb_cSymbol", (RUBY_PROC*)&dll_rb_cSymbol}, |
583 {"rb_cTrueClass", (RUBY_PROC*)&dll_rb_cTrueClass}, | 588 {"rb_cTrueClass", (RUBY_PROC*)&dll_rb_cTrueClass}, |
589 {"rb_class_new_instance", (RUBY_PROC*)&dll_rb_class_new_instance}, | |
584 {"rb_check_type", (RUBY_PROC*)&dll_rb_check_type}, | 590 {"rb_check_type", (RUBY_PROC*)&dll_rb_check_type}, |
585 # ifdef USE_TYPEDDATA | 591 # ifdef USE_TYPEDDATA |
586 {"rb_check_typeddata", (RUBY_PROC*)&dll_rb_check_typeddata}, | 592 {"rb_check_typeddata", (RUBY_PROC*)&dll_rb_check_typeddata}, |
587 # endif | 593 # endif |
588 {"rb_class_path", (RUBY_PROC*)&dll_rb_class_path}, | 594 {"rb_class_path", (RUBY_PROC*)&dll_rb_class_path}, |
1162 { | 1168 { |
1163 if (tv->vval.v_number == VVAL_TRUE) | 1169 if (tv->vval.v_number == VVAL_TRUE) |
1164 result = Qtrue; | 1170 result = Qtrue; |
1165 else if (tv->vval.v_number == VVAL_FALSE) | 1171 else if (tv->vval.v_number == VVAL_FALSE) |
1166 result = Qfalse; | 1172 result = Qfalse; |
1167 } /* else return Qnil; */ | 1173 } |
1174 else if (tv->v_type == VAR_BLOB) | |
1175 { | |
1176 result = rb_str_new(tv->vval.v_blob->bv_ga.ga_data, | |
1177 tv->vval.v_blob->bv_ga.ga_len); | |
1178 } | |
1179 /* else return Qnil; */ | |
1168 | 1180 |
1169 return result; | 1181 return result; |
1170 } | 1182 } |
1171 #endif | 1183 #endif |
1172 | 1184 |
1238 Data_Get_Struct(obj, buf_T, buf); | 1250 Data_Get_Struct(obj, buf_T, buf); |
1239 #endif | 1251 #endif |
1240 if (buf == NULL) | 1252 if (buf == NULL) |
1241 rb_raise(eDeletedBufferError, "attempt to refer to deleted buffer"); | 1253 rb_raise(eDeletedBufferError, "attempt to refer to deleted buffer"); |
1242 return buf; | 1254 return buf; |
1255 } | |
1256 | |
1257 static VALUE vim_blob(VALUE self UNUSED, VALUE str) | |
1258 { | |
1259 VALUE result = rb_str_new("0z", 2); | |
1260 char buf[4]; | |
1261 int i; | |
1262 for (i = 0; i < RSTRING_LEN(str); i++) | |
1263 { | |
1264 sprintf(buf, "%02X", RSTRING_PTR(str)[i]); | |
1265 rb_str_concat(result, rb_str_new_cstr(buf)); | |
1266 } | |
1267 return result; | |
1243 } | 1268 } |
1244 | 1269 |
1245 static VALUE buffer_s_current(void) | 1270 static VALUE buffer_s_current(void) |
1246 { | 1271 { |
1247 return buffer_new(curbuf); | 1272 return buffer_new(curbuf); |
1660 rb_define_const(mVIM, "VERSION_LONG_DATE", rb_str_new2(VIM_VERSION_LONG_DATE)); | 1685 rb_define_const(mVIM, "VERSION_LONG_DATE", rb_str_new2(VIM_VERSION_LONG_DATE)); |
1661 rb_define_module_function(mVIM, "message", vim_message, 1); | 1686 rb_define_module_function(mVIM, "message", vim_message, 1); |
1662 rb_define_module_function(mVIM, "set_option", vim_set_option, 1); | 1687 rb_define_module_function(mVIM, "set_option", vim_set_option, 1); |
1663 rb_define_module_function(mVIM, "command", vim_command, 1); | 1688 rb_define_module_function(mVIM, "command", vim_command, 1); |
1664 rb_define_module_function(mVIM, "evaluate", vim_evaluate, 1); | 1689 rb_define_module_function(mVIM, "evaluate", vim_evaluate, 1); |
1690 rb_define_module_function(mVIM, "blob", vim_blob, 1); | |
1665 | 1691 |
1666 eDeletedBufferError = rb_define_class_under(mVIM, "DeletedBufferError", | 1692 eDeletedBufferError = rb_define_class_under(mVIM, "DeletedBufferError", |
1667 rb_eStandardError); | 1693 rb_eStandardError); |
1668 eDeletedWindowError = rb_define_class_under(mVIM, "DeletedWindowError", | 1694 eDeletedWindowError = rb_define_class_under(mVIM, "DeletedWindowError", |
1669 rb_eStandardError); | 1695 rb_eStandardError); |