experimented on setting the number of fixed fields forcibly in a module import function - sck.addr, SocketAddress

This commit is contained in:
hyunghwan.chung 2018-01-09 13:43:44 +00:00
parent 5b7ad01194
commit 68259e735f
3 changed files with 23 additions and 16 deletions

View File

@ -208,20 +208,7 @@ class(#byte(16)) IP6Address(IP4Address)
##} ##}
} }
class(#byte(19)) SocketAddress(Object) class(#byte) SocketAddress(Object) from 'sck.addr'
{
method(#primitive) port.
method(#primitive) port: port.
method(#primitive) ipaddr.
method(#primitive) ipaddr: ipaddr.
method fromString: str
{
}
}
class SocketAddress(Object) from 'sck.addr'
{ {
##method(#primitive) family. ##method(#primitive) family.
method(#primitive) fromString: str. method(#primitive) fromString: str.
@ -391,6 +378,11 @@ class MyObject(Object)
method(#class) main method(#class) main
{ {
| s conact inact outact | | s conact inact outact |
SocketAddress new dump.
'****************************' dump.
(* (*
s:= X new: 20. s:= X new: 20.
s basicSize dump. s basicSize dump.

View File

@ -7728,7 +7728,8 @@ static int __compile_class_definition (moo_t* moo, int extend)
* this extra module name, i'm free from GC headache */ * this extra module name, i'm free from GC headache */
if (moo_importmod (moo, moo->c->cls.self_oop, moo->c->cls.modname.ptr, moo->c->cls.modname.len) <= -1) if (moo_importmod (moo, moo->c->cls.self_oop, moo->c->cls.modname.ptr, moo->c->cls.modname.len) <= -1)
{ {
set_syntax_error (moo, MOO_SYNERR_MODIMPFAIL, &moo->c->cls.modname_loc, &moo->c->cls.modname); moo_copyoocstr (moo->errmsg.tmpbuf.ooch, MOO_COUNTOF(moo->errmsg.tmpbuf.ooch), moo->errmsg.buf);
set_syntax_errbfmt (moo, MOO_SYNERR_MODIMPFAIL, &moo->c->cls.modname_loc, &moo->c->cls.modname, "%js", moo->errmsg.tmpbuf.ooch);
return -1; return -1;
} }
} }

View File

@ -25,6 +25,7 @@
*/ */
#include "_sck.h" #include "_sck.h"
#include "../lib/moo-prv.h"
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
@ -94,7 +95,20 @@ static moo_pfinfo_t pfinfos[] =
static int import (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class) static int import (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class)
{ {
if (moo_setclasstrsize (moo, _class, MOO_SIZEOF(sck_addr_trailer_t), MOO_NULL) <= -1) return -1; moo_ooi_t spec;
/*if (moo_setclasstrsize (moo, _class, MOO_SIZEOF(sck_addr_trailer_t), MOO_NULL) <= -1) return -1;*/
spec = MOO_OOP_TO_SMOOI(_class->spec);
if (!MOO_CLASS_SPEC_IS_INDEXED(spec) || MOO_CLASS_SPEC_INDEXED_TYPE(spec) != MOO_OBJ_TYPE_BYTE || MOO_CLASS_SPEC_NAMED_INSTVARS(spec) != 0)
{
moo_seterrbfmt (moo, MOO_EINVAL, "%O not a plain byte class", _class);
return -1;
}
/* change the number of the fixed fields forcibly */
/* TODO: check if the super class has what kind of size ... */
spec = MOO_CLASS_SPEC_MAKE (10, MOO_CLASS_SPEC_FLAGS(spec), MOO_CLASS_SPEC_INDEXED_TYPE(spec));
_class->spec = MOO_SMOOI_TO_OOP(spec);
return 0; return 0;
} }