fxruby 1.6.35-x64-mingw32 → 1.6.36-x64-mingw32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5ae09258c405f4a6457003eb889f69f530084f93
4
- data.tar.gz: 3fdff3a7126dbbc442631f4ebf7905a2be79ffd9
3
+ metadata.gz: 3cde95f49d756372079e10771ba5d7c143edc51a
4
+ data.tar.gz: 942334d1a8e18419db53237d7847678332cf2324
5
5
  SHA512:
6
- metadata.gz: 1d02feb8a9d184e3a3c29d5749de52ae80d212a345faa4ca29a71556c51cee80ea85de548ab37c866a8bb697bfa7ebbd8b419c7c9514054afbef9a89b1529bd0
7
- data.tar.gz: fb8b7b4f3a47bf2bf02bfa4deaeccd8280a0b5a1ad035669e58eb268c16d9c0f33a90502a16624f38e7623e71b771e0654a5c06d558982be5cf79f908aa44f84
6
+ metadata.gz: 41e9c0a0a50324569e46bbdb89ae684ef89a1a7e11d483823d76a8a92e995b1bce0861aa2c30cd2239690248f8df75bda998b73a25649a94d842391c34664453
7
+ data.tar.gz: fae1628f002c90afa5ea84ab62603cdf25eb76704a639c6e872b140bdc3818b7ac6e7519536fda5d68e5208ef18982fbdb9159dea5bbc678e6eabeda079aa1b6
data/.gitignore CHANGED
@@ -6,9 +6,21 @@ ext/fox16_c/*_wrap.cpp
6
6
  ext/fox16_c/*.o
7
7
  ext/fox16_c/conftest.dSYM
8
8
  ext/fox16_c/include/inlinestubs.h
9
+ ext/fox16_c/extconf.h
9
10
  ext/fox16_c/swigruby.h
10
11
  ext/fox16_c/fox16.bundle
11
12
  ext/fox16_c/mkmf.log
12
13
  lib/fox16/kwargs.rb
14
+ lib/[0-9].[0-9]
15
+ lib/*.so
13
16
  fox-includes/diffs.py
14
17
  fox-includes/diffs.txt
18
+ pkg
19
+ tmp
20
+ vendor
21
+ *.orig
22
+ *.rej
23
+ /Gemfile.lock
24
+ /ports
25
+ /.bundle
26
+ /.yardoc
@@ -0,0 +1,45 @@
1
+ dist: trusty
2
+ sudo: false
3
+ group: beta
4
+ language: ruby
5
+
6
+ addons:
7
+ apt:
8
+ packages:
9
+ - xpra
10
+ - xserver-xorg-video-dummy
11
+ - g++
12
+ - libxrandr-dev
13
+ - libfox-1.6-dev
14
+ - libfxscintilla-dev
15
+ - swig
16
+
17
+ install:
18
+ - swig -version
19
+ - ls -l /usr/lib/libfxscintilla*
20
+ - bundle install
21
+
22
+ before_script:
23
+ - "xpra --xvfb=\"Xorg +extension GLX -config `pwd`/test/dummy.xorg.conf -logfile ${HOME}/.xpra/xorg.log\" start :9"
24
+
25
+ script: bundle exec rake test DISPLAY=:9
26
+
27
+ after_failure:
28
+ - "cat ~/.xpra/*"
29
+
30
+ after_script:
31
+ - "xpra stop :9"
32
+
33
+ rvm:
34
+ - "2.0.0"
35
+ - "2.1"
36
+ - "2.2"
37
+ - "2.3.1"
38
+ - "2.4.0"
39
+ - "ruby-head"
40
+ # swig compilation is sooo slow on rbx-3, that it exceeds the time limit on travis-ci
41
+ #- "rbx-3"
42
+ matrix:
43
+ allow_failures:
44
+ - rvm: ruby-head
45
+ - rvm: rbx-3
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's runtime dependencies in fxruby.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'rake-compiler', '~> 1.0'
8
+ gem 'rake-compiler-dock', '~> 0.6.0'
9
+ gem 'yard', '~> 0.8'
10
+ gem "bundler", "~> 1.12"
11
+ gem "rake", "~> 12.0"
12
+ end
13
+
14
+ group :test do
15
+ gem 'opengl', '~> 0.8'
16
+ gem 'glu', '~> 8.0'
17
+ gem 'test-unit', '~> 3.1'
18
+ end
@@ -1,3 +1,13 @@
1
+ === 1.6.36 / 2017-06-04
2
+
3
+ * Support the fxruby source gem on Windows (only RubyInstaller-2.4).
4
+ * Replace our self-made directory search methods by pgk-config.
5
+ * Enable the use of Win32 unicode functions. Fixes #30 and #38
6
+ * Fix segfault in vsprintf on Windows 10.
7
+ * Update support for RubyInstaller-2.4.1-1
8
+ * Update to libjpeg-9b
9
+ * More automation for gem releases
10
+
1
11
  === 1.6.35 / 2017-02-15
2
12
 
3
13
  * Adjust for Ruby-2.4 with unified Integers
data/Rakefile CHANGED
@@ -1,107 +1,112 @@
1
1
  require 'rubygems'
2
- require 'hoe'
3
2
  require 'erb'
4
3
  require 'rake/extensiontask'
4
+ require 'bundler'
5
+ require 'bundler/gem_helper'
5
6
  require './lib/fox16/version.rb'
6
7
 
7
- Hoe.plugin :bundler
8
-
9
- # Use forked process for chdir'ed environment, to allow parallel execution with drake
8
+ # Use forked process for chdir'ed environment, to allow parallel execution with rake -m
10
9
  module FileUtils
11
10
  alias unforked_fileutils_cd cd
12
11
  def cd(dir, options={}, &block)
13
12
  raise "chdir called without block" unless block_given?
14
- Process.waitpid(fork{ unforked_fileutils_cd(dir, options, &block) })
13
+ begin
14
+ pid = Process.waitpid(fork{ unforked_fileutils_cd(dir, options, &block) })
15
+ raise "Error in subprocess" if $?.exitstatus != 0
16
+ rescue NotImplementedError
17
+ unforked_fileutils_cd(dir, options, &block)
18
+ end
15
19
  end
16
20
  module_function :cd
17
21
  alias chdir cd
18
22
  module_function :chdir
19
23
  end
20
24
 
21
- # Some constants we'll need
22
- PKG_VERSION = Fox.fxrubyversion
23
25
 
26
+ class FoxGemHelper < Bundler::GemHelper
27
+ attr_accessor :cross_platforms
28
+
29
+ def install
30
+ super
31
+
32
+ task "release:guard_clean" => ["release:update_history"]
33
+
34
+ task "release:update_history" do
35
+ update_history
36
+ end
37
+
38
+ task "release:rubygem_push" => ["gem:windows"]
39
+ end
40
+
41
+ def hfile
42
+ "History.md"
43
+ end
44
+
45
+ def headline
46
+ '([^\w]*)(\d+\.\d+\.\d+)([^\w]+)([2Y][0Y][0-9Y][0-9Y]-[0-1M][0-9M]-[0-3D][0-9D])([^\w]*|$)'
47
+ end
48
+
49
+ def reldate
50
+ Time.now.strftime("%Y-%m-%d")
51
+ end
52
+
53
+ def update_history
54
+ hin = File.read(hfile)
55
+ hout = hin.sub(/#{headline}/) do
56
+ raise "#{hfile} isn't up-to-date for version #{version}" unless $2==version.to_s
57
+ $1 + $2 + $3 + reldate + $5
58
+ end
59
+ if hout != hin
60
+ Bundler.ui.confirm "Updating #{hfile} for release."
61
+ File.write(hfile, hout)
62
+ Rake::FileUtilsExt.sh "git", "commit", hfile, "-m", "Update release date in #{hfile}"
63
+ end
64
+ end
65
+
66
+ def tag_version
67
+ Bundler.ui.confirm "Tag release with annotation:"
68
+ m = File.read(hfile).match(/(?<annotation>#{headline}.*?)#{headline}/m) || raise("Unable to find release notes in #{hfile}")
69
+ Bundler.ui.info(m[:annotation].gsub(/^/, " "))
70
+ IO.popen(["git", "tag", "--file=-", version_tag], "w") do |fd|
71
+ fd.write m[:annotation]
72
+ end
73
+ yield if block_given?
74
+ rescue
75
+ Bundler.ui.error "Untagging #{version_tag} due to error."
76
+ sh_with_code "git tag -d #{version_tag}"
77
+ raise
78
+ end
79
+
80
+ def rubygem_push(path)
81
+ cross_platforms.each do |ruby_platform|
82
+ super(path.gsub(/\.gem\z/, "-#{ruby_platform}.gem"))
83
+ end
84
+ super(path)
85
+ end
86
+ end
87
+
88
+ # Some constants we'll need
24
89
  LIBFXSCINTILLA_VERSION = ENV['LIBFXSCINTILLA_VERSION'] || '2.28.0'
25
90
  LIBFXSCINTILLA_SOURCE_URI = "http://download.savannah.gnu.org/releases/fxscintilla/fxscintilla-#{LIBFXSCINTILLA_VERSION}.tar.gz"
26
91
 
27
92
  SWIG = (RUBY_PLATFORM =~ /mingw/) ? "swig.exe" : "swig"
28
93
  SWIGFLAGS = "-c++ -ruby -nodefaultdtor -nodefaultctor -w302 -features compactdefaultargs -I../fox-includes"
29
- SWIG_MODULES = {
30
- "core.i" => "core_wrap.cpp",
31
- "dcmodule.i" => "dc_wrap.cpp",
32
- "dialogs.i" => "dialogs_wrap.cpp",
33
- "framesmodule.i" => "frames_wrap.cpp",
34
- "iconlistmodule.i" => "iconlist_wrap.cpp",
35
- "icons.i" => "icons_wrap.cpp",
36
- "image.i" => "image_wrap.cpp",
37
- "labelmodule.i" => "label_wrap.cpp",
38
- "layout.i" => "layout_wrap.cpp",
39
- "listmodule.i" => "list_wrap.cpp",
40
- "mdi.i" => "mdi_wrap.cpp",
41
- "menumodule.i" => "menu_wrap.cpp",
42
- "fx3d.i" => "fx3d_wrap.cpp",
43
- "scintilla.i" => "scintilla_wrap.cpp",
44
- "table-module.i" => "table_wrap.cpp",
45
- "text-module.i" => "text_wrap.cpp",
46
- "treelist-module.i" => "treelist_wrap.cpp",
47
- "ui.i" => "ui_wrap.cpp"
48
- }
49
-
50
-
51
- hoe = Hoe.spec "fxruby" do
52
- # ... project specific data ...
53
- self.blog_categories = %w{FXRuby}
54
- self.clean_globs = [".config", "ext/fox16_c/Makefile", "ext/fox16_c/*.o", "ext/fox16_c/*.bundle", "ext/fox16_c/mkmf.log", "ext/fox16_c/conftest.dSYM", "ext/fox16_c/swigruby.h", "ext/fox16_c/librb.c", "ext/fox16_c/include/inlinestubs.h", "ext/fox16_c/*_wrap.cpp", "tmp", "ports/*.installed", "ports/*mingw32*"]
55
- developer("Lyle Johnson", "lyle@lylejohnson.name")
56
- developer("Lars Kanis", "kanis@comcard.de")
57
- self.extra_rdoc_files = ["rdoc-sources", File.join("rdoc-sources", "README.rdoc")]
58
- self.remote_rdoc_dir = "doc/api"
59
- self.spec_extras = {
60
- :description => "FXRuby is the Ruby binding to the FOX GUI toolkit.",
61
- :extensions => ["ext/fox16_c/extconf.rb"],
62
- :rdoc_options => ['--main', File.join('rdoc-sources', 'README.rdoc'), '--exclude', 'ext/fox16_c', '--exclude', %r{aliases|kwargs|missingdep|responder}.inspect],
63
- :require_paths => ['lib'],
64
- :summary => "FXRuby is the Ruby binding to the FOX GUI toolkit."
65
- }
66
- self.test_globs = ["test/**/TC_*.rb"]
67
- self.testlib = :testunit
68
- self.version = PKG_VERSION
69
- self.readme_file = 'README.rdoc'
70
- self.extra_rdoc_files << self.readme_file
71
- self.extra_deps << ['mini_portile2', '~> 2.1']
72
- self.extra_dev_deps << ['rake-compiler', '~> 1.0']
73
- self.extra_dev_deps << ['rake-compiler-dock', '~> 0.6.0']
74
- self.extra_dev_deps << ['opengl', '~> 0.8']
75
- self.extra_dev_deps << ['glu', '~> 8.0']
76
- self.extra_dev_deps << ['test-unit', '~> 3.1']
77
- self.extra_dev_deps << ['yard', '~> 0.8']
78
- self.extra_dev_deps << ['hoe-bundler', '~> 1.1']
79
- self.license 'LGPL'
80
-
81
- spec_extras[:files] = File.read_utf("Manifest.txt").split(/\r?\n\r?/).reject{|f| f=~/^fox-includes|^web/ }
82
- spec_extras[:files] += SWIG_MODULES.values.map{|f| File.join("ext/fox16_c", f) }
83
- spec_extras[:files] << 'ext/fox16_c/include/inlinestubs.h'
84
- spec_extras[:files] << 'ext/fox16_c/swigruby.h'
85
- spec_extras[:files] << 'doap.rdf'
86
- spec_extras[:files] << 'lib/fox16/kwargs.rb'
87
- end
94
+
95
+ CLEAN.include( ".config", "ext/fox16_c/Makefile", "ext/fox16_c/*.o", "ext/fox16_c/*.bundle", "ext/fox16_c/mkmf.log", "ext/fox16_c/conftest.dSYM", "ext/fox16_c/swigruby.h", "ext/fox16_c/librb.c", "ext/fox16_c/include/inlinestubs.h", "ext/fox16_c/*_wrap.cpp", "tmp", "ports/*.installed", "ports/*mingw32*" )
96
+
97
+ CLOBBER.include( "pkg" )
88
98
 
89
99
  # Make sure extension is built before tests are run
90
- task :test => [:compile]
100
+ task :test => [:compile] do
101
+ sh "ruby -w -W2 -Ilib test/TS_All.rb -v"
102
+ end
91
103
 
92
- # The "docs" task created by Hoe assumes that we want to run RDoc
93
- # over everything under the "lib" and "ext" subdirectories.
94
- # We need to go back and tell it to skip the stuff under ext.
95
- # rdoc_target = Rake::Task['docs'].prerequisites.first
96
- # rdoc_files = Rake::Task[rdoc_target].prerequisites
97
- # rdoc_files.reject! {|x| x == "ext/fox16_c" }
104
+ task :gem => [:compile, :build]
98
105
 
99
- # Make sure that all of the package contents exist before we try to build the package
100
- #Rake::Task['package'].prerequisites.unshift("swig:swig", "fxruby:setversions", "fxruby:generate_kwargs_lib")
101
106
 
102
- # ... project specific tasks ...
107
+ gem_spec = Bundler.load_gemspec('fxruby.gemspec')
103
108
 
104
- Rake::ExtensionTask.new("fox16_c", hoe.spec) do |ext|
109
+ Rake::ExtensionTask.new("fox16_c", gem_spec) do |ext|
105
110
  ext.cross_compile = true
106
111
  ext.cross_platform = ['x86-mingw32', 'x64-mingw32']
107
112
  # Enable FXTRACE and FXASSERT for 'rake compile'
@@ -111,9 +116,13 @@ Rake::ExtensionTask.new("fox16_c", hoe.spec) do |ext|
111
116
  "--enable-win32-cross",
112
117
  "--with-fxscintilla",
113
118
  ]
119
+ ext.cross_config_options << "--enable-debug" if ENV['FXRUBY_MINGW_DEBUG']
114
120
 
115
121
  # Add dependent DLLs to the cross gems
116
122
  ext.cross_compiling do |spec|
123
+ # The fat binary gem doesn't depend on the fox package, since it bundles the libraries.
124
+ spec.metadata.delete('msys2_mingw_dependencies')
125
+
117
126
  platform_host_map = {
118
127
  'x86-mingw32' => ['i686-w64-mingw32'],
119
128
  'x64-mingw32' => ['x86_64-w64-mingw32'],
@@ -128,7 +137,7 @@ Rake::ExtensionTask.new("fox16_c", hoe.spec) do |ext|
128
137
  dlls += [
129
138
  "libfxscintilla-20.dll",
130
139
  "libFOX-1.6-0.dll",
131
- "libjpeg-8.dll",
140
+ "libjpeg-9.dll",
132
141
  "libpng16-16.dll",
133
142
  "libtiff-5.dll",
134
143
  "zlib1.dll",
@@ -136,23 +145,30 @@ Rake::ExtensionTask.new("fox16_c", hoe.spec) do |ext|
136
145
 
137
146
  spec.files += dlls.map{|dll| "ports/#{host}/bin/#{dll}" }
138
147
 
139
- dlls.each do |dll|
140
- task "ports/#{host}/bin/#{dll}" do |t|
141
- sh "x86_64-w64-mingw32-strip", t.name
148
+ unless ENV['FXRUBY_MINGW_DEBUG']
149
+ dlls.each do |dll|
150
+ task "ports/#{host}/bin/#{dll}" do |t|
151
+ sh "x86_64-w64-mingw32-strip", t.name
152
+ end
142
153
  end
143
154
  end
144
155
  end
145
156
  end
157
+
158
+ FoxGemHelper.install_tasks
159
+ Bundler::GemHelper.instance.cross_platforms = ext.cross_platform
146
160
  end
147
161
 
148
162
  # To reduce the gem file size strip mingw32 dlls before packaging
149
- ENV['RUBY_CC_VERSION'].to_s.split(':').each do |ruby_version|
150
- task "tmp/x86-mingw32/stage/lib/#{ruby_version[/^\d+\.\d+/]}/fox16_c.so" do |t|
151
- sh "i686-w64-mingw32-strip -S tmp/x86-mingw32/stage/lib/#{ruby_version[/^\d+\.\d+/]}/fox16_c.so"
152
- end
163
+ unless ENV['FXRUBY_MINGW_DEBUG']
164
+ ENV['RUBY_CC_VERSION'].to_s.split(':').each do |ruby_version|
165
+ task "tmp/x86-mingw32/stage/lib/#{ruby_version[/^\d+\.\d+/]}/fox16_c.so" do |t|
166
+ sh "i686-w64-mingw32-strip -S tmp/x86-mingw32/stage/lib/#{ruby_version[/^\d+\.\d+/]}/fox16_c.so"
167
+ end
153
168
 
154
- task "tmp/x64-mingw32/stage/lib/#{ruby_version[/^\d+\.\d+/]}/fox16_c.so" do |t|
155
- sh "x86_64-w64-mingw32-strip -S tmp/x64-mingw32/stage/lib/#{ruby_version[/^\d+\.\d+/]}/fox16_c.so"
169
+ task "tmp/x64-mingw32/stage/lib/#{ruby_version[/^\d+\.\d+/]}/fox16_c.so" do |t|
170
+ sh "x86_64-w64-mingw32-strip -S tmp/x64-mingw32/stage/lib/#{ruby_version[/^\d+\.\d+/]}/fox16_c.so"
171
+ end
156
172
  end
157
173
  end
158
174
 
@@ -160,11 +176,9 @@ desc "Build the windows binary gems"
160
176
  task 'gem:windows' => 'gem' do
161
177
  require 'rake_compiler_dock'
162
178
 
163
- gf = "tmp/Gemfile-rcd"
164
- File.write(gf, File.read("Gemfile").gsub(/.*"(glu|opengl)".*/, ""))
165
-
166
- sh "BUNDLE_GEMFILE=#{gf} bundle package"
167
- RakeCompilerDock.sh "BUNDLE_GEMFILE=#{gf} bundle --local --without=norcd && rake cross native gem MAKE=\"nice make V=1 -j `nproc`\" "
179
+ sh "bundle package"
180
+ debug = "FXRUBY_MINGW_DEBUG=#{ENV['FXRUBY_MINGW_DEBUG'].inspect}" if ENV['FXRUBY_MINGW_DEBUG']
181
+ RakeCompilerDock.sh "bundle --local --without=test && rake cross native gem MAKE=\"nice make V=1 -j `nproc`\" #{debug}"
168
182
  end
169
183
 
170
184
  # Set environment variable SWIG_LIB to
@@ -172,6 +186,7 @@ end
172
186
  # before running swig on MinGW.
173
187
  namespace :swig do
174
188
  def sed(wrapper_src_file_name)
189
+ puts "Update #{wrapper_src_file_name}"
175
190
  results = []
176
191
  IO.readlines(wrapper_src_file_name).each do |line|
177
192
  line.gsub!(/static VALUE mCore;/, "VALUE mCore;")
@@ -188,11 +203,21 @@ namespace :swig do
188
203
  end
189
204
  end
190
205
 
206
+ def add_with_fxscintilla_cond(file)
207
+ puts "Update #{file} for fxscintilla"
208
+ content = File.binread(file)
209
+ content = "#ifdef WITH_FXSCINTILLA\n" + content + "#endif /* WITH_FXSCINTILLA */\n"
210
+ File.binwrite(file, content)
211
+ end
212
+
191
213
  def swig(swig_interface_file_name, wrapper_src_file_name)
192
214
  cmd = "#{SWIG} #{SWIGFLAGS} -o #{wrapper_src_file_name} #{swig_interface_file_name}"
193
215
  puts cmd
194
216
  system cmd
217
+
218
+ # Do our own wrapper file modifications:
195
219
  sed wrapper_src_file_name
220
+ add_with_fxscintilla_cond(wrapper_src_file_name) if ["scintilla_wrap.cpp"].include?(File.basename(wrapper_src_file_name))
196
221
  end
197
222
 
198
223
  task :swigruby_h => ["ext/fox16_c/swigruby.h"]
@@ -202,7 +227,7 @@ namespace :swig do
202
227
  end
203
228
 
204
229
  desc "Run SWIG to generate the wrapper files."
205
- task :swig => [:swigruby_h] + SWIG_MODULES.map{|ifile, cppfile| File.join("ext/fox16_c", cppfile) }
230
+ multitask :swig => [:swigruby_h] + SWIG_MODULES.map{|ifile, cppfile| File.join("ext/fox16_c", cppfile) }
206
231
 
207
232
  # add dependencies for compile *.i to *_wrap.cpp
208
233
  SWIG_MODULES.each do |ifile, cppfile|
@@ -262,8 +287,7 @@ namespace :fxruby do
262
287
  make_impl
263
288
  end
264
289
 
265
- file "ext/fox16_c/extconf.rb" => ['ext/fox16_c/swigruby.h', 'ext/fox16_c/impl.cpp', 'ext/fox16_c/include/inlinestubs.h'] +
266
- SWIG_MODULES.map{|ifile, cppfile| File.join("ext/fox16_c", cppfile) }
290
+ file "ext/fox16_c/extconf.rb" => ['ext/fox16_c/impl.cpp', 'ext/fox16_c/include/inlinestubs.h', 'swig:swig']
267
291
 
268
292
 
269
293
  directory "ports/archives"
@@ -78,7 +78,7 @@
78
78
  <doap:Version>
79
79
  <doap:branch>fox16</doap:branch>
80
80
  <doap:created><%= Date.today %></doap:created>
81
- <doap:revision><%= PKG_VERSION %></doap:revision>
81
+ <doap:revision><%= Fox.fxrubyversion %></doap:revision>
82
82
  </doap:Version>
83
83
  </doap:release>
84
84
 
@@ -0,0 +1,169 @@
1
+ /***********************************************************************
2
+ * FXRuby -- the Ruby language bindings for the FOX GUI toolkit.
3
+ * Copyright (c) 2017-2017 by Lyle Johnson. All Rights Reserved.
4
+ *
5
+ * This library is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU Lesser General Public
7
+ * License as published by the Free Software Foundation; either
8
+ * version 2.1 of the License, or (at your option) any later version.
9
+ *
10
+ * This library is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ * Lesser General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Lesser General Public
16
+ * License along with this library; if not, write to the Free Software
17
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
+ *
19
+ * For further information please contact the author by e-mail
20
+ * at "lars@greiz-reinsdorf.de".
21
+ ***********************************************************************/
22
+
23
+ #include "FXRbObjRegistry.h"
24
+ #include "FXRbCommon.h"
25
+ #include "swigruby.h"
26
+
27
+ FXRbObjRegistry::FXRbObjRegistry(){
28
+ FXRuby_Objects=st_init_numtable();
29
+ }
30
+
31
+ const char * FXRbObjRegistry::safe_rb_obj_classname(VALUE obj)
32
+ {
33
+ int tdata = TYPE(obj)==T_DATA;
34
+ if( (tdata && IsInGC(DATA_PTR(obj)))
35
+ #ifdef HAVE_RB_DURING_GC
36
+ || rb_during_gc()
37
+ #endif
38
+ ){
39
+ /* It's not safe to call rb_obj_classname() during GC.
40
+ * Return dummy value in this case. */
41
+ return "during GC";
42
+ } else if (tdata) {
43
+ return rb_obj_classname(obj);
44
+ } else {
45
+ return "no T_DATA";
46
+ }
47
+ }
48
+
49
+ VALUE FXRbObjRegistry::NewBorrowedObj(void *ptr,swig_type_info* ty){
50
+ if(ptr!=0){
51
+ FXASSERT(ty!=0);
52
+ ObjDesc *desc;
53
+
54
+ if(FXMALLOC(&desc,ObjDesc,1)){
55
+ VALUE obj = SWIG_Ruby_NewPointerObj(ptr,ty,1);
56
+ FXTRACE((1,"FXRbNewPointerObj(foxObj=%p) => rubyObj=%p (%s)\n",ptr,(void *)obj,safe_rb_obj_classname(obj)));
57
+ desc->obj = obj;
58
+ desc->type = borrowed;
59
+ desc->in_gc = false;
60
+ int overwritten = st_insert(FXRuby_Objects,reinterpret_cast<st_data_t>(ptr),reinterpret_cast<st_data_t>(desc));
61
+ FXASSERT(!overwritten);
62
+ return obj;
63
+ } else {
64
+ FXASSERT(FALSE);
65
+ return Qnil;
66
+ }
67
+ }
68
+ else{
69
+ return Qnil;
70
+ }
71
+ }
72
+
73
+ void FXRbObjRegistry::RegisterRubyObj(VALUE rubyObj,const void* foxObj) {
74
+ FXASSERT(!NIL_P(rubyObj));
75
+ FXASSERT(foxObj!=0);
76
+ ObjDesc* desc;
77
+ FXTRACE((1,"FXRbRegisterRubyObj(rubyObj=%p (%s),foxObj=%p)\n",(void *)rubyObj,safe_rb_obj_classname(rubyObj),foxObj));
78
+ if(st_lookup(FXRuby_Objects,reinterpret_cast<st_data_t>(const_cast<void*>(foxObj)),reinterpret_cast<st_data_t *>(&desc))!=0){
79
+ FXASSERT(desc->type == borrowed);
80
+ /* There is already a Ruby object registered for this foxObj.
81
+ * This can happen, if libfox calls methods out of the C++ object constructor,
82
+ * that can be overwritten in Ruby (like changeFocus) with the object as
83
+ * parameter. FXFileSelector is one example.
84
+ * To avoid double references to the same foxObj from different Ruby objects,
85
+ * we decouple the foxObj from previoius ruby object and point to the new one.
86
+ */
87
+ DATA_PTR(desc->obj) = 0;
88
+ desc->obj = rubyObj;
89
+ desc->type = own;
90
+ } else {
91
+ if(FXMALLOC(&desc,ObjDesc,1)){
92
+ desc->obj = rubyObj;
93
+ desc->type = own;
94
+ desc->in_gc = false;
95
+ int overwritten = st_insert(FXRuby_Objects,reinterpret_cast<st_data_t>(const_cast<void*>(foxObj)),reinterpret_cast<st_data_t>(desc));
96
+ FXASSERT(!overwritten);
97
+ } else {
98
+ FXASSERT(FALSE);
99
+ }
100
+ }
101
+ FXASSERT(GetRubyObj(foxObj,false)==rubyObj);
102
+ }
103
+
104
+ void FXRbObjRegistry::UnregisterRubyObj(const void* foxObj, bool alsoOwned){
105
+ if(foxObj!=0){
106
+ ObjDesc* desc;
107
+ if(st_lookup(FXRuby_Objects,reinterpret_cast<st_data_t>(const_cast<void*>(foxObj)),reinterpret_cast<st_data_t *>(&desc))!=0){
108
+ if( !alsoOwned && desc->type!=borrowed ) return;
109
+ FXTRACE((1,"FXRbUnregisterRubyObj(rubyObj=%p (%s),foxObj=%p)\n",(void *)desc->obj,safe_rb_obj_classname(desc->obj),foxObj));
110
+ DATA_PTR(desc->obj)=0;
111
+ FXFREE(&desc);
112
+ st_delete(FXRuby_Objects,reinterpret_cast<st_data_t *>(const_cast<void**>(&foxObj)),reinterpret_cast<st_data_t *>(0));
113
+ FXASSERT(st_lookup(FXRuby_Objects,reinterpret_cast<st_data_t>(const_cast<void*>(foxObj)),reinterpret_cast<st_data_t *>(0))==0);
114
+ }
115
+ }
116
+ }
117
+
118
+
119
+ VALUE FXRbObjRegistry::GetRubyObj(const void *foxObj,bool alsoBorrowed, bool in_gc_mark){
120
+ ObjDesc* desc;
121
+ if(foxObj!=0 && st_lookup(FXRuby_Objects,reinterpret_cast<st_data_t>(const_cast<void*>(foxObj)),reinterpret_cast<st_data_t *>(&desc))!=0){
122
+ FXASSERT(desc!=0);
123
+ if(alsoBorrowed || desc->type!=borrowed){
124
+ const char *classname = in_gc_mark ? "in GC" : safe_rb_obj_classname(desc->obj);
125
+ FXTRACE((2,"%s(foxObj=%p) => rubyObj=%p (%s)\n", in_gc_mark ? "FXRbGcMark" : "FXRbGetRubyObj", foxObj, (void *)desc->obj, classname));
126
+ return desc->obj;
127
+ }
128
+ }
129
+ return Qnil;
130
+ }
131
+
132
+
133
+ bool FXRbObjRegistry::IsBorrowed(void* ptr){
134
+ FXASSERT(ptr!=0);
135
+ ObjDesc *desc;
136
+ if(st_lookup(FXRuby_Objects,reinterpret_cast<st_data_t>(ptr),reinterpret_cast<st_data_t *>(&desc))!=0){
137
+ return desc->type == borrowed;
138
+ }
139
+ else{
140
+ return true;
141
+ }
142
+ }
143
+
144
+ bool FXRbObjRegistry::SetInGC(const void* ptr, bool enabled){
145
+ FXASSERT(ptr!=0);
146
+ ObjDesc *desc;
147
+ if(st_lookup(FXRuby_Objects,reinterpret_cast<st_data_t>(ptr),reinterpret_cast<st_data_t *>(&desc))!=0){
148
+ desc->in_gc=enabled;
149
+ return enabled;
150
+ }
151
+ return false;
152
+ }
153
+
154
+ bool FXRbObjRegistry::IsInGC(const void* ptr){
155
+ FXASSERT(ptr!=0);
156
+ ObjDesc *desc;
157
+
158
+ #ifdef HAVE_RB_DURING_GC
159
+ if( rb_during_gc() ){
160
+ return true;
161
+ }
162
+ #endif
163
+ if(st_lookup(FXRuby_Objects,reinterpret_cast<st_data_t>(ptr),reinterpret_cast<st_data_t *>(&desc))!=0){
164
+ return desc->in_gc;
165
+ }
166
+ return false;
167
+ }
168
+
169
+ FXRbObjRegistry FXRbObjRegistry::main;