object2module 0.4.2-i386-mswin32 → 0.4.3-i386-mswin32

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -21,6 +21,10 @@ def apply_spec_defaults(s)
21
21
  s.date = Time.now.strftime '%Y-%m-%d'
22
22
  s.require_path = 'lib'
23
23
  s.homepage = "http://banisterfiend.wordpress.com"
24
+ s.files = FileList["Rakefile", "README.markdown", "LICENSE",
25
+ "lib/**/*.rb", "test/**/*.rb", "ext/**/extconf.rb",
26
+ "ext/**/*.h", "ext/**/*.c"].to_a
27
+
24
28
  end
25
29
 
26
30
  task :test do
@@ -32,9 +36,7 @@ end
32
36
  spec = Gem::Specification.new do |s|
33
37
  apply_spec_defaults(s)
34
38
  s.platform = "i386-#{v}"
35
- s.files = FileList["Rakefile", "README.markdown", "LICENSE",
36
- "lib/object2module.rb", "lib/1.8/object2module.#{dlext}",
37
- "lib/1.9/object2module.#{dlext}", "lib/object2module/version.rb", "test/*.rb"].to_a
39
+ s.files += FileList["lib/**/*.#{dlext}"].to_a
38
40
  end
39
41
 
40
42
  Rake::GemPackageTask.new(spec) do |pkg|
@@ -50,9 +52,6 @@ task :ruby do
50
52
  spec = Gem::Specification.new do |s|
51
53
  apply_spec_defaults(s)
52
54
  s.platform = Gem::Platform::RUBY
53
- s.files = FileList["Rakefile", "README.markdown", "LICENSE",
54
- "lib/object2module.rb","lib/object2module/version.rb",
55
- "test/*.rb", "ext/**/extconf.rb", "ext/**/*.h", "ext/**/*.c"].to_a
56
55
  s.extensions = ["ext/object2module/extconf.rb"]
57
56
  end
58
57
 
@@ -0,0 +1,57 @@
1
+ /* contains basic macros to facilitate ruby 1.8 and ruby 1.9 compatibility */
2
+
3
+ #ifndef GUARD_COMPAT_H
4
+ #define GUARD_COMPAT_H
5
+
6
+ #include <ruby.h>
7
+
8
+ /* test for 1.9 */
9
+ #if !defined(RUBY_19) && defined(ROBJECT_EMBED_LEN_MAX)
10
+ # define RUBY_19
11
+ #endif
12
+
13
+ /* macros for backwards compatibility with 1.8 */
14
+ #ifndef RUBY_19
15
+ # define RCLASS_M_TBL(c) (RCLASS(c)->m_tbl)
16
+ # define RCLASS_SUPER(c) (RCLASS(c)->super)
17
+ # define RCLASS_IV_TBL(c) (RCLASS(c)->iv_tbl)
18
+ # define OBJ_UNTRUSTED OBJ_TAINTED
19
+ # include "st.h"
20
+ #endif
21
+
22
+ #ifdef RUBY_19
23
+ inline static VALUE
24
+ class_alloc(VALUE flags, VALUE klass)
25
+ {
26
+ rb_classext_t *ext = ALLOC(rb_classext_t);
27
+ NEWOBJ(obj, struct RClass);
28
+ OBJSETUP(obj, klass, flags);
29
+ obj->ptr = ext;
30
+ RCLASS_IV_TBL(obj) = 0;
31
+ RCLASS_M_TBL(obj) = 0;
32
+ RCLASS_SUPER(obj) = 0;
33
+ RCLASS_IV_INDEX_TBL(obj) = 0;
34
+ return (VALUE)obj;
35
+ }
36
+ #endif
37
+
38
+ inline static VALUE
39
+ create_class(VALUE flags, VALUE klass)
40
+ {
41
+ #ifdef RUBY_19
42
+ VALUE new_klass = class_alloc(flags, klass);
43
+ #else
44
+ NEWOBJ(new_klass, struct RClass);
45
+ OBJSETUP(new_klass, klass, flags);
46
+ #endif
47
+
48
+ return (VALUE)new_klass;
49
+ }
50
+
51
+ # define FALSE 0
52
+ # define TRUE 1
53
+
54
+ /* a useful macro. cannot use ordinary CLASS_OF as it does not return an lvalue */
55
+ #define KLASS_OF(c) (RBASIC(c)->klass)
56
+
57
+ #endif
@@ -0,0 +1,6 @@
1
+ require 'mkmf'
2
+
3
+ # let's use c99
4
+ $CFLAGS += " -std=c99"
5
+
6
+ create_makefile('object2module')
@@ -0,0 +1,97 @@
1
+ /* object2module.c */
2
+ /* (C) John Mair 2009
3
+ * This program is distributed under the terms of the MIT License
4
+ * */
5
+
6
+ #include <ruby.h>
7
+ #include "compat.h"
8
+
9
+ static VALUE
10
+ include_class_new(VALUE module, VALUE super)
11
+ {
12
+ VALUE klass = create_class(T_ICLASS, rb_cClass);
13
+
14
+ if (BUILTIN_TYPE(module) == T_ICLASS) {
15
+
16
+ /* for real_include compat */
17
+ if (!NIL_P(rb_iv_get(module, "__module__")))
18
+ module = rb_iv_get(module, "__module__");
19
+ else
20
+ module = RBASIC(module)->klass;
21
+ }
22
+
23
+ if (!RCLASS_IV_TBL(module)) {
24
+ RCLASS_IV_TBL(module) = st_init_numtable();
25
+ }
26
+ RCLASS_IV_TBL(klass) = RCLASS_IV_TBL(module);
27
+ RCLASS_M_TBL(klass) = RCLASS_M_TBL(module);
28
+ RCLASS_SUPER(klass) = super;
29
+ if (TYPE(module) == T_ICLASS) {
30
+ RBASIC(klass)->klass = RBASIC(module)->klass;
31
+ }
32
+ else {
33
+ RBASIC(klass)->klass = module;
34
+ }
35
+
36
+ OBJ_INFECT(klass, module);
37
+ OBJ_INFECT(klass, super);
38
+
39
+ return (VALUE)klass;
40
+ }
41
+
42
+ VALUE
43
+ rb_gen_include_one(VALUE klass, VALUE module)
44
+ {
45
+ VALUE p, c;
46
+ int changed = 0;
47
+
48
+ rb_frozen_class_p(klass);
49
+ if (!OBJ_UNTRUSTED(klass)) {
50
+ rb_secure(4);
51
+ }
52
+
53
+ /* when including an object, include its singleton class */
54
+ if (TYPE(module) == T_OBJECT)
55
+ module = rb_singleton_class(module);
56
+
57
+ OBJ_INFECT(klass, module);
58
+ c = klass;
59
+ while (module) {
60
+ int superclass_seen = FALSE;
61
+
62
+ if (RCLASS_M_TBL(klass) == RCLASS_M_TBL(module))
63
+ rb_raise(rb_eArgError, "cyclic include detected");
64
+ /* ignore if the module included already in superclasses */
65
+ for (p = RCLASS_SUPER(klass); p; p = RCLASS_SUPER(p)) {
66
+ switch (BUILTIN_TYPE(p)) {
67
+ case T_ICLASS:
68
+ if (RCLASS_M_TBL(p) == RCLASS_M_TBL(module)) {
69
+ if (!superclass_seen) {
70
+ c = p; /* move insertion point */
71
+ }
72
+ goto skip;
73
+ }
74
+ break;
75
+ case T_CLASS:
76
+ superclass_seen = TRUE;
77
+ break;
78
+ }
79
+ }
80
+ c = RCLASS_SUPER(c) = include_class_new(module, RCLASS_SUPER(c));
81
+ if (RMODULE_M_TBL(module) && RMODULE_M_TBL(module)->num_entries)
82
+ changed = 1;
83
+ skip:
84
+ module = RCLASS_SUPER(module);
85
+ }
86
+ if (changed) rb_clear_cache();
87
+
88
+ return Qnil;
89
+ }
90
+
91
+
92
+ void
93
+ Init_object2module()
94
+ {
95
+ rb_define_method(rb_cModule, "gen_include_one", rb_gen_include_one, 1);
96
+ }
97
+
@@ -0,0 +1,8 @@
1
+ /* object2module.h */
2
+
3
+ #ifndef GUARD_OBJECT2MODULE_H
4
+ #define GUARD_OBJECT2MODULE_H
5
+
6
+ void Init_object2module(void);
7
+
8
+ #endif
@@ -1,3 +1,3 @@
1
1
  module Object2module
2
- VERSION = "0.4.2"
2
+ VERSION = "0.4.3"
3
3
  end
data/test/test.rb CHANGED
@@ -3,11 +3,12 @@ require 'rubygems'
3
3
  require 'bacon'
4
4
  require "#{direc}/../lib/object2module"
5
5
 
6
-
7
6
  class Module
8
7
  public :include, :remove_const
9
8
  end
10
9
 
10
+ puts "testing Object2module version #{Object2module::VERSION}..."
11
+
11
12
  describe Object2module do
12
13
  before do
13
14
  class A
@@ -9,6 +9,8 @@ class Module
9
9
  public :include, :remove_const
10
10
  end
11
11
 
12
+ puts "testing Object2module version #{Object2module::VERSION} with Remix version #{Remix::VERSION}..."
13
+
12
14
  describe Object2module do
13
15
  before do
14
16
  class A
@@ -122,6 +124,20 @@ describe Object2module do
122
124
  o.singleton_class.ancestors.first.should == Object
123
125
  end
124
126
 
127
+ it 'unextends an object by object (not by singleton)' do
128
+ o = Object.new
129
+ def o.hello
130
+ :o
131
+ end
132
+
133
+ n = Object.new
134
+ n.gen_extend o
135
+ n.hello.should == :o
136
+ n.unextend o
137
+ lambda { n.hello }.should.raise NameError
138
+ end
139
+
140
+
125
141
  it 'recursively unextends a singleton class gen_extended into another singleton class' do
126
142
  o = Object.new
127
143
  def o.hello
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: object2module
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 4
9
- - 2
10
- version: 0.4.2
8
+ - 3
9
+ version: 0.4.3
11
10
  platform: i386-mswin32
12
11
  authors:
13
12
  - John Mair (banisterfiend)
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-10-31 00:00:00 +13:00
17
+ date: 2010-11-01 00:00:00 +13:00
19
18
  default_executable:
20
19
  dependencies: []
21
20
 
@@ -31,13 +30,17 @@ files:
31
30
  - Rakefile
32
31
  - README.markdown
33
32
  - LICENSE
34
- - lib/object2module.rb
35
- - lib/1.8/object2module.so
36
- - lib/1.9/object2module.so
37
33
  - lib/object2module/version.rb
34
+ - lib/object2module.rb
38
35
  - test/test.rb
39
36
  - test/test_stress.rb
40
37
  - test/test_with_remix.rb
38
+ - ext/object2module/extconf.rb
39
+ - ext/object2module/compat.h
40
+ - ext/object2module/object2module.h
41
+ - ext/object2module/object2module.c
42
+ - lib/1.8/object2module.so
43
+ - lib/1.9/object2module.so
41
44
  has_rdoc: yard
42
45
  homepage: http://banisterfiend.wordpress.com
43
46
  licenses: []
@@ -52,7 +55,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
52
55
  requirements:
53
56
  - - ">="
54
57
  - !ruby/object:Gem::Version
55
- hash: 3
56
58
  segments:
57
59
  - 0
58
60
  version: "0"
@@ -61,7 +63,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
63
  requirements:
62
64
  - - ">="
63
65
  - !ruby/object:Gem::Version
64
- hash: 3
65
66
  segments:
66
67
  - 0
67
68
  version: "0"