summaryrefslogtreecommitdiffstats
path: root/qtruby/rubylib/qtruby/handlers.cpp
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-09-11 12:52:49 -0500
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-09-11 12:52:49 -0500
commitef7a60860d18e9be343b6fa5fe8d76fd080cead0 (patch)
tree640a3f17c9f0e1d133b05f1eb434d13057a78e8d /qtruby/rubylib/qtruby/handlers.cpp
parent46659f992d49f86347c43528a8705657b6896cb7 (diff)
downloadtdebindings-ef7a60860d18e9be343b6fa5fe8d76fd080cead0.tar.gz
tdebindings-ef7a60860d18e9be343b6fa5fe8d76fd080cead0.zip
Fix FTBS on ruby 1.9.x
Thanks to Darrell Anderson for the majority of the patch!
Diffstat (limited to 'qtruby/rubylib/qtruby/handlers.cpp')
-rw-r--r--qtruby/rubylib/qtruby/handlers.cpp46
1 files changed, 27 insertions, 19 deletions
diff --git a/qtruby/rubylib/qtruby/handlers.cpp b/qtruby/rubylib/qtruby/handlers.cpp
index 703c9d03..f3d0ddaf 100644
--- a/qtruby/rubylib/qtruby/handlers.cpp
+++ b/qtruby/rubylib/qtruby/handlers.cpp
@@ -47,6 +47,14 @@
#define HINT_BYTES HINT_BYTE
#endif
+#include "config.h"
+
+#ifndef HAVE_RUBY_1_9
+#define RARRAY_LEN(x) (RARRAY(x)->len)
+#define RSTRING_LEN(x) (RSTRING(x)->len)
+#define rb_str_catf_1 rb_str_catf
+#endif
+
extern "C" {
extern VALUE set_obj_info(const char * className, smokeruby_object * o);
extern VALUE qt_internal_module;
@@ -755,7 +763,7 @@ static void marshall_charP(Marshall *m) {
break;
}
- int len = RSTRING(rv)->len;
+ int len = RSTRING_LEN(rv);
char* mem = (char*) malloc(len+1);
memcpy(mem, StringValuePtr(rv), len);
mem[len] ='\0';
@@ -788,7 +796,7 @@ void marshall_ucharP(Marshall *m) {
m->item().s_voidp = 0;
break;
}
- int len = RSTRING(rv)->len;
+ int len = RSTRING_LEN(rv);
char* mem = (char*) malloc(len+1);
memcpy(mem, StringValuePtr(rv), len);
mem[len] ='\0';
@@ -824,7 +832,7 @@ qstringFromRString(VALUE rstring) {
TQString * s;
if (tqstrcmp(KCODE, "UTF8") == 0)
- s = new TQString(TQString::fromUtf8(StringValuePtr(rstring), RSTRING(rstring)->len));
+ s = new TQString(TQString::fromUtf8(StringValuePtr(rstring), RSTRING_LEN(rstring)));
else if (tqstrcmp(KCODE, "EUC") == 0)
s = new TQString(codec->toUnicode(StringValuePtr(rstring)));
else if (tqstrcmp(KCODE, "SJIS") == 0)
@@ -832,7 +840,7 @@ qstringFromRString(VALUE rstring) {
else if(tqstrcmp(KCODE, "NONE") == 0)
s = new TQString(TQString::fromLatin1(StringValuePtr(rstring)));
else
- s = new TQString(TQString::fromLocal8Bit(StringValuePtr(rstring), RSTRING(rstring)->len));
+ s = new TQString(TQString::fromLocal8Bit(StringValuePtr(rstring), RSTRING_LEN(rstring)));
return s;
}
@@ -944,7 +952,7 @@ static void marshall_TQCString(Marshall *m) {
s = new TQCString();
} else {
// Add 1 to the ruby string length to allow for a TQCString '\0' terminator
- s = new TQCString(StringValuePtr(*(m->var())), RSTRING(*(m->var()))->len + 1);
+ s = new TQCString(StringValuePtr(*(m->var())), RSTRING_LEN(*(m->var())) + 1);
}
m->item().s_voidp = s;
@@ -1007,7 +1015,7 @@ static void marshall_TQCOORD_array(Marshall *m) {
m->item().s_voidp = 0;
break;
}
- int count = RARRAY(av)->len;
+ int count = RARRAY_LEN(av);
TQCOORD *coord = new TQCOORD[count + 2];
for(long i = 0; i < count; i++) {
VALUE svp = rb_ary_entry(av, i);
@@ -1167,15 +1175,15 @@ static void marshall_charP_array(Marshall *m) {
VALUE arglist = *(m->var());
if (arglist == Qnil
|| TYPE(arglist) != T_ARRAY
- || RARRAY(arglist)->len == 0 )
+ || RARRAY_LEN(arglist) == 0 )
{
m->item().s_voidp = 0;
break;
}
- char **argv = new char *[RARRAY(arglist)->len + 1];
+ char **argv = new char *[RARRAY_LEN(arglist) + 1];
long i;
- for(i = 0; i < RARRAY(arglist)->len; i++) {
+ for(i = 0; i < RARRAY_LEN(arglist); i++) {
VALUE item = rb_ary_entry(arglist, i);
char *s = StringValuePtr(item);
argv[i] = new char[strlen(s) + 1];
@@ -1207,7 +1215,7 @@ void marshall_TQStringList(Marshall *m) {
break;
}
- int count = RARRAY(list)->len;
+ int count = RARRAY_LEN(list);
TQStringList *stringlist = new TQStringList;
for(long i = 0; i < count; i++) {
@@ -1269,7 +1277,7 @@ void marshall_TQStrList(Marshall *m) {
break;
}
- int count = RARRAY(list)->len;
+ int count = RARRAY_LEN(list);
TQStrList *stringlist = new TQStrList;
for(long i = 0; i < count; i++) {
@@ -1278,7 +1286,7 @@ void marshall_TQStrList(Marshall *m) {
stringlist->append(TQString());
continue;
}
- stringlist->append(TQString::fromUtf8(StringValuePtr(item), RSTRING(item)->len));
+ stringlist->append(TQString::fromUtf8(StringValuePtr(item), RSTRING_LEN(item)));
}
m->item().s_voidp = stringlist;
@@ -1331,7 +1339,7 @@ void marshall_ItemList(Marshall *m) {
m->item().s_voidp = 0;
break;
}
- int count = RARRAY(list)->len;
+ int count = RARRAY_LEN(list);
ItemList *cpplist = new ItemList;
long i;
for(i = 0; i < count; i++) {
@@ -1421,7 +1429,7 @@ void marshall_TQValueListInt(Marshall *m) {
m->item().s_voidp = 0;
break;
}
- int count = RARRAY(list)->len;
+ int count = RARRAY_LEN(list);
TQValueList<int> *valuelist = new TQValueList<int>;
long i;
for(i = 0; i < count; i++) {
@@ -1513,7 +1521,7 @@ void marshall_TQMapTQStringTQString(Marshall *m) {
// Convert the ruby hash to an array of key/value arrays
VALUE temp = rb_funcall(hash, rb_intern("to_a"), 0);
- for (long i = 0; i < RARRAY(temp)->len; i++) {
+ for (long i = 0; i < RARRAY_LEN(temp); i++) {
VALUE key = rb_ary_entry(rb_ary_entry(temp, i), 0);
VALUE value = rb_ary_entry(rb_ary_entry(temp, i), 1);
(*map)[TQString(StringValuePtr(key))] = TQString(StringValuePtr(value));
@@ -1569,7 +1577,7 @@ void marshall_TQMapTQStringTQVariant(Marshall *m) {
// Convert the ruby hash to an array of key/value arrays
VALUE temp = rb_funcall(hash, rb_intern("to_a"), 0);
- for (long i = 0; i < RARRAY(temp)->len; i++) {
+ for (long i = 0; i < RARRAY_LEN(temp); i++) {
VALUE key = rb_ary_entry(rb_ary_entry(temp, i), 0);
VALUE value = rb_ary_entry(rb_ary_entry(temp, i), 1);
@@ -1673,7 +1681,7 @@ void marshall_TQRgb_array(Marshall *m) {
m->item().s_voidp = 0;
break;
}
- int count = RARRAY(list)->len;
+ int count = RARRAY_LEN(list);
TQRgb *rgb = new TQRgb[count + 2];
long i;
for(i = 0; i < count; i++) {
@@ -1702,7 +1710,7 @@ void marshall_TQPairintint(Marshall *m) {
case Marshall::FromVALUE:
{
VALUE list = *(m->var());
- if (TYPE(list) != T_ARRAY || RARRAY(list)->len != 2) {
+ if (TYPE(list) != T_ARRAY || RARRAY_LEN(list) != 2) {
m->item().s_voidp = 0;
break;
}
@@ -1770,7 +1778,7 @@ void marshall_ValueItemList(Marshall *m) {
m->item().s_voidp = 0;
break;
}
- int count = RARRAY(list)->len;
+ int count = RARRAY_LEN(list);
ItemList *cpplist = new ItemList;
long i;
for(i = 0; i < count; i++) {