[Kde-bindings] KDE/kdebindings/qtruby
Richard Dale
Richard_Dale at tipitina.demon.co.uk
Wed Jan 17 02:07:38 UTC 2007
SVN commit 624328 by rdale:
* QtRuby was crashing in virtual method callbacks with a memory corruption
problem. The stack of ruby VALUES for the arguments to the callback is
now allocated via ALLOCA_N, rather than calloc which cures the crashes.
* Changed tabs to spaces in the pixelator example
CCMAIL: kde-bindings at kde.org
M +7 -0 ChangeLog
M +23 -23 rubylib/examples/itemviews/pixelator/imagemodel.rb
M +32 -32 rubylib/examples/itemviews/pixelator/pixeldelegate.rb
M +2 -2 rubylib/qtruby/Qt.cpp
M +6 -7 rubylib/qtruby/marshall_types.cpp
M +1 -1 rubylib/qtruby/marshall_types.h
--- trunk/KDE/kdebindings/qtruby/ChangeLog #624327:624328
@@ -1,3 +1,10 @@
+2007-01-17 Richard Dale <rdale at foton.es>
+
+ * QtRuby was crashing in virtual method callbacks with a memory corruption
+ problem. The stack of ruby VALUES for the arguments to the callback is
+ now allocated via ALLOCA_N, rather than calloc which cures the crashes.
+ * Changed tabs to spaces in the pixelator example
+
2007-01-15 Richard Dale <rdale at foton.es>
* Code generated with the rbuic tool '-x' option has a require 'Qt4'
--- trunk/KDE/kdebindings/qtruby/rubylib/examples/itemviews/pixelator/imagemodel.rb #624327:624328
@@ -22,30 +22,30 @@
** Translated to QtRuby by Richard Dale
=end
-
+
class ImageModel < Qt::AbstractTableModel
-
- def initialize(image, parent = nil)
- super(parent)
- @modelImage = Qt::Image.new(image)
- end
-
- def rowCount(parent)
- return @modelImage.height
- end
-
- def columnCount(parent)
- return @modelImage.width
- end
-
- def data(index, role)
- if !index.valid?
- return Qt::Variant.new
- elsif role == Qt::ToolTipRole
- return Qt::Variant.new
- end
+
+ def initialize(image, parent = nil)
+ super(parent)
+ @modelImage = Qt::Image.new(image)
+ end
+
+ def rowCount(parent)
+ return @modelImage.height
+ end
+
+ def columnCount(parent)
+ return @modelImage.width
+ end
+
+ def data(index, role)
+ if !index.valid?
+ return Qt::Variant.new
+ elsif role == Qt::ToolTipRole
+ return Qt::Variant.new
+ end
- return Qt::Variant.new(qGray(@modelImage.pixel(index.column, index.row)))
- end
+ return Qt::Variant.new(qGray(@modelImage.pixel(index.column, index.row)))
+ end
end
--- trunk/KDE/kdebindings/qtruby/rubylib/examples/itemviews/pixelator/pixeldelegate.rb #624327:624328
@@ -22,46 +22,46 @@
** Translated to QtRuby by Richard Dale
=end
-
+
class PixelDelegate < Qt::AbstractItemDelegate
- ItemSize = 256
- slots 'pixelSize=(int)'
- attr_accessor :pixelSize
+ ItemSize = 256
+ slots 'pixelSize=(int)'
+ attr_accessor :pixelSize
- def initialize(parent = nil)
- super(parent)
- @pixelSize = 12
- end
+ def initialize(parent = nil)
+ super(parent)
+ @pixelSize = 12
+ end
- def paint(painter, option, index)
- painter.renderHint = Qt::Painter::Antialiasing
- painter.pen = Qt::NoPen
+ def paint(painter, option, index)
+ painter.renderHint = Qt::Painter::Antialiasing
+ painter.pen = Qt::NoPen
- if (option.state & Qt::Style::State_Selected.to_i) != 0
- painter.brush = option.palette.highlight
- else
- painter.brush = Qt::Brush.new(Qt::white)
- end
+ if (option.state & Qt::Style::State_Selected.to_i) != 0
+ painter.brush = option.palette.highlight
+ else
+ painter.brush = Qt::Brush.new(Qt::white)
+ end
- painter.drawRect(option.rect)
+ painter.drawRect(option.rect)
- if (option.state & Qt::Style::State_Selected.to_i) != 0
- painter.brush = option.palette.highlightedText
- else
- painter.brush = Qt::Brush.new(Qt::black)
- end
-
- size = [option.rect.width, option.rect.height].min
- brightness = index.model.data(index, Qt::DisplayRole).to_i
- radius = (size/2.0) - (brightness/255.0 * size/2.0)
+ if (option.state & Qt::Style::State_Selected.to_i) != 0
+ painter.brush = option.palette.highlightedText
+ else
+ painter.brush = Qt::Brush.new(Qt::black)
+ end
+
+ size = [option.rect.width, option.rect.height].min
+ brightness = index.model.data(index, Qt::DisplayRole).to_i
+ radius = (size/2.0) - (brightness/255.0 * size/2.0)
- painter.drawEllipse(Qt::RectF.new(option.rect.x + option.rect.width/2 - radius,
+ painter.drawEllipse(Qt::RectF.new(option.rect.x + option.rect.width/2 - radius,
option.rect.y + option.rect.height/2 - radius,
2*radius, 2*radius))
- end
-
- def sizeHint(option, index)
- return Qt::Size.new(@pixelSize, @pixelSize)
- end
+ end
+
+ def sizeHint(option, index)
+ return Qt::Size.new(@pixelSize, @pixelSize)
+ end
end
--- trunk/KDE/kdebindings/qtruby/rubylib/qtruby/Qt.cpp #624327:624328
@@ -331,8 +331,8 @@
if (rb_respond_to(obj, rb_intern(methodName)) == 0) {
return false;
}
-
- VirtualMethodCall c(smoke, method, args, obj);
+
+ VirtualMethodCall c(smoke, method, args, obj, ALLOCA_N(VALUE, smoke->methods[method].numArgs));
c.next();
return true;
}
--- trunk/KDE/kdebindings/qtruby/rubylib/qtruby/marshall_types.cpp #624327:624328
@@ -356,16 +356,15 @@
}
-VirtualMethodCall::VirtualMethodCall(Smoke *smoke, Smoke::Index meth, Smoke::Stack stack, VALUE obj) :
- MethodCallBase(smoke,meth,stack), _obj(obj)
+VirtualMethodCall::VirtualMethodCall(Smoke *smoke, Smoke::Index meth, Smoke::Stack stack, VALUE obj, VALUE *sp) :
+ MethodCallBase(smoke,meth,stack), _obj(obj)
{
- _sp = (VALUE *) calloc(method().numArgs, sizeof(VALUE));
+ _sp = sp;
_args = _smoke->argumentList + method().args;
}
VirtualMethodCall::~VirtualMethodCall()
{
- free(_sp);
}
Marshall::Action
@@ -541,7 +540,7 @@
// qt_metacall()
void * ptr = o[0];
smokeStackToQtStack(_stack, o, 1, _replyType);
- // Only if the zeroth element of the arrary of 'void*'s passed to qt_metacall()
+ // Only if the zeroth element of the array of 'void*'s passed to qt_metacall()
// contains an address, is the return value of the slot needed.
if (ptr != 0) {
*(void**)ptr = *(void**)(o[0]);
@@ -575,13 +574,13 @@
InvokeSlot::InvokeSlot(VALUE obj, ID slotname, VALUE args, void ** o) : SigSlotBase(args),
_obj(obj), _slotname(slotname), _o(o)
{
- _sp = (VALUE *) calloc(_items - 1, sizeof(VALUE));
+ _sp = (VALUE *) ALLOC_N(VALUE, _items - 1);
copyArguments();
}
InvokeSlot::~InvokeSlot()
{
- free(_sp);
+ xfree(_sp);
}
Marshall::Action
--- trunk/KDE/kdebindings/qtruby/rubylib/qtruby/marshall_types.h #624327:624328
@@ -102,7 +102,7 @@
class VirtualMethodCall : public MethodCallBase {
public:
- VirtualMethodCall(Smoke *smoke, Smoke::Index meth, Smoke::Stack stack, VALUE obj);
+ VirtualMethodCall(Smoke *smoke, Smoke::Index meth, Smoke::Stack stack, VALUE obj, VALUE *sp);
~VirtualMethodCall();
Marshall::Action action();
VALUE * var();
More information about the Kde-bindings
mailing list