ruby_deep_clone 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/deep_clone.gemspec CHANGED
@@ -4,14 +4,14 @@ Gem::Specification.new do |s|
4
4
  s.rubygems_version = '1.3.5'
5
5
 
6
6
  s.name = 'ruby_deep_clone'
7
- s.version = '0.3.0'
8
- s.date = '2013-04-03'
7
+ s.version = '0.4.0'
8
+ s.date = '2014-01-21'
9
9
 
10
10
  s.summary = "Ruby native deep clone"
11
11
  s.description = "Native implementation to create deep clones of Ruby objects"
12
12
 
13
- s.authors = ["Matthias Balmer", "Andre Medeiros"]
14
- s.email = ['balmma@sysinf.ch', 'me@andremedeiros.info']
13
+ s.authors = ["Matthias Balmer", "Andre Medeiros", "Anthony Williams"]
14
+ s.email = ['balmma@sysinf.ch', 'me@andremedeiros.info', 'hi@antw.io']
15
15
 
16
16
  s.homepage = "https://github.com/balmma/ruby-deepclone"
17
17
 
@@ -33,9 +33,11 @@ void Init_deep_clone()
33
33
 
34
34
  static int clone_variable(st_data_t key, st_data_t index, struct dump_call_arg *arg)
35
35
  {
36
- VALUE val = rb_ivar_get(arg->obj, (ID)key);// ROBJECT_IVPTR(arg->src)[(long)index];
36
+ VALUE val = rb_ivar_get(arg->obj, (ID)key);
37
37
  inspect_kvp((ID)key, val);
38
- rb_ivar_set(arg->obj, (ID)key, clone_object(val,arg->tracker));
38
+ // Check if value is nil. For some reason, if you "force" an instance value
39
+ // to nil, the ||= operator won't work.
40
+ if(!NIL_P(val)) rb_ivar_set(arg->obj, (ID)key, clone_object(val,arg->tracker));
39
41
  return ST_CONTINUE;
40
42
  }
41
43
 
@@ -103,7 +105,8 @@ static VALUE clone_object(VALUE object, VALUE tracker)
103
105
  OBJ_UNFREEZE(new_obj);
104
106
 
105
107
  rb_hash_aset(tracker,id,new_obj);
106
- st_table *tbl = ROBJECT_IV_INDEX_TBL(object);
108
+ st_table *tbl = DC_ROBJECT_IV_INDEX_TBL(object);
109
+
107
110
  if(tbl) {
108
111
  struct dump_call_arg arg = {new_obj,tracker, object};
109
112
  TABLE_FOREACH(tbl, clone_variable, (st_data_t)&arg);
@@ -3,6 +3,7 @@
3
3
 
4
4
  #include "ruby.h"
5
5
  #include "ruby/st.h"
6
+ #include "ruby/version.h"
6
7
 
7
8
  struct dump_call_arg {
8
9
  VALUE obj;
@@ -17,7 +18,7 @@ struct dump_call_arg {
17
18
  #ifdef SA_EMPTY
18
19
 
19
20
  // Gotta do this because of 1.9.3's falcon patch
20
- struct rb_classext_struct {
21
+ struct rb_classext_struct {
21
22
  sa_table m_tbl;
22
23
  sa_table iv_tbl;
23
24
  sa_table const_tbl;
@@ -25,16 +26,35 @@ struct dump_call_arg {
25
26
  };
26
27
 
27
28
  #define TABLE_FOREACH sa_foreach
28
- #define RCLASS_EXT(c) (RCLASS(c)->ptr)
29
- #define RCLASS_IV_INDEX_TBL(c) (&RCLASS_EXT(c)->iv_index_tbl)
29
+ #define DC_RCLASS_EXT(c) (RCLASS(c)->ptr)
30
+ #define DC_RCLASS_IV_INDEX_TBL(c) (&DC_RCLASS_EXT(c)->iv_index_tbl)
30
31
 
31
32
  #else
32
33
  // Make it work with vanilla ruby (including 2.0)
33
- #define RCLASS_IV_INDEX_TBL(c) (RCLASS(c)->iv_index_tbl)
34
34
  #define TABLE_FOREACH st_foreach
35
35
 
36
+ #if RUBY_API_VERSION_CODE >= 20100
37
+
38
+ // In Ruby 2.1, iv_index_tbl was moved into internal.h and cannot be accessed
39
+ // directly. We work around this by defining our own RCLASS helpers (since the
40
+ // rb_classext_struct returned by RCLASS_EXT is also effectively private).
41
+ typedef struct dc_iv_tbl_classext_struct {
42
+ struct st_table *iv_index_tbl;
43
+ } dc_iv_tbl_classext_t;
44
+
45
+ #define DC_RCLASS_EXT(c) ((dc_iv_tbl_classext_t *)RCLASS(c)->ptr)
46
+ #define DC_RCLASS_IV_INDEX_TBL(c) (DC_RCLASS_EXT(c)->iv_index_tbl)
47
+
48
+ #else
49
+ #define DC_RCLASS_IV_INDEX_TBL(c) (RCLASS(c)->iv_index_tbl)
50
+ #endif
36
51
  #endif
37
52
 
53
+ #define DC_ROBJECT_IV_INDEX_TBL(o) \
54
+ ((RBASIC(o)->flags & ROBJECT_EMBED) ? \
55
+ DC_RCLASS_IV_INDEX_TBL(rb_obj_class(o)) : \
56
+ ROBJECT(o)->as.heap.iv_index_tbl)
57
+
38
58
  VALUE DeepClone = Qnil;
39
59
 
40
60
  void Init_deep_clone();
metadata CHANGED
@@ -1,20 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_deep_clone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Matthias Balmer
9
9
  - Andre Medeiros
10
+ - Anthony Williams
10
11
  autorequire:
11
12
  bindir: bin
12
13
  cert_chain: []
13
- date: 2013-04-03 00:00:00.000000000 Z
14
+ date: 2014-01-21 00:00:00.000000000 Z
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
16
17
  name: rspec
17
- requirement: &18286920 !ruby/object:Gem::Requirement
18
+ requirement: !ruby/object:Gem::Requirement
18
19
  none: false
19
20
  requirements:
20
21
  - - ~>
@@ -22,10 +23,15 @@ dependencies:
22
23
  version: 2.13.0
23
24
  type: :development
24
25
  prerelease: false
25
- version_requirements: *18286920
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ~>
30
+ - !ruby/object:Gem::Version
31
+ version: 2.13.0
26
32
  - !ruby/object:Gem::Dependency
27
33
  name: rake-compiler
28
- requirement: &18285940 !ruby/object:Gem::Requirement
34
+ requirement: !ruby/object:Gem::Requirement
29
35
  none: false
30
36
  requirements:
31
37
  - - ~>
@@ -33,10 +39,15 @@ dependencies:
33
39
  version: 0.8.3
34
40
  type: :development
35
41
  prerelease: false
36
- version_requirements: *18285940
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 0.8.3
37
48
  - !ruby/object:Gem::Dependency
38
49
  name: rake
39
- requirement: &18285120 !ruby/object:Gem::Requirement
50
+ requirement: !ruby/object:Gem::Requirement
40
51
  none: false
41
52
  requirements:
42
53
  - - ~>
@@ -44,11 +55,17 @@ dependencies:
44
55
  version: 10.0.4
45
56
  type: :development
46
57
  prerelease: false
47
- version_requirements: *18285120
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ~>
62
+ - !ruby/object:Gem::Version
63
+ version: 10.0.4
48
64
  description: Native implementation to create deep clones of Ruby objects
49
65
  email:
50
66
  - balmma@sysinf.ch
51
67
  - me@andremedeiros.info
68
+ - hi@antw.io
52
69
  executables: []
53
70
  extensions:
54
71
  - ext/deep_clone/extconf.rb
@@ -80,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
97
  version: '0'
81
98
  requirements: []
82
99
  rubyforge_project:
83
- rubygems_version: 1.8.11
100
+ rubygems_version: 1.8.25
84
101
  signing_key:
85
102
  specification_version: 2
86
103
  summary: Ruby native deep clone