summaryrefslogtreecommitdiff
path: root/ruby
diff options
context:
space:
mode:
authorfrsyuki <frsyuki@users.sourceforge.jp>2010-08-31 07:00:19 +0900
committerfrsyuki <frsyuki@users.sourceforge.jp>2010-08-31 07:00:19 +0900
commit09b47cc536ebd951c231fd5e09b4382a25b98020 (patch)
tree68e3fc9d921834b429469306ac4b8947410b6b8b /ruby
parentb5c78de2ddf82783a6f80a199b68927d1a1747ca (diff)
downloadmsgpack-python-09b47cc536ebd951c231fd5e09b4382a25b98020.tar.gz
ruby: fixes compatibility with ruby-1.8.5
Diffstat (limited to 'ruby')
-rw-r--r--ruby/compat.h (renamed from ruby/encoding.h)35
-rw-r--r--ruby/pack.c6
-rw-r--r--ruby/rbinit.c6
-rw-r--r--ruby/test/test_pack_unpack.rb12
-rw-r--r--ruby/unpack.c12
5 files changed, 48 insertions, 23 deletions
diff --git a/ruby/encoding.h b/ruby/compat.h
index 2ad3fd7..98c8881 100644
--- a/ruby/encoding.h
+++ b/ruby/compat.h
@@ -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
+
+
+/* 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 /* encoding.h */
+#endif /* compat.h */
diff --git a/ruby/pack.c b/ruby/pack.c
index 35878c7..49b69fc 100644
--- a/ruby/pack.c
+++ b/ruby/pack.c
@@ -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);
diff --git a/ruby/rbinit.c b/ruby/rbinit.c
index 4678159..1d1cbc6 100644
--- a/ruby/rbinit.c
+++ b/ruby/rbinit.c
@@ -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();
diff --git a/ruby/test/test_pack_unpack.rb b/ruby/test/test_pack_unpack.rb
index 25bde81..545e593 100644
--- a/ruby/test/test_pack_unpack.rb
+++ b/ruby/test/test_pack_unpack.rb
@@ -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
diff --git a/ruby/unpack.c b/ruby/unpack.c
index 3c5e350..2d10e75 100644
--- a/ruby/unpack.c
+++ b/ruby/unpack.c
@@ -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)