diff --git a/Rakefile.cross b/Rakefile.cross index 1cecb7a87787c901ff1363106a270007b9c7a8f9..5ea87349dfeca9026139520829c25021f5333fdf 100644 --- a/Rakefile.cross +++ b/Rakefile.cross @@ -6,7 +6,8 @@ require 'hoe' require 'rake/extensiontask' require 'rake/extensioncompiler' require 'uri' -require "rbconfig" +require 'rbconfig' +require 'pathname' ENV['RUBY_CC_VERSION'] ||= '1.8.7:1.9.2' diff --git a/ext/fox16/FXRuby.cpp b/ext/fox16/FXRuby.cpp index 9b99d890ca29b56bf420cf430f991f0f94018e3c..81bb2f1eb00c124a108b04dbcb122a85117a3c17 100644 --- a/ext/fox16/FXRuby.cpp +++ b/ext/fox16/FXRuby.cpp @@ -53,6 +53,7 @@ extern "C" { #endif /* RUBY_1_9 */ + // Opaque type declaration from SWIG runtime struct swig_type_info; @@ -173,16 +174,16 @@ FXInputHandle FXRbGetReadFileHandle(VALUE obj) { // Returns an FXInputHandle for this Ruby file object FXInputHandle FXRbGetWriteFileHandle(VALUE obj) { int fd; -#ifdef RUBY_1_9 +#if defined(RUBINIUS) + VALUE vwrite = rb_intern("@write"); + if(rb_ivar_defined(obj, vwrite)) obj = rb_ivar_get(obj, vwrite); + fd = FIX2INT(rb_funcall(obj, rb_intern("fileno"), 0)); +#elif defined(RUBY_1_9) rb_io_t *fptr; GetOpenFile(obj, fptr); VALUE wrio = fptr->tied_io_for_writing; if(wrio) obj = wrio; fd = FIX2INT(rb_funcall(obj, rb_intern("fileno"), 0)); -#elif defined(RBX_CAPI_RUBY_H) - VALUE vwrite = rb_intern("@write"); - if(rb_ivar_defined(obj, vwrite)) obj = rb_ivar_get(obj, vwrite); - fd = FIX2INT(rb_funcall(obj, rb_intern("fileno"), 0)); #else OpenFile *fptr; GetOpenFile(obj, fptr); diff --git a/swig-interfaces/FXMemoryStream.i b/swig-interfaces/FXMemoryStream.i index 613cd5d7b44bbc793475b18e77665f1922005ea5..82c4209d25b716cf483771ff5c095947042a2980 100644 --- a/swig-interfaces/FXMemoryStream.i +++ b/swig-interfaces/FXMemoryStream.i @@ -44,7 +44,7 @@ public: return self->open(save_or_load,data); } } - + // Take buffer away from stream VALUE takeBuffer() { FXuchar* buffer; @@ -54,19 +54,23 @@ public: FXFREE(&buffer); return result; } - + /// Give buffer to stream void giveBuffer(VALUE str){ + FXuchar* copy = NULL; Check_Type(str,T_STRING); FXuchar* buffer=reinterpret_cast<FXuchar*>(StringValuePtr(str)); FXuval sp=RSTRING_LEN(str); - self->giveBuffer(buffer,sp); + if( FXMALLOC(©, FXuchar *, sp)) { + memcpy(copy, buffer, sp); + self->giveBuffer(copy,sp); + } } } - + /// Get position FXlong position() const; - + /// Destructor virtual ~FXMemoryStream(); }; diff --git a/swig-interfaces/ruby-typemaps.i b/swig-interfaces/ruby-typemaps.i index f0fda1f2102ac99b40cc1baa0f6e720b15409ca7..d59085df476002aa9cdb30c2967a9870ab7b48ac 100644 --- a/swig-interfaces/ruby-typemaps.i +++ b/swig-interfaces/ruby-typemaps.i @@ -184,7 +184,7 @@ inline FXbool to_FXbool(VALUE obj){ $1 = NULL; if(!NIL_P($input)){ Check_Type($input, T_ARRAY); - if (FXMALLOC(&$1, FXchar *, RARRAY_LEN($input))+1) { + if (FXMALLOC(&$1, FXchar *, RARRAY_LEN($input)+1)) { for (long i = 0; i < RARRAY_LEN($input); i++) { VALUE e = rb_ary_entry($input, i); $1[i] = (FXchar *) StringValuePtr(e); @@ -201,7 +201,7 @@ inline FXbool to_FXbool(VALUE obj){ $1 = NULL; if(!NIL_P($input)){ Check_Type($input, T_ARRAY); - if (FXMALLOC(&$1, FXColor, RARRAY_LEN($input))+1) { + if (FXMALLOC(&$1, FXColor, RARRAY_LEN($input)+1)) { for (long i = 0; i < RARRAY_LEN($input); i++) { $1[i] = static_cast<FXColor>(NUM2ULONG(rb_ary_entry($input, i))); } @@ -599,7 +599,7 @@ inline void* to_FXEvent(VALUE obj){ /* Output typemap for FXViewport instances */ %typemap(out) FXViewport { - FXViewport* resultptr = new FXViewport($1); + FXViewport* resultptr = new FXViewport($1); $result = FXRbGetRubyObj(resultptr, "FXViewport *"); } @@ -731,7 +731,7 @@ inline void* to_FXEvent(VALUE obj){ * be able to pass either zero, -1, or a window to that function and get * the same behavior as in FOX. */ - + %typemap(in) FXWindow* TOOLBAR_DOCK_AFTER { if (TYPE($input) == T_FIXNUM) { $1 = reinterpret_cast<FXWindow *>(static_cast<long>(NUM2INT($input))); diff --git a/test/TC_FXDCPrint.rb b/test/TC_FXDCPrint.rb index c06fa52cdf0c86f3dba80ef9f072c9488a2cf83e..3f72299f90c7cbe5995c6ef39ef86188da7b9285 100755 --- a/test/TC_FXDCPrint.rb +++ b/test/TC_FXDCPrint.rb @@ -1,6 +1,7 @@ require 'test/unit' require 'fox16' +require 'fileutils' include Fox @@ -25,7 +26,7 @@ private job.flags = PRINT_DEST_FILE job end - + def hexdump(ios) count = 0 ios.each_byte do |byte| @@ -48,7 +49,7 @@ private File.open(actual, 'rb') { |f| actual_contents = crlf_to_lf(f.read) } assert_equal(expected_contents, actual_contents) end - + public def setup if FXApp.instance.nil? @@ -92,7 +93,7 @@ public end # assert_same_file_contents("howdypage.ps", printJob.name) end - + def teardown if File.exists?("output.ps") FileUtils.rm_f("output.ps")