commit c9175a2565a7b74c4b0761027eaf958819c4a126 Author: Richard Dale Date: Thu Dec 11 16:31:20 2008 +0000 * Make some changes from the patch at http://napalm.sf.cz/qt4-qtruby-ruby1.9.patch to make it easier to port qtruby to Ruby 1.9. Thanks to Davor Ocelic and Mr Napalm. CCMAIL: kde-bindings@kde.org svn path=/trunk/KDE/kdebindings/ruby/; revision=895746 diff --git a/qtruby/src/Qt.cpp b/qtruby/src/Qt.cpp index 7389fa5..f0ef78d 100644 --- a/qtruby/src/Qt.cpp +++ b/qtruby/src/Qt.cpp @@ -443,7 +443,7 @@ InvokeNativeSlot::cleanup() } -void rb_str_catf(VALUE self, const char *format, ...) +VALUE rb_str_catf(VALUE self, const char *format, ...) { #define CAT_BUFFER_SIZE 2048 static char p[CAT_BUFFER_SIZE]; @@ -453,6 +453,7 @@ static char p[CAT_BUFFER_SIZE]; p[CAT_BUFFER_SIZE - 1] = '\0'; rb_str_cat2(self, p); va_end(ap); + return self; } const char * diff --git a/qtruby/src/handlers.cpp b/qtruby/src/handlers.cpp index 8579229..2335338 100644 --- a/qtruby/src/handlers.cpp +++ b/qtruby/src/handlers.cpp @@ -896,7 +896,7 @@ qstringFromRString(VALUE rstring) { } if (qstrcmp(KCODE, "UTF8") == 0) - return new QString(QString::fromUtf8(StringValuePtr(rstring), RSTRING(rstring)->len)); + return new QString(QString::fromUtf8(StringValuePtr(rstring), RSTRING_LEN(rstring))); else if (qstrcmp(KCODE, "EUC") == 0) return new QString(codec->toUnicode(StringValuePtr(rstring))); else if (qstrcmp(KCODE, "SJIS") == 0) @@ -904,12 +904,12 @@ qstringFromRString(VALUE rstring) { else if(qstrcmp(KCODE, "NONE") == 0) return new QString(QString::fromLatin1(StringValuePtr(rstring))); - return new QString(QString::fromLocal8Bit(StringValuePtr(rstring), RSTRING(rstring)->len)); + return new QString(QString::fromLocal8Bit(StringValuePtr(rstring), RSTRING_LEN(rstring))); } QByteArray* qbytearrayFromRString(VALUE rstring) { - return new QByteArray(StringValuePtr(rstring), RSTRING(rstring)->len); + return new QByteArray(StringValuePtr(rstring), RSTRING_LEN(rstring)); } VALUE @@ -1234,7 +1234,7 @@ void marshall_QByteArrayList(Marshall *m) { stringlist->append(QByteArray()); continue; } - stringlist->append(QByteArray(StringValuePtr(item), RSTRING(item)->len)); + stringlist->append(QByteArray(StringValuePtr(item), RSTRING_LEN(item))); } m->item().s_voidp = stringlist; diff --git a/qtruby/src/qtruby.cpp b/qtruby/src/qtruby.cpp index f84c835..8a82504 100644 --- a/qtruby/src/qtruby.cpp +++ b/qtruby/src/qtruby.cpp @@ -253,7 +253,7 @@ inspect_qobject(VALUE self) // Start with # from the original inspect() call // Drop the closing '>' VALUE inspect_str = rb_call_super(0, 0); - rb_str_resize(inspect_str, RSTRING(inspect_str)->len - 1); + rb_str_resize(inspect_str, RSTRING_LEN(inspect_str) - 1); smokeruby_object * o = 0; Data_Get_Struct(self, smokeruby_object, o); @@ -296,7 +296,7 @@ pretty_print_qobject(VALUE self, VALUE pp) // Start with # // Drop the closing '>' VALUE inspect_str = rb_funcall(self, rb_intern("to_s"), 0, 0); - rb_str_resize(inspect_str, RSTRING(inspect_str)->len - 1); + rb_str_resize(inspect_str, RSTRING_LEN(inspect_str) - 1); rb_funcall(pp, rb_intern("text"), 1, inspect_str); rb_funcall(pp, rb_intern("breakable"), 0); @@ -311,7 +311,7 @@ pretty_print_qobject(VALUE self, VALUE pp) VALUE obj = getPointerObject(qobject->parent()); if (obj != Qnil) { VALUE parent_inspect_str = rb_funcall(obj, rb_intern("to_s"), 0, 0); - rb_str_resize(parent_inspect_str, RSTRING(parent_inspect_str)->len - 1); + rb_str_resize(parent_inspect_str, RSTRING_LEN(parent_inspect_str) - 1); parentInspectString = StringValuePtr(parent_inspect_str); } else { parentInspectString.sprintf("#<%s:0x0", qobject->parent()->metaObject()->className()); @@ -374,14 +374,14 @@ pretty_print_qobject(VALUE self, VALUE pp) static VALUE q_register_resource_data(VALUE /*self*/, VALUE version, VALUE tree_value, VALUE name_value, VALUE data_value) { - const unsigned char * tree = (const unsigned char *) malloc(RSTRING(tree_value)->len); - memcpy((void *) tree, (const void *) RSTRING(tree_value)->ptr, RSTRING(tree_value)->len); + const unsigned char * tree = (const unsigned char *) malloc(RSTRING_LEN(tree_value)); + memcpy((void *) tree, (const void *) RSTRING(tree_value)->ptr, RSTRING_LEN(tree_value)); - const unsigned char * name = (const unsigned char *) malloc(RSTRING(name_value)->len); - memcpy((void *) name, (const void *) RSTRING(name_value)->ptr, RSTRING(name_value)->len); + const unsigned char * name = (const unsigned char *) malloc(RSTRING_LEN(name_value)); + memcpy((void *) name, (const void *) RSTRING(name_value)->ptr, RSTRING_LEN(name_value)); - const unsigned char * data = (const unsigned char *) malloc(RSTRING(data_value)->len); - memcpy((void *) data, (const void *) RSTRING(data_value)->ptr, RSTRING(data_value)->len); + const unsigned char * data = (const unsigned char *) malloc(RSTRING_LEN(data_value)); + memcpy((void *) data, (const void *) RSTRING(data_value)->ptr, RSTRING_LEN(data_value)); return qRegisterResourceData(NUM2INT(version), tree, name, data) ? Qtrue : Qfalse; } @@ -389,14 +389,14 @@ q_register_resource_data(VALUE /*self*/, VALUE version, VALUE tree_value, VALUE static VALUE q_unregister_resource_data(VALUE /*self*/, VALUE version, VALUE tree_value, VALUE name_value, VALUE data_value) { - const unsigned char * tree = (const unsigned char *) malloc(RSTRING(tree_value)->len); - memcpy((void *) tree, (const void *) RSTRING(tree_value)->ptr, RSTRING(tree_value)->len); + const unsigned char * tree = (const unsigned char *) malloc(RSTRING_LEN(tree_value)); + memcpy((void *) tree, (const void *) RSTRING(tree_value)->ptr, RSTRING_LEN(tree_value)); - const unsigned char * name = (const unsigned char *) malloc(RSTRING(name_value)->len); - memcpy((void *) name, (const void *) RSTRING(name_value)->ptr, RSTRING(name_value)->len); + const unsigned char * name = (const unsigned char *) malloc(RSTRING_LEN(name_value)); + memcpy((void *) name, (const void *) RSTRING(name_value)->ptr, RSTRING_LEN(name_value)); - const unsigned char * data = (const unsigned char *) malloc(RSTRING(data_value)->len); - memcpy((void *) data, (const void *) RSTRING(data_value)->ptr, RSTRING(data_value)->len); + const unsigned char * data = (const unsigned char *) malloc(RSTRING_LEN(data_value)); + memcpy((void *) data, (const void *) RSTRING(data_value)->ptr, RSTRING_LEN(data_value)); return qUnregisterResourceData(NUM2INT(version), tree, name, data) ? Qtrue : Qfalse; } @@ -1813,12 +1813,12 @@ make_metaObject(VALUE /*self*/, VALUE obj, VALUE parentMeta, VALUE stringdata_va superdata = (QMetaObject *) p->ptr; } - char *stringdata = new char[RSTRING(stringdata_value)->len]; + char *stringdata = new char[RSTRING_LEN(stringdata_value)]; int count = RARRAY(data_value)->len; uint * data = new uint[count]; - memcpy( (void *) stringdata, RSTRING(stringdata_value)->ptr, RSTRING(stringdata_value)->len ); + memcpy( (void *) stringdata, RSTRING(stringdata_value)->ptr, RSTRING_LEN(stringdata_value) ); for (long i = 0; i < count; i++) { VALUE rv = rb_ary_entry(data_value, i); @@ -1890,7 +1890,7 @@ make_metaObject(VALUE /*self*/, VALUE obj, VALUE parentMeta, VALUE stringdata_va printf("\nqt_meta_stringdata:\n \""); int strlength = 0; - for (int j = 0; j < RSTRING(stringdata_value)->len; j++) { + for (int j = 0; j < RSTRING_LEN(stringdata_value); j++) { strlength++; if (meta->d.stringdata[j] == 0) { printf("\\0"); diff --git a/qtruby/src/qtruby.h b/qtruby/src/qtruby.h index f0f4f0e..d8c8d1d 100644 --- a/qtruby/src/qtruby.h +++ b/qtruby/src/qtruby.h @@ -135,7 +135,7 @@ extern Q_DECL_EXPORT void mapPointer(VALUE obj, smokeruby_object *o, Smoke::Inde extern Q_DECL_EXPORT void unmapPointer(smokeruby_object *, Smoke::Index, void*); extern Q_DECL_EXPORT const char * resolve_classname(smokeruby_object * o); -extern Q_DECL_EXPORT void rb_str_catf(VALUE self, const char *format, ...) __attribute__ ((format (printf, 2, 3))); +extern Q_DECL_EXPORT VALUE rb_str_catf(VALUE self, const char *format, ...) __attribute__ ((format (printf, 2, 3))); extern Q_DECL_EXPORT VALUE findMethod(VALUE self, VALUE c_value, VALUE name_value); extern Q_DECL_EXPORT VALUE findAllMethods(int argc, VALUE * argv, VALUE self); commit 085db5fa127193750f5e6819e54690ed0695066a Author: Richard Dale Date: Fri Dec 12 14:52:17 2008 +0000 * When resolving overloaded methods with 'uchar*' and 'const uchar*' arg types prefer the non-const version of the arg. Thanks to Davor Ocelic for explaining why this was a good idea in the case of the Qt::Image constructors. CCMAIL: kde-bindings@kde.org svn path=/trunk/KDE/kdebindings/ruby/; revision=896114 diff --git a/qtruby/src/lib/Qt/qtruby4.rb b/qtruby/src/lib/Qt/qtruby4.rb index 055f877..35af308 100644 --- a/qtruby/src/lib/Qt/qtruby4.rb +++ b/qtruby/src/lib/Qt/qtruby4.rb @@ -2447,9 +2447,9 @@ module Qt if typename =~ /^(const )?((QChar)[*&]?)$/ return 3 elsif typename =~ /^(?:u?char\*)$/ - return 1 - elsif typename =~ /^(?:const u?char\*)$/ return 2 + elsif typename =~ /^(?:const u?char\*)$/ + return 1 elsif typename =~ /^(?:(?:const )?(QString)[*&]?)$/ return 4 end commit dddf0c6d30a80b8f0f2b7bf293a6d0a8375acb7b Author: Richard Dale Date: Fri Dec 12 17:44:38 2008 +0000 * Added Davor Ocelic's patch for Ruby 1.9 compatible RSTRING usage and improved instructions for building QtRuby without KDE. CCMAIL: kde-bindings@kde.org svn path=/trunk/KDE/kdebindings/ruby/; revision=896147 diff --git a/CMakeLists.txt b/CMakeLists.txt index 21bd61d..a5d7020 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,7 @@ OPTION(ENABLE_KORUNDUM_RUBY "build Korundum" ON) OPTION(ENABLE_KHTML_RUBY "build KHTML" ON) OPTION(ENABLE_KTEXTEDITOR_RUBY "build KTextEditor" ON) OPTION(ENABLE_SOLID_RUBY "build Solid" ON) +OPTION(ENABLE_PLASMA_RUBY "build Plasma" ON) SET(CUSTOM_RUBY_SITE_ARCH_DIR ${RUBY_SITE_ARCH_DIR} CACHE DIR "custom installation directory for ruby binary extension" ) SET(CUSTOM_RUBY_SITE_LIB_DIR ${RUBY_SITE_LIB_DIR} CACHE DIR "custom installation directory for ruby extension" ) @@ -29,6 +30,7 @@ set(QTUITOOLS_ENABLED "no") set(QTSCRIPT_ENABLED "no") set(QTTEST_ENABLED "no") +set(PHONON_ENABLED "no") set(QSCINTILLA_ENABLED "no") set(QWT_ENABLED "no") set(SOPRANO_ENABLED "no") @@ -36,10 +38,12 @@ set(SOPRANO_ENABLED "no") set(AKONADI_ENABLED "no") set(KDEVPLATFORM_ENABLED "no") set(KORUNDUM_ENABLED "no") +set(KHTML_ENABLED "no") set(KTEXTEDITOR_ENABLED "no") set(NEPOMUK_ENABLED "no") set(OKULAR_ENABLED "no") set(SOLID_ENABLED "no") +set(PLASMA_ENABLED "no") if(RUBY_EXECUTABLE AND RUBY_LIBRARY AND RUBY_INCLUDE_PATH) if(ENABLE_QTRUBY) @@ -111,8 +115,10 @@ if(RUBY_EXECUTABLE AND RUBY_LIBRARY AND RUBY_INCLUDE_PATH) add_subdirectory( okular ) set(OKULAR_ENABLED "yes") endif(OKULAR_FOUND) - add_subdirectory( plasma ) - set(PLASMA_ENABLED "yes") + if(ENABLE_PLASMA_RUBY) + add_subdirectory( plasma ) + set(PLASMA_ENABLED "yes") + endif(ENABLE_PLASMA_RUBY) if(ENABLE_SOLID_RUBY) add_subdirectory( solid ) set(SOLID_ENABLED "yes") diff --git a/qtruby/src/handlers.cpp b/qtruby/src/handlers.cpp index 2335338..2139a76 100644 --- a/qtruby/src/handlers.cpp +++ b/qtruby/src/handlers.cpp @@ -1118,15 +1118,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]; @@ -1158,7 +1158,7 @@ void marshall_QStringList(Marshall *m) { break; } - int count = RARRAY(list)->len; + int count = RARRAY_LEN(list); QStringList *stringlist = new QStringList; for(long i = 0; i < count; i++) { @@ -1225,7 +1225,7 @@ void marshall_QByteArrayList(Marshall *m) { break; } - int count = RARRAY(list)->len; + int count = RARRAY_LEN(list); QList *stringlist = new QList; for(long i = 0; i < count; i++) { @@ -1289,7 +1289,7 @@ void marshall_QListCharStar(Marshall *m) { m->item().s_voidp = 0; break; } - int count = RARRAY(av)->len; + int count = RARRAY_LEN(av); QList *list = new QList; long i; for(i = 0; i < count; i++) { @@ -1340,7 +1340,7 @@ void marshall_QListInt(Marshall *m) { m->item().s_voidp = 0; break; } - int count = RARRAY(list)->len; + int count = RARRAY_LEN(list); QList *valuelist = new QList; long i; for(i = 0; i < count; i++) { @@ -1412,7 +1412,7 @@ void marshall_QListUInt(Marshall *m) { m->item().s_voidp = 0; break; } - int count = RARRAY(list)->len; + int count = RARRAY_LEN(list); QList *valuelist = new QList; long i; for(i = 0; i < count; i++) { @@ -1483,7 +1483,7 @@ void marshall_QListqreal(Marshall *m) { m->item().s_voidp = 0; break; } - int count = RARRAY(list)->len; + int count = RARRAY_LEN(list); QList *valuelist = new QList; long i; for(i = 0; i < count; i++) { @@ -1557,7 +1557,7 @@ void marshall_QVectorqreal(Marshall *m) { break; } - int count = RARRAY(list)->len; + int count = RARRAY_LEN(list); QVector *valuelist = new QVector; long i; for (i = 0; i < count; i++) { @@ -1626,7 +1626,7 @@ void marshall_QVectorint(Marshall *m) { break; } - int count = RARRAY(list)->len; + int count = RARRAY_LEN(list); QVector *valuelist = new QVector; long i; for (i = 0; i < count; i++) { @@ -1720,7 +1720,7 @@ void marshall_QMapQStringQString(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)[QString(StringValuePtr(key))] = QString(StringValuePtr(value)); @@ -1776,7 +1776,7 @@ void marshall_QMapQStringQVariant(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); @@ -1855,7 +1855,7 @@ void marshall_QMapIntQVariant(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); @@ -1934,7 +1934,7 @@ void marshall_QMapintQVariant(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); @@ -2026,7 +2026,7 @@ void marshall_QRgb_array(Marshall *m) { m->item().s_voidp = 0; break; } - int count = RARRAY(list)->len; + int count = RARRAY_LEN(list); QRgb *rgb = new QRgb[count + 2]; long i; for(i = 0; i < count; i++) { @@ -2061,11 +2061,11 @@ void marshall_QPairQStringQStringList(Marshall *m) { } QList > * pairlist = new QList >(); - int count = RARRAY(list)->len; + int count = RARRAY_LEN(list); for (long i = 0; i < count; i++) { VALUE item = rb_ary_entry(list, i); - if (TYPE(item) != T_ARRAY || RARRAY(item)->len != 2) { + if (TYPE(item) != T_ARRAY || RARRAY_LEN(item) != 2) { continue; } VALUE s1 = rb_ary_entry(item, 0); @@ -2122,7 +2122,7 @@ void marshall_QPairqrealQColor(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; } @@ -2193,7 +2193,7 @@ void marshall_QPairintint(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; } diff --git a/qtruby/src/marshall_macros.h b/qtruby/src/marshall_macros.h index 29b8716..861abbc 100644 --- a/qtruby/src/marshall_macros.h +++ b/qtruby/src/marshall_macros.h @@ -56,7 +56,7 @@ void marshall_ItemList(Marshall *m) { break; } - int count = RARRAY(list)->len; + int count = RARRAY_LEN(list); ItemList *cpplist = new ItemList; long i; for(i = 0; i < count; i++) { @@ -148,7 +148,7 @@ void marshall_ValueListItem(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++) { @@ -264,7 +264,7 @@ void marshall_LinkedItemList(Marshall *m) { break; } - int count = RARRAY(list)->len; + int count = RARRAY_LEN(list); ItemList *cpplist = new ItemList; long i; for (i = 0; i < count; i++) { @@ -358,7 +358,7 @@ void marshall_LinkedValueListItem(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++) { @@ -476,7 +476,7 @@ void marshall_Hash(Marshall *m) { // Convert the ruby hash to an array of key/value arrays VALUE temp = rb_funcall(hv, 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); @@ -553,7 +553,7 @@ void marshall_Map(Marshall *m) { // Convert the ruby hash to an array of key/value arrays VALUE temp = rb_funcall(hv, 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); diff --git a/qtruby/src/marshall_types.cpp b/qtruby/src/marshall_types.cpp index 566379c..bd381e8 100644 --- a/qtruby/src/marshall_types.cpp +++ b/qtruby/src/marshall_types.cpp @@ -72,7 +72,7 @@ show_exception_message() { VALUE info = rb_gv_get("$!"); VALUE bt = rb_funcall(info, rb_intern("backtrace"), 0); - VALUE message = RARRAY(bt)->ptr[0]; + VALUE message = RARRAY_PTR(bt)[0]; QString errormessage = QString("%1: %2 (%3)") .arg( STR2CSTR(message) ) @@ -81,9 +81,9 @@ show_exception_message() fprintf(stderr, "%s\n", errormessage.toLatin1().data()); QString tracemessage; - for(int i = 1; i < RARRAY(bt)->len; ++i) { - if( TYPE(RARRAY(bt)->ptr[i]) == T_STRING ) { - QString s = QString("%1\n").arg( STR2CSTR(RARRAY(bt)->ptr[i]) ); + for(int i = 1; i < RARRAY_LEN(bt); ++i) { + if( TYPE(RARRAY_PTR(bt)[i]) == T_STRING ) { + QString s = QString("%1\n").arg( STR2CSTR(RARRAY_PTR(bt)[i]) ); Q_ASSERT( ! s.isNull() ); tracemessage += s; fprintf(stderr, "\t%s", s.toLatin1().data()); diff --git a/qtruby/src/qtruby.cpp b/qtruby/src/qtruby.cpp index 8a82504..d0fc525 100644 --- a/qtruby/src/qtruby.cpp +++ b/qtruby/src/qtruby.cpp @@ -375,13 +375,13 @@ static VALUE q_register_resource_data(VALUE /*self*/, VALUE version, VALUE tree_value, VALUE name_value, VALUE data_value) { const unsigned char * tree = (const unsigned char *) malloc(RSTRING_LEN(tree_value)); - memcpy((void *) tree, (const void *) RSTRING(tree_value)->ptr, RSTRING_LEN(tree_value)); + memcpy((void *) tree, (const void *) RSTRING_PTR(tree_value), RSTRING_LEN(tree_value)); const unsigned char * name = (const unsigned char *) malloc(RSTRING_LEN(name_value)); - memcpy((void *) name, (const void *) RSTRING(name_value)->ptr, RSTRING_LEN(name_value)); + memcpy((void *) name, (const void *) RSTRING_PTR(name_value), RSTRING_LEN(name_value)); const unsigned char * data = (const unsigned char *) malloc(RSTRING_LEN(data_value)); - memcpy((void *) data, (const void *) RSTRING(data_value)->ptr, RSTRING_LEN(data_value)); + memcpy((void *) data, (const void *) RSTRING_PTR(data_value), RSTRING_LEN(data_value)); return qRegisterResourceData(NUM2INT(version), tree, name, data) ? Qtrue : Qfalse; } @@ -390,13 +390,13 @@ static VALUE q_unregister_resource_data(VALUE /*self*/, VALUE version, VALUE tree_value, VALUE name_value, VALUE data_value) { const unsigned char * tree = (const unsigned char *) malloc(RSTRING_LEN(tree_value)); - memcpy((void *) tree, (const void *) RSTRING(tree_value)->ptr, RSTRING_LEN(tree_value)); + memcpy((void *) tree, (const void *) RSTRING_PTR(tree_value), RSTRING_LEN(tree_value)); const unsigned char * name = (const unsigned char *) malloc(RSTRING_LEN(name_value)); - memcpy((void *) name, (const void *) RSTRING(name_value)->ptr, RSTRING_LEN(name_value)); + memcpy((void *) name, (const void *) RSTRING_PTR(name_value), RSTRING_LEN(name_value)); const unsigned char * data = (const unsigned char *) malloc(RSTRING_LEN(data_value)); - memcpy((void *) data, (const void *) RSTRING(data_value)->ptr, RSTRING_LEN(data_value)); + memcpy((void *) data, (const void *) RSTRING_PTR(data_value), RSTRING_LEN(data_value)); return qUnregisterResourceData(NUM2INT(version), tree, name, data) ? Qtrue : Qfalse; } @@ -661,7 +661,7 @@ static Smoke::Index drawlines_point_vector = 0; static Smoke::Index drawlines_linef_vector = 0; static Smoke::Index drawlines_line_vector = 0; - if (argc == 1 && TYPE(argv[0]) == T_ARRAY && RARRAY(argv[0])->len > 0) { + if (argc == 1 && TYPE(argv[0]) == T_ARRAY && RARRAY_LEN(argv[0]) > 0) { if (drawlines_point_vector == 0) { Smoke::ModuleIndex nameId = qt_Smoke->findMethodName("QPainter", "drawLines?"); Smoke::ModuleIndex meth = qt_Smoke->findMethod(qt_Smoke->findClass("QPainter"), nameId); @@ -716,7 +716,7 @@ qpainter_drawrects(int argc, VALUE * argv, VALUE self) static Smoke::Index drawlines_rectf_vector = 0; static Smoke::Index drawlines_rect_vector = 0; - if (argc == 1 && TYPE(argv[0]) == T_ARRAY && RARRAY(argv[0])->len > 0) { + if (argc == 1 && TYPE(argv[0]) == T_ARRAY && RARRAY_LEN(argv[0]) > 0) { if (drawlines_rectf_vector == 0) { Smoke::ModuleIndex nameId = qt_Smoke->findMethodName("QPainter", "drawRects?"); Smoke::ModuleIndex meth = qt_Smoke->findMethod(qt_Smoke->findClass("QPainter"), nameId); @@ -1209,7 +1209,7 @@ static Smoke::Index new_qvariant_qmap = 0; return *(c.var()); } else if ( argc == 1 && TYPE(argv[0]) == T_ARRAY - && RARRAY(argv[0])->len > 0 + && RARRAY_LEN(argv[0]) > 0 && TYPE(rb_ary_entry(argv[0], 0)) != T_STRING ) { _current_method.smoke = qt_Smoke; @@ -1593,8 +1593,8 @@ rb_qFindChildren_helper(VALUE parent, const QString &name, VALUE re, return; VALUE children = rb_funcall(parent, rb_intern("children"), 0); VALUE rv = Qnil; - for (int i = 0; i < RARRAY(children)->len; ++i) { - rv = RARRAY(children)->ptr[i]; + for (int i = 0; i < RARRAY_LEN(children); ++i) { + rv = RARRAY_PTR(children)[i]; smokeruby_object *o = value_obj_info(rv); QObject * obj = (QObject *) o->smoke->cast(o->ptr, o->classId, o->smoke->idClass("QObject").index); @@ -1653,15 +1653,15 @@ rb_qFindChild_helper(VALUE parent, const QString &name, const QMetaObject &mo) VALUE children = rb_funcall(parent, rb_intern("children"), 0); VALUE rv; int i; - for (i = 0; i < RARRAY(children)->len; ++i) { - rv = RARRAY(children)->ptr[i]; + for (i = 0; i < RARRAY_LEN(children); ++i) { + rv = RARRAY_PTR(children)[i]; smokeruby_object *o = value_obj_info(rv); QObject * obj = (QObject *) o->smoke->cast(o->ptr, o->classId, o->smoke->idClass("QObject").index); if (obj->qt_metacast(mo.className()) != 0 && (name.isNull() || obj->objectName() == name)) return rv; } - for (i = 0; i < RARRAY(children)->len; ++i) { - rv = rb_qFindChild_helper(RARRAY(children)->ptr[i], name, mo); + for (i = 0; i < RARRAY_LEN(children); ++i) { + rv = rb_qFindChild_helper(RARRAY_PTR(children)[i], name, mo); if (rv != Qnil) return rv; } @@ -1815,10 +1815,10 @@ make_metaObject(VALUE /*self*/, VALUE obj, VALUE parentMeta, VALUE stringdata_va char *stringdata = new char[RSTRING_LEN(stringdata_value)]; - int count = RARRAY(data_value)->len; + int count = RARRAY_LEN(data_value); uint * data = new uint[count]; - memcpy( (void *) stringdata, RSTRING(stringdata_value)->ptr, RSTRING_LEN(stringdata_value) ); + memcpy( (void *) stringdata, RSTRING_PTR(stringdata_value), RSTRING_LEN(stringdata_value) ); for (long i = 0; i < count; i++) { VALUE rv = rb_ary_entry(data_value, i); @@ -1924,7 +1924,7 @@ add_metaobject_methods(VALUE self, VALUE klass) static VALUE add_signal_methods(VALUE self, VALUE klass, VALUE signalNames) { - for (long index = 0; index < RARRAY(signalNames)->len; index++) { + for (long index = 0; index < RARRAY_LEN(signalNames); index++) { VALUE signal = rb_ary_entry(signalNames, index); rb_define_method(klass, StringValuePtr(signal), (VALUE (*) (...)) qt_signal, -1); } @@ -2018,7 +2018,7 @@ dumpCandidates(VALUE /*self*/, VALUE rmeths) { VALUE errmsg = rb_str_new2(""); if(rmeths != Qnil) { - int count = RARRAY(rmeths)->len; + int count = RARRAY_LEN(rmeths); for(int i = 0; i < count; i++) { rb_str_catf(errmsg, "\t"); int id = NUM2INT(rb_funcall(rb_ary_entry(rmeths, i), rb_intern("index"), 0)); diff --git a/qtruby/src/qtruby.h b/qtruby/src/qtruby.h index d8c8d1d..e93cd67 100644 --- a/qtruby/src/qtruby.h +++ b/qtruby/src/qtruby.h @@ -28,6 +28,19 @@ #endif #define QTRUBY_VERSION "1.4.10" +#if !defined RSTRING_LEN +#define RSTRING_LEN(a) RSTRING(a)->len +#endif +#if !defined RSTRING_PTR +#define RSTRING_PTR(a) RSTRING(a)->ptr +#endif +#if !defined RARRAY_LEN +#define RARRAY_LEN(a) RARRAY(a)->len +#endif +#if !defined RARRAY_PTR +#define RARRAY_PTR(a) RARRAY(a)->ptr +#endif + inline bool operator==(const Smoke::ModuleIndex& a, const Smoke::ModuleIndex& b) { if (a.index == b.index && a.smoke == b.smoke) return true; commit 3d6d8dee83320ddc41ed961949f042681f66c6ce Author: Richard Dale Date: Thu Dec 18 14:11:43 2008 +0000 * Added another patch from Davor Ocelic for Ruby 1.9 compatible RSTRING usage - thanks Davor CCMAIL: kde-bindings@kde.org svn path=/trunk/KDE/kdebindings/ruby/; revision=898619 diff --git a/qtruby/src/marshall_macros.h b/qtruby/src/marshall_macros.h index 00366d2..6b674b2 100644 --- a/qtruby/src/marshall_macros.h +++ b/qtruby/src/marshall_macros.h @@ -56,7 +56,7 @@ void marshall_ItemList(Marshall *m) { break; } - int count = RARRAY(list)->len; + int count = RARRAY_LEN(list); ItemList *cpplist = new ItemList; long i; for(i = 0; i < count; i++) { @@ -127,7 +127,7 @@ void marshall_ItemList(Marshall *m) { m->next(); if (!m->type().isConst()) { - int count = RARRAY(av)->len; + int count = RARRAY_LEN(av); long i; cpplist->clear(); for (i = 0; i < count; i++) { @@ -169,7 +169,7 @@ void marshall_ValueListItem(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++) { @@ -285,7 +285,7 @@ void marshall_LinkedItemList(Marshall *m) { break; } - int count = RARRAY(list)->len; + int count = RARRAY_LEN(list); ItemList *cpplist = new ItemList; long i; for (i = 0; i < count; i++) { @@ -379,7 +379,7 @@ void marshall_LinkedValueListItem(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++) { @@ -497,7 +497,7 @@ void marshall_Hash(Marshall *m) { // Convert the ruby hash to an array of key/value arrays VALUE temp = rb_funcall(hv, 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); @@ -574,7 +574,7 @@ void marshall_Map(Marshall *m) { // Convert the ruby hash to an array of key/value arrays VALUE temp = rb_funcall(hv, 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); commit c1c5377ac8f8416d6f8676934b0584846313c7a8 Author: Richard Dale Date: Mon Mar 16 18:17:03 2009 +0000 * A problem has been found with QtRuby when it is run with Ruby 1.9.1 and GC.stess is true. Thanks to Davor Ocelic for reporting it. In the smokeruby_mark() function called during garbage collection, any virtual methods which are called on the instances being checked could have overriden by Ruby methods. So the Wt::Ruby runtime uses 'respond_to()' to find out whether they have been overriden. However, this involves calling 'rb_intern()' on the method name, which means memory could be allocated, giving an error when running under GC.stress mode. So workround it by pre-allocating any strings with rb_intern() for all the C++ methods used in smokeruby_mark() svn path=/trunk/KDE/kdebindings/ruby/; revision=940158 diff --git a/qtruby/ChangeLog b/qtruby/ChangeLog index 025197b..87688f1 100644 --- a/qtruby/ChangeLog +++ b/qtruby/ChangeLog @@ -3,6 +3,16 @@ is deleted from within irb, it makes irb crash when it tries to run run inspect() on the newly deleted value returned by dispose(). Thanks to Stefano Crocco for finding the problem. + * A problem has been found with QtRuby when it is run with Ruby 1.9.1 + and GC.stess is true. Thanks to Davor Ocelic for reporting it. + In the smokeruby_mark() function called during garbage collection, + any virtual methods which are called on the instances being checked + could have overriden by Ruby methods. So the Wt::Ruby runtime uses + 'respond_to()' to find out whether they have been overriden. + However, this involves calling 'rb_intern()' on the method name, + which means memory could be allocated, giving an error when running under + GC.stress mode. So workround it by pre-allocating any strings with + rb_intern() for all the C++ methods used in smokeruby_mark() 2009-03-13 Richard Dale * Improved the rbqtapi '-s' option diff --git a/qtruby/bin/rbqtapi b/qtruby/bin/rbqtapi index 6f25e05..3a14340 100755 --- a/qtruby/bin/rbqtapi +++ b/qtruby/bin/rbqtapi @@ -109,8 +109,8 @@ class String method_name = self.clone - if method_name =~ /([A-Za-z0-9]+)\* ([A-Za-z0-9]+)::([A-Za-z0-9]+)(\(.*\))/ && $2 == $3 - method_name = $1 + ' new' + $4 + "\n" + if method_name =~ /([:A-Za-z0-9]+)\*.*[ :]+([A-Za-z0-9]+)::([A-Za-z0-9]+)(\(.*\))/ && $2 == $3 + method_name = $1 + '#new' + $4 + "\n" end method_name.gsub!(/char*/, 'String') diff --git a/qtruby/src/qtruby.cpp b/qtruby/src/qtruby.cpp index 4658c62..14e595b 100644 --- a/qtruby/src/qtruby.cpp +++ b/qtruby/src/qtruby.cpp @@ -2360,6 +2360,34 @@ Init_qtruby4() rb_define_module_function(qt_module, "qRegisterResourceData", (VALUE (*) (...)) q_register_resource_data, 4); rb_define_module_function(qt_module, "qUnregisterResourceData", (VALUE (*) (...)) q_unregister_resource_data, 4); + // A problem has been found with QtRuby when it is run with Ruby 1.9.1 + // and GC.stess is true. + // In the smokeruby_mark() function called during garbage collection, + // any virtual methods which are called on the instances being checked + // could have overriden by Ruby methods. So the Wt::Ruby runtime uses + // 'respond_to()' to find out whether they have been overriden. + // However, this involves calling 'rb_intern()' on the method name, + // which means memory could be allocated, giving an error when running under + // GC.stress mode. So workround it by pre-allocating any strings with + // rb_intern() for all the C++ methods used in smokeruby_mark() + rb_intern("children"); + rb_intern("childItems"); + rb_intern("childCount"); + rb_intern("child"); + rb_intern("hasChildren"); + rb_intern("parent"); + rb_intern("parentItem"); + rb_intern("item"); + rb_intern("items"); + rb_intern("rowCount"); + rb_intern("rowAt"); + rb_intern("columnCount"); + rb_intern("elementAt"); + rb_intern("columnAt"); + rb_intern("topLevelItem"); + rb_intern("itemAt"); + rb_intern("internalPointer"); + rb_require("Qt/qtruby4.rb"); // Do package initialization commit 695a183b802725f7c3fd544780e5a4659d6c96f1 Author: Richard Dale Date: Thu Nov 12 14:33:50 2009 +0000 * Applied a patch from Davor Ocelic. Here's an overview of the changes: ruby/qtruby/src/handlers.cpp: Added { "unsigned char*", marshall_ucharP } so that conversion from String to "unsigned char*" would work. Qt code doesn't have unsigned char*, but Smoke seems to internally convert uchar* to unsigned char*. ruby/qtruby/src/Qt.cpp: The code at the place of patch checks whether a method is overriden in Ruby. But during GC, it's not allowed to execute Ruby code anyway, so the patch removes this check altogether. (In rare, but existing situations, this check itself lead to new object allocation, crashing the application). (New info: the function we've used to check if it's running during GC or not seems to be Ruby 1.9 specific, so a simple compatibility for 1.8 should be added before committing). ruby/qtruby/src/lib/Qt/qtruby4.rb 1) Added GC.disable around line of code that says: "@block = block". This makes a difference between being and being not able to run with GC.stress= true. Reason unclear, comments appreciated. 2) Extended typename =~ /^(?:u?char\*)$/ checks to support unsigned char. 3) Skip "def instance_exec" if it is already defined (it is in Ruby 1.9) * Thanks to Davor for the patch CCMAIL: kde-bindings@kde.org svn path=/trunk/KDE/kdebindings/ruby/; revision=1047984 diff --git a/qtruby/src/Qt.cpp b/qtruby/src/Qt.cpp index ef7a472..633b8f6 100644 --- a/qtruby/src/Qt.cpp +++ b/qtruby/src/Qt.cpp @@ -269,7 +269,8 @@ Binding::callMethod(Smoke::Index method, void *ptr, Smoke::Stack args, bool /*is methodName += (sizeof("operator") - 1); } // If the virtual method hasn't been overriden, just call the C++ one. - if (rb_respond_to(obj, rb_intern(methodName)) == 0) { + // During GC, avoid checking for override and just call the C++ version + if (rb_during_gc() || rb_respond_to(obj, rb_intern(methodName)) == 0) { return false; } QtRuby::VirtualMethodCall c(smoke, method, args, obj, ALLOCA_N(VALUE, smoke->methods[method].numArgs)); diff --git a/qtruby/src/handlers.cpp b/qtruby/src/handlers.cpp index 8bb7f81..b6ccb8b 100644 --- a/qtruby/src/handlers.cpp +++ b/qtruby/src/handlers.cpp @@ -2516,6 +2516,7 @@ Q_DECL_EXPORT TypeHandler Qt_handlers[] = { { "QwtArray&", marshall_QVectorint }, { "signed int&", marshall_it }, { "uchar*", marshall_ucharP }, + { "unsigned char*", marshall_ucharP }, { "unsigned long long int", marshall_it }, { "unsigned long long int&", marshall_it }, { "void", marshall_void }, diff --git a/qtruby/src/lib/Qt/qtruby4.rb b/qtruby/src/lib/Qt/qtruby4.rb index d697fb3..ccb9798 100644 --- a/qtruby/src/lib/Qt/qtruby4.rb +++ b/qtruby/src/lib/Qt/qtruby4.rb @@ -2361,7 +2361,11 @@ module Qt if metaObject.indexOfSlot(signature) == -1 self.class.slots signature end + # This makes a difference between being and not being able + # to run with GC.stress= true. Reason unclear. + gc_disabled= GC.disable @block = block + GC.enable unless gc_disabled end def invoke(*args) @@ -2515,9 +2519,9 @@ module Qt elsif argtype == 's' if typename =~ /^(const )?((QChar)[*&]?)$/ return 3 - elsif typename =~ /^(?:u?char\*)$/ + elsif typename =~ /^(?:(u(nsigned )?)?char\*)$/ return 2 - elsif typename =~ /^(?:const u?char\*)$/ + elsif typename =~ /^(?:const (u(nsigned )?)?char\*)$/ return 1 elsif typename =~ /^(?:(?:const )?(QString)[*&]?)$/ return 4 @@ -3047,7 +3051,7 @@ class Object # matter for the intended use in invoking blocks as Qt slots. def instance_exec(*arguments, &block) block.bind(self)[*arguments] - end + end unless defined? instance_exec end class Proc