fixed a bug of setting a byte object field wrongly in pf-basic.c

This commit is contained in:
hyunghwan.chung 2017-12-31 03:19:50 +00:00
parent d0b20bee08
commit c4daf616f0
3 changed files with 18 additions and 18 deletions

View File

@ -45,10 +45,8 @@ class Association(Magnitude)
class(#limited) Character(Magnitude) class(#limited) Character(Magnitude)
{ {
## method basicSize ## method(#primitive,#class) fromCode: code.
## { ## method(#primitive) toCode.
## ^0
## }
method(#primitive) asInteger. method(#primitive) asInteger.

View File

@ -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(4)) IP4Address(IPAddress) -> new basicNew always create 4 bytes. size to new: or basicNew: is ignored.
###class(#byte(16)) IP6Address(IPAddress) ###class(#byte(16)) IP6Address(IPAddress)
@ -52,7 +53,7 @@ class(#byte) IP4Address(IPAddress)
if (c >= $0 and: [c <= $9]) 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). }. if (acc > 255) { Exception signal: ('invalid IPv4 address B ' & str). }.
digits := digits + 1. digits := digits + 1.
} }
@ -253,12 +254,13 @@ class MyObject(Object)
| s conact inact outact | | s conact inact outact |
s := IP4Address fromString: '192.168.1.1'. s := IP4Address fromString: '192.168.123.232'.
s dump.
s := IP6Address new.
s dump.
s := IP4SocketAddress new.
s dump. s dump.
s basicSize dump.
##s := IP6Address new.
##s dump.
##s := IP4SocketAddress new.
##s dump.
thisProcess terminate. thisProcess terminate.
inact := [:sck :state | inact := [:sck :state |
| data n | | data n |

View File

@ -260,11 +260,13 @@ moo_pfrc_t moo_pf_basic_size (moo_t* moo, moo_ooi_t nargs)
if (!MOO_OOP_IS_POINTER(rcv)) 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); sz = MOO_SMOOI_TO_OOP(0);
} }
else 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; 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: case MOO_OBJ_TYPE_BYTE:
if (!MOO_OOP_IS_SMOOI(val)) if (!MOO_OOP_IS_SMOOI(val))
{ {
/* the value is not a character */ moo_seterrbfmt (moo, MOO_EINVAL, "value not a byte - %O", val);
moo_seterrnum (moo, MOO_EINVAL);
return MOO_PF_FAILURE; return MOO_PF_FAILURE;
} }
/* TOOD: must I check the range of the value? */ /* 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; break;
case MOO_OBJ_TYPE_CHAR: case MOO_OBJ_TYPE_CHAR:
if (!MOO_OOP_IS_CHAR(val)) if (!MOO_OOP_IS_CHAR(val))
{ {
/* the value is not a character */ moo_seterrbfmt (moo, MOO_EINVAL, "value not a character - %O", val);
moo_seterrnum (moo, MOO_EINVAL);
return MOO_PF_FAILURE; return MOO_PF_FAILURE;
} }
((moo_oop_char_t)rcv)->slot[idx] = MOO_OOP_TO_CHAR(val); ((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)) if (!MOO_OOP_IS_SMOOI(val))
{ {
/* the value is not a number */ /* 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; 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) if (moo_inttooow (moo, val, &w) <= 0)
{ {
/* the value is not a number, out of range, or negative */ /* 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; return MOO_PF_FAILURE;
} }
((moo_oop_word_t)rcv)->slot[idx] = w; ((moo_oop_word_t)rcv)->slot[idx] = w;