enhanced error handling in some object allocation functions
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
ba2e5d1ed6
commit
2bd510181c
@ -512,6 +512,8 @@ static int on_fed_cnode_in_interactive_mode (hcl_t* hcl, hcl_cnode_t* obj)
|
|||||||
|
|
||||||
if (!xtn->feed.ongoing)
|
if (!xtn->feed.ongoing)
|
||||||
{
|
{
|
||||||
|
/* the first expression in the current user input line.
|
||||||
|
* arrange to clear byte-codes before compiling the expression. */
|
||||||
flags = HCL_COMPILE_CLEAR_CODE | HCL_COMPILE_CLEAR_FNBLK;
|
flags = HCL_COMPILE_CLEAR_CODE | HCL_COMPILE_CLEAR_FNBLK;
|
||||||
xtn->feed.ongoing = 1;
|
xtn->feed.ongoing = 1;
|
||||||
}
|
}
|
||||||
@ -525,8 +527,13 @@ static int on_fed_cnode_in_interactive_mode (hcl_t* hcl, hcl_cnode_t* obj)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
hcl_oow_t i;
|
hcl_oow_t i;
|
||||||
|
|
||||||
for (i = xtn->feed.pos; i < xtn->feed.len; i++)
|
for (i = xtn->feed.pos; i < xtn->feed.len; i++)
|
||||||
{
|
{
|
||||||
|
/* this loop is kind of weird. it is to check the current feed buffer is left with
|
||||||
|
* spaces only and to execute the compiled bytecodes so far if the check is true.
|
||||||
|
* the check is performed because a single line of the user input can have multiple
|
||||||
|
* expressions joined with a semicolon or contains trailing spaces. */
|
||||||
if (!hcl_is_bch_space(xtn->feed.buf[i])) break;
|
if (!hcl_is_bch_space(xtn->feed.buf[i])) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2404,7 +2404,7 @@ HCL_EXPORT int hcl_addliteraltocode (
|
|||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The hcl_brewcode() initializes the structure pointed to by \a code.partially or entirely.
|
* The hcl_brewcode() initializes the structure pointed to by \a code partially or entirely.
|
||||||
* The part already initialized is not destroyed and/or reinitialized.
|
* The part already initialized is not destroyed and/or reinitialized.
|
||||||
*/
|
*/
|
||||||
HCL_EXPORT int hcl_brewcode (
|
HCL_EXPORT int hcl_brewcode (
|
||||||
@ -2413,7 +2413,7 @@ HCL_EXPORT int hcl_brewcode (
|
|||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The hcl_purgecode() function cleans up the data held in memory
|
* The hcl_purgecode() function cleans up the data held in code space memory
|
||||||
* pointed to by \a code.
|
* pointed to by \a code.
|
||||||
*/
|
*/
|
||||||
HCL_EXPORT void hcl_purgecode (
|
HCL_EXPORT void hcl_purgecode (
|
||||||
|
44
lib/obj.c
44
lib/obj.c
@ -24,7 +24,6 @@
|
|||||||
|
|
||||||
#include "hcl-prv.h"
|
#include "hcl-prv.h"
|
||||||
|
|
||||||
|
|
||||||
#if defined(HCL_PROFILE_VM)
|
#if defined(HCL_PROFILE_VM)
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/resource.h> /* getrusage */
|
#include <sys/resource.h> /* getrusage */
|
||||||
@ -339,13 +338,19 @@ hcl_oop_t hcl_makebytestring (hcl_t* hcl, const hcl_ooch_t* ptr, hcl_oow_t len,
|
|||||||
hcl_oow_t i;
|
hcl_oow_t i;
|
||||||
hcl_oob_t v;
|
hcl_oob_t v;
|
||||||
|
|
||||||
b = alloc_numeric_array(hcl, HCL_BRAND_BYTE_ARRAY, HCL_NULL, len, HCL_OBJ_TYPE_BYTE, HCL_SIZEOF(hcl_oob_t), 1, ngc);
|
b = (hcl_oop_byte_t)alloc_numeric_array(hcl, HCL_BRAND_BYTE_ARRAY, HCL_NULL, len, HCL_OBJ_TYPE_BYTE, HCL_SIZEOF(hcl_oob_t), 1, ngc);
|
||||||
if (HCL_UNLIKELY(!b)) return HCL_NULL;
|
if (HCL_UNLIKELY(!b))
|
||||||
|
|
||||||
for (i = 0; i < len; i++)
|
|
||||||
{
|
{
|
||||||
v = ptr[i] & 0xFF;
|
const hcl_ooch_t* orgmsg = hcl_backuperrmsg(hcl);
|
||||||
HCL_OBJ_SET_BYTE_VAL(b, i, v);
|
hcl_seterrbfmt (hcl, HCL_ERRNUM(hcl), "unable to make bytestring - %js", orgmsg);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
v = ptr[i] & 0xFF;
|
||||||
|
HCL_OBJ_SET_BYTE_VAL(b, i, v);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (hcl_oop_t)b;
|
return (hcl_oop_t)b;
|
||||||
@ -353,8 +358,15 @@ hcl_oop_t hcl_makebytestring (hcl_t* hcl, const hcl_ooch_t* ptr, hcl_oow_t len,
|
|||||||
|
|
||||||
hcl_oop_t hcl_makestring (hcl_t* hcl, const hcl_ooch_t* ptr, hcl_oow_t len, int ngc)
|
hcl_oop_t hcl_makestring (hcl_t* hcl, const hcl_ooch_t* ptr, hcl_oow_t len, int ngc)
|
||||||
{
|
{
|
||||||
/*return hcl_alloccharobj(hcl, HCL_BRAND_STRING, ptr, len);*/
|
hcl_oop_char_t c;
|
||||||
return alloc_numeric_array(hcl, HCL_BRAND_STRING, ptr, len, HCL_OBJ_TYPE_CHAR, HCL_SIZEOF(hcl_ooch_t), 1, ngc);
|
/*c = hcl_alloccharobj(hcl, HCL_BRAND_STRING, ptr, len);*/
|
||||||
|
c = (hcl_oop_char_t)alloc_numeric_array(hcl, HCL_BRAND_STRING, ptr, len, HCL_OBJ_TYPE_CHAR, HCL_SIZEOF(hcl_ooch_t), 1, ngc);
|
||||||
|
if (HCL_UNLIKELY(!c))
|
||||||
|
{
|
||||||
|
const hcl_ooch_t* orgmsg = hcl_backuperrmsg(hcl);
|
||||||
|
hcl_seterrbfmt (hcl, HCL_ERRNUM(hcl), "unable to make string - %js", orgmsg);
|
||||||
|
}
|
||||||
|
return (hcl_oop_t)c;
|
||||||
}
|
}
|
||||||
|
|
||||||
hcl_oop_t hcl_makefpdec (hcl_t* hcl, hcl_oop_t value, hcl_ooi_t scale)
|
hcl_oop_t hcl_makefpdec (hcl_t* hcl, hcl_oop_t value, hcl_ooi_t scale)
|
||||||
@ -375,7 +387,12 @@ hcl_oop_t hcl_makefpdec (hcl_t* hcl, hcl_oop_t value, hcl_ooi_t scale)
|
|||||||
f = (hcl_oop_fpdec_t)hcl_allocoopobj(hcl, HCL_BRAND_FPDEC, HCL_FPDEC_NAMED_INSTVARS);
|
f = (hcl_oop_fpdec_t)hcl_allocoopobj(hcl, HCL_BRAND_FPDEC, HCL_FPDEC_NAMED_INSTVARS);
|
||||||
hcl_popvolat (hcl);
|
hcl_popvolat (hcl);
|
||||||
|
|
||||||
if (HCL_UNLIKELY(!f)) return HCL_NULL;
|
if (HCL_UNLIKELY(!f))
|
||||||
|
{
|
||||||
|
const hcl_ooch_t* orgmsg = hcl_backuperrmsg(hcl);
|
||||||
|
hcl_seterrbfmt (hcl, HCL_ERRNUM(hcl), "unable to make fpdec - %js", orgmsg);
|
||||||
|
return HCL_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
f->value = value;
|
f->value = value;
|
||||||
f->scale = HCL_SMOOI_TO_OOP(scale);
|
f->scale = HCL_SMOOI_TO_OOP(scale);
|
||||||
@ -392,7 +409,12 @@ hcl_oop_t hcl_makeclass (hcl_t* hcl, hcl_oop_t superclass, hcl_ooi_t nivars, hcl
|
|||||||
hcl_pushvolat (hcl, &cvars_str);
|
hcl_pushvolat (hcl, &cvars_str);
|
||||||
c = (hcl_oop_class_t)hcl_allocoopobj(hcl, HCL_BRAND_CLASS, HCL_CLASS_NAMED_INSTVARS + ncvars);
|
c = (hcl_oop_class_t)hcl_allocoopobj(hcl, HCL_BRAND_CLASS, HCL_CLASS_NAMED_INSTVARS + ncvars);
|
||||||
hcl_popvolats (hcl, 3);
|
hcl_popvolats (hcl, 3);
|
||||||
if (HCL_UNLIKELY(!c)) return HCL_NULL;
|
if (HCL_UNLIKELY(!c))
|
||||||
|
{
|
||||||
|
const hcl_ooch_t* orgmsg = hcl_backuperrmsg(hcl);
|
||||||
|
hcl_seterrbfmt (hcl, HCL_ERRNUM(hcl), "unable to make class - %js", orgmsg);
|
||||||
|
return HCL_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
c->superclass = superclass;
|
c->superclass = superclass;
|
||||||
c->nivars = HCL_SMOOI_TO_OOP(nivars);
|
c->nivars = HCL_SMOOI_TO_OOP(nivars);
|
||||||
|
@ -604,6 +604,8 @@ int hcl_unmarshalcodefrommem (hcl_t* hcl, hcl_code_t* code, const hcl_ptl_t* src
|
|||||||
|
|
||||||
int hcl_brewcode (hcl_t* hcl, hcl_code_t* code)
|
int hcl_brewcode (hcl_t* hcl, hcl_code_t* code)
|
||||||
{
|
{
|
||||||
|
/* create space to hold byte code and debug information */
|
||||||
|
|
||||||
if (!code->bc.ptr)
|
if (!code->bc.ptr)
|
||||||
{
|
{
|
||||||
code->bc.ptr = (hcl_oob_t*)hcl_allocmem(hcl, HCL_SIZEOF(*code->bc.ptr) * HCL_BC_BUFFER_INIT); /* TODO: set a proper intial size */
|
code->bc.ptr = (hcl_oob_t*)hcl_allocmem(hcl, HCL_SIZEOF(*code->bc.ptr) * HCL_BC_BUFFER_INIT); /* TODO: set a proper intial size */
|
||||||
|
Loading…
Reference in New Issue
Block a user