real_include 0.1.1-i386-mswin32 → 0.1.2-i386-mswin32

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,2 +1,5 @@
1
+ 5/10/2010 version 0.1.2
2
+ * added 1.8 support
3
+ * added bacon tests
1
4
  4/10/10 version 0.1.0
2
5
  * release! This is still beta, not 100% tested yet..but appears to work OK so far
data/README.markdown CHANGED
@@ -4,8 +4,6 @@ Real Include
4
4
  (c) John Mair (banisterfiend)
5
5
  MIT license
6
6
 
7
- ** Currently supports Ruby 1.9 only **
8
-
9
7
  Removes the shackles from Module#include - use Module#real_include to
10
8
  bring in singleton classes from modules. No more ugly ClassMethods and
11
9
  included() hook hacks.
data/Rakefile CHANGED
@@ -25,9 +25,10 @@ specification = Gem::Specification.new do |s|
25
25
  s.homepage = "http://banisterfiend.wordpress.com"
26
26
  s.has_rdoc = false
27
27
 
28
- # s.extensions = ["ext/real_include/extconf.rb"]
28
+ # s.extensions = ["ext/real_include/extconf.rb"]
29
29
  s.files = ["Rakefile", "README.markdown", "CHANGELOG",
30
- "lib/_real_include.rb", "lib/real_include/version.rb", "lib/real_include.so"]
30
+ "lib/real_include.rb", "lib/real_include/version.rb", "lib/1.9/real_include.so",
31
+ "lib/1.8/real_include.so"] +
31
32
  FileList["ext/**/extconf.rb", "ext/**/*.h", "ext/**/*.c"].to_a
32
33
  end
33
34
 
@@ -0,0 +1,18 @@
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
+ /* macros for backwards compatibility with 1.8 */
9
+ #ifndef RUBY_19
10
+ # define RCLASS_M_TBL(c) (RCLASS(c)->m_tbl)
11
+ # define RCLASS_SUPER(c) (RCLASS(c)->super)
12
+ # define RCLASS_IV_TBL(c) (RCLASS(c)->iv_tbl)
13
+ #endif
14
+
15
+ /* a useful macro. cannot use ordinary CLASS_OF as it does not return an lvalue */
16
+ #define KLASS_OF(c) (RBASIC(c)->klass)
17
+
18
+ #endif
@@ -0,0 +1,9 @@
1
+ require 'mkmf'
2
+
3
+ # 1.9 compatibility
4
+ $CFLAGS += " -DRUBY_19" if RUBY_VERSION =~ /1.9/
5
+
6
+ # let's use c99
7
+ $CFLAGS += " -std=c99"
8
+
9
+ create_makefile('real_include')
@@ -0,0 +1,140 @@
1
+ /* (c) 2010 John Mair (banisterfiend), MIT license */
2
+
3
+ #include "compat.h"
4
+ #include "ruby.h"
5
+
6
+ #ifndef RUBY_19
7
+ # include "st.h"
8
+ # define OBJ_UNTRUSTED OBJ_TAINTED
9
+ #endif
10
+
11
+ #define FALSE 0
12
+ #define TRUE 1
13
+
14
+ #ifdef RUBY_19
15
+ static VALUE
16
+ class_alloc(VALUE flags, VALUE klass)
17
+ {
18
+ rb_classext_t *ext = ALLOC(rb_classext_t);
19
+ NEWOBJ(obj, struct RClass);
20
+ OBJSETUP(obj, klass, flags);
21
+ obj->ptr = ext;
22
+ RCLASS_IV_TBL(obj) = 0;
23
+ RCLASS_M_TBL(obj) = 0;
24
+ RCLASS_SUPER(obj) = 0;
25
+ RCLASS_IV_INDEX_TBL(obj) = 0;
26
+ return (VALUE)obj;
27
+ }
28
+ #endif
29
+
30
+ static VALUE
31
+ include_class_new(VALUE module, VALUE super)
32
+ {
33
+ /* base case for recursion */
34
+ if (module == rb_singleton_class(rb_cModule))
35
+ return module;
36
+
37
+ /* allocate iclass */
38
+ #ifdef RUBY_19
39
+ VALUE klass = class_alloc(T_ICLASS, rb_singleton_class(rb_cModule));
40
+ #else
41
+ NEWOBJ(klass, struct RClass);
42
+ OBJSETUP(klass, rb_cClass, T_ICLASS);
43
+ #endif
44
+ /* we want a fresh ivtbl */
45
+ RCLASS_IV_TBL(klass) = st_init_numtable();
46
+
47
+ /* we want to copy the mtbl */
48
+ RCLASS_M_TBL(klass) = RCLASS_M_TBL(module);
49
+ RCLASS_SUPER(klass) = super;
50
+
51
+ /* create IClass for module's singleton */
52
+ /* if super is 0 then we're including into a module (not a class), so treat as special case */
53
+ VALUE meta = include_class_new(KLASS_OF(module), super ? KLASS_OF(super) : rb_cModule);
54
+
55
+ /* don't mess with (Module) */
56
+ if (meta != rb_singleton_class(rb_cModule)) {
57
+
58
+ /* set it as a singleton */
59
+ FL_SET(meta, FL_SINGLETON);
60
+
61
+ /* attach singleton to module */
62
+ rb_singleton_class_attached((VALUE)meta, (VALUE)klass);
63
+ }
64
+ /* assign the metaclass to module's klass */
65
+ KLASS_OF(klass) = meta;
66
+
67
+ OBJ_INFECT(klass, module);
68
+ OBJ_INFECT(klass, super);
69
+
70
+ return (VALUE)klass;
71
+ }
72
+
73
+ VALUE
74
+ rb_real_include_module(VALUE klass, VALUE module)
75
+ {
76
+ VALUE p, c;
77
+ int changed = 0;
78
+
79
+ rb_frozen_class_p(klass);
80
+ if (!OBJ_UNTRUSTED(klass)) {
81
+ rb_secure(4);
82
+ }
83
+
84
+ if (TYPE(module) != T_MODULE) {
85
+ Check_Type(module, T_MODULE);
86
+ }
87
+
88
+ OBJ_INFECT(klass, module);
89
+ c = klass;
90
+
91
+ /* ensure singleton classes exist, both for includer and includee */
92
+ rb_singleton_class(module);
93
+ rb_singleton_class(klass);
94
+
95
+ while (module) {
96
+ int superclass_seen = FALSE;
97
+
98
+ if (RCLASS_M_TBL(klass) == RCLASS_M_TBL(module))
99
+ rb_raise(rb_eArgError, "cyclic include detected");
100
+ /* ignore if the module included already in superclasses */
101
+ for (p = RCLASS_SUPER(klass); p; p = RCLASS_SUPER(p)) {
102
+ switch (BUILTIN_TYPE(p)) {
103
+ case T_ICLASS:
104
+ if (RCLASS_M_TBL(p) == RCLASS_M_TBL(module)) {
105
+ if (!superclass_seen) {
106
+ c = p; /* move insertion point */
107
+ }
108
+ goto skip;
109
+ }
110
+ break;
111
+ case T_CLASS:
112
+ superclass_seen = TRUE;
113
+ break;
114
+ }
115
+ }
116
+
117
+ /* we're including the module, so create the iclass */
118
+ VALUE imod = include_class_new(module, RCLASS_SUPER(c));
119
+
120
+ /* module gets included directly above c, so set the super */
121
+ RCLASS_SUPER(c) = imod;
122
+
123
+ /* also do the same for parallel inheritance chain (singleton classes) */
124
+ RCLASS_SUPER(KLASS_OF(c)) = KLASS_OF(imod);
125
+ c = imod;
126
+
127
+ if (RMODULE_M_TBL(module) && RMODULE_M_TBL(module)->num_entries)
128
+ changed = 1;
129
+ skip:
130
+ module = RCLASS_SUPER(module);
131
+ }
132
+ if (changed) rb_clear_cache();
133
+
134
+ return Qnil;
135
+ }
136
+
137
+ void
138
+ Init_real_include() {
139
+ rb_define_method(rb_cModule, "real_include", rb_real_include_module, 1);
140
+ }
Binary file
@@ -1,3 +1,3 @@
1
1
  module RealInclude
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -0,0 +1,15 @@
1
+ # bring in user-defined extensions to TexPlay
2
+ direc = File.dirname(__FILE__)
3
+
4
+ begin
5
+ if RUBY_VERSION && RUBY_VERSION =~ /1.9/
6
+ require "#{direc}/1.9/real_include"
7
+ else
8
+ require "#{direc}/1.8/real_include"
9
+ end
10
+ rescue LoadError => e
11
+ dlext = Config::CONFIG['DLEXT']
12
+ require "#{direc}/real_include.#{dlext}"
13
+ end
14
+
15
+ require "#{direc}/real_include/version"
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 1
9
- version: 0.1.1
8
+ - 2
9
+ version: 0.1.2
10
10
  platform: i386-mswin32
11
11
  authors:
12
12
  - John Mair (banisterfiend)
@@ -30,9 +30,13 @@ files:
30
30
  - Rakefile
31
31
  - README.markdown
32
32
  - CHANGELOG
33
- - lib/_real_include.rb
33
+ - lib/real_include.rb
34
34
  - lib/real_include/version.rb
35
- - lib/real_include.so
35
+ - lib/1.9/real_include.so
36
+ - lib/1.8/real_include.so
37
+ - ext/real_include/extconf.rb
38
+ - ext/real_include/compat.h
39
+ - ext/real_include/real_include.c
36
40
  has_rdoc: false
37
41
  homepage: http://banisterfiend.wordpress.com
38
42
  licenses: []
data/lib/_real_include.rb DELETED
@@ -1,14 +0,0 @@
1
- # bring in user-defined extensions to TexPlay
2
- direc = File.dirname(__FILE__)
3
- dlext = Config::CONFIG['DLEXT']
4
- begin
5
- if RUBY_VERSION && RUBY_VERSION =~ /1.9/
6
- require "#{direc}/1.9/real_include.#{dlext}"
7
- else
8
- require "#{direc}/1.8/real_include.#{dlext}"
9
- end
10
- rescue LoadError => e
11
- require "#{direc}/real_include.#{dlext}"
12
- end
13
-
14
- require "#{direc}/real_include/version"