added moo_inttooow_noseterr(), moo_intttoooi_noseterr(), moo_inttouintmax_noseterr(), moo_inttointmax_toseterr()

This commit is contained in:
hyunghwan.chung 2019-11-01 09:15:53 +00:00
parent 9c743960d8
commit b2d7f4bb58
10 changed files with 367 additions and 232 deletions

View File

@ -279,7 +279,7 @@ static int is_normalized_integer (moo_t* moo, moo_oop_t oop)
return 0;
}
static MOO_INLINE int bigint_to_oow (moo_t* moo, moo_oop_t num, moo_oow_t* w)
static MOO_INLINE int bigint_to_oow_noseterr (moo_t* moo, moo_oop_t num, moo_oow_t* w)
{
MOO_ASSERT (moo, MOO_OOP_IS_POINTER(num));
MOO_ASSERT (moo, MOO_POINTER_IS_PBIGINT(moo, num) || MOO_POINTER_IS_NBIGINT(moo, num));
@ -308,11 +308,10 @@ static MOO_INLINE int bigint_to_oow (moo_t* moo, moo_oop_t num, moo_oow_t* w)
# error UNSUPPORTED LIW BIT SIZE
#endif
moo_seterrnum (moo, MOO_ERANGE);
return 0; /* not convertable */
}
static MOO_INLINE int integer_to_oow (moo_t* moo, moo_oop_t x, moo_oow_t* w)
static MOO_INLINE int integer_to_oow_noseterr (moo_t* moo, moo_oop_t x, moo_oow_t* w)
{
/* return value
* 1 - a positive number including 0 that can fit into moo_oow_t
@ -338,10 +337,10 @@ static MOO_INLINE int integer_to_oow (moo_t* moo, moo_oop_t x, moo_oow_t* w)
}
MOO_ASSERT (moo, moo_isbigint(moo, x));
return bigint_to_oow(moo, x, w);
return bigint_to_oow_noseterr(moo, x, w);
}
int moo_inttooow (moo_t* moo, moo_oop_t x, moo_oow_t* w)
int moo_inttooow_noseterr (moo_t* moo, moo_oop_t x, moo_oow_t* w)
{
if (MOO_OOP_IS_SMOOI(x))
{
@ -360,26 +359,95 @@ int moo_inttooow (moo_t* moo, moo_oop_t x, moo_oow_t* w)
}
}
if (moo_isbigint(moo, x)) return bigint_to_oow(moo, x, w);
/* 0 -> too big, too small, or not an integer */
return moo_isbigint(moo, x)? bigint_to_oow_noseterr(moo, x, w): 0;
}
int moo_inttooow (moo_t* moo, moo_oop_t x, moo_oow_t* w)
{
if (MOO_OOP_IS_SMOOI(x))
{
moo_ooi_t v;
v = MOO_OOP_TO_SMOOI(x);
if (v < 0)
{
*w = -v;
moo_seterrnum (moo, MOO_ERANGE);
return -1; /* negative number negated - kind of an error */
}
else
{
*w = v;
return 1; /* zero or positive number */
}
}
/* 0 -> too big, too small, or not an integer */
if (moo_isbigint(moo, x))
{
int n;
if ((n = bigint_to_oow_noseterr(moo, x, w)) <= 0) moo_seterrnum (moo, MOO_ERANGE);
return n;
}
moo_seterrbfmt (moo, MOO_EINVAL, "not an integer - %O", x);
return 0; /* not convertable - too big, too small, or not an integer */
return 0; /* error. not convertible */
}
int moo_inttoooi_noseterr (moo_t* moo, moo_oop_t x, moo_ooi_t* i)
{
if (MOO_OOP_IS_SMOOI(x))
{
*i = MOO_OOP_TO_SMOOI(x);
return (*i < 0)? -1: 1;
}
if (moo_isbigint(moo, x))
{
moo_oow_t w;
int n;
n = bigint_to_oow_noseterr(moo, x, &w);
if (n < 0)
{
MOO_STATIC_ASSERT (MOO_TYPE_MAX(moo_ooi_t) + MOO_TYPE_MIN(moo_ooi_t) == -1); /* assume 2's complement */
if (w > (moo_oow_t)MOO_TYPE_MAX(moo_ooi_t) + 1) return 0; /* too small */
*i = -w; /* negate back */
}
else if (n > 0)
{
if (w > MOO_TYPE_MAX(moo_ooi_t)) return 0; /* too big */
*i = w;
}
return n;
}
return 0; /* not integer */
}
int moo_inttoooi (moo_t* moo, moo_oop_t x, moo_ooi_t* i)
{
if (MOO_OOP_IS_SMOOI(x))
{
*i = MOO_OOP_TO_SMOOI(x);
return (*i < 0)? -1: 1;
}
if (moo_isbigint(moo, x))
{
moo_oow_t w;
int n;
n = moo_inttooow(moo, x, &w);
n = bigint_to_oow_noseterr(moo, x, &w);
if (n < 0)
{
/* negative number negated to a positve number */
MOO_STATIC_ASSERT (MOO_TYPE_MAX(moo_ooi_t) + MOO_TYPE_MIN(moo_ooi_t) == -1); /* assume 2's complement */
if (w > (moo_oow_t)MOO_TYPE_MAX(moo_ooi_t) + 1)
{
moo_seterrnum (moo, MOO_ERANGE); /* not convertable. number too small */
return 0;
moo_seterrnum (moo, MOO_ERANGE);
return 0; /* too small */
}
*i = -w; /* negate back */
}
@ -387,13 +455,21 @@ int moo_inttoooi (moo_t* moo, moo_oop_t x, moo_ooi_t* i)
{
if (w > MOO_TYPE_MAX(moo_ooi_t))
{
moo_seterrnum (moo, MOO_ERANGE); /* not convertable. number too big */
return 0;
moo_seterrnum (moo, MOO_ERANGE);
return 0; /* too big */
}
*i = w;
}
else
{
moo_seterrnum (moo, MOO_ERANGE);
}
return n;
}
moo_seterrbfmt (moo, MOO_EINVAL, "not an integer - %O", x);
return 0; /* not integer */
}
#if (MOO_SIZEOF_UINTMAX_T == MOO_SIZEOF_OOW_T)
@ -401,7 +477,7 @@ int moo_inttoooi (moo_t* moo, moo_oop_t x, moo_ooi_t* i)
/* do nothing. required macros are defined in moo.h */
#elif (MOO_SIZEOF_UINTMAX_T == MOO_SIZEOF_OOW_T * 2)
static MOO_INLINE int bigint_to_uintmax (moo_t* moo, moo_oop_t num, moo_uintmax_t* w)
static MOO_INLINE int bigint_to_uintmax_noseterr (moo_t* moo, moo_oop_t num, moo_uintmax_t* w)
{
MOO_ASSERT (moo, MOO_OOP_IS_POINTER(num));
MOO_ASSERT (moo, MOO_POINTER_IS_PBIGINT(moo, num) || MOO_POINTER_IS_NBIGINT(moo, num));
@ -420,7 +496,7 @@ static MOO_INLINE int bigint_to_uintmax (moo_t* moo, moo_oop_t num, moo_uintmax_
goto done;
default:
goto oops_range;
return 0; /* not convertable */
}
#elif (MOO_LIW_BITS == MOO_OOHW_BITS)
@ -439,7 +515,7 @@ static MOO_INLINE int bigint_to_uintmax (moo_t* moo, moo_oop_t num, moo_uintmax_
goto done;
default:
goto oops_range;
return 0; /* not convertable */
}
#else
# error UNSUPPORTED LIW BIT SIZE
@ -447,13 +523,9 @@ static MOO_INLINE int bigint_to_uintmax (moo_t* moo, moo_oop_t num, moo_uintmax_
done:
return (MOO_POINTER_IS_NBIGINT(moo, num))? -1: 1;
oops_range:
moo_seterrnum (moo, MOO_ERANGE);
return 0; /* not convertable */
}
int moo_inttouintmax (moo_t* moo, moo_oop_t x, moo_uintmax_t* w)
int moo_inttouintmax_noseterr (moo_t* moo, moo_oop_t x, moo_uintmax_t* w)
{
if (MOO_OOP_IS_SMOOI(x))
{
@ -472,26 +544,97 @@ int moo_inttouintmax (moo_t* moo, moo_oop_t x, moo_uintmax_t* w)
}
}
if (moo_isbigint(moo, x)) return bigint_to_uintmax(moo, x, w);
if (moo_isbigint(moo, x)) return bigint_to_uintmax_noseterr(moo, x, w);
return 0; /* not convertable - too big, too small, or not an integer */
}
int moo_inttouintmax (moo_t* moo, moo_oop_t x, moo_uintmax_t* w)
{
if (MOO_OOP_IS_SMOOI(x))
{
moo_ooi_t v;
v = MOO_OOP_TO_SMOOI(x);
if (v < 0)
{
*w = -v;
moo_seterrnum (moo, MOO_ERANGE);
return -1; /* negative number negated - kind of an error */
}
else
{
*w = v;
return 1; /* zero or positive number */
}
}
if (moo_isbigint(moo, x))
{
int n;
if ((n = bigint_to_uintmax_noseterr(moo, x, w)) <= 0) moo_seterrnum (moo, MOO_ERANGE);
return n;
}
moo_seterrbfmt (moo, MOO_EINVAL, "not an integer - %O", x);
return 0; /* not convertable - too big, too small, or not an integer */
}
int moo_inttointmax_noseterr (moo_t* moo, moo_oop_t x, moo_intmax_t* i)
{
if (MOO_OOP_IS_SMOOI(x))
{
*i = MOO_OOP_TO_SMOOI(x);
return (*i < 0)? -1: 1;
}
if (moo_isbigint(moo, x))
{
int n;
moo_uintmax_t w;
n = bigint_to_uintmax_noseterr(moo, x, &w);
if (n < 0)
{
/* negative number negated to a positve number */
MOO_STATIC_ASSERT (MOO_TYPE_MAX(moo_intmax_t) + MOO_TYPE_MIN(moo_intmax_t) == -1); /* assume 2's complement */
if (w > (moo_uintmax_t)MOO_TYPE_MAX(moo_intmax_t) + 1) return 0; /* not convertable - too small */
*i = -w; /* negate it back */
}
else if (n > 0)
{
if (w > MOO_TYPE_MAX(moo_intmax_t)) return 0; /* not convertable - too big */
*i = w;
}
return n;
}
moo_seterrbfmt (moo, MOO_EINVAL, "not an integer - %O", x);
return 0; /* not convertable - not an integer */
}
int moo_inttointmax (moo_t* moo, moo_oop_t x, moo_intmax_t* i)
{
moo_uintmax_t w;
int n;
if (MOO_OOP_IS_SMOOI(x))
{
*i = MOO_OOP_TO_SMOOI(x);
return (*i < 0)? -1: 1;
}
n = moo_inttouintmax(moo, x, &w);
if (moo_isbigint(moo, x))
{
int n;
moo_uintmax_t w;
n = bigint_to_uintmax_noseterr(moo, x, &w);
if (n < 0)
{
/* negative number negated to a positve number */
MOO_STATIC_ASSERT (MOO_TYPE_MAX(moo_intmax_t) + MOO_TYPE_MIN(moo_intmax_t) == -1); /* assume 2's complement */
if (w > (moo_uintmax_t)MOO_TYPE_MAX(moo_intmax_t) + 1)
{
moo_seterrnum (moo, MOO_ERANGE); /* not convertable. number too small */
return 0;
moo_seterrnum (moo, MOO_ERANGE);
return 0; /* not convertable. too small */
}
*i = -w; /* negate it back */
}
@ -499,13 +642,20 @@ int moo_inttointmax (moo_t* moo, moo_oop_t x, moo_intmax_t* i)
{
if (w > MOO_TYPE_MAX(moo_intmax_t))
{
moo_seterrnum (moo, MOO_ERANGE); /* not convertable. number too big */
return 0;
moo_seterrnum (moo, MOO_ERANGE);
return 0; /* not convertable. too big */
}
*i = w;
}
else
{
moo_seterrnum (moo, MOO_ERANGE);
}
return n;
}
moo_seterrbfmt (moo, MOO_EINVAL, "not an integer - %O", x);
return 0; /* not convertable - too big, too small, or not an integer */
}
#else
@ -2989,7 +3139,7 @@ moo_oop_t moo_bitatint (moo_t* moo, moo_oop_t x, moo_oop_t y)
if (MOO_POINTER_IS_NBIGINT(moo, y)) return MOO_SMOOI_TO_OOP(0);
sign = bigint_to_oow(moo, y, &w);
sign = bigint_to_oow_noseterr(moo, y, &w);
MOO_ASSERT (moo, sign >= 0);
if (sign >= 1)
{
@ -3007,7 +3157,7 @@ moo_oop_t moo_bitatint (moo_t* moo, moo_oop_t x, moo_oop_t y)
moo_popvolat (moo);
if (!quo) return MOO_NULL;
sign = integer_to_oow(moo, quo, &wp);
sign = integer_to_oow_noseterr(moo, quo, &wp);
MOO_ASSERT (moo, sign >= 0);
if (sign == 0)
{
@ -3892,7 +4042,7 @@ static MOO_INLINE moo_oop_t rshift_negative_bigint_and_normalize (moo_t* moo, mo
moo_popvolat (moo);
if (!y) return MOO_NULL;
sign = integer_to_oow(moo, y, &shift);
sign = integer_to_oow_noseterr(moo, y, &shift);
if (sign == 0) shift = MOO_SMOOI_MAX;
else
{
@ -3980,7 +4130,7 @@ static MOO_INLINE moo_oop_t rshift_positive_bigint_and_normalize (moo_t* moo, mo
moo_popvolat (moo);
if (!y) return MOO_NULL;
sign = integer_to_oow(moo, y, &shift);
sign = integer_to_oow_noseterr(moo, y, &shift);
if (sign == 0) shift = MOO_SMOOI_MAX;
else
{
@ -4033,7 +4183,7 @@ static MOO_INLINE moo_oop_t lshift_bigint_and_normalize (moo_t* moo, moo_oop_t x
moo_popvolat (moo);
if (!y) return MOO_NULL;
sign = integer_to_oow(moo, y, &shift);
sign = integer_to_oow_noseterr(moo, y, &shift);
if (sign == 0) shift = MOO_SMOOI_MAX;
else
{
@ -4194,7 +4344,7 @@ moo_oop_t moo_bitshiftint (moo_t* moo, moo_oop_t x, moo_oop_t y)
negx = (MOO_POINTER_IS_NBIGINT(moo, x))? 1: 0;
negy = (MOO_POINTER_IS_NBIGINT(moo, y))? 1: 0;
sign = bigint_to_oow(moo, y, &shift);
sign = bigint_to_oow_noseterr(moo, y, &shift);
if (sign == 0)
{
/* y is too big or too small */
@ -4822,7 +4972,7 @@ moo_oop_t moo_inttostr (moo_t* moo, moo_oop_t num, int flagged_radix)
MOO_ASSERT (moo, radix >= 2 && radix <= 36);
if (!moo_isint(moo,num)) goto oops_einval;
v = integer_to_oow(moo, num, &w);
v = integer_to_oow_noseterr(moo, num, &w);
if (v)
{
@ -4858,6 +5008,8 @@ moo_oop_t moo_inttostr (moo_t* moo, moo_oop_t num, int flagged_radix)
return moo_makestring(moo, xbuf, xlen);
}
/* the number can't be represented as a single moo_oow_t value.
* mutli-word conversion begins now */
as = MOO_OBJ_GET_SIZE(num);
reqcapa = as * MOO_LIW_BITS + 1;

View File

@ -1562,7 +1562,7 @@ int moo_fmt_object_ (moo_fmtout_t* fmtout, moo_oop_t oop)
else if (c == moo->_namespace)
{
moo_oop_t ns;
struct
struct node_t
{
moo_oop_nsdic_t v;
struct node_t* next;
@ -1614,7 +1614,7 @@ int moo_fmt_object_ (moo_fmtout_t* fmtout, moo_oop_t oop)
{
/* print the class name */
moo_oop_t ns;
struct
struct node_t
{
moo_oop_nsdic_t v;
struct node_t* next;
@ -1664,7 +1664,7 @@ int moo_fmt_object_ (moo_fmtout_t* fmtout, moo_oop_t oop)
else if (c == moo->_interface)
{
moo_oop_t ns;
struct
struct node_t
{
moo_oop_nsdic_t v;
struct node_t* next;
@ -2209,7 +2209,7 @@ static MOO_INLINE int format_stack_args (moo_fmtout_t* fmtout, moo_ooi_t nargs,
flagc |= FLAGC_STAR2;
GET_NEXT_ARG_TO (moo, nargs, &arg_state, arg);
if (moo_inttoooi(moo, arg, &precision) <= -1) goto invalid_format;
if (moo_inttoooi_noseterr(moo, arg, &precision) <= -1) goto invalid_format;
if (precision < 0)
{
/* if precision is less than 0,
@ -2224,7 +2224,7 @@ static MOO_INLINE int format_stack_args (moo_fmtout_t* fmtout, moo_ooi_t nargs,
flagc |= FLAGC_STAR1;
GET_NEXT_ARG_TO (moo, nargs, &arg_state, arg);
if (moo_inttoooi(moo, arg, &width) <= -1) goto invalid_format;
if (moo_inttoooi_noseterr(moo, arg, &width) <= -1) goto invalid_format;
if (width < 0)
{
flagc |= FLAGC_LEFTADJ;

View File

@ -788,8 +788,8 @@ static void* query_mod (moo_t* moo, const moo_ooch_t* pid, moo_oow_t pidlen, moo
if (!mdp) return MOO_NULL;
}
base = pv? mdp->mod.querypv(moo, &mdp->mod, sep + 1, pidlen - mod_name_len - 1):
mdp->mod.querypf(moo, &mdp->mod, sep + 1, pidlen - mod_name_len - 1);
base = pv? (void*)mdp->mod.querypv(moo, &mdp->mod, sep + 1, pidlen - mod_name_len - 1):
(void*)mdp->mod.querypf(moo, &mdp->mod, sep + 1, pidlen - mod_name_len - 1);
if (!base)
{
/* the primitive function is not found. but keep the module open even if it's opened above */

View File

@ -2275,7 +2275,9 @@ MOO_EXPORT moo_oop_t moo_makestringwithbchars (
#if (MOO_SIZEOF_UINTMAX_T == MOO_SIZEOF_OOW_T)
# define moo_inttouintmax_noseterr moo_inttooow_noseterr
# define moo_inttouintmax moo_inttooow
# define moo_inttointmax_noseterr moo_inttoooi_noseterr
# define moo_inttointmax moo_inttoooi
# define moo_uintmaxtoint moo_oowtoint
# define moo_intmaxtoint moo_ooitoint
@ -2292,12 +2294,24 @@ MOO_EXPORT moo_oop_t moo_ooitoint (
moo_ooi_t i
);
MOO_EXPORT int moo_inttooow_noseterr (
moo_t* moo,
moo_oop_t x,
moo_oow_t* w
);
MOO_EXPORT int moo_inttooow (
moo_t* moo,
moo_oop_t x,
moo_oow_t* w
);
MOO_EXPORT int moo_inttoooi_noseterr (
moo_t* moo,
moo_oop_t x,
moo_ooi_t* i
);
MOO_EXPORT int moo_inttoooi (
moo_t* moo,
moo_oop_t x,
@ -2314,12 +2328,25 @@ MOO_EXPORT moo_oop_t moo_uintmaxtoint (
moo_uintmax_t i
);
MOO_EXPORT int moo_inttouintmax_noseterr (
moo_t* moo,
moo_oop_t x,
moo_uintmax_t* w
);
MOO_EXPORT int moo_inttouintmax (
moo_t* moo,
moo_oop_t x,
moo_uintmax_t* w
);
MOO_EXPORT int moo_inttointmax_noseterr (
moo_t* moo,
moo_oop_t x,
moo_intmax_t* i
);
MOO_EXPORT int moo_inttointmax (
moo_t* moo,
moo_oop_t x,

View File

@ -213,7 +213,7 @@ moo_pfrc_t moo_pf_basic_new (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
if (nargs >= 1)
{
szoop = MOO_STACK_GETARG(moo, nargs, 0);
if (moo_inttooow(moo, szoop, &size) <= 0)
if (moo_inttooow_noseterr(moo, szoop, &size) <= 0)
{
/* integer out of range or not integer */
moo_seterrbfmt (moo, MOO_EINVAL, "size out of range or not integer - %O", szoop);
@ -366,7 +366,7 @@ moo_pfrc_t moo_pf_basic_at (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
}
pos = MOO_STACK_GETARG(moo, nargs, 0);
if (moo_inttooow (moo, pos, &idx) <= 0)
if (moo_inttooow_noseterr(moo, pos, &idx) <= 0)
{
/* negative integer or not integer */
moo_seterrbfmt (moo, MOO_EINVAL, "invalid position - %O", pos);
@ -436,7 +436,7 @@ moo_pfrc_t moo_pf_basic_at_put (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
pos = MOO_STACK_GETARG(moo, nargs, 0);
val = MOO_STACK_GETARG(moo, nargs, 1);
if (moo_inttooow(moo, pos, &idx) <= 0)
if (moo_inttooow_noseterr(moo, pos, &idx) <= 0)
{
/* negative integer or not integer */
moo_seterrbfmt (moo, MOO_EINVAL, "invalid position - %O", pos);
@ -486,7 +486,7 @@ moo_pfrc_t moo_pf_basic_at_put (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
moo_oow_t w;
if (moo_inttooow(moo, val, &w) <= 0)
if (moo_inttooow_noseterr(moo, val, &w) <= 0)
{
/* the value is not a number, out of range, or negative */
moo_seterrbfmt (moo, MOO_EINVAL, "value not a word integer - %O", val);
@ -535,7 +535,7 @@ moo_pfrc_t moo_pf_basic_at_test_put (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs
oldval = MOO_STACK_GETARG(moo, nargs, 1);
newval = MOO_STACK_GETARG(moo, nargs, 1);
if (moo_inttooow(moo, pos, &idx) <= 0)
if (moo_inttooow_noseterr(moo, pos, &idx) <= 0)
{
/* negative integer or not integer */
moo_seterrbfmt (moo, MOO_EINVAL, "invalid position - %O", pos);
@ -606,14 +606,14 @@ moo_pfrc_t moo_pf_basic_at_test_put (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs
{
moo_oow_t w, ow;
if (moo_inttooow(moo, newval, &w) <= 0)
if (moo_inttooow_noseterr(moo, newval, &w) <= 0)
{
/* the new value is not a number, out of range, or negative */
moo_seterrbfmt (moo, MOO_EINVAL, "new value not a word integer - %O", newval);
return MOO_PF_FAILURE;
}
if (moo_inttooow(moo, oldval, &ow) >= 1 && ow == MOO_OBJ_GET_WORD_VAL(rcv, idx))
if (moo_inttooow_noseterr(moo, oldval, &ow) >= 1 && ow == MOO_OBJ_GET_WORD_VAL(rcv, idx))
{
MOO_OBJ_SET_WORD_VAL (rcv, idx, w);
retval = moo->_true;
@ -664,13 +664,13 @@ moo_pfrc_t moo_pf_basic_fill (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
dval = MOO_STACK_GETARG(moo, nargs, 1);
slen = MOO_STACK_GETARG(moo, nargs, 2);
if (moo_inttooow(moo, spos, &sidx) <= 0)
if (moo_inttooow_noseterr(moo, spos, &sidx) <= 0)
{
/* negative integer or not integer */
moo_seterrbfmt (moo, MOO_EINVAL, "invalid source position - %O", spos);
return MOO_PF_FAILURE;
}
if (moo_inttooow(moo, slen, &ssz) <= 0)
if (moo_inttooow_noseterr(moo, slen, &ssz) <= 0)
{
/* negative integer or not integer */
moo_seterrbfmt (moo, MOO_EINVAL, "invalid fill count - %O", slen);
@ -716,7 +716,7 @@ moo_pfrc_t moo_pf_basic_fill (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
case MOO_OBJ_TYPE_WORD:
{
moo_oow_t dw;
if (moo_inttooow(moo, dval, &dw) <= 0) goto invalid_fill_value;
if (moo_inttooow_noseterr(moo, dval, &dw) <= 0) goto invalid_fill_value;
for (i = sidx; i < end; i++) MOO_OBJ_SET_WORD_VAL (rcv, i, dw);
break;
}
@ -781,19 +781,19 @@ moo_pfrc_t moo_pf_basic_shift (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
dpos = MOO_STACK_GETARG(moo, nargs, 1);
slen = MOO_STACK_GETARG(moo, nargs, 2);
if (moo_inttooow(moo, spos, &sidx) <= 0)
if (moo_inttooow_noseterr(moo, spos, &sidx) <= 0)
{
/* negative integer or not integer */
moo_seterrbfmt (moo, MOO_EINVAL, "invalid source position - %O", spos);
return MOO_PF_FAILURE;
}
if (moo_inttooow(moo, dpos, &didx) <= 0)
if (moo_inttooow_noseterr(moo, dpos, &didx) <= 0)
{
/* negative integer or not integer */
moo_seterrbfmt (moo, MOO_EINVAL, "invalid destination position - %O", dpos);
return MOO_PF_FAILURE;
}
if (moo_inttooow(moo, slen, &ssz) <= 0)
if (moo_inttooow_noseterr(moo, slen, &ssz) <= 0)
{
/* negative integer or not integer */
moo_seterrbfmt (moo, MOO_EINVAL, "invalid shift count - %O", slen);

View File

@ -122,14 +122,14 @@ static MOO_INLINE moo_pfrc_t _system_alloc (moo_t* moo, moo_ooi_t nargs, int cle
moo_allocmem(moo, MOO_OOP_TO_SMOOI(tmp));
if (!ptr) return MOO_PF_FAILURE;
if (!MOO_IN_SMPTR_RANGE(ptr))
tmp = moo_oowtoptr(moo, (moo_oow_t)ptr);
if (!tmp)
{
moo_seterrbfmt (moo, MOO_ERANGE, "%p not in smptr range for raw memory allocation", ptr);
moo_freemem (moo, ptr);
return MOO_PF_FAILURE;
}
MOO_STACK_SETRET (moo, nargs, MOO_SMPTR_TO_OOP(ptr));
MOO_STACK_SETRET (moo, nargs, tmp);
return MOO_PF_SUCCESS;
}
@ -148,22 +148,16 @@ moo_pfrc_t moo_pf_system_malloc (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
moo_pfrc_t moo_pf_system_free (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
moo_oop_t tmp;
void* rawptr;
moo_oow_t rawptr;
/*MOO_PF_CHECK_RCV (moo, MOO_STACK_GETRCV(moo, nargs) == (moo_oop_t)moo->_system);*/
MOO_ASSERT (moo, nargs == 1);
tmp = MOO_STACK_GETARG(moo, nargs, 0);
if (MOO_OOP_IS_SMPTR(tmp))
{
moo_freemem (moo, MOO_OOP_TO_SMPTR(tmp));
}
else if (moo_inttooow(moo, tmp, (moo_oow_t*)&rawptr) >= 1)
{
moo_freemem (moo, rawptr);
}
if (moo_ptrtooow(moo, tmp, &rawptr) <= -1) return MOO_PF_FAILURE;
moo_freemem (moo, (void*)rawptr);
MOO_STACK_SETRETTORCV (moo, nargs);
return MOO_PF_SUCCESS;
}
@ -171,13 +165,14 @@ moo_pfrc_t moo_pf_system_free (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
moo_pfrc_t moo_pf_smptr_free (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
moo_oop_t tmp;
moo_oow_t rawptr;
MOO_ASSERT (moo, nargs == 0);
tmp = MOO_STACK_GETRCV(moo, nargs);
MOO_PF_CHECK_RCV (moo, MOO_OOP_IS_SMPTR(tmp));
if (moo_ptrtooow(moo, tmp, &rawptr) <= -1) return MOO_PF_FAILURE;
moo_freemem (moo, MOO_OOP_TO_SMPTR(tmp));
moo_freemem (moo, (void*)rawptr);
MOO_STACK_SETRETTORCV (moo, nargs);
return MOO_PF_SUCCESS;
@ -287,7 +282,7 @@ static MOO_INLINE int _store_raw_int (moo_t* moo, moo_uint8_t* rawptr, moo_oow_t
int n;
moo_ooi_t w, max, min;
if ((n = moo_inttoooi(moo, voop, &w)) == 0) /* not convertable */
if ((n = moo_inttoooi_noseterr(moo, voop, &w)) == 0) /* not convertable */
{
moo_seterrbfmt (moo, moo_geterrnum(moo), "invalid value %O for raw signed memory store", voop);
return -1;
@ -344,7 +339,7 @@ static MOO_INLINE int _store_raw_uint (moo_t* moo, moo_uint8_t* rawptr, moo_oow_
int n;
moo_oow_t w, max;
if ((n = moo_inttooow(moo, voop, &w)) <= 0)
if ((n = moo_inttooow_noseterr(moo, voop, &w)) <= 0)
{
if (n <= -1)
{
@ -419,7 +414,7 @@ static moo_pfrc_t _get_system_int (moo_t* moo, moo_ooi_t nargs, int size)
}
tmp = MOO_STACK_GETARG(moo, nargs, 1);
if (moo_inttooow(moo, tmp, &offset) <= 0)
if (moo_inttooow_noseterr(moo, tmp, &offset) <= 0)
{
moo_seterrbfmt (moo, MOO_EINVAL, "invalid offset %O for raw signed memory fetch", tmp);
return MOO_PF_FAILURE;
@ -449,7 +444,7 @@ static moo_pfrc_t _get_system_uint (moo_t* moo, moo_ooi_t nargs, int size)
}
tmp = MOO_STACK_GETARG(moo, nargs, 1);
if (moo_inttooow (moo, tmp, &offset) <= 0)
if (moo_inttooow_noseterr(moo, tmp, &offset) <= 0)
{
moo_seterrbfmt (moo, MOO_EINVAL, "invalid offset %O for raw unsigned memory fetch", tmp);
return MOO_PF_FAILURE;
@ -520,7 +515,7 @@ static moo_pfrc_t _put_system_int (moo_t* moo, moo_ooi_t nargs, int size)
}
tmp = MOO_STACK_GETARG(moo, nargs, 1);
if (moo_inttooow(moo, tmp, &offset) <= 0)
if (moo_inttooow_noseterr(moo, tmp, &offset) <= 0)
{
moo_seterrbfmt (moo, MOO_EINVAL, "invalid offset %O for raw signed memory store", tmp);
return MOO_PF_FAILURE;
@ -552,7 +547,7 @@ static moo_pfrc_t _put_system_uint (moo_t* moo, moo_ooi_t nargs, int size)
}
tmp = MOO_STACK_GETARG(moo, nargs, 1);
if (moo_inttooow(moo, tmp, &offset) <= 0)
if (moo_inttooow_noseterr(moo, tmp, &offset) <= 0)
{
moo_seterrbfmt (moo, MOO_EINVAL, "invalid offset %O for raw unsigned memory store", tmp);
return MOO_PF_FAILURE;
@ -627,21 +622,21 @@ moo_pfrc_t moo_pf_system_get_bytes (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
}
tmp = MOO_STACK_GETARG(moo, nargs, 1);
if (moo_inttooow(moo, tmp, &offset) <= 0)
if (moo_inttooow_noseterr(moo, tmp, &offset) <= 0)
{
moo_seterrbfmt (moo, MOO_EINVAL, "invalid offset %O for raw memory fetch", tmp);
return MOO_PF_FAILURE;
}
tmp = MOO_STACK_GETARG(moo, nargs, 3);
if (moo_inttooow(moo, tmp, &offset_in_buffer) <= 0)
if (moo_inttooow_noseterr(moo, tmp, &offset_in_buffer) <= 0)
{
moo_seterrbfmt (moo, MOO_EINVAL, "invalid buffer offset %O for raw memory fetch", tmp);
return MOO_PF_FAILURE;
}
tmp = MOO_STACK_GETARG(moo, nargs, 4);
if (moo_inttooow(moo, tmp, &len_in_buffer) <= 0)
if (moo_inttooow_noseterr(moo, tmp, &len_in_buffer) <= 0)
{
moo_seterrbfmt (moo, MOO_EINVAL, "invalid buffer length %O for raw memory fetch", tmp);
return MOO_PF_FAILURE;
@ -689,21 +684,21 @@ moo_pfrc_t moo_pf_system_put_bytes (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
}
tmp = MOO_STACK_GETARG(moo, nargs, 1);
if (moo_inttooow(moo, tmp, &offset) <= 0)
if (moo_inttooow_noseterr(moo, tmp, &offset) <= 0)
{
moo_seterrbfmt (moo, MOO_EINVAL, "invalid offset %O for raw memory store", tmp);
return MOO_PF_FAILURE;
}
tmp = MOO_STACK_GETARG(moo, nargs, 3);
if (moo_inttooow(moo, tmp, &offset_in_buffer) <= 0)
if (moo_inttooow_noseterr(moo, tmp, &offset_in_buffer) <= 0)
{
moo_seterrbfmt (moo, MOO_EINVAL, "invalid buffer offset %O for raw memory fetch", tmp);
return MOO_PF_FAILURE;
}
tmp = MOO_STACK_GETARG(moo, nargs, 4);
if (moo_inttooow(moo, tmp, &len_in_buffer) <= 0)
if (moo_inttooow_noseterr(moo, tmp, &len_in_buffer) <= 0)
{
moo_seterrbfmt (moo, MOO_EINVAL, "invalid buffer length %O for raw memory fetch", tmp);
return MOO_PF_FAILURE;
@ -754,7 +749,7 @@ static moo_pfrc_t _get_smptr_int (moo_t* moo, moo_ooi_t nargs, int size)
}
tmp = MOO_STACK_GETARG(moo, nargs, 0);
if (moo_inttooow(moo, tmp, &offset) <= 0)
if (moo_inttooow_noseterr(moo, tmp, &offset) <= 0)
{
moo_seterrbfmt (moo, MOO_EINVAL, "invalid offset %O for raw signed memory fetch", tmp);
return MOO_PF_FAILURE;
@ -786,7 +781,7 @@ static moo_pfrc_t _get_smptr_uint (moo_t* moo, moo_ooi_t nargs, int size)
}
tmp = MOO_STACK_GETARG(moo, nargs, 0);
if (moo_inttooow(moo, tmp, &offset) <= 0)
if (moo_inttooow_noseterr(moo, tmp, &offset) <= 0)
{
moo_seterrbfmt (moo, MOO_EINVAL, "invalid offset %O for raw unsigned memory fetch", tmp);
return MOO_PF_FAILURE;
@ -857,7 +852,7 @@ static moo_pfrc_t _put_smptr_int (moo_t* moo, moo_ooi_t nargs, int size)
}
tmp = MOO_STACK_GETARG(moo, nargs, 0);
if (moo_inttooow(moo, tmp, &offset) <= 0)
if (moo_inttooow_noseterr(moo, tmp, &offset) <= 0)
{
moo_seterrbfmt (moo, MOO_EINVAL, "invalid offset %O for raw signed memory store", tmp);
return MOO_PF_FAILURE;
@ -890,7 +885,7 @@ static moo_pfrc_t _put_smptr_uint (moo_t* moo, moo_ooi_t nargs, int size)
}
tmp = MOO_STACK_GETARG(moo, nargs, 0);
if (moo_inttooow(moo, tmp, &offset) <= 0)
if (moo_inttooow_noseterr(moo, tmp, &offset) <= 0)
{
moo_seterrbfmt (moo, MOO_EINVAL, "invalid offset %O for raw unsigned memory store", tmp);
return MOO_PF_FAILURE;
@ -966,21 +961,21 @@ moo_pfrc_t moo_pf_smptr_get_bytes (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
}
tmp = MOO_STACK_GETARG(moo, nargs, 0);
if (moo_inttooow(moo, tmp, &offset) <= 0)
if (moo_inttooow_noseterr(moo, tmp, &offset) <= 0)
{
moo_seterrbfmt (moo, MOO_EINVAL, "invalid offset %O for raw memory fetch", tmp);
return MOO_PF_FAILURE;
}
tmp = MOO_STACK_GETARG(moo, nargs, 2);
if (moo_inttooow(moo, tmp, &offset_in_buffer) <= 0)
if (moo_inttooow_noseterr(moo, tmp, &offset_in_buffer) <= 0)
{
moo_seterrbfmt (moo, MOO_EINVAL, "invalid buffer offset %O for raw memory fetch", tmp);
return MOO_PF_FAILURE;
}
tmp = MOO_STACK_GETARG(moo, nargs, 3);
if (moo_inttooow(moo, tmp, &len_in_buffer) <= 0)
if (moo_inttooow_noseterr(moo, tmp, &len_in_buffer) <= 0)
{
moo_seterrbfmt (moo, MOO_EINVAL, "invalid buffer length %O for raw memory fetch", tmp);
return MOO_PF_FAILURE;
@ -1029,21 +1024,21 @@ moo_pfrc_t moo_pf_smptr_put_bytes (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
}
tmp = MOO_STACK_GETARG(moo, nargs, 0);
if (moo_inttooow(moo, tmp, &offset) <= 0)
if (moo_inttooow_noseterr(moo, tmp, &offset) <= 0)
{
moo_seterrbfmt (moo, MOO_EINVAL, "invalid offset %O for raw memory store", tmp);
return MOO_PF_FAILURE;
}
tmp = MOO_STACK_GETARG(moo, nargs, 2);
if (moo_inttooow(moo, tmp, &offset_in_buffer) <= 0)
if (moo_inttooow_noseterr(moo, tmp, &offset_in_buffer) <= 0)
{
moo_seterrbfmt (moo, MOO_EINVAL, "invalid buffer offset %O for raw memory fetch", tmp);
return MOO_PF_FAILURE;
}
tmp = MOO_STACK_GETARG(moo, nargs, 3);
if (moo_inttooow(moo, tmp, &len_in_buffer) <= 0)
if (moo_inttooow_noseterr(moo, tmp, &len_in_buffer) <= 0)
{
moo_seterrbfmt (moo, MOO_EINVAL, "invalid buffer length %O for raw memory fetch", tmp);
return MOO_PF_FAILURE;

View File

@ -346,7 +346,8 @@ static MOO_INLINE int add_ffi_arg (moo_t* moo, ffi_t* ffi, moo_ooch_t fmtc, int
if (_unsigned)
{
moo_oow_t v;
if (moo_inttooow(moo, arg, &v) == 0) goto oops;
if (MOO_OOP_IS_CHAR(arg)) v = MOO_OOP_TO_CHAR(arg);
else if (moo_inttooow_noseterr(moo, arg, &v) <= 0) goto inval_arg_value;;
#if defined(USE_DYNCALL)
__dcArgInt8 (ffi->dc, v);
#elif defined(USE_LIBFFI)
@ -357,7 +358,8 @@ static MOO_INLINE int add_ffi_arg (moo_t* moo, ffi_t* ffi, moo_ooch_t fmtc, int
else
{
moo_ooi_t v;
if (moo_inttoooi(moo, arg, &v) == 0) goto oops;
if (MOO_OOP_IS_CHAR(arg)) v = MOO_OOP_TO_CHAR(arg);
else if (moo_inttoooi_noseterr(moo, arg, &v) == 0) goto inval_arg_value;;
#if defined(USE_DYNCALL)
__dcArgInt8 (ffi->dc, v);
#elif defined(USE_LIBFFI)
@ -371,7 +373,7 @@ static MOO_INLINE int add_ffi_arg (moo_t* moo, ffi_t* ffi, moo_ooch_t fmtc, int
if (_unsigned)
{
moo_oow_t v;
if (moo_inttooow(moo, arg, &v) == 0) goto oops;
if (moo_inttooow_noseterr(moo, arg, &v) <= 0) goto inval_arg_value;;
#if defined(USE_DYNCALL)
__dcArgInt16 (ffi->dc, v);
#elif defined(USE_LIBFFI)
@ -382,7 +384,7 @@ static MOO_INLINE int add_ffi_arg (moo_t* moo, ffi_t* ffi, moo_ooch_t fmtc, int
else
{
moo_ooi_t v;
if (moo_inttoooi(moo, arg, &v) == 0) goto oops;
if (moo_inttoooi_noseterr(moo, arg, &v) == 0) goto inval_arg_value;;
#if defined(USE_DYNCALL)
__dcArgInt16 (ffi->dc, v);
#elif defined(USE_LIBFFI)
@ -397,7 +399,7 @@ static MOO_INLINE int add_ffi_arg (moo_t* moo, ffi_t* ffi, moo_ooch_t fmtc, int
if (_unsigned)
{
moo_oow_t v;
if (moo_inttooow(moo, arg, &v) == 0) goto oops;
if (moo_inttooow_noseterr(moo, arg, &v) <= 0) goto inval_arg_value;;
#if defined(USE_DYNCALL)
__dcArgInt32 (ffi->dc, v);
#elif defined(USE_LIBFFI)
@ -408,7 +410,7 @@ static MOO_INLINE int add_ffi_arg (moo_t* moo, ffi_t* ffi, moo_ooch_t fmtc, int
else
{
moo_ooi_t v;
if (moo_inttoooi(moo, arg, &v) == 0) goto oops;
if (moo_inttoooi_noseterr(moo, arg, &v) == 0) goto inval_arg_value;;
#if defined(USE_DYNCALL)
__dcArgInt32 (ffi->dc, v);
#elif defined(USE_LIBFFI)
@ -424,7 +426,7 @@ static MOO_INLINE int add_ffi_arg (moo_t* moo, ffi_t* ffi, moo_ooch_t fmtc, int
if (_unsigned)
{
moo_oow_t v;
if (moo_inttooow(moo, arg, &v) == 0) goto oops;
if (moo_inttooow_noseterr(moo, arg, &v) <= 0) goto inval_arg_value;
#if defined(USE_DYNCALL)
__dcArgInt64 (ffi->dc, v);
#elif defined(USE_LIBFFI)
@ -435,7 +437,7 @@ static MOO_INLINE int add_ffi_arg (moo_t* moo, ffi_t* ffi, moo_ooch_t fmtc, int
else
{
moo_ooi_t v;
if (moo_inttoooi(moo, arg, &v) == 0) goto oops;
if (moo_inttoooi_noseterr(moo, arg, &v) == 0) goto inval_arg_value;
#if defined(USE_DYNCALL)
__dcArgInt64 (ffi->dc, v);
#elif defined(USE_LIBFFI)
@ -448,24 +450,29 @@ static MOO_INLINE int add_ffi_arg (moo_t* moo, ffi_t* ffi, moo_ooch_t fmtc, int
goto inval_sig_ch;
#endif
case FMTC_CHAR:
if (!MOO_OOP_IS_CHAR(arg)) goto inval_arg_value;
case FMTC_CHAR: /* this is a byte */
if (_unsigned)
{
moo_oow_t v;
if (MOO_OOP_IS_CHAR(arg)) v = MOO_OOP_TO_CHAR(arg);
else if (moo_inttooow_noseterr(moo, arg, &v) <= 0) goto inval_arg_value;;
#if defined(USE_DYNCALL)
dcArgChar (ffi->dc, MOO_OOP_TO_CHAR(arg));
dcArgChar (ffi->dc, v);
#elif defined(USE_LIBFFI)
ffi->arg_values[ffi->arg_count] = &ffi->arg_svs[ffi->arg_count].uc;
ffi->arg_svs[ffi->arg_count].uc = MOO_OOP_TO_CHAR(arg);
ffi->arg_svs[ffi->arg_count].uc = v;
#endif
}
else
{
moo_ooi_t v;
if (MOO_OOP_IS_CHAR(arg)) v = MOO_OOP_TO_CHAR(arg);
else if (moo_inttoooi_noseterr(moo, arg, &v) == 0) goto inval_arg_value;;
#if defined(USE_DYNCALL)
dcArgChar (ffi->dc, MOO_OOP_TO_CHAR(arg));
dcArgChar (ffi->dc, v);
#elif defined(USE_LIBFFI)
ffi->arg_values[ffi->arg_count] = &ffi->arg_svs[ffi->arg_count].c;
ffi->arg_svs[ffi->arg_count].c = MOO_OOP_TO_CHAR(arg);
ffi->arg_svs[ffi->arg_count].c = v;
#endif
}
break;
@ -474,7 +481,7 @@ static MOO_INLINE int add_ffi_arg (moo_t* moo, ffi_t* ffi, moo_ooch_t fmtc, int
if (_unsigned)
{
moo_oow_t v;
if (moo_inttooow(moo, arg, &v) == 0) goto oops;
if (moo_inttooow_noseterr(moo, arg, &v) <= 0) goto inval_arg_value;
#if defined(USE_DYNCALL)
dcArgShort (ffi->dc, v);
#elif defined(USE_LIBFFI)
@ -485,7 +492,7 @@ static MOO_INLINE int add_ffi_arg (moo_t* moo, ffi_t* ffi, moo_ooch_t fmtc, int
else
{
moo_ooi_t v;
if (moo_inttoooi(moo, arg, &v) == 0) goto oops;
if (moo_inttoooi_noseterr(moo, arg, &v) == 0) goto inval_arg_value;
#if defined(USE_DYNCALL)
dcArgShort (ffi->dc, v);
#elif defined(USE_LIBFFI)
@ -499,7 +506,7 @@ static MOO_INLINE int add_ffi_arg (moo_t* moo, ffi_t* ffi, moo_ooch_t fmtc, int
if (_unsigned)
{
moo_oow_t v;
if (moo_inttooow(moo, arg, &v) == 0) goto oops;
if (moo_inttooow_noseterr(moo, arg, &v) <= 0) goto inval_arg_value;
#if defined(USE_DYNCALL)
dcArgInt (ffi->dc, v);
#elif defined(USE_LIBFFI)
@ -510,7 +517,7 @@ static MOO_INLINE int add_ffi_arg (moo_t* moo, ffi_t* ffi, moo_ooch_t fmtc, int
else
{
moo_ooi_t v;
if (moo_inttoooi(moo, arg, &v) == 0) goto oops;
if (moo_inttoooi_noseterr(moo, arg, &v) == 0) goto inval_arg_value;
#if defined(USE_DYNCALL)
dcArgInt (ffi->dc, v);
#elif defined(USE_LIBFFI)
@ -525,7 +532,7 @@ static MOO_INLINE int add_ffi_arg (moo_t* moo, ffi_t* ffi, moo_ooch_t fmtc, int
if (_unsigned)
{
moo_oow_t v;
if (moo_inttooow(moo, arg, &v) == 0) goto oops;
if (moo_inttooow_noseterr(moo, arg, &v) <= 0) goto inval_arg_value;
#if defined(USE_DYNCALL)
dcArgLong (ffi->dc, v);
#elif defined(USE_LIBFFI)
@ -536,7 +543,7 @@ static MOO_INLINE int add_ffi_arg (moo_t* moo, ffi_t* ffi, moo_ooch_t fmtc, int
else
{
moo_ooi_t v;
if (moo_inttoooi(moo, arg, &v) == 0) goto oops;
if (moo_inttoooi_noseterr(moo, arg, &v) == 0) goto inval_arg_value;;
#if defined(USE_DYNCALL)
dcArgLong (ffi->dc, v);
#elif defined(USE_LIBFFI)
@ -553,7 +560,7 @@ static MOO_INLINE int add_ffi_arg (moo_t* moo, ffi_t* ffi, moo_ooch_t fmtc, int
if (_unsigned)
{
moo_uintmax_t v;
if (moo_inttouintmax(moo, arg, &v) == 0) goto oops;
if (moo_inttouintmax_noseterr(moo, arg, &v) <= 0) goto inval_arg_value;
#if defined(USE_DYNCALL)
dcArgLongLong (ffi->dc, v);
#elif defined(USE_LIBFFI)
@ -564,7 +571,7 @@ static MOO_INLINE int add_ffi_arg (moo_t* moo, ffi_t* ffi, moo_ooch_t fmtc, int
else
{
moo_intmax_t v;
if (moo_inttointmax(moo, arg, &v) == 0) goto oops;
if (moo_inttointmax_noseterr(moo, arg, &v) == 0) goto inval_arg_value;
#if defined(USE_DYNCALL)
dcArgLongLong (ffi->dc, v);
#elif defined(USE_LIBFFI)

View File

@ -113,31 +113,37 @@ oops:
return MOO_PF_FAILURE;
}
#define RCV_TO_FD(moo, nargs, fd_) \
do \
{ \
oop_io_t rcv_; \
rcv_ = (oop_io_t)MOO_STACK_GETRCV(moo, nargs); \
MOO_PF_CHECK_RCV (moo, \
MOO_OOP_IS_POINTER(rcv_) && \
MOO_OBJ_BYTESOF(rcv_) >= (MOO_SIZEOF(*rcv_) - MOO_SIZEOF(moo_obj_t)) && \
MOO_OOP_IS_SMOOI(rcv_->handle) \
); \
fd_ = MOO_OOP_TO_SMOOI(rcv_->handle); \
if (fd_ <= -1) \
{ \
moo_seterrbfmt (moo, MOO_EINVAL, "bad IO handle - %d", fd_); \
return MOO_PF_FAILURE; \
} \
} \
while(0)
static moo_pfrc_t pf_chmod_file (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
oop_io_t io;
moo_oop_t tmp;
int fd, n;
moo_oow_t mode;
io = (oop_io_t)MOO_STACK_GETRCV(moo, nargs);
MOO_PF_CHECK_RCV (moo,
MOO_OOP_IS_POINTER(io) &&
MOO_OBJ_BYTESOF(io) >= (MOO_SIZEOF(*io) - MOO_SIZEOF(moo_obj_t)) &&
MOO_OOP_IS_SMOOI(io->handle)
);
fd = MOO_OOP_TO_SMOOI(io->handle);
if (fd <= -1)
{
moo_seterrbfmt (moo, MOO_EINVAL, "bad IO handle - %d", fd);
return MOO_PF_FAILURE;
}
RCV_TO_FD (moo, nargs, fd);
MOO_STATIC_ASSERT (MOO_TYPE_IS_UNSIGNED(mode_t));
tmp = MOO_STACK_GETARG(moo, nargs, 0);
if (moo_inttooow(moo, tmp, &mode) == 0 || mode > MOO_TYPE_MAX(mode_t))
if (moo_inttooow_noseterr(moo, tmp, &mode) == 0 || mode > MOO_TYPE_MAX(mode_t))
{
moo_seterrbfmt (moo, MOO_EINVAL, "invalid mode - %O", tmp);
return MOO_PF_FAILURE;
@ -156,37 +162,24 @@ static moo_pfrc_t pf_chmod_file (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
static moo_pfrc_t pf_chown_file (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
oop_io_t io;
moo_oop_t tmp;
int fd, n;
moo_ooi_t uid, gid;
io = (oop_io_t)MOO_STACK_GETRCV(moo, nargs);
MOO_PF_CHECK_RCV (moo,
MOO_OOP_IS_POINTER(io) &&
MOO_OBJ_BYTESOF(io) >= (MOO_SIZEOF(*io) - MOO_SIZEOF(moo_obj_t)) &&
MOO_OOP_IS_SMOOI(io->handle)
);
fd = MOO_OOP_TO_SMOOI(io->handle);
if (fd <= -1)
{
moo_seterrbfmt (moo, MOO_EINVAL, "bad IO handle - %d", fd);
return MOO_PF_FAILURE;
}
RCV_TO_FD (moo, nargs, fd);
MOO_STATIC_ASSERT (MOO_TYPE_IS_UNSIGNED(uid_t));
MOO_STATIC_ASSERT (MOO_TYPE_IS_UNSIGNED(gid_t));
tmp = MOO_STACK_GETARG(moo, nargs, 0);
if (moo_inttoooi(moo, tmp, &uid) == 0 || uid > MOO_TYPE_MAX(uid_t))
if (moo_inttoooi_noseterr(moo, tmp, &uid) == 0 || uid > MOO_TYPE_MAX(uid_t))
{
moo_seterrbfmt (moo, MOO_EINVAL, "invalid uid - %O", tmp);
return MOO_PF_FAILURE;
}
tmp = MOO_STACK_GETARG(moo, nargs, 1);
if (moo_inttoooi(moo, tmp, &gid) == 0 || gid > MOO_TYPE_MAX(gid_t))
if (moo_inttoooi_noseterr(moo, tmp, &gid) == 0 || gid > MOO_TYPE_MAX(gid_t))
{
moo_seterrbfmt (moo, MOO_EINVAL, "invalid gid - %O", tmp);
return MOO_PF_FAILURE;
@ -208,23 +201,10 @@ static moo_pfrc_t pf_chown_file (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
static moo_pfrc_t pf_lock_file (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
oop_io_t io;
moo_oop_t tmp;
int fd, n;
io = (oop_io_t)MOO_STACK_GETRCV(moo, nargs);
MOO_PF_CHECK_RCV (moo,
MOO_OOP_IS_POINTER(io) &&
MOO_OBJ_BYTESOF(io) >= (MOO_SIZEOF(*io) - MOO_SIZEOF(moo_obj_t)) &&
MOO_OOP_IS_SMOOI(io->handle)
);
fd = MOO_OOP_TO_SMOOI(io->handle);
if (fd <= -1)
{
moo_seterrbfmt (moo, MOO_EINVAL, "bad IO handle - %d", fd);
return MOO_PF_FAILURE;
}
RCV_TO_FD (moo, nargs, fd);
tmp = MOO_STACK_GETARG(moo, nargs, 0);
if (!MOO_OOP_IS_SMOOI(tmp))
@ -247,36 +227,23 @@ static moo_pfrc_t pf_lock_file (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
static moo_pfrc_t pf_seek_file (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
oop_io_t io;
moo_oop_t tmp;
moo_intmax_t offset;
moo_ooi_t whence;
int fd;
off_t n;
io = (oop_io_t)MOO_STACK_GETRCV(moo, nargs);
MOO_PF_CHECK_RCV (moo,
MOO_OOP_IS_POINTER(io) &&
MOO_OBJ_BYTESOF(io) >= (MOO_SIZEOF(*io) - MOO_SIZEOF(moo_obj_t)) &&
MOO_OOP_IS_SMOOI(io->handle)
);
fd = MOO_OOP_TO_SMOOI(io->handle);
if (fd <= -1)
{
moo_seterrbfmt (moo, MOO_EINVAL, "bad IO handle - %d", fd);
return MOO_PF_FAILURE;
}
RCV_TO_FD (moo, nargs, fd);
tmp = MOO_STACK_GETARG(moo, nargs, 0);
if (moo_inttointmax(moo, tmp, &offset) == 0 || offset < MOO_TYPE_MIN(off_t) || offset > MOO_TYPE_MAX(off_t))
if (moo_inttointmax_noseterr(moo, tmp, &offset) == 0 || offset < MOO_TYPE_MIN(off_t) || offset > MOO_TYPE_MAX(off_t))
{
moo_seterrbfmt (moo, MOO_EINVAL, "invalid offset - %O", tmp);
return MOO_PF_FAILURE;
}
tmp = MOO_STACK_GETARG(moo, nargs, 1);
if (moo_inttoooi(moo, tmp, &whence) == 0)
if (moo_inttoooi_noseterr(moo, tmp, &whence) == 0)
{
moo_seterrbfmt (moo, MOO_EINVAL, "invalid whence - %O", tmp);
return MOO_PF_FAILURE;
@ -298,27 +265,14 @@ static moo_pfrc_t pf_seek_file (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
static moo_pfrc_t pf_truncate_file (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
oop_io_t io;
moo_oop_t tmp;
moo_intmax_t size;
int fd, n;
io = (oop_io_t)MOO_STACK_GETRCV(moo, nargs);
MOO_PF_CHECK_RCV (moo,
MOO_OOP_IS_POINTER(io) &&
MOO_OBJ_BYTESOF(io) >= (MOO_SIZEOF(*io) - MOO_SIZEOF(moo_obj_t)) &&
MOO_OOP_IS_SMOOI(io->handle)
);
fd = MOO_OOP_TO_SMOOI(io->handle);
if (fd <= -1)
{
moo_seterrbfmt (moo, MOO_EINVAL, "bad IO handle - %d", fd);
return MOO_PF_FAILURE;
}
RCV_TO_FD (moo, nargs, fd);
tmp = MOO_STACK_GETARG(moo, nargs, 0);
if (moo_inttointmax(moo, tmp, &size) == 0 || size < MOO_TYPE_MIN(off_t) || size > MOO_TYPE_MAX(off_t))
if (moo_inttointmax_noseterr(moo, tmp, &size) == 0 || size < MOO_TYPE_MIN(off_t) || size > MOO_TYPE_MAX(off_t))
{
moo_seterrbfmt (moo, MOO_EINVAL, "invalid size - %O", tmp);
return MOO_PF_FAILURE;

View File

@ -103,7 +103,7 @@ static moo_pfrc_t pf_read_bytes (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
moo_oop_t tmp;
tmp = MOO_STACK_GETARG(moo, nargs, 1);
if (moo_inttooow(moo, tmp, &offset) <= 0)
if (moo_inttooow_noseterr(moo, tmp, &offset) <= 0)
{
moo_seterrbfmt (moo, MOO_EINVAL, "invalid offset - %O", tmp);
return MOO_PF_FAILURE;
@ -112,7 +112,7 @@ static moo_pfrc_t pf_read_bytes (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
if (nargs >= 3)
{
tmp = MOO_STACK_GETARG(moo, nargs, 2);
if (moo_inttooow(moo, tmp, &length) <= 0)
if (moo_inttooow_noseterr(moo, tmp, &length) <= 0)
{
moo_seterrbfmt (moo, MOO_EINVAL, "invalid length - %O", tmp);
return MOO_PF_FAILURE;
@ -176,7 +176,7 @@ static moo_pfrc_t pf_write_bytes (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
moo_oop_t tmp;
tmp = MOO_STACK_GETARG(moo, nargs, 1);
if (moo_inttooow(moo, tmp, &offset) <= 0)
if (moo_inttooow_noseterr(moo, tmp, &offset) <= 0)
{
moo_seterrbfmt (moo, MOO_EINVAL, "invalid offset - %O", tmp);
return MOO_PF_FAILURE;
@ -185,7 +185,7 @@ static moo_pfrc_t pf_write_bytes (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
if (nargs >= 3)
{
tmp = MOO_STACK_GETARG(moo, nargs, 2);
if (moo_inttooow(moo, tmp, &length) <= 0)
if (moo_inttooow_noseterr(moo, tmp, &length) <= 0)
{
moo_seterrbfmt (moo, MOO_EINVAL, "invalid length - %O", tmp);
return MOO_PF_FAILURE;

View File

@ -460,7 +460,7 @@ static moo_pfrc_t pf_read_socket (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
moo_oop_t tmp;
tmp = MOO_STACK_GETARG(moo, nargs, 1);
if (moo_inttooow (moo, tmp, &offset) <= 0)
if (moo_inttooow_noseterr(moo, tmp, &offset) <= 0)
{
moo_seterrbfmt (moo, MOO_EINVAL, "invalid offset - %O", tmp);
return MOO_PF_FAILURE;
@ -469,7 +469,7 @@ static moo_pfrc_t pf_read_socket (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
if (nargs >= 3)
{
tmp = MOO_STACK_GETARG(moo, nargs, 2);
if (moo_inttooow(moo, tmp, &length) <= 0)
if (moo_inttooow_noseterr(moo, tmp, &length) <= 0)
{
moo_seterrbfmt (moo, MOO_EINVAL, "invalid length - %O", tmp);
return MOO_PF_FAILURE;
@ -533,7 +533,7 @@ static moo_pfrc_t pf_write_socket (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
moo_oop_t tmp;
tmp = MOO_STACK_GETARG(moo, nargs, 1);
if (moo_inttooow (moo, tmp, &offset) <= 0)
if (moo_inttooow_noseterr(moo, tmp, &offset) <= 0)
{
moo_seterrbfmt (moo, MOO_EINVAL, "invalid offset - %O", tmp);
return MOO_PF_FAILURE;
@ -542,7 +542,7 @@ static moo_pfrc_t pf_write_socket (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
if (nargs >= 3)
{
tmp = MOO_STACK_GETARG(moo, nargs, 2);
if (moo_inttooow(moo, tmp, &length) <= 0)
if (moo_inttooow_noseterr(moo, tmp, &length) <= 0)
{
moo_seterrbfmt (moo, MOO_EINVAL, "invalid length - %O", tmp);
return MOO_PF_FAILURE;