[Kde-bindings] KDE/kdebindings/ruby/qtruby/src
Richard Dale
richard.dale at telefonica.net
Sun Jul 25 14:57:07 UTC 2010
On Sunday, July 25, 2010 03:22:35 pm Arno Rehn wrote:
> SVN commit 1154467 by arnorehn:
>
> Choose the const/non-const version of a method based on whether the object
> is frozen or not. 'Frozen' objects in Ruby roughly translate to const
> objects in C++, so this should work out fine.
> Quick testing with the QDBusArgument API (which now doesn't need special
> casing anymore) worked well.
I'm not sure that freezing ruby variable to force const/non const method
overload resolution is a good idea. Once you have frozen a variable you can't
unfreeze it, and i'm sure some variable being used with dbus will need to be
updated after they have been read from. Also it doesn't feel like a Ruby idiom
to freeze/unfreeze to get the api working - I would rather have different names
for the methods to read and to write.
-- Richard
> CCMAIL: kde-bindings at kde.org
>
> M +6 -0 lib/Qt/qtruby4.rb
> M +11 -0 marshall_basetypes.h
> M +4 -0 marshall_types.h
> M +2 -51 qtruby.cpp
>
>
> --- trunk/KDE/kdebindings/ruby/qtruby/src/lib/Qt/qtruby4.rb
> #1154466:1154467 @@ -2727,7 +2727,13 @@
> methodIds.each do
>
> |id|
>
> puts "matching => smoke: #{id.smoke} index:
#{id.index}" if
> debug_level >= DebugLevel::High +
> + if this.frozen?
> current_match = (isConstMethod(id) ? 1 : 0)
> + else
> + current_match = (isConstMethod(id) ? 0 : 1)
> + end
> +
> (0...args.length).each do
>
> |i|
>
> current_match +=
checkarg(get_value_type(args[i]),
> get_arg_type_name(id, i)) ---
> trunk/KDE/kdebindings/ruby/qtruby/src/marshall_basetypes.h
> #1154466:1154467 @@ -10,6 +10,9 @@
> #ifndef MARSHALL_BASETYPES_H
> #define MARSHALL_BASETYPES_H
>
> +#include "qtruby.h"
> +#include "smokeruby.h"
> +
> template <class T> T* smoke_ptr(Marshall *m) { return (T*)
> m->item().s_voidp; }
>
> template<> bool* smoke_ptr<bool>(Marshall *m) { return &m->item().s_bool;
> } @@ -144,6 +147,7 @@
> smokeruby_object * o = alloc_smokeruby_object(false, m->smoke(),
> m->type().classId(), p);
>
> const char * classname = resolve_classname(o);
> + bool freeze = false;
> if (m->type().isConst() && m->type().isRef()) {
> p = construct_copy( o );
> if (do_debug & qtdb_gc) {
> @@ -153,13 +157,20 @@
> if (p) {
> o->ptr = p;
> o->allocated = true;
> + } else {
> + freeze = true;
> }
> + } else if (m->type().isConst() && m->type().isPtr()) {
> + freeze = true;
> }
>
> obj = set_obj_info(classname, o);
> if (do_debug & qtdb_gc) {
> qWarning("allocating %s %p -> %p\n", classname, o->ptr, (void*)obj);
> }
> + if (freeze) {
> + rb_obj_freeze(obj);
> + }
>
> /*
> if(m->type().isStack()) {
> --- trunk/KDE/kdebindings/ruby/qtruby/src/marshall_types.h #1154466:1154467
> @@ -133,6 +133,10 @@
> rb_raise(rb_eArgError, "%s is not a class method\n",
> _smoke->methodNames[method().name]); }
>
> + if (rb_obj_frozen_p(_target) && !(method().flags & Smoke::mf_const)) {
> + rb_raise(rb_eRuntimeError, "%p (%s) is frozen, can't call non-
const
> method '%s' on it\n", _o->ptr, classname(),
> _smoke->methodNames[method().name]); + }
> +
> Smoke::ClassFn fn = _smoke->classes[method().classId].classFn;
> void * ptr = 0;
>
> --- trunk/KDE/kdebindings/ruby/qtruby/src/qtruby.cpp #1154466:1154467
> @@ -40,7 +40,8 @@
> #include <QtGui/qwidget.h>
>
> #ifdef QT_QTDBUS
> -#include <QtDBus/qdbusargument.h>
> +#include <QtDBus/QDBusObjectPath>
> +#include <QtDBus/QDBusSignature>
> #endif
>
> #include <smoke/smoke.h>
> @@ -617,45 +618,6 @@
> return rb_str_new((const char *) bytes, image->bytesPerLine());
> }
>
> -#ifdef QT_QTDBUS
> -static VALUE
> -qdbusargument_endarraywrite(VALUE self)
> -{
> - smokeruby_object *o = value_obj_info(self);
> - QDBusArgument * arg = (QDBusArgument *) o->ptr;
> - arg->endArray();
> - return self;
> -}
> -
> -static VALUE
> -qdbusargument_endmapwrite(VALUE self)
> -{
> - smokeruby_object *o = value_obj_info(self);
> - QDBusArgument * arg = (QDBusArgument *) o->ptr;
> - arg->endMap();
> - return self;
> -}
> -
> -static VALUE
> -qdbusargument_endmapentrywrite(VALUE self)
> -{
> - smokeruby_object *o = value_obj_info(self);
> - QDBusArgument * arg = (QDBusArgument *) o->ptr;
> - arg->endMapEntry();
> - return self;
> -}
> -
> -static VALUE
> -qdbusargument_endstructurewrite(VALUE self)
> -{
> - smokeruby_object *o = value_obj_info(self);
> - QDBusArgument * arg = (QDBusArgument *) o->ptr;
> - arg->endStructure();
> - return self;
> -}
> -
> -#endif
> -
> // The QtRuby runtime's overloaded method resolution mechanism can't
> currently // distinguish between Ruby Arrays containing different sort of
> instances. // Unfortunately Qt::Painter.drawLines() and
> Qt::Painter.drawRects() methods can @@ -2280,17 +2242,6 @@
> rb_define_method(klass, "mapping", (VALUE (*) (...))
> qsignalmapper_mapping, -1); rb_define_method(klass, "setMapping", (VALUE
> (*) (...)) qsignalmapper_set_mapping, -1); rb_define_method(klass,
> "set_mapping", (VALUE (*) (...)) qsignalmapper_set_mapping, -1); -#ifdef
> QT_QTDBUS
> - } else if (packageName == "Qt::DBusArgument") {
> - rb_define_method(klass, "endArrayWrite", (VALUE (*) (...))
> qdbusargument_endarraywrite, 0); - rb_define_method(klass,
> "end_array_write", (VALUE (*) (...)) qdbusargument_endarraywrite, 0);
> - rb_define_method(klass, "endMapEntryWrite", (VALUE (*) (...))
> qdbusargument_endmapentrywrite, 0); - rb_define_method(klass,
> "end_map_entry_write", (VALUE (*) (...)) qdbusargument_endmapentrywrite,
> 0); - rb_define_method(klass, "endMapWrite", (VALUE (*) (...))
> qdbusargument_endmapwrite, 0); - rb_define_method(klass,
"end_map_write",
> (VALUE (*) (...)) qdbusargument_endmapwrite, 0);
> - rb_define_method(klass, "endStructureWrite", (VALUE (*) (...))
> qdbusargument_endstructurewrite, 0); - rb_define_method(klass,
> "end_structure_write", (VALUE (*) (...)) qdbusargument_endstructurewrite,
> 0); -#endif
> }
>
> foreach(QtRubyModule m, qtruby_modules.values()) {
> _______________________________________________
> Kde-bindings mailing list
> Kde-bindings at kde.org
> https://mail.kde.org/mailman/listinfo/kde-bindings
More information about the Kde-bindings
mailing list