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

* ext/socket/socket.c (setup_domain_and_type): honor duck typing.

[ruby-dev:23522]

* ext/socket/socket.c (sock_s_getnameinfo): ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@6347 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2004-05-17 07:18:29 +00:00
parent 36b02b16a1
commit dcae18de82
3 changed files with 43 additions and 15 deletions

View file

@ -7,6 +7,13 @@ Mon May 17 16:14:25 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
(p 0.00000000000000000001 was '9.999999999999999e-21', now is
'1.0e-20')
Mon May 17 10:13:33 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/socket/socket.c (setup_domain_and_type): honor duck typing.
[ruby-dev:23522]
* ext/socket/socket.c (sock_s_getnameinfo): ditto.
Mon May 17 01:15:23 2004 why the lucky stiff <why@ruby-lang.org>
* lib/yaml.rb: removed fallback to pure Ruby parser.

View file

@ -1729,10 +1729,13 @@ setup_domain_and_type(domain, dv, type, tv)
VALUE domain, type;
int *dv, *tv;
{
VALUE tmp;
char *ptr;
if (TYPE(domain) == T_STRING) {
SafeStringValue(domain);
tmp = rb_check_string_type(domain);
if (!NIL_P(domain)) {
domain = tmp;
rb_check_safe_obj(domain);
ptr = RSTRING(domain)->ptr;
if (strcmp(ptr, "AF_INET") == 0)
*dv = AF_INET;
@ -1780,8 +1783,10 @@ setup_domain_and_type(domain, dv, type, tv)
else {
*dv = NUM2INT(domain);
}
if (TYPE(type) == T_STRING) {
SafeStringValue(type);
tmp = rb_check_string_type(type);
if (!NIL_P(tmp)) {
type = tmp;
rb_check_safe_obj(type);
ptr = RSTRING(type)->ptr;
if (strcmp(ptr, "SOCK_STREAM") == 0)
*tv = SOCK_STREAM;
@ -2193,7 +2198,7 @@ sock_s_getnameinfo(argc, argv)
int argc;
VALUE *argv;
{
VALUE sa, af = Qnil, host = Qnil, port = Qnil, flags;
VALUE sa, af = Qnil, host = Qnil, port = Qnil, flags, tmp;
char *hptr, *pptr;
char hbuf[1024], pbuf[1024];
int fl;
@ -2210,7 +2215,9 @@ sock_s_getnameinfo(argc, argv)
if (!NIL_P(flags)) {
fl = NUM2INT(flags);
}
if (TYPE(sa) == T_STRING) {
tmp = rb_check_string_type(sa);
if (!NIL_P(tmp)) {
sa = tmp;
if (sizeof(ss) < RSTRING(sa)->len) {
rb_raise(rb_eTypeError, "sockaddr length too big");
}
@ -2219,8 +2226,11 @@ sock_s_getnameinfo(argc, argv)
rb_raise(rb_eTypeError, "sockaddr size differs - should not happen");
}
sap = (struct sockaddr*)&ss;
goto call_nameinfo;
}
else if (TYPE(sa) == T_ARRAY) {
tmp = rb_check_array_type(sa);
if (!NIL_P(tmp)) {
sa = tmp;
MEMZERO(&hints, struct addrinfo, 1);
if (RARRAY(sa)->len == 3) {
af = RARRAY(sa)->ptr[0];
@ -2295,6 +2305,7 @@ sock_s_getnameinfo(argc, argv)
rb_raise(rb_eTypeError, "expecting String or Array");
}
call_nameinfo:
error = getnameinfo(sap, SA_LEN(sap), hbuf, sizeof(hbuf),
pbuf, sizeof(pbuf), fl);
if (error) goto error_exit_name;

View file

@ -87,14 +87,24 @@ def DelegateClass(superclass)
methods = superclass.public_instance_methods(true)
methods -= ::Kernel.public_instance_methods(false)
methods |= ["to_s","to_a","inspect","==","=~","==="]
klass.module_eval <<-EOS
def initialize(obj)
@_dc_obj = obj
end
def __getobj__
@_dc_obj
end
EOS
klass.module_eval {
def initialize(obj)
@_dc_obj = obj
end
def method_missing(m, *args)
p [m, *args]
unless @_dc_obj.respond_to?(m)
super(m, *args)
end
@_dc_obj.__send__(m, *args)
end
def __getobj__
@_dc_obj
end
def __setobj__(obj)
@_dc_obj = obj
end
}
for method in methods
begin
klass.module_eval <<-EOS