1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37275 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nari 2012-10-20 06:57:51 +00:00
parent f1e488e524
commit c3a46d6aca
20 changed files with 74 additions and 42 deletions

View file

@ -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

View file

@ -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));

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

21
gc.c
View file

@ -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)
{

10
hash.c
View file

@ -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);

View file

@ -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);\

3
io.c
View file

@ -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;

View file

@ -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);

View file

@ -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;

View file

@ -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;
}

View file

@ -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);

View file

@ -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;

View file

@ -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;

6
re.c
View file

@ -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;

View file

@ -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;

View file

@ -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);