changed code to get rid of some type conversion warnings

This commit is contained in:
hyunghwan.chung 2018-02-26 15:30:38 +00:00
parent f9372e9d61
commit 18ca2b30a0
9 changed files with 138 additions and 106 deletions

View File

@ -70,7 +70,7 @@
#define IS_SIGN_DIFF(x,y) (((x) ^ (y)) < 0) #define IS_SIGN_DIFF(x,y) (((x) ^ (y)) < 0)
/* digit character array */ /* digit character array */
static char* _digitc = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; static char _digitc[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
/* exponent table */ /* exponent table */
static moo_uint8_t _exp_tab[] = static moo_uint8_t _exp_tab[] =
@ -1166,12 +1166,12 @@ static MOO_INLINE moo_oow_t multiply_unsigned_array_karatsuba (moo_t* moo, const
tmplen[0] = ndigits_xh + ndigits_yh; tmplen[0] = ndigits_xh + ndigits_yh;
tmplen[1] = ndigits_yl + ndigits_yh + 1; tmplen[1] = ndigits_yl + ndigits_yh + 1;
if (tmplen[1] < tmplen[0]) tmplen[1] = tmplen[0]; if (tmplen[1] < tmplen[0]) tmplen[1] = tmplen[0];
tmp[1] = moo_callocmem (moo, MOO_SIZEOF(moo_liw_t) * tmplen[1]); /* TODO: should i use the object memory? */ tmp[1] = (moo_liw_t*)moo_callocmem(moo, MOO_SIZEOF(moo_liw_t) * tmplen[1]); /* TODO: should i use the object memory? */
if (!tmp[1]) goto oops; if (!tmp[1]) goto oops;
/* make a temporary for (a0 + a1) and (a0 * b0) */ /* make a temporary for (a0 + a1) and (a0 * b0) */
tmplen[0] = ndigits_xl + ndigits_yl + 1; tmplen[0] = ndigits_xl + ndigits_yl + 1;
tmp[0] = moo_callocmem (moo, MOO_SIZEOF(moo_liw_t) * tmplen[0]); tmp[0] = (moo_liw_t*)moo_callocmem(moo, MOO_SIZEOF(moo_liw_t) * tmplen[0]);
if (!tmp[0]) goto oops; if (!tmp[0]) goto oops;
/* tmp[0] = a0 + a1 */ /* tmp[0] = a0 + a1 */
@ -1286,12 +1286,12 @@ oops:
tmplen[0] = ndigits_yl + ndigits_yh + 1; tmplen[0] = ndigits_yl + ndigits_yh + 1;
tmplen[1] = ndigits_xh + ndigits_yh; tmplen[1] = ndigits_xh + ndigits_yh;
if (tmplen[1] < tmplen[0]) tmplen[1] = tmplen[0]; if (tmplen[1] < tmplen[0]) tmplen[1] = tmplen[0];
tmp[1] = moo_callocmem (moo, MOO_SIZEOF(moo_liw_t) * tmplen[1]); tmp[1] = (hcl_liw_t*)moo_callocmem(moo, MOO_SIZEOF(moo_liw_t) * tmplen[1]);
if (!tmp[1]) goto oops; if (!tmp[1]) goto oops;
/* make a temporary for (a0 + a1) and (a0 * b0) */ /* make a temporary for (a0 + a1) and (a0 * b0) */
tmplen[0] = ndigits_xl + ndigits_yl; tmplen[0] = ndigits_xl + ndigits_yl;
tmp[0] = moo_callocmem (moo, MOO_SIZEOF(moo_liw_t) * tmplen[0]); tmp[0] = (hcl_liw_t*)moo_callocmem(moo, MOO_SIZEOF(moo_liw_t) * tmplen[0]);
if (!tmp[0]) goto oops; if (!tmp[0]) goto oops;
/* tmp[0] = a0 + a1 */ /* tmp[0] = a0 + a1 */

View File

@ -1036,7 +1036,7 @@ moo_oop_t moo_shallowcopy (moo_t* moo, moo_oop_t oop)
total_bytes = MOO_SIZEOF(moo_obj_t) + get_payload_bytes(moo, oop); total_bytes = MOO_SIZEOF(moo_obj_t) + get_payload_bytes(moo, oop);
moo_pushtmp (moo, &oop); moo_pushtmp (moo, &oop);
z = moo_allocbytes (moo, total_bytes); z = (moo_oop_t)moo_allocbytes (moo, total_bytes);
moo_poptmp(moo); moo_poptmp(moo);
MOO_MEMCPY (z, oop, total_bytes); MOO_MEMCPY (z, oop, total_bytes);
@ -1059,7 +1059,7 @@ int moo_regfinalizable (moo_t* moo, moo_oop_t oop)
return -1; return -1;
} }
x = moo_allocmem (moo, MOO_SIZEOF(*x)); x = (moo_finalizable_t*)moo_allocmem(moo, MOO_SIZEOF(*x));
if (!x) return -1; if (!x) return -1;
MOO_OBJ_SET_FLAGS_GCFIN (oop, MOO_GCFIN_FINALIZABLE); MOO_OBJ_SET_FLAGS_GCFIN (oop, MOO_GCFIN_FINALIZABLE);

View File

@ -92,14 +92,15 @@
static int logfmtv (moo_t* moo, const fmtchar_t* fmt, moo_fmtout_t* data, va_list ap, outbfmt_t outbfmt) static int logfmtv (moo_t* moo, const fmtchar_t* fmt, moo_fmtout_t* data, va_list ap, outbfmt_t outbfmt)
{ {
const fmtchar_t* percent; const fmtchar_t* percent;
#if defined(FMTCHAR_IS_OOCH)
const fmtchar_t* checkpoint; const fmtchar_t* checkpoint;
#endif
moo_bch_t nbuf[MAXNBUF], bch; moo_bch_t nbuf[MAXNBUF], bch;
const moo_bch_t* nbufp; const moo_bch_t* nbufp;
int n, base, neg, sign; int n, base, neg, sign;
moo_ooi_t tmp, width, precision; moo_ooi_t tmp, width, precision;
moo_ooch_t ch, padc; moo_ooch_t ch, padc;
#if !defined(FMTCHAR_IS_OOCH)
fmtchar_t fch;
#endif
int lm_flag, lm_dflag, flagc, numlen; int lm_flag, lm_dflag, flagc, numlen;
moo_uintmax_t num = 0; moo_uintmax_t num = 0;
int stop = 0; int stop = 0;
@ -137,11 +138,38 @@ static int logfmtv (moo_t* moo, const fmtchar_t* fmt, moo_fmtout_t* data, va_lis
} }
PUT_OOCS (checkpoint, fmt - checkpoint - 1); PUT_OOCS (checkpoint, fmt - checkpoint - 1);
#else #else
while ((ch = *fmt++) != '%' || stop) #if defined(MOO_OOCH_IS_UCH)
/* fmtchar is bch. ooch is uch. convert bch to uch */
checkpoint = fmt;
while ((fch = *fmt++) != '%' || stop)
{ {
if (ch == '\0') goto done; if (fch == '\0') break;
}
while (checkpoint < fmt - 1)
{
moo_oow_t cvlen, bclen;
bclen = fmt - checkpoint - 1;
cvlen = moo->cmgr->bctouc(checkpoint, bclen, &ch);
if (cvlen == 0 || cvlen > bclen) goto oops;
checkpoint += cvlen;
PUT_OOCH (ch, 1); PUT_OOCH (ch, 1);
} }
if (fch == '\0') goto done;
#else
while ((fch = *fmt++) != '%' || stop)
{
moo_bch_t bcsbuf[MOO_MBLEN_MAX + 1];
moo_oow_t ucslen, bcslen;
if (fch == '\0') goto done;
/* fmtchar is uch. ooch is bch. convert uch to bch */
ucslen = 1;
bcslen = MOO_COUNTOF(bcsbuf);
if (moo_convutooochars(moo, &fch, &ucslen, bcsbuf, &bcslen) <= -1) goto oops;
PUT_OOCS (bcsbuf, bcslen);
}
#endif
#endif #endif
percent = fmt - 1; percent = fmt - 1;

View File

@ -322,9 +322,7 @@ struct moo_ioarg_t
/*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/
}; };
struct moo_iotok_t enum moo_iotok_type_t
{
enum
{ {
MOO_IOTOK_EOF, MOO_IOTOK_EOF,
@ -377,11 +375,14 @@ struct moo_iotok_t
MOO_IOTOK_PERIOD, MOO_IOTOK_PERIOD,
MOO_IOTOK_COMMA, MOO_IOTOK_COMMA,
MOO_IOTOK_SEMICOLON MOO_IOTOK_SEMICOLON
} type; };
typedef enum moo_iotok_type_t moo_iotok_type_t;
struct moo_iotok_t
{
moo_iotok_type_t type;
moo_oocs_t name; moo_oocs_t name;
moo_oow_t name_capa; moo_oow_t name_capa;
moo_ioloc_t loc; moo_ioloc_t loc;
}; };
typedef struct moo_iotok_t moo_iotok_t; typedef struct moo_iotok_t moo_iotok_t;

View File

@ -167,6 +167,13 @@ typedef moo_rbt_pair_t* (*moo_rbt_cbserter_t) (
void* ctx /**< callback context */ void* ctx /**< callback context */
); );
enum moo_rbt_pair_color_t
{
MOO_RBT_RED,
MOO_RBT_BLACK
};
typedef enum moo_rbt_pair_color_t moo_rbt_pair_color_t;
/** /**
* The moo_rbt_pair_t type defines red-black tree pair. A pair is composed * The moo_rbt_pair_t type defines red-black tree pair. A pair is composed
* of a key and a value. It maintains pointers to the beginning of a key and * of a key and a value. It maintains pointers to the beginning of a key and
@ -188,11 +195,7 @@ struct moo_rbt_pair_t
} val; } val;
/* management information below */ /* management information below */
enum moo_rbt_pair_color_t color;
{
MOO_RBT_RED,
MOO_RBT_BLACK
} color;
moo_rbt_pair_t* parent; moo_rbt_pair_t* parent;
moo_rbt_pair_t* child[2]; /* left and right */ moo_rbt_pair_t* child[2]; /* left and right */
}; };

View File

@ -33,7 +33,7 @@ moo_t* moo_open (moo_mmgr_t* mmgr, moo_oow_t xtnsize, moo_oow_t heapsize, const
/* if this assertion fails, correct the type definition in moo.h */ /* if this assertion fails, correct the type definition in moo.h */
MOO_ASSERT (moo, MOO_SIZEOF(moo_oow_t) == MOO_SIZEOF(moo_oop_t)); MOO_ASSERT (moo, MOO_SIZEOF(moo_oow_t) == MOO_SIZEOF(moo_oop_t));
moo = MOO_MMGR_ALLOC (mmgr, MOO_SIZEOF(*moo) + xtnsize); moo = (moo_t*)MOO_MMGR_ALLOC(mmgr, MOO_SIZEOF(*moo) + xtnsize);
if (moo) if (moo)
{ {
if (moo_init(moo, mmgr, heapsize, vmprim) <= -1) if (moo_init(moo, mmgr, heapsize, vmprim) <= -1)
@ -369,7 +369,7 @@ moo_cb_t* moo_regcb (moo_t* moo, moo_cb_t* tmpl)
{ {
moo_cb_t* actual; moo_cb_t* actual;
actual = moo_allocmem (moo, MOO_SIZEOF(*actual)); actual = (moo_cb_t*)moo_allocmem(moo, MOO_SIZEOF(*actual));
if (!actual) return MOO_NULL; if (!actual) return MOO_NULL;
*actual = *tmpl; *actual = *tmpl;

View File

@ -1103,7 +1103,7 @@ typedef void (*moo_mod_gc_t) (
struct moo_mod_t struct moo_mod_t
{ {
/* input */ /* input */
const moo_ooch_t name[MOO_MOD_NAME_LEN_MAX + 1]; /*const*/ moo_ooch_t name[MOO_MOD_NAME_LEN_MAX + 1];
/*const*/ int hints; /* bitwised-ORed of moo_mod_hint_t enumerators */ /*const*/ int hints; /* bitwised-ORed of moo_mod_hint_t enumerators */
/* user-defined data */ /* user-defined data */
@ -1342,7 +1342,7 @@ struct moo_t
{ {
struct struct
{ {
moo_uch_t* ptr; moo_ooch_t* ptr;
moo_oow_t capa; moo_oow_t capa;
moo_oow_t len; moo_oow_t len;
} xbuf; } xbuf;

View File

@ -34,7 +34,7 @@ void* moo_allocbytes (moo_t* moo, moo_oow_t size)
if ((moo->option.trait & MOO_DEBUG_GC) && !(moo->option.trait & MOO_NOGC)) moo_gc (moo); if ((moo->option.trait & MOO_DEBUG_GC) && !(moo->option.trait & MOO_NOGC)) moo_gc (moo);
#endif #endif
ptr = moo_allocheapmem (moo, moo->curheap, size); ptr = (moo_uint8_t*)moo_allocheapmem(moo, moo->curheap, size);
if (!ptr && moo->errnum == MOO_EOOMEM && !(moo->option.trait & MOO_NOGC)) if (!ptr && moo->errnum == MOO_EOOMEM && !(moo->option.trait & MOO_NOGC))
{ {
moo_gc (moo); moo_gc (moo);
@ -44,7 +44,7 @@ void* moo_allocbytes (moo_t* moo, moo_oow_t size)
(moo_oow_t)(moo->curheap->limit - moo->curheap->base), (moo_oow_t)(moo->curheap->limit - moo->curheap->base),
(moo_oow_t)(moo->curheap->limit - moo->curheap->ptr) (moo_oow_t)(moo->curheap->limit - moo->curheap->ptr)
); );
ptr = moo_allocheapmem (moo, moo->curheap, size); ptr = (moo_uint8_t*)moo_allocheapmem(moo, moo->curheap, size);
/* TODO: grow heap if ptr is still null. */ /* TODO: grow heap if ptr is still null. */
} }
@ -66,7 +66,7 @@ moo_oop_t moo_allocoopobj (moo_t* moo, moo_oow_t size)
* MOO_SIZEOF(moo_oop_t) will guarantee the starting address * MOO_SIZEOF(moo_oop_t) will guarantee the starting address
* of the allocated space to be an even number. * of the allocated space to be an even number.
* see MOO_OOP_IS_NUMERIC() and MOO_OOP_IS_POINTER() */ * see MOO_OOP_IS_NUMERIC() and MOO_OOP_IS_POINTER() */
hdr = moo_allocbytes (moo, MOO_SIZEOF(moo_obj_t) + nbytes_aligned); hdr = (moo_oop_oop_t)moo_allocbytes(moo, MOO_SIZEOF(moo_obj_t) + nbytes_aligned);
if (!hdr) return MOO_NULL; if (!hdr) return MOO_NULL;
hdr->_flags = MOO_OBJ_MAKE_FLAGS(MOO_OBJ_TYPE_OOP, MOO_SIZEOF(moo_oop_t), 0, 0, 0, 0, 0); hdr->_flags = MOO_OBJ_MAKE_FLAGS(MOO_OBJ_TYPE_OOP, MOO_SIZEOF(moo_oop_t), 0, 0, 0, 0, 0);
@ -88,7 +88,7 @@ moo_oop_t moo_allocoopobjwithtrailer (moo_t* moo, moo_oow_t size, const moo_oob_
nbytes = (size + 1) * MOO_SIZEOF(moo_oop_t) + blen; nbytes = (size + 1) * MOO_SIZEOF(moo_oop_t) + blen;
nbytes_aligned = MOO_ALIGN(nbytes, MOO_SIZEOF(moo_oop_t)); nbytes_aligned = MOO_ALIGN(nbytes, MOO_SIZEOF(moo_oop_t));
hdr = moo_allocbytes (moo, MOO_SIZEOF(moo_obj_t) + nbytes_aligned); hdr = (moo_oop_oop_t)moo_allocbytes(moo, MOO_SIZEOF(moo_obj_t) + nbytes_aligned);
if (!hdr) return MOO_NULL; if (!hdr) return MOO_NULL;
hdr->_flags = MOO_OBJ_MAKE_FLAGS(MOO_OBJ_TYPE_OOP, MOO_SIZEOF(moo_oop_t), 0, 0, 0, 0, 1); hdr->_flags = MOO_OBJ_MAKE_FLAGS(MOO_OBJ_TYPE_OOP, MOO_SIZEOF(moo_oop_t), 0, 0, 0, 0, 1);
@ -128,7 +128,7 @@ static MOO_INLINE moo_oop_t alloc_numeric_array (moo_t* moo, const void* ptr, mo
if (MOO_UNLIKELY(ngc)) if (MOO_UNLIKELY(ngc))
{ {
hdr = moo_callocmem (moo, MOO_SIZEOF(moo_obj_t) + nbytes_aligned); hdr = (moo_oop_t)moo_callocmem(moo, MOO_SIZEOF(moo_obj_t) + nbytes_aligned);
if (!hdr) return MOO_NULL; if (!hdr) return MOO_NULL;
} }
else else
@ -137,7 +137,7 @@ static MOO_INLINE moo_oop_t alloc_numeric_array (moo_t* moo, const void* ptr, mo
* MOO_SIZEOF(moo_oop_t) will guarantee the starting address * MOO_SIZEOF(moo_oop_t) will guarantee the starting address
* of the allocated space to be an even number. * of the allocated space to be an even number.
* see MOO_OOP_IS_NUMERIC() and MOO_OOP_IS_POINTER() */ * see MOO_OOP_IS_NUMERIC() and MOO_OOP_IS_POINTER() */
hdr = moo_allocbytes (moo, MOO_SIZEOF(moo_obj_t) + nbytes_aligned); hdr = (moo_oop_t)moo_allocbytes(moo, MOO_SIZEOF(moo_obj_t) + nbytes_aligned);
if (!hdr) return MOO_NULL; if (!hdr) return MOO_NULL;
} }

View File

@ -369,7 +369,7 @@ int moo_concatoocstrtosbuf (moo_t* moo, const moo_ooch_t* str, int id)
newcapa = MOO_ALIGN(p->len + len, 512); /* TODO: adjust this capacity */ newcapa = MOO_ALIGN(p->len + len, 512); /* TODO: adjust this capacity */
/* +1 to handle line ending injection more easily */ /* +1 to handle line ending injection more easily */
tmp = moo_reallocmem (moo, p->ptr, (newcapa + 1) * MOO_SIZEOF(*tmp)); tmp = (moo_ooch_t*)moo_reallocmem(moo, p->ptr, (newcapa + 1) * MOO_SIZEOF(*tmp));
if (!tmp) return -1; if (!tmp) return -1;
p->ptr = tmp; p->ptr = tmp;
@ -801,7 +801,7 @@ MOO_INLINE moo_uch_t* moo_dupbtoucharswithheadroom (moo_t* moo, moo_oow_t headro
return MOO_NULL; return MOO_NULL;
} }
ptr = moo_allocmem (moo, headroom_bytes + ((outlen + 1) * MOO_SIZEOF(moo_uch_t))); ptr = (moo_uch_t*)moo_allocmem(moo, headroom_bytes + ((outlen + 1) * MOO_SIZEOF(moo_uch_t)));
if (!ptr) return MOO_NULL; if (!ptr) return MOO_NULL;
inlen = bcslen; inlen = bcslen;
@ -834,7 +834,7 @@ MOO_INLINE moo_bch_t* moo_duputobcharswithheadroom (moo_t* moo, moo_oow_t headro
return MOO_NULL; return MOO_NULL;
} }
ptr = moo_allocmem (moo, headroom_bytes + ((outlen + 1) * MOO_SIZEOF(moo_bch_t))); ptr = (moo_bch_t*)moo_allocmem(moo, headroom_bytes + ((outlen + 1) * MOO_SIZEOF(moo_bch_t)));
if (!ptr) return MOO_NULL; if (!ptr) return MOO_NULL;
inlen = ucslen; inlen = ucslen;
@ -866,7 +866,7 @@ MOO_INLINE moo_uch_t* moo_dupbtoucstrwithheadroom (moo_t* moo, moo_oow_t headroo
} }
outlen++; outlen++;
ptr = moo_allocmem (moo, headroom_bytes + (outlen * MOO_SIZEOF(moo_uch_t))); ptr = (moo_uch_t*)moo_allocmem(moo, headroom_bytes + (outlen * MOO_SIZEOF(moo_uch_t)));
if (!ptr) return MOO_NULL; if (!ptr) return MOO_NULL;
moo_convbtoucstr (moo, bcs, &inlen, ptr, &outlen); moo_convbtoucstr (moo, bcs, &inlen, ptr, &outlen);
@ -891,7 +891,7 @@ MOO_INLINE moo_bch_t* moo_duputobcstrwithheadroom (moo_t* moo, moo_oow_t headroo
} }
outlen++; outlen++;
ptr = moo_allocmem (moo, headroom_bytes + (outlen * MOO_SIZEOF(moo_bch_t))); ptr = (moo_bch_t*)moo_allocmem(moo, headroom_bytes + (outlen * MOO_SIZEOF(moo_bch_t)));
if (!ptr) return MOO_NULL; if (!ptr) return MOO_NULL;
ptr = (moo_bch_t*)((moo_oob_t*)ptr + headroom_bytes); ptr = (moo_bch_t*)((moo_oob_t*)ptr + headroom_bytes);
@ -911,7 +911,7 @@ moo_uch_t* moo_dupuchars (moo_t* moo, const moo_uch_t* ucs, moo_oow_t ucslen)
{ {
moo_uch_t* ptr; moo_uch_t* ptr;
ptr = moo_allocmem (moo, (ucslen + 1) * MOO_SIZEOF(moo_uch_t)); ptr = (moo_uch_t*)moo_allocmem(moo, (ucslen + 1) * MOO_SIZEOF(moo_uch_t));
if (!ptr) return MOO_NULL; if (!ptr) return MOO_NULL;
moo_copyuchars (ptr, ucs, ucslen); moo_copyuchars (ptr, ucs, ucslen);
@ -923,7 +923,7 @@ moo_bch_t* moo_dupbchars (moo_t* moo, const moo_bch_t* bcs, moo_oow_t bcslen)
{ {
moo_bch_t* ptr; moo_bch_t* ptr;
ptr = moo_allocmem (moo, (bcslen + 1) * MOO_SIZEOF(moo_bch_t)); ptr = (moo_bch_t*)moo_allocmem(moo, (bcslen + 1) * MOO_SIZEOF(moo_bch_t));
if (!ptr) return MOO_NULL; if (!ptr) return MOO_NULL;
moo_copybchars (ptr, bcs, bcslen); moo_copybchars (ptr, bcs, bcslen);