added some argument checks into ffi
added more string manipulation functiions
This commit is contained in:
parent
70f9976af3
commit
bc83b95acb
@ -94,4 +94,4 @@ class MyObject(Object)
|
||||
ffi close.
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -420,7 +420,7 @@ static MOO_INLINE moo_oop_t make_bloated_bigint_with_ooi (moo_t* moo, moo_ooi_t
|
||||
if (i >= 0)
|
||||
{
|
||||
w = i;
|
||||
z =moo_instantiate (moo, moo->_large_positive_integer, MOO_NULL, 1 + extra);
|
||||
z = moo_instantiate (moo, moo->_large_positive_integer, MOO_NULL, 1 + extra);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -284,7 +284,7 @@ typedef enum moo_obj_type_t moo_obj_type_t;
|
||||
* unit: the size of a payload item in bytes.
|
||||
* extra: 0 or 1. 1 indicates that the payload contains 1 more
|
||||
* item than the value of the size field. used for a
|
||||
* terminating null in a variable-char object. internel
|
||||
* terminating null in a variable-character object. internel
|
||||
* use only.
|
||||
* kernel: 0 or 1. indicates that the object is a kernel object.
|
||||
* VM disallows layout changes of a kernel object.
|
||||
@ -1471,6 +1471,9 @@ int moo_convutobcstr (
|
||||
# define moo_dupbtooocharswithheadroom(moo,hrb,bcs,bcslen,oocslen) moo_dupbtoucharswithheadroom(moo,hrb,bcs,bcslen,oocslen)
|
||||
# define moo_dupootobchars(moo,oocs,oocslen,bcslen) moo_duputobchars(moo,oocs,oocslen,bcslen)
|
||||
# define moo_dupbtooochars(moo,bcs,bcslen,oocslen) moo_dupbtouchars(moo,bcs,bcslen,oocslen)
|
||||
|
||||
# define moo_dupootobcstrwithheadroom(moo,hrb,oocs,bcslen) moo_duputobcstrwithheadroom(moo,hrb,oocs,bcslen)
|
||||
# define moo_dupbtooocstrwithheadroom(moo,hrb,bcs,oocslen) moo_dupbtoucstrwithheadroom(moo,hrb,bcs,oocslen)
|
||||
# define moo_dupootobcstr(moo,oocs,bcslen) moo_duputobcstr(moo,oocs,bcslen)
|
||||
# define moo_dupbtooocstr(moo,bcs,oocslen) moo_dupbtoucstr(moo,bcs,oocslen)
|
||||
#else
|
||||
@ -1478,6 +1481,9 @@ int moo_convutobcstr (
|
||||
# define moo_duputooocharswithheadroom(moo,hrb,ucs,ucslen,oocslen) moo_duputobcharswithheadroom(moo,hrb,ucs,ucslen,oocslen)
|
||||
# define moo_dupootouchars(moo,oocs,oocslen,ucslen) moo_dupbtouchars(moo,oocs,oocslen,ucslen)
|
||||
# define moo_duputooochars(moo,ucs,ucslen,oocslen) moo_duputobchars(moo,ucs,ucslen,oocslen)
|
||||
|
||||
# define moo_dupootoucstrwithheadroom(moo,hrb,oocs,ucslen) moo_dupbtoucstrwithheadroom(moo,hrb,oocs,ucslen)
|
||||
# define moo_duputooocstrwithheadroom(moo,hrb,ucs,oocslen) moo_duputobcstrwithheadroom(moo,hrb,ucs,oocslen)
|
||||
# define moo_dupootoucstr(moo,oocs,ucslen) moo_dupbtoucstr(moo,oocs,ucslen)
|
||||
# define moo_duputooocstr(moo,ucs,oocslen) moo_duputobcstr(moo,ucs,oocslen)
|
||||
#endif
|
||||
@ -1513,6 +1519,21 @@ MOO_EXPORT moo_bch_t* moo_duputobchars (
|
||||
moo_oow_t* bcslen
|
||||
);
|
||||
|
||||
|
||||
MOO_EXPORT moo_uch_t* moo_dupbtoucstrwithheadroom (
|
||||
moo_t* moo,
|
||||
moo_oow_t headroom_bytes,
|
||||
const moo_bch_t* bcs,
|
||||
moo_oow_t* ucslen
|
||||
);
|
||||
|
||||
MOO_EXPORT moo_bch_t* moo_duputobcstrwithheadroom (
|
||||
moo_t* moo,
|
||||
moo_oow_t headroom_bytes,
|
||||
const moo_uch_t* ucs,
|
||||
moo_oow_t* bcslen
|
||||
);
|
||||
|
||||
MOO_EXPORT moo_uch_t* moo_dupbtoucstr (
|
||||
moo_t* moo,
|
||||
const moo_bch_t* bcs,
|
||||
|
@ -732,7 +732,10 @@ moo_bch_t* moo_duputobchars (moo_t* moo, const moo_uch_t* ucs, moo_oow_t ucslen,
|
||||
return moo_duputobcharswithheadroom (moo, 0, ucs, ucslen, bcslen);
|
||||
}
|
||||
|
||||
moo_uch_t* moo_dupbtoucstr (moo_t* moo, const moo_bch_t* bcs, moo_oow_t* ucslen)
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
MOO_INLINE moo_uch_t* moo_dupbtoucstrwithheadroom (moo_t* moo, moo_oow_t headroom_bytes, const moo_bch_t* bcs, moo_oow_t* ucslen)
|
||||
{
|
||||
moo_oow_t inlen, outlen;
|
||||
moo_uch_t* ptr;
|
||||
@ -744,7 +747,7 @@ moo_uch_t* moo_dupbtoucstr (moo_t* moo, const moo_bch_t* bcs, moo_oow_t* ucslen)
|
||||
}
|
||||
|
||||
outlen++;
|
||||
ptr = moo_allocmem (moo, outlen * MOO_SIZEOF(moo_uch_t));
|
||||
ptr = moo_allocmem (moo, headroom_bytes + (outlen * MOO_SIZEOF(moo_uch_t)));
|
||||
if (!ptr) return MOO_NULL;
|
||||
|
||||
moo_convbtoucstr (moo, bcs, &inlen, ptr, &outlen);
|
||||
@ -752,7 +755,12 @@ moo_uch_t* moo_dupbtoucstr (moo_t* moo, const moo_bch_t* bcs, moo_oow_t* ucslen)
|
||||
return ptr;
|
||||
}
|
||||
|
||||
moo_bch_t* moo_duputobcstr (moo_t* moo, const moo_uch_t* ucs, moo_oow_t* bcslen)
|
||||
moo_uch_t* moo_dupbtoucstr (moo_t* moo, const moo_bch_t* bcs, moo_oow_t* ucslen)
|
||||
{
|
||||
return moo_dupbtoucstrwithheadroom (moo, 0, bcs, ucslen);
|
||||
}
|
||||
|
||||
MOO_INLINE moo_bch_t* moo_duputobcstrwithheadroom (moo_t* moo, moo_oow_t headroom_bytes, const moo_uch_t* ucs, moo_oow_t* bcslen)
|
||||
{
|
||||
moo_oow_t inlen, outlen;
|
||||
moo_bch_t* ptr;
|
||||
@ -764,14 +772,20 @@ moo_bch_t* moo_duputobcstr (moo_t* moo, const moo_uch_t* ucs, moo_oow_t* bcslen)
|
||||
}
|
||||
|
||||
outlen++;
|
||||
ptr = moo_allocmem (moo, outlen * MOO_SIZEOF(moo_bch_t));
|
||||
ptr = moo_allocmem (moo, headroom_bytes + (outlen * MOO_SIZEOF(moo_bch_t)));
|
||||
if (!ptr) return MOO_NULL;
|
||||
|
||||
ptr = (moo_bch_t*)((moo_oob_t*)ptr + headroom_bytes);
|
||||
|
||||
moo_convutobcstr (moo, ucs, &inlen, ptr, &outlen);
|
||||
if (bcslen) *bcslen = outlen;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
moo_bch_t* moo_duputobcstr (moo_t* moo, const moo_uch_t* ucs, moo_oow_t* bcslen)
|
||||
{
|
||||
return moo_duputobcstrwithheadroom (moo, 0, ucs, bcslen);
|
||||
}
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
moo_uch_t* moo_dupuchars (moo_t* moo, const moo_uch_t* ucs, moo_oow_t ucslen)
|
||||
|
@ -100,7 +100,7 @@ static moo_pfrc_t pf_open (moo_t* moo, moo_ooi_t nargs)
|
||||
rcv = (ffi_t*)MOO_STACK_GETRCV(moo, nargs);
|
||||
name = MOO_STACK_GETARG(moo, nargs, 0);
|
||||
|
||||
if (!MOO_ISTYPEOF(moo, name, MOO_OBJ_TYPE_CHAR) || !MOO_OBJ_GET_FLAGS_EXTRA(name)) /* TODO: better null check instead of FLAGS_EXTREA check */
|
||||
if (!MOO_ISTYPEOF(moo, name, MOO_OBJ_TYPE_CHAR))
|
||||
{
|
||||
moo_seterrnum (moo, MOO_EINVAL);
|
||||
goto softfail;
|
||||
@ -198,6 +198,8 @@ static moo_pfrc_t pf_call (moo_t* moo, moo_ooi_t nargs)
|
||||
sig = MOO_STACK_GETARG(moo, nargs, 1);
|
||||
args = MOO_STACK_GETARG(moo, nargs, 2);
|
||||
|
||||
/* the signature must not be empty. at least the return type must be
|
||||
* specified */
|
||||
if (!MOO_ISTYPEOF(moo, sig, MOO_OBJ_TYPE_CHAR) || MOO_OBJ_GET_SIZE(sig) <= 0) goto inval;
|
||||
|
||||
#if 0
|
||||
@ -308,7 +310,7 @@ static moo_pfrc_t pf_call (moo_t* moo, moo_ooi_t nargs)
|
||||
{
|
||||
moo_bch_t* ptr;
|
||||
|
||||
/* TOOD: check if arg is a string. */
|
||||
if (!MOO_ISTYPEOF(moo,arg,MOO_OBJ_TYPE_CHAR)) goto inval;
|
||||
|
||||
#if defined(MOO_OOCH_IS_UCH)
|
||||
ptr = moo_dupootobcharswithheadroom (moo, MOO_SIZEOF_VOID_P, MOO_OBJ_GET_CHAR_SLOT(arg), MOO_OBJ_GET_SIZE(arg), MOO_NULL);
|
||||
@ -329,6 +331,8 @@ static moo_pfrc_t pf_call (moo_t* moo, moo_ooi_t nargs)
|
||||
{
|
||||
moo_uch_t* ptr;
|
||||
|
||||
if (!MOO_ISTYPEOF(moo,arg,MOO_OBJ_TYPE_CHAR)) goto inval;
|
||||
|
||||
#if defined(MOO_OOCH_IS_UCH)
|
||||
ptr = MOO_OBJ_GET_CHAR_SLOT(arg);
|
||||
/*ptr = moo_dupoochars (moo, MOO_OBJ_GET_CHAR_SLOT(arg), MOO_OBJ_GET_SIZE(arg));
|
||||
@ -350,8 +354,6 @@ static moo_pfrc_t pf_call (moo_t* moo, moo_ooi_t nargs)
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO: clean up strings duplicated... using moo_dupootobchars... */
|
||||
|
||||
if (i >= MOO_OBJ_GET_SIZE(sig)) goto call_void;
|
||||
|
||||
switch (((moo_oop_char_t)sig)->slot[i])
|
||||
@ -435,7 +437,6 @@ static moo_pfrc_t pf_call (moo_t* moo, moo_ooi_t nargs)
|
||||
{
|
||||
moo_oop_t s;
|
||||
moo_uch_t* r;
|
||||
|
||||
|
||||
r = dcCallPointer (rcv->dc, f);
|
||||
|
||||
@ -503,7 +504,7 @@ static moo_pfrc_t pf_getsym (moo_t* moo, moo_ooi_t nargs)
|
||||
rcv = (ffi_t*)MOO_STACK_GETRCV(moo, nargs);
|
||||
name = MOO_STACK_GETARG(moo, nargs, 0);
|
||||
|
||||
if (!MOO_ISTYPEOF(moo,name,MOO_OBJ_TYPE_CHAR)) /* TODO: null check on the symbol name? is '\0' contained in the middle of the name? */
|
||||
if (!MOO_ISTYPEOF(moo,name,MOO_OBJ_TYPE_CHAR))
|
||||
{
|
||||
moo_seterrnum (moo, MOO_EINVAL);
|
||||
goto softfail;
|
||||
|
Loading…
Reference in New Issue
Block a user