Skip to content

Commit

Permalink
updated to most recent version of compat.h
Browse files Browse the repository at this point in the history
  • Loading branch information
banister committed Oct 30, 2010
1 parent f354a71 commit 6c496e5
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 29 deletions.
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,5 @@ no sign of the mixin at all.
Until _why might reappear someday, this project is maintained by Konstantin Haase (rkh).
konstantin.mailinglists <at> googlemail <dot> com
http://github.com/rkh/mixico
* updated for Ruby 1.9 by banisterfiend
* updated for Ruby 1.9 + other changes by banisterfiend
http://github.com/banister
39 changes: 37 additions & 2 deletions ext/mixico/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,52 @@

#include <ruby.h>

/* test for 1.9 */
#if !defined(RUBY_19) && defined(ROBJECT_EMBED_LEN_MAX)
# define RUBY_19
#endif

/* macros for backwards compatibility with 1.8 */
#ifndef RUBY_19
# define RCLASS_M_TBL(c) (RCLASS(c)->m_tbl)
# define RCLASS_SUPER(c) (RCLASS(c)->super)
# define RCLASS_IV_TBL(c) (RCLASS(c)->iv_tbl)
# define OBJ_UNTRUSTED OBJ_TAINTED
# define FALSE 0
# define TRUE 1
# include "st.h"
#endif

#ifdef RUBY_19
inline static VALUE
class_alloc(VALUE flags, VALUE klass)
{
rb_classext_t *ext = ALLOC(rb_classext_t);
NEWOBJ(obj, struct RClass);
OBJSETUP(obj, klass, flags);
obj->ptr = ext;
RCLASS_IV_TBL(obj) = 0;
RCLASS_M_TBL(obj) = 0;
RCLASS_SUPER(obj) = 0;
RCLASS_IV_INDEX_TBL(obj) = 0;
return (VALUE)obj;
}
#endif

inline static VALUE
create_class(VALUE flags, VALUE klass)
{
#ifdef RUBY_19
VALUE new_klass = class_alloc(flags, klass);
#else
NEWOBJ(new_klass, struct RClass);
OBJSETUP(new_klass, klass, flags);
#endif

return (VALUE)new_klass;
}

# define FALSE 0
# define TRUE 1

/* a useful macro. cannot use ordinary CLASS_OF as it does not return an lvalue */
#define KLASS_OF(c) (RBASIC(c)->klass)

Expand Down
3 changes: 0 additions & 3 deletions ext/mixico/extconf.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
require 'mkmf'

# 1.9 compatibility
$CFLAGS += " -DRUBY_19" if RUBY_VERSION =~ /1.9/

create_makefile("mixico")
23 changes: 1 addition & 22 deletions ext/mixico/mixico.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,6 @@

static VALUE mixin_eval, mixout_eval;

#ifdef RUBY_19
static VALUE
class_alloc(VALUE flags, VALUE klass)
{
rb_classext_t *ext = ALLOC(rb_classext_t);
NEWOBJ(obj, struct RClass);
OBJSETUP(obj, klass, flags);
obj->ptr = ext;
RCLASS_IV_TBL(obj) = 0;
RCLASS_M_TBL(obj) = 0;
RCLASS_SUPER(obj) = 0;
RCLASS_IV_INDEX_TBL(obj) = 0;
return (VALUE)obj;
}
#endif

static VALUE
rb_mod_disable_mixin(VALUE module, VALUE super)
{
Expand Down Expand Up @@ -66,13 +50,8 @@ static VALUE
rb_mod_mixin_object(VALUE target, VALUE obj)
{
VALUE singleton = rb_singleton_class(obj);
VALUE iclass = create_class(T_ICLASS, rb_cClass);

#ifdef RUBY_19
VALUE iclass = class_alloc(T_ICLASS, rb_cClass);
#else
NEWOBJ(iclass, struct RClass);
OBJSETUP(iclass, rb_cClass, T_ICLASS);
#endif
Check_Type(target, T_MODULE);
if (!RCLASS_IV_TBL(obj))
RCLASS_IV_TBL(obj) = st_init_numtable();
Expand Down
4 changes: 4 additions & 0 deletions lib/mixico.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# mixico.rb
# added by John Mair (banisterfiend) 2010
# License: MIT

direc = File.dirname(__FILE__)

begin
Expand Down
2 changes: 1 addition & 1 deletion lib/mixico/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Mixico
VERSION = "0.1.3"
VERSION = "0.1.4"
end

0 comments on commit 6c496e5

Please sign in to comment.