mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-03-19 04:52:59 +01:00
ruby: fixes compatibility with ruby-1.8.5
This commit is contained in:
parent
b5c78de2dd
commit
09b47cc536
@ -15,19 +15,46 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef ENCODING_H__
|
||||
#define ENCODING_H__
|
||||
#ifndef COMPAT_H__
|
||||
#define COMPAT_H__
|
||||
|
||||
|
||||
#ifdef HAVE_RUBY_ENCODING_H
|
||||
#include "ruby/encoding.h"
|
||||
#define MSGPACK_RUBY_ENCODING
|
||||
#define COMPAT_HAVE_ENCODING
|
||||
extern int s_enc_utf8;
|
||||
extern int s_enc_ascii8bit;
|
||||
extern int s_enc_usascii;
|
||||
extern VALUE s_enc_utf8_value;
|
||||
#endif
|
||||
|
||||
#ifdef RUBY_VM
|
||||
#define COMPAT_RERAISE rb_exc_raise(rb_errinfo())
|
||||
#else
|
||||
#define COMPAT_RERAISE rb_exc_raise(ruby_errinfo)
|
||||
#endif
|
||||
|
||||
#endif /* encoding.h */
|
||||
|
||||
/* ruby 1.8.5 */
|
||||
#ifndef RSTRING_PTR
|
||||
#define RSTRING_PTR(s) (RSTRING(s)->ptr)
|
||||
#endif
|
||||
|
||||
/* ruby 1.8.5 */
|
||||
#ifndef RSTRING_LEN
|
||||
#define RSTRING_LEN(s) (RSTRING(s)->len)
|
||||
#endif
|
||||
|
||||
/* ruby 1.8.5 */
|
||||
#ifndef RARRAY_PTR
|
||||
#define RARRAY_PTR(s) (RARRAY(s)->ptr)
|
||||
#endif
|
||||
|
||||
/* ruby 1.8.5 */
|
||||
#ifndef RARRAY_LEN
|
||||
#define RARRAY_LEN(s) (RARRAY(s)->len)
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* compat.h */
|
||||
|
@ -16,7 +16,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "ruby.h"
|
||||
#include "encoding.h"
|
||||
#include "compat.h"
|
||||
|
||||
#include "msgpack/pack_define.h"
|
||||
|
||||
@ -169,7 +169,7 @@ static VALUE MessagePack_Float_to_msgpack(int argc, VALUE *argv, VALUE self)
|
||||
static VALUE MessagePack_String_to_msgpack(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
ARG_BUFFER(out, argc, argv);
|
||||
#ifdef MSGPACK_RUBY_ENCODING
|
||||
#ifdef COMPAT_HAVE_ENCODING
|
||||
int enc = ENCODING_GET(self);
|
||||
if(enc != s_enc_utf8 && enc != s_enc_ascii8bit && enc != s_enc_usascii) {
|
||||
if(!ENC_CODERANGE_ASCIIONLY(self)) {
|
||||
@ -193,7 +193,7 @@ static VALUE MessagePack_String_to_msgpack(int argc, VALUE *argv, VALUE self)
|
||||
*/
|
||||
static VALUE MessagePack_Symbol_to_msgpack(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
#ifdef MSGPACK_RUBY_ENCODING
|
||||
#ifdef COMPAT_HAVE_ENCODING
|
||||
return MessagePack_String_to_msgpack(argc, argv, rb_id2str(SYM2ID(self)));
|
||||
#else
|
||||
ARG_BUFFER(out, argc, argv);
|
||||
|
@ -17,11 +17,11 @@
|
||||
*/
|
||||
#include "pack.h"
|
||||
#include "unpack.h"
|
||||
#include "encoding.h"
|
||||
#include "compat.h"
|
||||
|
||||
static VALUE mMessagePack;
|
||||
|
||||
#ifdef MSGPACK_RUBY_ENCODING
|
||||
#ifdef COMPAT_HAVE_ENCODING
|
||||
int s_enc_utf8;
|
||||
int s_enc_ascii8bit;
|
||||
int s_enc_usascii;
|
||||
@ -54,7 +54,7 @@ void Init_msgpack(void)
|
||||
|
||||
rb_define_const(mMessagePack, "VERSION", rb_str_new2(MESSAGEPACK_VERSION));
|
||||
|
||||
#ifdef MSGPACK_RUBY_ENCODING
|
||||
#ifdef COMPAT_HAVE_ENCODING
|
||||
s_enc_ascii8bit = rb_ascii8bit_encindex();
|
||||
s_enc_utf8 = rb_utf8_encindex();
|
||||
s_enc_usascii = rb_usascii_encindex();
|
||||
|
@ -153,7 +153,8 @@ class MessagePackTestPackUnpack < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
it "{1=>1}" do
|
||||
match ({1=>1}), "\x81\x01\x01"
|
||||
obj = {1=>1}
|
||||
match obj, "\x81\x01\x01"
|
||||
end
|
||||
|
||||
it "1.0" do
|
||||
@ -165,15 +166,18 @@ class MessagePackTestPackUnpack < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
it "[0, 1, ..., 14]" do
|
||||
match (0..14).to_a, "\x9f\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e"
|
||||
obj = (0..14).to_a
|
||||
match obj, "\x9f\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e"
|
||||
end
|
||||
|
||||
it "[0, 1, ..., 15]" do
|
||||
match (0..15).to_a, "\xdc\x00\x10\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
|
||||
obj = (0..15).to_a
|
||||
match obj, "\xdc\x00\x10\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
|
||||
end
|
||||
|
||||
it "{}" do
|
||||
match ({}), "\x80"
|
||||
obj = {}
|
||||
match obj, "\x80"
|
||||
end
|
||||
|
||||
## FIXME
|
||||
|
@ -16,7 +16,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "ruby.h"
|
||||
#include "encoding.h"
|
||||
#include "compat.h"
|
||||
|
||||
#include "msgpack/unpack_define.h"
|
||||
|
||||
@ -132,7 +132,7 @@ static inline int template_callback_raw(unpack_user* u, const char* b, const cha
|
||||
} else {
|
||||
*o = rb_str_substr(u->source, p - b, l);
|
||||
}
|
||||
#ifdef MSGPACK_RUBY_ENCODING
|
||||
#ifdef COMPAT_HAVE_ENCODING
|
||||
ENCODING_SET(*o, s_enc_utf8);
|
||||
#endif
|
||||
return 0;
|
||||
@ -155,17 +155,11 @@ static inline int template_callback_raw(unpack_user* u, const char* b, const cha
|
||||
rb_raise(rb_eTypeError, "instance of String needed"); \
|
||||
}
|
||||
|
||||
#ifdef RUBY_VM
|
||||
#define RERAISE rb_exc_raise(rb_errinfo())
|
||||
#else
|
||||
#define RERAISE rb_exc_raise(ruby_errinfo)
|
||||
#endif
|
||||
|
||||
|
||||
static VALUE template_execute_rescue(VALUE nouse)
|
||||
{
|
||||
rb_gc_enable();
|
||||
RERAISE;
|
||||
COMPAT_RERAISE;
|
||||
}
|
||||
|
||||
static VALUE template_execute_do(VALUE argv)
|
||||
|
Loading…
x
Reference in New Issue
Block a user