[Kde-bindings] KDE/kdebindings/ruby/qtruby
Richard Dale
Richard_Dale at tipitina.demon.co.uk
Tue Apr 8 09:53:46 UTC 2008
SVN commit 794672 by rdale:
* Added a QTRUBY_FUNCALL2 macro. If QtRuby is built with the
-DRUBY_EMBEDDED option, then the rb_funcall2s for invoking
virtual method callbacks and slot invocations in wrapped with
a rb_protect() call. Otherwise, rb_funcall() is called directly
and any uncaught Ruby exceptions will terminate the app.
CCMAIL: kde-bindings at kde.org
M +8 -0 ChangeLog
M +31 -28 src/marshall_types.cpp
--- trunk/KDE/kdebindings/ruby/qtruby/ChangeLog #794671:794672
@@ -1,3 +1,11 @@
+2008-04-07 Richard Dale <richard.j.dale at gmail.com>
+
+ * Added a QTRUBY_FUNCALL2 macro. If QtRuby is built with the
+ -DRUBY_EMBEDDED option, then the rb_funcall2s for invoking
+ virtual method callbacks and slot invocations in wrapped with
+ a rb_protect() call. Otherwise, rb_funcall() is called directly
+ and any uncaught Ruby exceptions will terminate the app.
+
2008-04-06 Richard Dale <richard.j.dale at gmail.com>
* Change the way the 'MocArgument*' structs are created, instead
--- trunk/KDE/kdebindings/ruby/qtruby/src/marshall_types.cpp #794671:794672
@@ -21,13 +21,14 @@
// This is based on the SWIG SWIG_INIT_STACK and SWIG_RELEASE_STACK macros.
// If RUBY_INIT_STACK is only called when an embedded extension such as, a
-// Ruby Plasma plugin is loaded, the C++ stack can drop below where the Ruby
-// runtime thinks the stack should start, and result in sys stackerror exceptions
+// Ruby Plasma plugin is loaded, then later the C++ stack can drop below where the
+// Ruby runtime thinks the stack should start (ie the stack position when the
+// plugin was loaded), and result in sys stackerror exceptions
//
-// There is a problem when a virtual method or slot is called from the main
-// class of a plugin when it is being loaded because RUBY_INIT_STACK will
-// have aleady have been called from krubypluginfactory, and this may cause
-// problems.
+// TODO: While constructing the main class of a plugin when it is being loaded,
+// there could be a problem when a custom virtual method is called or a slot is
+// invoked, because RUBY_INIT_STACK will have aleady have been called from within
+// the krubypluginfactory code, and it shouldn't be called again.
#ifdef RUBY_EMBEDDED
# define QTRUBY_INIT_STACK \
@@ -43,6 +44,8 @@
# define QTRUBY_RELEASE_STACK
#endif /* RUBY_EMBEDDED */
+#ifdef RUBY_EMBEDDED
+
static VALUE funcall2_protect_id = Qnil;
static int funcall2_protect_argc = 0;
static VALUE * funcall2_protect_args = 0;
@@ -55,6 +58,24 @@
return result;
}
+# define QTRUBY_FUNCALL2(result, obj, id, argc, args) \
+ int state = 0; \
+ funcall2_protect_id = id; \
+ funcall2_protect_argc = argc; \
+ funcall2_protect_args = args; \
+ result = rb_protect(funcall2_protect, obj, &state); \
+ if (state != 0) { \
+ rb_backtrace(); \
+ result = Qnil; \
+ }
+
+#else
+
+# define QTRUBY_FUNCALL2(result, obj, id, argc, args) \
+ result = rb_funcall2(obj, id, argc, args);
+
+#endif
+
void
smokeStackToQtStack(Smoke::Stack stack, void ** o, int start, int end, QList<MocArgument*> args)
{
@@ -446,20 +467,11 @@
if (_called) return;
_called = true;
- funcall2_protect_id = rb_intern(_smoke->methodNames[method().name]);
- funcall2_protect_argc = method().numArgs;
- funcall2_protect_args = _sp;
- int state = 0;
-
+ VALUE _retval;
QTRUBY_INIT_STACK
- VALUE _retval = rb_protect(funcall2_protect, _obj, &state);
+ QTRUBY_FUNCALL2(_retval, _obj, rb_intern(_smoke->methodNames[method().name]), method().numArgs, _sp)
QTRUBY_RELEASE_STACK
- if (state != 0) {
- rb_backtrace();
- _retval = Qnil;
- }
-
VirtualMethodReturnValue r(_smoke, _method, _stack, _retval);
}
@@ -682,20 +694,11 @@
if (_called) return;
_called = true;
- funcall2_protect_id = _slotname;
- funcall2_protect_argc = _items - 1;
- funcall2_protect_args = _sp;
- int state = 0;
-
+ VALUE result;
QTRUBY_INIT_STACK
- VALUE result = rb_protect(funcall2_protect, _obj, &state);
+ QTRUBY_FUNCALL2(result, _obj, _slotname, _items - 1, _sp)
QTRUBY_RELEASE_STACK
- if (state != 0) {
- rb_backtrace();
- result = Qnil;
- }
-
if (_args[0]->argType != xmoc_void) {
SlotReturnValue r(_o, &result, _args);
}
More information about the Kde-bindings
mailing list