[Kde-bindings] qtruby.rb: backporting the 'Module includes Qt' bug to 3.3
Adeodato Simó
asp16 at alu.ua.es
Sat Apr 9 21:50:36 UTC 2005
Hello Richard,
I'm one of the KDE packagers in Debian. Our next release, Sarge, will
be shipping with KDE 3.3, and a user has requested [1] that we
backport the "include 'Qt' in Module pollutes its namespace" fix from
KDE_3_4_BRANCH.
[1] http://bugs.debian.org/303608
I've digged into it today and backported the CVS commit. I've tested
the resulting package and seems to work, but I'd really appreciate if
you could have a quick look at the patch we'll be applying (attached).
I'm asking this because, although the patch came from CVS, I've needed
to do a bit of tweaking to it, and I fear having left something out,
or having included something that will have some nasty effects that my
testing hasn't discovered.
The changes are explained at the top of the diff, the involved CVS
revisions are listed in it too.
Thanks in advance,
--
Adeodato Simó
EM: asp16 [ykwim] alu.ua.es | PK: DA6AE621
Listening to: Eric Clapton - Old love
Kindness is a language which the deaf can hear and the blind can read.
-- Mark Twain
-------------- next part --------------
Index: rubylib/qtruby/lib/Qt/qtruby.rb
===================================================================
RCS file: /home/kde/kdebindings/qtruby/rubylib/qtruby/lib/Qt/qtruby.rb,v
retrieving revision 1.61
retrieving revision 1.62
NOTE: This is not a pristine patch from CVS. A hunk had to be
removed (the one reverting the Time hack, since it was not in 3.3),
and a couple of them (try_initialize, do_method_missing) had to had
their context adjusted. Also, continue_new_instance wasn't present
in the 3_4_BRANCH version, so I added a hunk to change it from a
method to a module function. Rediffed, too, to get offsets right.
diff -u -p -r1.61 -r1.62
--- kdebindings/qtruby/rubylib/qtruby/lib/Qt/qtruby.rb 24 Mar 2005 04:59:58 -0000 1.61
+++ kdebindings/qtruby/rubylib/qtruby/lib/Qt/qtruby.rb 30 Mar 2005 13:35:01 -0000 1.62
@@ -18,9 +18,9 @@
=end
module Qt
- module DebugLevel
- Off, Minimal, High, Extensive = 0, 1, 2, 3
- end
+ module DebugLevel
+ Off, Minimal, High, Extensive = 0, 1, 2, 3
+ end
module QtDebugChannel
QTDB_NONE = 0x00
@@ -30,17 +30,18 @@
QTDB_GC = 0x08
QTDB_VIRTUAL = 0x10
QTDB_VERBOSE = 0x20
- QTDB_ALL = QTDB_VERBOSE | QTDB_VIRTUAL | QTDB_GC | QTDB_CALLS | QTDB_METHOD_MISSING | QTDB_AMBIGUOUS
+ QTDB_ALL = QTDB_VERBOSE | QTDB_VIRTUAL | QTDB_GC | QTDB_CALLS | QTDB_METHOD_MISSING | QTDB_AMBIGUOUS
+ end
+
+ @@debug_level = DebugLevel::Off
+ def Qt.debug_level=(level)
+ @@debug_level = level
+ Internal::setDebug Qt::QtDebugChannel::QTDB_ALL if level >= DebugLevel::Extensive
end
- @@debug_level = DebugLevel::Off
- def Qt.debug_level=(level)
- @@debug_level = level
- Internal::setDebug Qt::QtDebugChannel::QTDB_ALL if level >= DebugLevel::Extensive
- end
- def Qt.debug_level
- @@debug_level
- end
+ def Qt.debug_level
+ @@debug_level
+ end
class Base
def **(a)
@@ -99,7 +100,7 @@
# def ==(a)
# return Qt::==(self, a)
# end
- end
+ end # Qt::Base
require 'delegate.rb'
@@ -241,12 +242,11 @@
end
module Internal
-
@@classes = {}
@@cpp_names = {}
@@idclass = []
- def normalize_classname(classname)
+ def Internal.normalize_classname(classname)
if classname =~ /^Q/
now = classname.sub(/^Q(?=[A-Z])/,'Qt::')
elsif classname !~ /::/
@@ -258,9 +258,9 @@
now
end
- def init_class(c)
- classname = normalize_classname(c)
- classId = idClass(c)
+ def Internal.init_class(c)
+ classname = Qt::Internal::normalize_classname(c)
+ classId = Qt::Internal.idClass(c)
insert_pclassid(classname, classId)
@@idclass[classId] = classname
@@cpp_names[classname] = c
@@ -269,11 +269,11 @@
@@classes[classname] = klass unless klass.nil?
end
- def debug_level
- Qt.debug_level
- end
+ def Internal.debug_level
+ Qt.debug_level
+ end
- def checkarg(argtype, typename)
+ def Internal.checkarg(argtype, typename)
puts " #{typename} (#{argtype})" if debug_level >= DebugLevel::High
if argtype == 'i'
if typename =~ /^int&?$|^signed$/
@@ -366,14 +366,14 @@
return -99
end
- def find_class(classname)
+ def Internal.find_class(classname)
# puts @@classes.keys.sort.join "\n"
@@classes[classname]
end
# Runs the initializer as far as allocating the Qt C++ instance.
# Then use the @@current_initializer continuation to jump back to here
- def try_initialize(instance, *args)
+ def Internal.try_initialize(instance, *args)
initializer = instance.method(:initialize)
return callcc {
|continuation|
@@ -383,7 +383,7 @@
end
# continues off here after first stage initialize is complete
- def continue_new_instance(instance)
+ def Internal.continue_new_instance(instance)
@@current_initializer.call(instance)
end
@@ -391,7 +391,7 @@
# run that now. Either run the context of the new instance
# if no args were passed to the block. Or otherwise,
# run the block in the context of the arg.
- def run_initializer_block(instance, block)
+ def Internal.run_initializer_block(instance, block)
if block.arity == -1
instance.instance_eval(&block)
elsif block.arity == 1
@@ -401,7 +401,7 @@
end
end
- def do_method_missing(package, method, klass, this, *args)
+ def Internal.do_method_missing(package, method, klass, this, *args)
classname = @@cpp_names[klass.name]
if classname.nil?
if klass != Object and klass != KDE and klass != Qt
@@ -512,16 +512,15 @@
return nil
end
- def init_all_classes()
- getClassList().each {
- |c|
+ def Internal.init_all_classes()
+ Qt::Internal::getClassList().each do |c|
if c == "Qt"
# Don't change Qt to Qt::t, just leave as is
@@cpp_names["Qt"] = c
elsif c != "QInternal"
- init_class(c)
+ Qt::Internal::init_class(c)
end
- }
+ end
# Special case QByteArray, as it's disguised as a ruby String
# and not in the public api.
@@classes['Qt::ByteArray'] = Qt::ByteArray.class
@@ -530,41 +529,132 @@
@@classes['Qt::Enum'] = Qt::Enum.class
end
- def create_qbytearray(string, data)
+ def Internal.create_qbytearray(string, data)
return Qt::ByteArray.new(string, data)
end
- def get_qbytearray(str)
+ def Internal.get_qbytearray(str)
if str.private_data.nil?
return str.data
end
return str.private_data
end
- def get_qinteger(num)
+ def Internal.get_qinteger(num)
return num.value
end
- def set_qinteger(num, val)
+ def Internal.set_qinteger(num, val)
return num.value = val
end
- def create_qenum(num, type)
+ def Internal.create_qenum(num, type)
return Qt::Enum.new(num, type)
end
- def get_qenum_type(e)
+ def Internal.get_qenum_type(e)
return e.type
end
- def get_qboolean(b)
+ def Internal.get_qboolean(b)
return b.value
end
- def set_qboolean(b, val)
+ def Internal.set_qboolean(b, val)
return b.value = val
end
- end
+
+ def Internal.getAllParents(class_id, res)
+ getIsa(class_id).each do |s|
+ c = idClass(s)
+ res << c
+ getAllParents(c, res)
+ end
+ end
+
+ def Internal.getSignalNames(klass)
+ meta = Meta[klass.name] || MetaInfo.new(klass)
+ signal_names = []
+ meta.get_signals.each do |signal|
+ signal_names.push signal.name
+ end
+ return signal_names
+ end
+
+ def Internal.signalInfo(qobject, signal_name)
+ signals = Meta[qobject.class.name].get_signals
+ signals.each_with_index do |signal, i|
+ if signal.name == signal_name
+ return [signal.full_name, i]
+ end
+ end
+ end
+
+ def Internal.signalAt(qobject, index)
+ classname = qobject.class.name
+ Meta[classname].get_signals[index].full_name
+ end
+
+ def Internal.slotAt(qobject, index)
+ classname = qobject.class.name
+ Meta[classname].get_slots[index].full_name
+ end
+
+ def Internal.getMocArguments(member)
+ argStr = member.sub(/.*\(/, '').sub(/\)$/, '')
+ args = argStr.scan(/([^,]*<[^>]+>)|([^,]+)/)
+ mocargs = allocateMocArguments(args.length)
+ args.each_with_index do |arg, i|
+ arg = arg.to_s
+ a = arg.sub(/^const\s+/, '')
+ a = (a =~ /^(bool|int|double|char\*|QString)&?$/) ? $1 : 'ptr'
+ valid = setMocType(mocargs, i, arg, a)
+ end
+ result = []
+ result << args.length << mocargs
+ result
+ end
+
+ def Internal.makeMetaData(data)
+ return nil if data.nil?
+ tbl = []
+ data.each do |entry|
+ name = entry.name
+ argStr = entry.arg_types
+ params = []
+ args = argStr.scan(/[^,]+/)
+ args.each do |arg|
+ name = '' # umm.. is this the aim?, well. it works. soo... ;-)
+ param = make_QUParameter(name, arg, 0, 1)
+ params << param
+ end
+ method = make_QUMethod(name, params)
+ tbl << make_QMetaData(entry.full_name, method)
+ end
+ make_QMetaData_tbl(tbl)
+ end
+
+ def Internal.getMetaObject(qobject)
+ meta = Meta[qobject.class.name]
+ return nil if meta.nil?
+
+ if meta.metaobject.nil? or meta.changed
+ slots = meta.get_slots
+ slotTable = makeMetaData(slots)
+ signals = meta.get_signals
+ signalTable = makeMetaData(signals)
+ meta.metaobject = make_metaObject(qobject.class.name,
+ qobject.staticMetaObject(),
+ slotTable,
+ slots.length,
+ signalTable,
+ signals.length)
+ meta.changed = false
+ end
+
+ meta.metaobject
+ end
+ end # Qt::Internal
Meta = {}
@@ -636,103 +726,7 @@
end
return all_slots
end
- end
-
- def getAllParents(class_id, res)
- getIsa(class_id).each {
- |s|
- c = idClass(s)
- res << c
- getAllParents(c, res)
- }
- end
-
- def getSignalNames(klass)
- meta = Meta[klass.name] || MetaInfo.new(klass)
- signal_names = []
- meta.get_signals.each do |signal|
- signal_names.push signal.name
- end
- return signal_names
- end
-
- def signalInfo(qobject, signal_name)
- signals = Meta[qobject.class.name].get_signals
- signals.each_with_index {
- |signal, i|
- if signal.name == signal_name
- return [signal.full_name, i]
- end
- }
- end
-
- def signalAt(qobject, index)
- classname = qobject.class.name
- Meta[classname].get_signals[index].full_name
- end
-
- def slotAt(qobject, index)
- classname = qobject.class.name
- Meta[classname].get_slots[index].full_name
- end
-
- def getMocArguments(member)
- argStr = member.sub(/.*\(/, '').sub(/\)$/, '')
- args = argStr.scan(/([^,]*<[^>]+>)|([^,]+)/)
- mocargs = allocateMocArguments(args.length)
- args.each_with_index {
- |arg, i|
- arg = arg.to_s
- a = arg.sub(/^const\s+/, '')
- a = (a =~ /^(bool|int|double|char\*|QString)&?$/) ? $1 : 'ptr'
- valid = setMocType(mocargs, i, arg, a)
- }
- result = []
- result << args.length << mocargs
- result
- end
-
- def makeMetaData(data)
- return nil if data.nil?
- tbl = []
- data.each {
- |entry|
- name = entry.name
- argStr = entry.arg_types
- params = []
- args = argStr.scan(/[^,]+/)
- args.each {
- |arg|
- name = '' # umm.. is this the aim?, well. it works. soo... ;-)
- param = make_QUParameter(name, arg, 0, 1)
- params << param
- }
- method = make_QUMethod(name, params)
- tbl << make_QMetaData(entry.full_name, method)
- }
- make_QMetaData_tbl(tbl)
- end
-
- def getMetaObject(qobject)
- meta = Meta[qobject.class.name]
- return nil if meta.nil?
-
- if meta.metaobject.nil? or meta.changed
- slots = meta.get_slots
- slotTable = makeMetaData(slots)
- signals = meta.get_signals
- signalTable = makeMetaData(signals)
- meta.metaobject = make_metaObject(qobject.class.name,
- qobject.staticMetaObject(),
- slotTable,
- slots.length,
- signalTable,
- signals.length)
- meta.changed = false
- end
-
- meta.metaobject
- end
+ end # Qt::MetaInfo
IO_Direct = 0x0100
IO_Sequential = 0x0200
@@ -760,7 +754,7 @@
IO_TimeOutError = 7
IO_UnspecifiedError= 8
-end
+end # Qt
class Object
# The Object.display() method conflicts with display() methods in Qt,
@@ -774,16 +768,14 @@
end
class Module
- include Qt
-
def signals(*signal_list)
- meta = Meta[self.name] || MetaInfo.new(self)
+ meta = Qt::Meta[self.name] || Qt::MetaInfo.new(self)
meta.add_signals(signal_list)
meta.changed = true
end
def slots(*slot_list)
- meta = Meta[self.name] || MetaInfo.new(self)
+ meta = Qt::Meta[self.name] || Qt::MetaInfo.new(self)
meta.add_slots(slot_list)
meta.changed = true
end
Index: rubylib/qtruby/Qt.cpp
===================================================================
RCS file: /home/kde/kdebindings/qtruby/rubylib/qtruby/Qt.cpp,v
retrieving revision 1.125
retrieving revision 1.126
diff -u -p -r1.125 -r1.126
--- kdebindings/qtruby/rubylib/qtruby/Qt.cpp 24 Mar 2005 04:59:58 -0000 1.125
+++ kdebindings/qtruby/rubylib/qtruby/Qt.cpp 30 Mar 2005 13:35:01 -0000 1.126
@@ -2509,49 +2509,48 @@ Init_qtruby()
rb_define_singleton_method(kate_module, "method_missing", (VALUE (*) (...)) kde_module_method_missing, -1);
rb_define_singleton_method(kate_module, "const_missing", (VALUE (*) (...)) kde_module_method_missing, -1);
- rb_define_method(qt_internal_module, "getMethStat", (VALUE (*) (...)) getMethStat, 0);
- rb_define_method(qt_internal_module, "getClassStat", (VALUE (*) (...)) getClassStat, 0);
- rb_define_method(qt_internal_module, "getIsa", (VALUE (*) (...)) getIsa, 1);
- rb_define_method(qt_internal_module, "allocateMocArguments", (VALUE (*) (...)) allocateMocArguments, 1);
- rb_define_method(qt_internal_module, "setMocType", (VALUE (*) (...)) setMocType, 4);
- rb_define_method(qt_internal_module, "setDebug", (VALUE (*) (...)) setDebug, 1);
- rb_define_method(qt_internal_module, "debug", (VALUE (*) (...)) debugging, 0);
- rb_define_method(qt_internal_module, "getTypeNameOfArg", (VALUE (*) (...)) getTypeNameOfArg, 2);
- rb_define_method(qt_internal_module, "classIsa", (VALUE (*) (...)) classIsa, 2);
- rb_define_method(qt_internal_module, "isEnum", (VALUE (*) (...)) isEnum, 1);
- rb_define_method(qt_internal_module, "insert_pclassid", (VALUE (*) (...)) insert_pclassid, 2);
- rb_define_method(qt_internal_module, "find_pclassid", (VALUE (*) (...)) find_pclassid, 1);
- rb_define_method(qt_internal_module, "insert_mcid", (VALUE (*) (...)) insert_mcid, 2);
- rb_define_method(qt_internal_module, "find_mcid", (VALUE (*) (...)) find_mcid, 1);
- rb_define_method(qt_internal_module, "getVALUEtype", (VALUE (*) (...)) getVALUEtype, 1);
- rb_define_method(qt_internal_module, "make_QUParameter", (VALUE (*) (...)) make_QUParameter, 4);
- rb_define_method(qt_internal_module, "make_QMetaData", (VALUE (*) (...)) make_QMetaData, 2);
- rb_define_method(qt_internal_module, "make_QUMethod", (VALUE (*) (...)) make_QUMethod, 2);
- rb_define_method(qt_internal_module, "make_QMetaData_tbl", (VALUE (*) (...)) make_QMetaData_tbl, 1);
- rb_define_method(qt_internal_module, "make_metaObject", (VALUE (*) (...)) make_metaObject, 6);
- rb_define_method(qt_internal_module, "setAllocated", (VALUE (*) (...)) setAllocated, 2);
- rb_define_method(qt_internal_module, "mapObject", (VALUE (*) (...)) mapObject, 1);
+ rb_define_module_function(qt_internal_module, "getMethStat", (VALUE (*) (...)) getMethStat, 0);
+ rb_define_module_function(qt_internal_module, "getClassStat", (VALUE (*) (...)) getClassStat, 0);
+ rb_define_module_function(qt_internal_module, "getIsa", (VALUE (*) (...)) getIsa, 1);
+ rb_define_module_function(qt_internal_module, "allocateMocArguments", (VALUE (*) (...)) allocateMocArguments, 1);
+ rb_define_module_function(qt_internal_module, "setMocType", (VALUE (*) (...)) setMocType, 4);
+ rb_define_module_function(qt_internal_module, "setDebug", (VALUE (*) (...)) setDebug, 1);
+ rb_define_module_function(qt_internal_module, "debug", (VALUE (*) (...)) debugging, 0);
+ rb_define_module_function(qt_internal_module, "getTypeNameOfArg", (VALUE (*) (...)) getTypeNameOfArg, 2);
+ rb_define_module_function(qt_internal_module, "classIsa", (VALUE (*) (...)) classIsa, 2);
+ rb_define_module_function(qt_internal_module, "isEnum", (VALUE (*) (...)) isEnum, 1);
+ rb_define_module_function(qt_internal_module, "insert_pclassid", (VALUE (*) (...)) insert_pclassid, 2);
+ rb_define_module_function(qt_internal_module, "find_pclassid", (VALUE (*) (...)) find_pclassid, 1);
+ rb_define_module_function(qt_internal_module, "insert_mcid", (VALUE (*) (...)) insert_mcid, 2);
+ rb_define_module_function(qt_internal_module, "find_mcid", (VALUE (*) (...)) find_mcid, 1);
+ rb_define_module_function(qt_internal_module, "getVALUEtype", (VALUE (*) (...)) getVALUEtype, 1);
+ rb_define_module_function(qt_internal_module, "make_QUParameter", (VALUE (*) (...)) make_QUParameter, 4);
+ rb_define_module_function(qt_internal_module, "make_QMetaData", (VALUE (*) (...)) make_QMetaData, 2);
+ rb_define_module_function(qt_internal_module, "make_QUMethod", (VALUE (*) (...)) make_QUMethod, 2);
+ rb_define_module_function(qt_internal_module, "make_QMetaData_tbl", (VALUE (*) (...)) make_QMetaData_tbl, 1);
+ rb_define_module_function(qt_internal_module, "make_metaObject", (VALUE (*) (...)) make_metaObject, 6);
+ rb_define_module_function(qt_internal_module, "setAllocated", (VALUE (*) (...)) setAllocated, 2);
+ rb_define_module_function(qt_internal_module, "mapObject", (VALUE (*) (...)) mapObject, 1);
// isQOjbect => isaQObject
- rb_define_method(qt_internal_module, "isQObject", (VALUE (*) (...)) isaQObject, 1);
- rb_define_method(qt_internal_module, "isValidAllocatedPointer", (VALUE (*) (...)) isValidAllocatedPointer, 1);
- rb_define_method(qt_internal_module, "findAllocatedObjectFor", (VALUE (*) (...)) findAllocatedObjectFor, 1);
- rb_define_method(qt_internal_module, "idClass", (VALUE (*) (...)) idClass, 1);
- rb_define_method(qt_internal_module, "idMethodName", (VALUE (*) (...)) idMethodName, 1);
- rb_define_method(qt_internal_module, "idMethod", (VALUE (*) (...)) idMethod, 2);
- rb_define_method(qt_internal_module, "findMethod", (VALUE (*) (...)) findMethod, 2);
- rb_define_method(qt_internal_module, "findAllMethods", (VALUE (*) (...)) findAllMethods, -1);
- rb_define_method(qt_internal_module, "dumpCandidates", (VALUE (*) (...)) dumpCandidates, 1);
- rb_define_method(qt_internal_module, "isObject", (VALUE (*) (...)) isObject, 1);
- rb_define_method(qt_internal_module, "setCurrentMethod", (VALUE (*) (...)) setCurrentMethod, 1);
- rb_define_method(qt_internal_module, "getClassList", (VALUE (*) (...)) getClassList, 0);
- rb_define_method(qt_internal_module, "create_qt_class", (VALUE (*) (...)) create_qt_class, 1);
- rb_define_method(qt_internal_module, "create_qobject_class", (VALUE (*) (...)) create_qobject_class, 1);
- rb_define_method(qt_internal_module, "version", (VALUE (*) (...)) version, 0);
- rb_define_method(qt_internal_module, "qtruby_version", (VALUE (*) (...)) qtruby_version, 0);
- rb_define_method(qt_internal_module, "cast_object_to", (VALUE (*) (...)) cast_object_to, 2);
- rb_define_method(qt_internal_module, "application_terminated=", (VALUE (*) (...)) set_application_terminated, 1);
+ rb_define_module_function(qt_internal_module, "isQObject", (VALUE (*) (...)) isaQObject, 1);
+ rb_define_module_function(qt_internal_module, "isValidAllocatedPointer", (VALUE (*) (...)) isValidAllocatedPointer, 1);
+ rb_define_module_function(qt_internal_module, "findAllocatedObjectFor", (VALUE (*) (...)) findAllocatedObjectFor, 1);
+ rb_define_module_function(qt_internal_module, "idClass", (VALUE (*) (...)) idClass, 1);
+ rb_define_module_function(qt_internal_module, "idMethodName", (VALUE (*) (...)) idMethodName, 1);
+ rb_define_module_function(qt_internal_module, "idMethod", (VALUE (*) (...)) idMethod, 2);
+ rb_define_module_function(qt_internal_module, "findMethod", (VALUE (*) (...)) findMethod, 2);
+ rb_define_module_function(qt_internal_module, "findAllMethods", (VALUE (*) (...)) findAllMethods, -1);
+ rb_define_module_function(qt_internal_module, "dumpCandidates", (VALUE (*) (...)) dumpCandidates, 1);
+ rb_define_module_function(qt_internal_module, "isObject", (VALUE (*) (...)) isObject, 1);
+ rb_define_module_function(qt_internal_module, "setCurrentMethod", (VALUE (*) (...)) setCurrentMethod, 1);
+ rb_define_module_function(qt_internal_module, "getClassList", (VALUE (*) (...)) getClassList, 0);
+ rb_define_module_function(qt_internal_module, "create_qt_class", (VALUE (*) (...)) create_qt_class, 1);
+ rb_define_module_function(qt_internal_module, "create_qobject_class", (VALUE (*) (...)) create_qobject_class, 1);
+ rb_define_module_function(qt_internal_module, "version", (VALUE (*) (...)) version, 0);
+ rb_define_module_function(qt_internal_module, "qtruby_version", (VALUE (*) (...)) qtruby_version, 0);
+ rb_define_module_function(qt_internal_module, "cast_object_to", (VALUE (*) (...)) cast_object_to, 2);
+ rb_define_module_function(qt_internal_module, "application_terminated=", (VALUE (*) (...)) set_application_terminated, 1);
- rb_include_module(qt_module, qt_internal_module);
rb_require("Qt/qtruby.rb");
// Do package initialization
More information about the Kde-bindings
mailing list