summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog29
-rw-r--r--array.c6
-rw-r--r--bignum.c3
-rw-r--r--class.c3
-rw-r--r--complex.c3
-rw-r--r--ext/socket/ancdata.c3
-rw-r--r--ext/socket/option.c3
-rw-r--r--gc.c21
-rw-r--r--hash.c10
-rw-r--r--include/ruby/ruby.h2
-rw-r--r--io.c3
-rw-r--r--marshal.c3
-rw-r--r--numeric.c3
-rw-r--r--object.c3
-rw-r--r--random.c3
-rw-r--r--range.c3
-rw-r--r--rational.c3
-rw-r--r--re.c6
-rw-r--r--string.c3
-rw-r--r--struct.c3
20 files changed, 74 insertions, 42 deletions
diff --git a/ChangeLog b/ChangeLog
index f781064..17074ac 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,32 @@
+Sat Oct 20 15:35:06 2012 Narihiro Nakamura <authornari@gmail.com>
+
+ * include/ruby/ruby.h: add C APIs.
+ VALUE rb_newobj_of(VALUE klass, VALUE flags)
+ #define NEWOBJ_OF(obj,type,klass,flags)
+ These allow to change a allocation strategy depending on klass
+ or flags.
+
+ * gc.c: ditto
+
+ * array.c: use new C API.
+ * bignum.c: ditto
+ * class.c: ditto
+ * complex.c: ditto
+ * ext/socket/ancdata.c: ditto
+ * ext/socket/option.c: ditto
+ * hash.c: ditto
+ * io.c: ditto
+ * marshal.c: ditto
+ * numeric.c: ditto
+ * object.c: ditto
+ * random.c: ditto
+ * range.c: ditto
+ * rational.c: ditto
+ * re.c: ditto
+ * string.c: ditto
+ * struct.c: ditto
+ [Feature #7177][Feature #7047]
+
Sat Oct 20 12:50:00 2012 Zachary Scott <zachary@zacharyscott.net>
* ext/socket/socket.c: Documentation for Socket
diff --git a/array.c b/array.c
index b009b14..e38c93b 100644
--- a/array.c
+++ b/array.c
@@ -308,8 +308,7 @@ rb_ary_frozen_p(VALUE ary)
static VALUE
ary_alloc(VALUE klass)
{
- NEWOBJ(ary, struct RArray);
- OBJSETUP(ary, klass, T_ARRAY);
+ NEWOBJ_OF(ary, struct RArray, klass, T_ARRAY);
FL_SET_EMBED((VALUE)ary);
ARY_SET_EMBED_LEN((VALUE)ary, 0);
@@ -436,8 +435,7 @@ ary_make_shared(VALUE ary)
return ary;
}
else {
- NEWOBJ(shared, struct RArray);
- OBJSETUP(shared, 0, T_ARRAY);
+ NEWOBJ_OF(shared, struct RArray, 0, T_ARRAY);
FL_UNSET_EMBED(shared);
ARY_SET_LEN((VALUE)shared, RARRAY_LEN(ary));
diff --git a/bignum.c b/bignum.c
index 6fb031e..685f9b8 100644
--- a/bignum.c
+++ b/bignum.c
@@ -166,8 +166,7 @@ rb_big_resize(VALUE big, long len)
static VALUE
bignew_1(VALUE klass, long len, int sign)
{
- NEWOBJ(big, struct RBignum);
- OBJSETUP(big, klass, T_BIGNUM);
+ NEWOBJ_OF(big, struct RBignum, klass, T_BIGNUM);
RBIGNUM_SET_SIGN(big, sign?1:0);
if (len <= RBIGNUM_EMBED_LEN_MAX) {
RBASIC(big)->flags |= RBIGNUM_EMBED_FLAG;
diff --git a/class.c b/class.c
index 79ba34e..5320a4c 100644
--- a/class.c
+++ b/class.c
@@ -49,8 +49,7 @@ static ID id_attached;
static VALUE
class_alloc(VALUE flags, VALUE klass)
{
- NEWOBJ(obj, struct RClass);
- OBJSETUP(obj, klass, flags);
+ NEWOBJ_OF(obj, struct RClass, klass, flags);
obj->ptr = ALLOC(rb_classext_t);
RCLASS_IV_TBL(obj) = 0;
RCLASS_CONST_TBL(obj) = 0;
diff --git a/complex.c b/complex.c
index 6a15dec..94a28f0 100644
--- a/complex.c
+++ b/complex.c
@@ -313,8 +313,7 @@ k_complex_p(VALUE x)
inline static VALUE
nucomp_s_new_internal(VALUE klass, VALUE real, VALUE imag)
{
- NEWOBJ(obj, struct RComplex);
- OBJSETUP(obj, klass, T_COMPLEX);
+ NEWOBJ_OF(obj, struct RComplex, klass, T_COMPLEX);
obj->real = real;
obj->imag = imag;
diff --git a/ext/socket/ancdata.c b/ext/socket/ancdata.c
index 9344252..4ba339a 100644
--- a/ext/socket/ancdata.c
+++ b/ext/socket/ancdata.c
@@ -86,8 +86,7 @@ ancillary_initialize(VALUE self, VALUE vfamily, VALUE vlevel, VALUE vtype, VALUE
static VALUE
ancdata_new(int family, int level, int type, VALUE data)
{
- NEWOBJ(obj, struct RObject);
- OBJSETUP(obj, rb_cAncillaryData, T_OBJECT);
+ NEWOBJ_OF(obj, struct RObject, rb_cAncillaryData, T_OBJECT);
StringValue(data);
ancillary_initialize((VALUE)obj, INT2NUM(family), INT2NUM(level), INT2NUM(type), data);
return (VALUE)obj;
diff --git a/ext/socket/option.c b/ext/socket/option.c
index 4e5f6c2..e3e59cf 100644
--- a/ext/socket/option.c
+++ b/ext/socket/option.c
@@ -61,8 +61,7 @@ sockopt_initialize(VALUE self, VALUE vfamily, VALUE vlevel, VALUE voptname, VALU
VALUE
rsock_sockopt_new(int family, int level, int optname, VALUE data)
{
- NEWOBJ(obj, struct RObject);
- OBJSETUP(obj, rb_cSockOpt, T_OBJECT);
+ NEWOBJ_OF(obj, struct RObject, rb_cSockOpt, T_OBJECT);
StringValue(data);
sockopt_initialize((VALUE)obj, INT2NUM(family), INT2NUM(level), INT2NUM(optname), data);
return (VALUE)obj;
diff --git a/gc.c b/gc.c
index 735ae85..bd64770 100644
--- a/gc.c
+++ b/gc.c
@@ -646,8 +646,8 @@ heaps_increment(rb_objspace_t *objspace)
return FALSE;
}
-VALUE
-rb_newobj(void)
+static VALUE
+newobj(VALUE klass, VALUE flags)
{
rb_objspace_t *objspace = &rb_objspace;
VALUE obj;
@@ -688,6 +688,23 @@ rb_newobj(void)
return obj;
}
+VALUE
+rb_newobj(void)
+{
+ return newobj(0, T_NONE);
+}
+
+VALUE
+rb_newobj_of(VALUE klass, VALUE flags)
+{
+ VALUE obj;
+
+ obj = newobj(klass, flags);
+ OBJSETUP(obj, klass, flags);
+
+ return obj;
+}
+
NODE*
rb_node_newnode(enum node_type type, VALUE a0, VALUE a1, VALUE a2)
{
diff --git a/hash.c b/hash.c
index 1ddf23a..ea9dd87 100644
--- a/hash.c
+++ b/hash.c
@@ -207,8 +207,7 @@ rb_hash_foreach(VALUE hash, int (*func)(ANYARGS), VALUE farg)
static VALUE
hash_alloc(VALUE klass)
{
- NEWOBJ(hash, struct RHash);
- OBJSETUP(hash, klass, T_HASH);
+ NEWOBJ_OF(hash, struct RHash, klass, T_HASH);
RHASH_IFNONE(hash) = Qnil;
@@ -224,8 +223,11 @@ rb_hash_new(void)
VALUE
rb_hash_dup(VALUE hash)
{
- NEWOBJ(ret, struct RHash);
- DUPSETUP(ret, hash);
+ NEWOBJ_OF(ret, struct RHash,
+ rb_obj_class(hash),
+ (RBASIC(hash)->flags)&(T_MASK|FL_EXIVAR|FL_TAINT|FL_UNTRUSTED));
+ if (FL_TEST((hash), FL_EXIVAR))
+ rb_copy_generic_ivar((VALUE)(ret),(VALUE)(hash));
if (!RHASH_EMPTY_P(hash))
ret->ntbl = st_copy(RHASH(hash)->ntbl);
diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h
index f3ad94a..e4afecc 100644
--- a/include/ruby/ruby.h
+++ b/include/ruby/ruby.h
@@ -657,7 +657,9 @@ VALUE rb_uint2big(VALUE);
VALUE rb_int2big(SIGNED_VALUE);
VALUE rb_newobj(void);
+VALUE rb_newobj_of(VALUE, VALUE);
#define NEWOBJ(obj,type) type *(obj) = (type*)rb_newobj()
+#define NEWOBJ_OF(obj,type,klass,flags) type *(obj) = (type*)rb_newobj_of(klass, flags)
#define OBJSETUP(obj,c,t) do {\
RBASIC(obj)->flags = (t);\
RBASIC(obj)->klass = (c);\
diff --git a/io.c b/io.c
index 43f3688..b3c02e9 100644
--- a/io.c
+++ b/io.c
@@ -837,8 +837,7 @@ ruby_dup(int orig)
static VALUE
io_alloc(VALUE klass)
{
- NEWOBJ(io, struct RFile);
- OBJSETUP(io, klass, T_FILE);
+ NEWOBJ_OF(io, struct RFile, klass, T_FILE);
io->fptr = 0;
diff --git a/marshal.c b/marshal.c
index 60922ad..ae38382 100644
--- a/marshal.c
+++ b/marshal.c
@@ -1459,8 +1459,7 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
BDIGIT *digits;
volatile VALUE data;
- NEWOBJ(big, struct RBignum);
- OBJSETUP(big, rb_cBignum, T_BIGNUM);
+ NEWOBJ_OF(big, struct RBignum, rb_cBignum, T_BIGNUM);
RBIGNUM_SET_SIGN(big, (r_byte(arg) == '+'));
len = r_long(arg);
data = r_bytes0(len * 2, arg);
diff --git a/numeric.c b/numeric.c
index 58ac7ad..722a6b8 100644
--- a/numeric.c
+++ b/numeric.c
@@ -617,8 +617,7 @@ num_to_int(VALUE num)
VALUE
rb_float_new_in_heap(double d)
{
- NEWOBJ(flt, struct RFloat);
- OBJSETUP(flt, rb_cFloat, T_FLOAT);
+ NEWOBJ_OF(flt, struct RFloat, rb_cFloat, T_FLOAT);
flt->float_value = d;
return (VALUE)flt;
diff --git a/object.c b/object.c
index 8b63340..eec42bf 100644
--- a/object.c
+++ b/object.c
@@ -1679,8 +1679,7 @@ rb_obj_alloc(VALUE klass)
static VALUE
rb_class_allocate_instance(VALUE klass)
{
- NEWOBJ(obj, struct RObject);
- OBJSETUP(obj, klass, T_OBJECT);
+ NEWOBJ_OF(obj, struct RObject, klass, T_OBJECT);
return (VALUE)obj;
}
diff --git a/random.c b/random.c
index ccae2a0..a137551 100644
--- a/random.c
+++ b/random.c
@@ -537,8 +537,7 @@ make_seed_value(const void *ptr)
{
const long len = DEFAULT_SEED_LEN/SIZEOF_BDIGITS;
BDIGIT *digits;
- NEWOBJ(big, struct RBignum);
- OBJSETUP(big, rb_cBignum, T_BIGNUM);
+ NEWOBJ_OF(big, struct RBignum, rb_cBignum, T_BIGNUM);
RBIGNUM_SET_SIGN(big, 1);
rb_big_resize((VALUE)big, len + 1);
diff --git a/range.c b/range.c
index 61fb643..c5e0d92 100644
--- a/range.c
+++ b/range.c
@@ -956,8 +956,7 @@ static VALUE
range_dumper(VALUE range)
{
VALUE v;
- NEWOBJ(m, struct RObject);
- OBJSETUP(m, rb_cObject, T_OBJECT);
+ NEWOBJ_OF(m, struct RObject, rb_cObject, T_OBJECT);
v = (VALUE)m;
diff --git a/rational.c b/rational.c
index e7a296a..99bb06a 100644
--- a/rational.c
+++ b/rational.c
@@ -348,8 +348,7 @@ f_lcm(VALUE x, VALUE y)
inline static VALUE
nurat_s_new_internal(VALUE klass, VALUE num, VALUE den)
{
- NEWOBJ(obj, struct RRational);
- OBJSETUP(obj, klass, T_RATIONAL);
+ NEWOBJ_OF(obj, struct RRational, klass, T_RATIONAL);
obj->num = num;
obj->den = den;
diff --git a/re.c b/re.c
index f512fa4..70e3c3f 100644
--- a/re.c
+++ b/re.c
@@ -826,8 +826,7 @@ VALUE rb_cMatch;
static VALUE
match_alloc(VALUE klass)
{
- NEWOBJ(match, struct RMatch);
- OBJSETUP(match, klass, T_MATCH);
+ NEWOBJ_OF(match, struct RMatch, klass, T_MATCH);
match->str = 0;
match->rmatch = 0;
@@ -2453,8 +2452,7 @@ rb_reg_initialize_str(VALUE obj, VALUE str, int options, onig_errmsg_buffer err,
static VALUE
rb_reg_s_alloc(VALUE klass)
{
- NEWOBJ(re, struct RRegexp);
- OBJSETUP(re, klass, T_REGEXP);
+ NEWOBJ_OF(re, struct RRegexp, klass, T_REGEXP);
re->ptr = 0;
re->src = 0;
diff --git a/string.c b/string.c
index fa95ee9..9c79b21 100644
--- a/string.c
+++ b/string.c
@@ -370,8 +370,7 @@ rb_str_capacity(VALUE str)
static inline VALUE
str_alloc(VALUE klass)
{
- NEWOBJ(str, struct RString);
- OBJSETUP(str, klass, T_STRING);
+ NEWOBJ_OF(str, struct RString, klass, T_STRING);
str->as.heap.ptr = 0;
str->as.heap.len = 0;
diff --git a/struct.c b/struct.c
index 91d562b..bd65541 100644
--- a/struct.c
+++ b/struct.c
@@ -384,8 +384,7 @@ static VALUE
struct_alloc(VALUE klass)
{
long n;
- NEWOBJ(st, struct RStruct);
- OBJSETUP(st, klass, T_STRUCT);
+ NEWOBJ_OF(st, struct RStruct, klass, T_STRUCT);
n = num_members(klass);