Merge branch 'lefticus-ruby_macos_static_data_conflicts'

* lefticus-ruby_macos_static_data_conflicts:
  Fix shared data problem on MacOS 10.9 with xcode 5.1
This commit is contained in:
William S Fulton 2014-09-27 15:12:04 +01:00
commit 1fea434400

View file

@ -37,9 +37,6 @@
%fragment("GC_VALUE_definition","header") { %fragment("GC_VALUE_definition","header") {
namespace swig { namespace swig {
class SwigGCReferences { class SwigGCReferences {
// Hash of all GC_VALUE's currently in use
static SwigGCReferences s_references;
VALUE _hash; VALUE _hash;
SwigGCReferences() : _hash(Qnil) { SwigGCReferences() : _hash(Qnil) {
@ -50,13 +47,18 @@ namespace swig {
} }
static void EndProcHandler(VALUE) { static void EndProcHandler(VALUE) {
// Ruby interpreter ending - _hash can no longer be accessed. // Ruby interpreter ending - _hash can no longer be accessed.
SwigGCReferences &s_references = instance();
s_references._hash = Qnil; s_references._hash = Qnil;
} }
public: public:
static SwigGCReferences& instance() { static SwigGCReferences& instance() {
// Hash of all GC_VALUE's currently in use
static SwigGCReferences s_references;
return s_references; return s_references;
} }
static void initialize() { static void initialize() {
SwigGCReferences &s_references = instance();
if (s_references._hash == Qnil) { if (s_references._hash == Qnil) {
rb_set_end_proc(&EndProcHandler, Qnil); rb_set_end_proc(&EndProcHandler, Qnil);
s_references._hash = rb_hash_new(); s_references._hash = rb_hash_new();
@ -81,13 +83,13 @@ namespace swig {
if (BUILTIN_TYPE(obj) == T_NONE) if (BUILTIN_TYPE(obj) == T_NONE)
return; return;
if (_hash != Qnil) { if (_hash != Qnil) {
VALUE val = rb_hash_aref(s_references._hash, obj); VALUE val = rb_hash_aref(_hash, obj);
unsigned n = FIXNUM_P(val) ? NUM2UINT(val) : 1; unsigned n = FIXNUM_P(val) ? NUM2UINT(val) : 1;
--n; --n;
if (n) if (n)
rb_hash_aset(s_references._hash, obj, INT2NUM(n)); rb_hash_aset(_hash, obj, INT2NUM(n));
else else
rb_hash_delete(s_references._hash, obj); rb_hash_delete(_hash, obj);
} }
} }
}; };
@ -302,8 +304,6 @@ namespace swig {
ID GC_VALUE::lshift_id = rb_intern("<<"); ID GC_VALUE::lshift_id = rb_intern("<<");
ID GC_VALUE::rshift_id = rb_intern(">>"); ID GC_VALUE::rshift_id = rb_intern(">>");
SwigGCReferences SwigGCReferences::s_references;
typedef GC_VALUE LANGUAGE_OBJ; typedef GC_VALUE LANGUAGE_OBJ;
} // namespace swig } // namespace swig