[Kde-bindings] KDE/kdebindings/ruby/qtruby
Richard Dale
Richard_Dale at tipitina.demon.co.uk
Thu Dec 4 19:06:56 UTC 2008
SVN commit 892615 by rdale:
* From Bartosz Wadolowski (thanks for the patch):
unsigned char* marshalling in qtruby didn't work. The patch works as char*
case does - I simply copied code and added one casting.
It also fixes method matching with string argument in qtruby4.rb. In
cases when method could take constant or regular (unsigned)char
pointer Qt::Internal.checkarg was returning the same value. Now in
case of constant arguments it returns lower value. I also made this
part of code a little bit more readable.
Those changes made possible to use those QImage constructors and
probably some other methods:
QImage ( uchar * data, int width, int height, Format format )
QImage ( const uchar * data, int width, int height, Format format )
QImage ( uchar * data, int width, int height, int bytesPerLine, Format
format )
QImage ( const uchar * data, int width, int height, int bytesPerLine,
Format format )
IMPORTANT NOTE:
Some Qt/KDE objects use Ruby String*, passed as (unsigned )char*
method argument, as internal buffer/array(call it as you like). In
those cases programmer need to make sure that Ruby String object is
not being garbage collected or changed(in most cases) for the time its
being used by Qt/KDE object. It is also quite possible that Qt/KDE
object will change Ruby String (or rather its internal C char array).
CCMAIL: kde-bindings at kde.org
M +30 -1 ChangeLog
M +6 -4 src/lib/Qt/qtruby4.rb
M +6 -0 src/marshall_basetypes.h
M +1 -5 src/marshall_primitives.h
--- trunk/KDE/kdebindings/ruby/qtruby/ChangeLog #892614:892615
@@ -1,3 +1,32 @@
+2008-12-04 Richard Dale <richard.j.dale at gmail.com>
+
+ * From Bartosz Wadolowski (thanks for the patch):
+
+ unsigned char* marshalling in qtruby didn't work. The patch works as char*
+ case does - I simply copied code and added one casting.
+ It also fixes method matching with string argument in qtruby4.rb. In
+ cases when method could take constant or regular (unsigned)char
+ pointer Qt::Internal.checkarg was returning the same value. Now in
+ case of constant arguments it returns lower value. I also made this
+ part of code a little bit more readable.
+ Those changes made possible to use those QImage constructors and
+ probably some other methods:
+
+ QImage ( uchar * data, int width, int height, Format format )
+ QImage ( const uchar * data, int width, int height, Format format )
+ QImage ( uchar * data, int width, int height, int bytesPerLine, Format
+ format )
+ QImage ( const uchar * data, int width, int height, int bytesPerLine,
+ Format format )
+
+ IMPORTANT NOTE:
+ Some Qt/KDE objects use Ruby String*, passed as (unsigned )char*
+ method argument, as internal buffer/array(call it as you like). In
+ those cases programmer need to make sure that Ruby String object is
+ not being garbage collected or changed(in most cases) for the time its
+ being used by Qt/KDE object. It is also quite possible that Qt/KDE
+ object will change Ruby String (or rather its internal C char array).
+
2008-11-24 Richard Dale <richard.j.dale at gmail.com>
* Added a DEF_MAP_MARSHALLER() macro for defining marshallers for
QMaps with QString keys and value types as the values
@@ -411,7 +440,7 @@
* Thanks to Sylvain Sauvage for reporting the problem on the Korundum
help forum
-2007-11-21 Â Sebastian Sauer <mail at dipe.org>
+2007-11-21 Â Sebastian Sauer <mail at dipe.org>
* Fixed crash on shutdown of Ruby cause of a partly destroyed
pointer_map QHash.
--- trunk/KDE/kdebindings/ruby/qtruby/src/lib/Qt/qtruby4.rb #892614:892615
@@ -2426,11 +2426,13 @@
end
elsif argtype == 's'
if typename =~ /^(const )?((QChar)[*&]?)$/
+ return 3
+ elsif typename =~ /^(?:u?char\*)$/
+ return 1
+ elsif typename =~ /^(?:const u?char\*)$/
return 2
- elsif typename =~ /^(?:u?char\*|const u?char\*|(?:const )?(Q(C?)String)[*&]?)$/
- qstring = !$1.nil?
- c = ("C" == $2)
- return c ? 3 : (qstring ? 4 : 1)
+ elsif typename =~ /^(?:(?:const )?(QString)[*&]?)$/
+ return 4
end
elsif argtype == 'a'
# FIXME: shouldn't be hardcoded. Installed handlers should tell what ruby type they expect.
--- trunk/KDE/kdebindings/ruby/qtruby/src/marshall_basetypes.h #892614:892615
@@ -53,6 +53,12 @@
}
template <>
+void marshall_from_ruby<unsigned char *>(Marshall *m)
+{
+ m->item().s_voidp = ruby_to_primitive<unsigned char*>(*(m->var()));
+}
+
+template <>
void marshall_from_ruby<SmokeEnumWrapper>(Marshall *m)
{
VALUE v = *(m->var());
--- trunk/KDE/kdebindings/ruby/qtruby/src/marshall_primitives.h #892614:892615
@@ -235,11 +235,7 @@
if(rv == Qnil)
return 0;
- int len = RSTRING(rv)->len;
- char* mem = (char*) malloc(len+1);
- memcpy(mem, StringValuePtr(rv), len);
- mem[len] ='\0';
- return (unsigned char*) mem;
+ return (unsigned char*)StringValuePtr(rv);
}
template <>
More information about the Kde-bindings
mailing list