From c4daf616f02cb54c3e09692c67d1da13bd4a4109 Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Sun, 31 Dec 2017 03:19:50 +0000 Subject: [PATCH] fixed a bug of setting a byte object field wrongly in pf-basic.c --- moo/kernel/Magnitu.moo | 6 ++---- moo/kernel/Socket.moo | 14 ++++++++------ moo/lib/pf-basic.c | 16 ++++++++-------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/moo/kernel/Magnitu.moo b/moo/kernel/Magnitu.moo index 3a9d879..2f19d97 100644 --- a/moo/kernel/Magnitu.moo +++ b/moo/kernel/Magnitu.moo @@ -45,10 +45,8 @@ class Association(Magnitude) class(#limited) Character(Magnitude) { - ## method basicSize - ## { - ## ^0 - ## } +## method(#primitive,#class) fromCode: code. +## method(#primitive) toCode. method(#primitive) asInteger. diff --git a/moo/kernel/Socket.moo b/moo/kernel/Socket.moo index 6c4d180..ff2afe7 100644 --- a/moo/kernel/Socket.moo +++ b/moo/kernel/Socket.moo @@ -9,6 +9,7 @@ class(#byte) IPAddress(Object) { } +### TODO: extend the compiler ###class(#byte(4)) IP4Address(IPAddress) -> new basicNew always create 4 bytes. size to new: or basicNew: is ignored. ###class(#byte(16)) IP6Address(IPAddress) @@ -52,7 +53,7 @@ class(#byte) IP4Address(IPAddress) if (c >= $0 and: [c <= $9]) { - acc := acc * 10 + (c - $0) asInteger. + acc := acc * 10 + (c asInteger - $0 asInteger). if (acc > 255) { Exception signal: ('invalid IPv4 address B ' & str). }. digits := digits + 1. } @@ -253,12 +254,13 @@ class MyObject(Object) | s conact inact outact | -s := IP4Address fromString: '192.168.1.1'. -s dump. -s := IP6Address new. -s dump. -s := IP4SocketAddress new. +s := IP4Address fromString: '192.168.123.232'. s dump. +s basicSize dump. +##s := IP6Address new. +##s dump. +##s := IP4SocketAddress new. +##s dump. thisProcess terminate. inact := [:sck :state | | data n | diff --git a/moo/lib/pf-basic.c b/moo/lib/pf-basic.c index 3920fb6..2fc3e74 100644 --- a/moo/lib/pf-basic.c +++ b/moo/lib/pf-basic.c @@ -260,11 +260,13 @@ moo_pfrc_t moo_pf_basic_size (moo_t* moo, moo_ooi_t nargs) if (!MOO_OOP_IS_POINTER(rcv)) { + /* a non-pointer object has the size of 0. + * such an object doesn't consume object memory space except an OOP word */ sz = MOO_SMOOI_TO_OOP(0); } else { - sz = moo_oowtoint (moo, MOO_OBJ_GET_SIZE(rcv)); + sz = moo_oowtoint(moo, MOO_OBJ_GET_SIZE(rcv)); if (!sz) return MOO_PF_FAILURE; } @@ -377,19 +379,17 @@ moo_pfrc_t moo_pf_basic_at_put (moo_t* moo, moo_ooi_t nargs) case MOO_OBJ_TYPE_BYTE: if (!MOO_OOP_IS_SMOOI(val)) { - /* the value is not a character */ - moo_seterrnum (moo, MOO_EINVAL); + moo_seterrbfmt (moo, MOO_EINVAL, "value not a byte - %O", val); return MOO_PF_FAILURE; } /* TOOD: must I check the range of the value? */ - ((moo_oop_char_t)rcv)->slot[idx] = MOO_OOP_TO_SMOOI(val); + ((moo_oop_byte_t)rcv)->slot[idx] = MOO_OOP_TO_SMOOI(val); break; case MOO_OBJ_TYPE_CHAR: if (!MOO_OOP_IS_CHAR(val)) { - /* the value is not a character */ - moo_seterrnum (moo, MOO_EINVAL); + moo_seterrbfmt (moo, MOO_EINVAL, "value not a character - %O", val); return MOO_PF_FAILURE; } ((moo_oop_char_t)rcv)->slot[idx] = MOO_OOP_TO_CHAR(val); @@ -399,7 +399,7 @@ moo_pfrc_t moo_pf_basic_at_put (moo_t* moo, moo_ooi_t nargs) if (!MOO_OOP_IS_SMOOI(val)) { /* the value is not a number */ - moo_seterrnum (moo, MOO_EINVAL); + moo_seterrbfmt (moo, MOO_EINVAL, "value not a half-word integer - %O", val); return MOO_PF_FAILURE; } @@ -414,7 +414,7 @@ moo_pfrc_t moo_pf_basic_at_put (moo_t* moo, moo_ooi_t nargs) if (moo_inttooow (moo, val, &w) <= 0) { /* the value is not a number, out of range, or negative */ - moo_seterrnum (moo, MOO_EINVAL); + moo_seterrbfmt (moo, MOO_EINVAL, "value not a word integer - %O", val); return MOO_PF_FAILURE; } ((moo_oop_word_t)rcv)->slot[idx] = w;