added the _instsize field to hcl_t, hcl_server_t, hcl_client_t

This commit is contained in:
hyung-hwan 2019-06-21 12:36:25 +00:00
parent ff685bac79
commit e27058d771
9 changed files with 81 additions and 75 deletions

View File

@ -201,7 +201,7 @@ static int err_bcs (hcl_fmtout_t* fmtout, const hcl_bch_t* ptr, hcl_oow_t len)
#if defined(HCL_OOCH_IS_UCH) #if defined(HCL_OOCH_IS_UCH)
if (max <= 0) return 1; if (max <= 0) return 1;
hcl_conv_bchars_to_uchars_with_cmgr (ptr, &len, &hcl->errmsg.buf[hcl->errmsg.len], &max, hcl->cmgr, 1); hcl_conv_bchars_to_uchars_with_cmgr (ptr, &len, &hcl->errmsg.buf[hcl->errmsg.len], &max, hcl_getcmgr(hcl), 1);
hcl->errmsg.len += max; hcl->errmsg.len += max;
#else #else
if (len > max) len = max; if (len > max) len = max;
@ -229,7 +229,7 @@ static int err_ucs (hcl_fmtout_t* fmtout, const hcl_uch_t* ptr, hcl_oow_t len)
hcl->errmsg.len += len; hcl->errmsg.len += len;
#else #else
if (max <= 0) return 1; if (max <= 0) return 1;
hcl_conv_uchars_to_bchars_with_cmgr (ptr, &len, &hcl->errmsg.buf[hcl->errmsg.len], &max, hcl->cmgr); hcl_conv_uchars_to_bchars_with_cmgr (ptr, &len, &hcl->errmsg.buf[hcl->errmsg.len], &max, hcl_getcmgr(hcl));
hcl->errmsg.len += max; hcl->errmsg.len += max;
#endif #endif
hcl->errmsg.buf[hcl->errmsg.len] = '\0'; hcl->errmsg.buf[hcl->errmsg.len] = '\0';

View File

@ -1485,7 +1485,7 @@ static int log_ucs (hcl_fmtout_t* fmtout, const hcl_uch_t* ptr, hcl_oow_t len)
{ {
len = rem; len = rem;
bcslen = HCL_COUNTOF(bcs); bcslen = HCL_COUNTOF(bcs);
hcl_conv_uchars_to_bchars_with_cmgr(ptr, &len, bcs, &bcslen, hcl->cmgr); hcl_conv_uchars_to_bchars_with_cmgr(ptr, &len, bcs, &bcslen, hcl_getcmgr(hcl));
log_bcs(fmtout, bcs, bcslen); log_bcs(fmtout, bcs, bcslen);
rem -= len; rem -= len;
ptr += len; ptr += len;
@ -1509,7 +1509,7 @@ static int log_bcs (hcl_fmtout_t* fmtout, const hcl_bch_t* ptr, hcl_oow_t len)
{ {
len = rem; len = rem;
ucslen = HCL_COUNTOF(ucs); ucslen = HCL_COUNTOF(ucs);
hcl_conv_bchars_to_uchars_with_cmgr(ptr, &len, ucs, &ucslen, hcl->cmgr, 1); hcl_conv_bchars_to_uchars_with_cmgr(ptr, &len, ucs, &ucslen, hcl_getcmgr(hcl), 1);
log_ucs(fmtout, ucs, ucslen); log_ucs(fmtout, ucs, ucslen);
rem -= len; rem -= len;
ptr += len; ptr += len;
@ -1643,7 +1643,7 @@ static int print_bcs (hcl_fmtout_t* fmtout, const hcl_bch_t* ptr, hcl_oow_t len)
{ {
bcslen = len; bcslen = len;
ucslen = HCL_COUNTOF(ucsbuf); ucslen = HCL_COUNTOF(ucsbuf);
hcl_conv_bchars_to_uchars_with_cmgr(ptr, &bcslen, ucsbuf, &ucslen, hcl->cmgr, 1); hcl_conv_bchars_to_uchars_with_cmgr(ptr, &bcslen, ucsbuf, &ucslen, hcl_getcmgr(hcl), 1);
ucsptr = ucsbuf; ucsptr = ucsbuf;
while (ucslen > 0) while (ucslen > 0)
@ -1711,7 +1711,7 @@ static int print_ucs (hcl_fmtout_t* fmtout, const hcl_uch_t* ptr, hcl_oow_t len)
{ {
ucslen = len; ucslen = len;
bcslen = HCL_COUNTOF(bcsbuf); bcslen = HCL_COUNTOF(bcsbuf);
hcl_conv_uchars_to_bchars_with_cmgr(ptr, &ucslen, bcsbuf, &bcslen, hcl->cmgr); hcl_conv_uchars_to_bchars_with_cmgr(ptr, &ucslen, bcsbuf, &bcslen, hcl_getcmgr(hcl));
bcsptr = bcsbuf; bcsptr = bcsbuf;
while (bcslen > 0) while (bcslen > 0)
@ -1812,7 +1812,7 @@ static int sprint_bcs (hcl_fmtout_t* fmtout, const hcl_bch_t* ptr, hcl_oow_t len
#if defined(HCL_OOCH_IS_UCH) #if defined(HCL_OOCH_IS_UCH)
blen = len; blen = len;
hcl_conv_bchars_to_uchars_with_cmgr (ptr, &blen, HCL_NULL, &oolen, hcl->cmgr, 1); hcl_conv_bchars_to_uchars_with_cmgr (ptr, &blen, HCL_NULL, &oolen, hcl_getcmgr(hcl), 1);
#else #else
oolen = len; oolen = len;
#endif #endif
@ -1833,7 +1833,7 @@ static int sprint_bcs (hcl_fmtout_t* fmtout, const hcl_bch_t* ptr, hcl_oow_t len
} }
#if defined(HCL_OOCH_IS_UCH) #if defined(HCL_OOCH_IS_UCH)
hcl_conv_bchars_to_uchars_with_cmgr (ptr, &len, &hcl->sprintf.xbuf.ptr[hcl->sprintf.xbuf.len], &oolen, hcl->cmgr, 1); hcl_conv_bchars_to_uchars_with_cmgr (ptr, &len, &hcl->sprintf.xbuf.ptr[hcl->sprintf.xbuf.len], &oolen, hcl_getcmgr(hcl), 1);
#else #else
HCL_MEMCPY (&hcl->sprintf.xbuf.ptr[hcl->sprintf.xbuf.len], ptr, len * HCL_SIZEOF(*ptr)); HCL_MEMCPY (&hcl->sprintf.xbuf.ptr[hcl->sprintf.xbuf.len], ptr, len * HCL_SIZEOF(*ptr));
#endif #endif
@ -1853,7 +1853,7 @@ static int sprint_ucs (hcl_fmtout_t* fmtout, const hcl_uch_t* ptr, hcl_oow_t len
oolen = len; oolen = len;
#else #else
ulen = len; ulen = len;
hcl_conv_uchars_to_bchars_with_cmgr (ptr, &ulen, HCL_NULL, &oolen, hcl->cmgr); hcl_conv_uchars_to_bchars_with_cmgr (ptr, &ulen, HCL_NULL, &oolen, hcl_getcmgr(hcl));
#endif #endif
if (oolen > unused) if (oolen > unused)
@ -1874,7 +1874,7 @@ static int sprint_ucs (hcl_fmtout_t* fmtout, const hcl_uch_t* ptr, hcl_oow_t len
#if defined(HCL_OOCH_IS_UCH) #if defined(HCL_OOCH_IS_UCH)
HCL_MEMCPY (&hcl->sprintf.xbuf.ptr[hcl->sprintf.xbuf.len], ptr, len * HCL_SIZEOF(*ptr)); HCL_MEMCPY (&hcl->sprintf.xbuf.ptr[hcl->sprintf.xbuf.len], ptr, len * HCL_SIZEOF(*ptr));
#else #else
hcl_conv_uchars_to_bchars_with_cmgr (ptr, &len, &hcl->sprintf.xbuf.ptr[hcl->sprintf.xbuf.len], &oolen, hcl->cmgr); hcl_conv_uchars_to_bchars_with_cmgr (ptr, &len, &hcl->sprintf.xbuf.ptr[hcl->sprintf.xbuf.len], &oolen, hcl_getcmgr(hcl));
#endif #endif
hcl->sprintf.xbuf.len += oolen; hcl->sprintf.xbuf.len += oolen;

View File

@ -48,8 +48,10 @@ typedef enum hcl_client_reply_attr_type_t hcl_client_reply_attr_type_t;
struct hcl_client_t struct hcl_client_t
{ {
hcl_mmgr_t* mmgr; hcl_oow_t _instsize;
hcl_cmgr_t* cmgr; hcl_mmgr_t* _mmgr;
hcl_cmgr_t* _cmgr;
hcl_client_prim_t prim; hcl_client_prim_t prim;
hcl_t* dummy_hcl; hcl_t* dummy_hcl;
@ -758,7 +760,7 @@ static int feed_reply_data (hcl_client_t* client, const hcl_bch_t* data, hcl_oow
bcslen = end - ptr; bcslen = end - ptr;
ucslen = 1; ucslen = 1;
n = hcl_conv_bchars_to_uchars_with_cmgr(ptr, &bcslen, &uc, &ucslen, client->cmgr, 0); n = hcl_conv_bchars_to_uchars_with_cmgr(ptr, &bcslen, &uc, &ucslen, hcl_client_getcmgr(client), 0);
if (n <= -1) if (n <= -1)
{ {
if (n == -3) if (n == -3)
@ -825,8 +827,9 @@ hcl_client_t* hcl_client_open (hcl_mmgr_t* mmgr, hcl_oow_t xtnsize, hcl_client_p
xtn->client = client; xtn->client = client;
HCL_MEMSET (client, 0, HCL_SIZEOF(*client) + xtnsize); HCL_MEMSET (client, 0, HCL_SIZEOF(*client) + xtnsize);
client->mmgr = mmgr; client->_instsize = HCL_SIZEOF(*client);
client->cmgr = hcl_get_utf8_cmgr(); client->_mmgr = mmgr;
client->_cmgr = hcl_get_utf8_cmgr();
client->prim = *prim; client->prim = *prim;
client->dummy_hcl = hcl; client->dummy_hcl = hcl;
@ -836,7 +839,7 @@ hcl_client_t* hcl_client_open (hcl_mmgr_t* mmgr, hcl_oow_t xtnsize, hcl_client_p
* such as getting system time or logging. so the heap size doesn't * such as getting system time or logging. so the heap size doesn't
* need to be changed from the tiny value set above. */ * need to be changed from the tiny value set above. */
hcl_setoption (client->dummy_hcl, HCL_LOG_MASK, &client->cfg.logmask); hcl_setoption (client->dummy_hcl, HCL_LOG_MASK, &client->cfg.logmask);
hcl_setcmgr (client->dummy_hcl, client->cmgr); hcl_setcmgr (client->dummy_hcl, client->_cmgr);
return client; return client;
} }
@ -846,7 +849,7 @@ void hcl_client_close (hcl_client_t* client)
if (client->rep.tok.ptr) hcl_client_freemem (client, client->rep.tok.ptr); if (client->rep.tok.ptr) hcl_client_freemem (client, client->rep.tok.ptr);
if (client->rep.last_attr_key.ptr) hcl_client_freemem (client, client->rep.last_attr_key.ptr); if (client->rep.last_attr_key.ptr) hcl_client_freemem (client, client->rep.last_attr_key.ptr);
hcl_close (client->dummy_hcl); hcl_close (client->dummy_hcl);
HCL_MMGR_FREE (client->mmgr, client); HCL_MMGR_FREE (client->_mmgr, client);
} }
int hcl_client_setoption (hcl_client_t* client, hcl_client_option_t id, const void* value) int hcl_client_setoption (hcl_client_t* client, hcl_client_option_t id, const void* value)
@ -894,22 +897,22 @@ int hcl_client_getoption (hcl_client_t* client, hcl_client_option_t id, void* va
void* hcl_client_getxtn (hcl_client_t* client) void* hcl_client_getxtn (hcl_client_t* client)
{ {
return (void*)(client + 1); return (void*)((hcl_uint8_t*)client + client->_instsize);
} }
hcl_mmgr_t* hcl_client_getmmgr (hcl_client_t* client) hcl_mmgr_t* hcl_client_getmmgr (hcl_client_t* client)
{ {
return client->mmgr; return client->_mmgr;
} }
hcl_cmgr_t* hcl_client_getcmgr (hcl_client_t* client) hcl_cmgr_t* hcl_client_getcmgr (hcl_client_t* client)
{ {
return client->cmgr; return client->_cmgr;
} }
void hcl_client_setcmgr (hcl_client_t* client, hcl_cmgr_t* cmgr) void hcl_client_setcmgr (hcl_client_t* client, hcl_cmgr_t* cmgr)
{ {
client->cmgr = cmgr; client->_cmgr = cmgr;
} }
hcl_errnum_t hcl_client_geterrnum (hcl_client_t* client) hcl_errnum_t hcl_client_geterrnum (hcl_client_t* client)
@ -987,7 +990,7 @@ void* hcl_client_allocmem (hcl_client_t* client, hcl_oow_t size)
{ {
void* ptr; void* ptr;
ptr = HCL_MMGR_ALLOC(client->mmgr, size); ptr = HCL_MMGR_ALLOC(client->_mmgr, size);
if (!ptr) hcl_client_seterrnum (client, HCL_ESYSMEM); if (!ptr) hcl_client_seterrnum (client, HCL_ESYSMEM);
return ptr; return ptr;
} }
@ -996,7 +999,7 @@ void* hcl_client_callocmem (hcl_client_t* client, hcl_oow_t size)
{ {
void* ptr; void* ptr;
ptr = HCL_MMGR_ALLOC(client->mmgr, size); ptr = HCL_MMGR_ALLOC(client->_mmgr, size);
if (!ptr) hcl_client_seterrnum (client, HCL_ESYSMEM); if (!ptr) hcl_client_seterrnum (client, HCL_ESYSMEM);
else HCL_MEMSET (ptr, 0, size); else HCL_MEMSET (ptr, 0, size);
return ptr; return ptr;
@ -1004,14 +1007,14 @@ void* hcl_client_callocmem (hcl_client_t* client, hcl_oow_t size)
void* hcl_client_reallocmem (hcl_client_t* client, void* ptr, hcl_oow_t size) void* hcl_client_reallocmem (hcl_client_t* client, void* ptr, hcl_oow_t size)
{ {
ptr = HCL_MMGR_REALLOC(client->mmgr, ptr, size); ptr = HCL_MMGR_REALLOC(client->_mmgr, ptr, size);
if (!ptr) hcl_client_seterrnum (client, HCL_ESYSMEM); if (!ptr) hcl_client_seterrnum (client, HCL_ESYSMEM);
return ptr; return ptr;
} }
void hcl_client_freemem (hcl_client_t* client, void* ptr) void hcl_client_freemem (hcl_client_t* client, void* ptr)
{ {
HCL_MMGR_FREE (client->mmgr, ptr); HCL_MMGR_FREE (client->_mmgr, ptr);
} }
/* ========================================================================= */ /* ========================================================================= */

View File

@ -282,8 +282,9 @@ struct hcl_server_listener_t
struct hcl_server_t struct hcl_server_t
{ {
hcl_mmgr_t* mmgr; hcl_oow_t _instsize;
hcl_cmgr_t* cmgr; hcl_mmgr_t* _mmgr;
hcl_cmgr_t* _cmgr;
hcl_server_prim_t prim; hcl_server_prim_t prim;
/* [NOTE] /* [NOTE]
@ -735,7 +736,7 @@ hcl_server_proto_t* hcl_server_proto_open (hcl_oow_t xtnsize, hcl_server_worker_
proto->worker = worker; proto->worker = worker;
proto->exec_runtime_event_index = HCL_TMR_INVALID_INDEX; proto->exec_runtime_event_index = HCL_TMR_INVALID_INDEX;
proto->hcl = hcl_open(proto->worker->server->mmgr, HCL_SIZEOF(*xtn), worker->server->cfg.actor_heap_size, &vmprim, HCL_NULL); proto->hcl = hcl_open(hcl_server_getmmgr(proto->worker->server), HCL_SIZEOF(*xtn), worker->server->cfg.actor_heap_size, &vmprim, HCL_NULL);
if (!proto->hcl) goto oops; if (!proto->hcl) goto oops;
xtn = (worker_hcl_xtn_t*)hcl_getxtn(proto->hcl); xtn = (worker_hcl_xtn_t*)hcl_getxtn(proto->hcl);
@ -743,7 +744,7 @@ hcl_server_proto_t* hcl_server_proto_open (hcl_oow_t xtnsize, hcl_server_worker_
hcl_setoption (proto->hcl, HCL_MOD_INCTX, &proto->worker->server->cfg.module_inctx); hcl_setoption (proto->hcl, HCL_MOD_INCTX, &proto->worker->server->cfg.module_inctx);
hcl_setoption (proto->hcl, HCL_LOG_MASK, &proto->worker->server->cfg.logmask); hcl_setoption (proto->hcl, HCL_LOG_MASK, &proto->worker->server->cfg.logmask);
hcl_setcmgr (proto->hcl, proto->worker->server->cmgr); hcl_setcmgr (proto->hcl, hcl_server_getcmgr(proto->worker->server));
hcl_getoption (proto->hcl, HCL_TRAIT, &trait); hcl_getoption (proto->hcl, HCL_TRAIT, &trait);
#if defined(HCL_BUILD_DEBUG) #if defined(HCL_BUILD_DEBUG)
@ -1643,8 +1644,9 @@ hcl_server_t* hcl_server_open (hcl_mmgr_t* mmgr, hcl_oow_t xtnsize, hcl_server_p
xtn->server = server; xtn->server = server;
HCL_MEMSET (server, 0, HCL_SIZEOF(*server) + xtnsize); HCL_MEMSET (server, 0, HCL_SIZEOF(*server) + xtnsize);
server->mmgr = mmgr; server->_instsize = HCL_SIZEOF(*server);
server->cmgr = hcl_get_utf8_cmgr(); server->_mmgr = mmgr;
server->_cmgr = hcl_get_utf8_cmgr();
server->prim = *prim; server->prim = *prim;
server->dummy_hcl = hcl; server->dummy_hcl = hcl;
server->tmr = tmr; server->tmr = tmr;
@ -1672,7 +1674,7 @@ hcl_server_t* hcl_server_open (hcl_mmgr_t* mmgr, hcl_oow_t xtnsize, hcl_server_p
* such as getting system time or logging. so the heap size doesn't * such as getting system time or logging. so the heap size doesn't
* need to be changed from the tiny value set above. */ * need to be changed from the tiny value set above. */
hcl_setoption (server->dummy_hcl, HCL_LOG_MASK, &server->cfg.logmask); hcl_setoption (server->dummy_hcl, HCL_LOG_MASK, &server->cfg.logmask);
hcl_setcmgr (server->dummy_hcl, server->cmgr); hcl_setcmgr (server->dummy_hcl, hcl_server_getcmgr(server));
hcl_getoption (server->dummy_hcl, HCL_TRAIT, &trait); hcl_getoption (server->dummy_hcl, HCL_TRAIT, &trait);
#if defined(HCL_BUILD_DEBUG) #if defined(HCL_BUILD_DEBUG)
if (server->cfg.trait & HCL_SERVER_TRAIT_DEBUG_GC) trait |= HCL_DEBUG_GC; if (server->cfg.trait & HCL_SERVER_TRAIT_DEBUG_GC) trait |= HCL_DEBUG_GC;
@ -1715,7 +1717,7 @@ void hcl_server_close (hcl_server_t* server)
hcl_tmr_close (server->tmr); hcl_tmr_close (server->tmr);
hcl_close (server->dummy_hcl); hcl_close (server->dummy_hcl);
HCL_MMGR_FREE (server->mmgr, server); HCL_MMGR_FREE (server->_mmgr, server);
} }
static HCL_INLINE int prepare_to_acquire_wid (hcl_server_t* server) static HCL_INLINE int prepare_to_acquire_wid (hcl_server_t* server)
@ -2454,22 +2456,22 @@ int hcl_server_getoption (hcl_server_t* server, hcl_server_option_t id, void* va
void* hcl_server_getxtn (hcl_server_t* server) void* hcl_server_getxtn (hcl_server_t* server)
{ {
return (void*)(server + 1); return (void*)((hcl_uint8_t*)server + server->_instsize);
} }
hcl_mmgr_t* hcl_server_getmmgr (hcl_server_t* server) hcl_mmgr_t* hcl_server_getmmgr (hcl_server_t* server)
{ {
return server->mmgr; return server->_mmgr;
} }
hcl_cmgr_t* hcl_server_getcmgr (hcl_server_t* server) hcl_cmgr_t* hcl_server_getcmgr (hcl_server_t* server)
{ {
return server->cmgr; return server->_cmgr;
} }
void hcl_server_setcmgr (hcl_server_t* server, hcl_cmgr_t* cmgr) void hcl_server_setcmgr (hcl_server_t* server, hcl_cmgr_t* cmgr)
{ {
server->cmgr = cmgr; server->_cmgr = cmgr;
} }
hcl_errnum_t hcl_server_geterrnum (hcl_server_t* server) hcl_errnum_t hcl_server_geterrnum (hcl_server_t* server)
@ -2528,7 +2530,7 @@ void* hcl_server_allocmem (hcl_server_t* server, hcl_oow_t size)
{ {
void* ptr; void* ptr;
ptr = HCL_MMGR_ALLOC(server->mmgr, size); ptr = HCL_MMGR_ALLOC(server->_mmgr, size);
if (!ptr) hcl_server_seterrnum (server, HCL_ESYSMEM); if (!ptr) hcl_server_seterrnum (server, HCL_ESYSMEM);
return ptr; return ptr;
} }
@ -2537,7 +2539,7 @@ void* hcl_server_callocmem (hcl_server_t* server, hcl_oow_t size)
{ {
void* ptr; void* ptr;
ptr = HCL_MMGR_ALLOC(server->mmgr, size); ptr = HCL_MMGR_ALLOC(server->_mmgr, size);
if (!ptr) hcl_server_seterrnum (server, HCL_ESYSMEM); if (!ptr) hcl_server_seterrnum (server, HCL_ESYSMEM);
else HCL_MEMSET (ptr, 0, size); else HCL_MEMSET (ptr, 0, size);
return ptr; return ptr;
@ -2545,12 +2547,12 @@ void* hcl_server_callocmem (hcl_server_t* server, hcl_oow_t size)
void* hcl_server_reallocmem (hcl_server_t* server, void* ptr, hcl_oow_t size) void* hcl_server_reallocmem (hcl_server_t* server, void* ptr, hcl_oow_t size)
{ {
ptr = HCL_MMGR_REALLOC(server->mmgr, ptr, size); ptr = HCL_MMGR_REALLOC(server->_mmgr, ptr, size);
if (!ptr) hcl_server_seterrnum (server, HCL_ESYSMEM); if (!ptr) hcl_server_seterrnum (server, HCL_ESYSMEM);
return ptr; return ptr;
} }
void hcl_server_freemem (hcl_server_t* server, void* ptr) void hcl_server_freemem (hcl_server_t* server, void* ptr)
{ {
HCL_MMGR_FREE (server->mmgr, ptr); HCL_MMGR_FREE (server->_mmgr, ptr);
} }

View File

@ -53,7 +53,7 @@ hcl_t* hcl_open (hcl_mmgr_t* mmgr, hcl_oow_t xtnsize, hcl_oow_t heapsize, const
void hcl_close (hcl_t* hcl) void hcl_close (hcl_t* hcl)
{ {
hcl_fini (hcl); hcl_fini (hcl);
HCL_MMGR_FREE (hcl->mmgr, hcl); HCL_MMGR_FREE (hcl_getmmgr(hcl), hcl);
} }
static void fill_bigint_tables (hcl_t* hcl) static void fill_bigint_tables (hcl_t* hcl)
@ -85,12 +85,12 @@ static void fill_bigint_tables (hcl_t* hcl)
static void* alloc_heap (hcl_t* hcl, hcl_oow_t size) static void* alloc_heap (hcl_t* hcl, hcl_oow_t size)
{ {
return HCL_MMGR_ALLOC(hcl->mmgr, size); return hcl_allocmem(hcl, size);
} }
static void free_heap (hcl_t* hcl, void* ptr) static void free_heap (hcl_t* hcl, void* ptr)
{ {
HCL_MMGR_FREE(hcl->mmgr, ptr); hcl_freemem (hcl, ptr);
} }
int hcl_init (hcl_t* hcl, hcl_mmgr_t* mmgr, hcl_oow_t heapsz, const hcl_vmprim_t* vmprim) int hcl_init (hcl_t* hcl, hcl_mmgr_t* mmgr, hcl_oow_t heapsz, const hcl_vmprim_t* vmprim)
@ -112,8 +112,9 @@ int hcl_init (hcl_t* hcl, hcl_mmgr_t* mmgr, hcl_oow_t heapsz, const hcl_vmprim_t
#endif #endif
HCL_MEMSET (hcl, 0, HCL_SIZEOF(*hcl)); HCL_MEMSET (hcl, 0, HCL_SIZEOF(*hcl));
hcl->mmgr = mmgr; hcl->_instsize = HCL_SIZEOF(*hcl);
hcl->cmgr = hcl_get_utf8_cmgr(); hcl->_mmgr = mmgr;
hcl->_cmgr = hcl_get_utf8_cmgr();
hcl->vmprim = *vmprim; hcl->vmprim = *vmprim;
if (!hcl->vmprim.alloc_heap) hcl->vmprim.alloc_heap = alloc_heap; if (!hcl->vmprim.alloc_heap) hcl->vmprim.alloc_heap = alloc_heap;
if (!hcl->vmprim.free_heap) hcl->vmprim.free_heap = free_heap; if (!hcl->vmprim.free_heap) hcl->vmprim.free_heap = free_heap;
@ -475,7 +476,7 @@ void* hcl_allocmem (hcl_t* hcl, hcl_oow_t size)
{ {
void* ptr; void* ptr;
ptr = HCL_MMGR_ALLOC (hcl->mmgr, size); ptr = HCL_MMGR_ALLOC (hcl_getmmgr(hcl), size);
if (!ptr) hcl_seterrnum (hcl, HCL_ESYSMEM); if (!ptr) hcl_seterrnum (hcl, HCL_ESYSMEM);
return ptr; return ptr;
} }
@ -484,7 +485,7 @@ void* hcl_callocmem (hcl_t* hcl, hcl_oow_t size)
{ {
void* ptr; void* ptr;
ptr = HCL_MMGR_ALLOC (hcl->mmgr, size); ptr = HCL_MMGR_ALLOC (hcl_getmmgr(hcl), size);
if (!ptr) hcl_seterrnum (hcl, HCL_ESYSMEM); if (!ptr) hcl_seterrnum (hcl, HCL_ESYSMEM);
else HCL_MEMSET (ptr, 0, size); else HCL_MEMSET (ptr, 0, size);
return ptr; return ptr;
@ -492,14 +493,14 @@ void* hcl_callocmem (hcl_t* hcl, hcl_oow_t size)
void* hcl_reallocmem (hcl_t* hcl, void* ptr, hcl_oow_t size) void* hcl_reallocmem (hcl_t* hcl, void* ptr, hcl_oow_t size)
{ {
ptr = HCL_MMGR_REALLOC (hcl->mmgr, ptr, size); ptr = HCL_MMGR_REALLOC (hcl_getmmgr(hcl), ptr, size);
if (!ptr) hcl_seterrnum (hcl, HCL_ESYSMEM); if (!ptr) hcl_seterrnum (hcl, HCL_ESYSMEM);
return ptr; return ptr;
} }
void hcl_freemem (hcl_t* hcl, void* ptr) void hcl_freemem (hcl_t* hcl, void* ptr)
{ {
HCL_MMGR_FREE (hcl->mmgr, ptr); HCL_MMGR_FREE (hcl_getmmgr(hcl), ptr);
} }

View File

@ -1071,8 +1071,9 @@ typedef struct hcl_compiler_t hcl_compiler_t;
struct hcl_t struct hcl_t
{ {
hcl_mmgr_t* mmgr; hcl_oow_t _instsize;
hcl_cmgr_t* cmgr; hcl_mmgr_t* _mmgr;
hcl_cmgr_t* _cmgr;
hcl_errnum_t errnum; hcl_errnum_t errnum;
struct struct
@ -1433,20 +1434,19 @@ HCL_EXPORT void hcl_setinloc (
); );
#if defined(HCL_HAVE_INLINE) #if defined(HCL_HAVE_INLINE)
static HCL_INLINE hcl_mmgr_t* hcl_getmmgr (hcl_t* hcl) { return hcl->mmgr; } static HCL_INLINE hcl_mmgr_t* hcl_getmmgr (hcl_t* hcl) { return hcl->_mmgr; }
static HCL_INLINE void* hcl_getxtn (hcl_t* hcl) { return (void*)(hcl + 1); } static HCL_INLINE void* hcl_getxtn (hcl_t* hcl) { return (void*)((hcl_uint8_t*)hcl + hcl->_instsize); }
static HCL_INLINE hcl_cmgr_t* hcl_getcmgr (hcl_t* hcl) { return hcl->cmgr; } static HCL_INLINE hcl_cmgr_t* hcl_getcmgr (hcl_t* hcl) { return hcl->_cmgr; }
static HCL_INLINE void hcl_setcmgr (hcl_t* hcl, hcl_cmgr_t* cmgr) { hcl->cmgr = cmgr; } static HCL_INLINE void hcl_setcmgr (hcl_t* hcl, hcl_cmgr_t* cmgr) { hcl->_cmgr = cmgr; }
static HCL_INLINE hcl_errnum_t hcl_geterrnum (hcl_t* hcl) { return hcl->errnum; } static HCL_INLINE hcl_errnum_t hcl_geterrnum (hcl_t* hcl) { return hcl->errnum; }
#else #else
# define hcl_getmmgr(hcl) (((hcl_t*)(hcl))->mmgr) # define hcl_getmmgr(hcl) (((hcl_t*)(hcl))->_mmgr)
# define hcl_getxtn(hcl) ((void*)((hcl_t*)(hcl) + 1)) # define hcl_getxtn(hcl) ((void*)((hcl_uint8_t*)hcl + ((hcl_t*)hcl)->_instsize))
# define hcl_getcmgr(hcl) (((hcl_t*)(hcl))->cmgr) # define hcl_getcmgr(hcl) (((hcl_t*)(hcl))->_cmgr)
# define hcl_setcmgr(hcl,mgr) (((hcl_t*)(hcl))->cmgr = (mgr)) # define hcl_setcmgr(hcl,cmgr) (((hcl_t*)(hcl))->_cmgr = (cmgr))
# define hcl_geterrnum(hcl) (((hcl_t*)(hcl))->errnum) # define hcl_geterrnum(hcl) (((hcl_t*)(hcl))->errnum)
#endif #endif

View File

@ -67,7 +67,7 @@ HCL_INLINE hcl_rbt_pair_t* hcl_rbt_allocpair (
if (kcop == HCL_RBT_COPIER_INLINE) as += HCL_ALIGN_POW2(KTOB(rbt,klen), HCL_SIZEOF_VOID_P); if (kcop == HCL_RBT_COPIER_INLINE) as += HCL_ALIGN_POW2(KTOB(rbt,klen), HCL_SIZEOF_VOID_P);
if (vcop == HCL_RBT_COPIER_INLINE) as += VTOB(rbt,vlen); if (vcop == HCL_RBT_COPIER_INLINE) as += VTOB(rbt,vlen);
pair = (hcl_rbt_pair_t*) HCL_MMGR_ALLOC (rbt->hcl->mmgr, as); pair = (hcl_rbt_pair_t*) HCL_MMGR_ALLOC (hcl_getmmgr(rbt->hcl), as);
if (pair == HCL_NULL) return HCL_NULL; if (pair == HCL_NULL) return HCL_NULL;
pair->color = HCL_RBT_RED; pair->color = HCL_RBT_RED;
@ -90,7 +90,7 @@ HCL_INLINE hcl_rbt_pair_t* hcl_rbt_allocpair (
KPTR(pair) = kcop (rbt, kptr, klen); KPTR(pair) = kcop (rbt, kptr, klen);
if (KPTR(pair) == HCL_NULL) if (KPTR(pair) == HCL_NULL)
{ {
HCL_MMGR_FREE (rbt->hcl->mmgr, pair); hcl_freemem (rbt->hcl, pair);
return HCL_NULL; return HCL_NULL;
} }
} }
@ -114,7 +114,7 @@ HCL_INLINE hcl_rbt_pair_t* hcl_rbt_allocpair (
{ {
if (rbt->style->freeer[HCL_RBT_KEY] != HCL_NULL) if (rbt->style->freeer[HCL_RBT_KEY] != HCL_NULL)
rbt->style->freeer[HCL_RBT_KEY] (rbt, KPTR(pair), KLEN(pair)); rbt->style->freeer[HCL_RBT_KEY] (rbt, KPTR(pair), KLEN(pair));
HCL_MMGR_FREE (rbt->hcl->mmgr, pair); hcl_freemem (rbt->hcl, pair);
return HCL_NULL; return HCL_NULL;
} }
} }
@ -128,7 +128,7 @@ HCL_INLINE void hcl_rbt_freepair (hcl_rbt_t* rbt, hcl_rbt_pair_t* pair)
rbt->style->freeer[HCL_RBT_KEY] (rbt, KPTR(pair), KLEN(pair)); rbt->style->freeer[HCL_RBT_KEY] (rbt, KPTR(pair), KLEN(pair));
if (rbt->style->freeer[HCL_RBT_VAL] != HCL_NULL) if (rbt->style->freeer[HCL_RBT_VAL] != HCL_NULL)
rbt->style->freeer[HCL_RBT_VAL] (rbt, VPTR(pair), VLEN(pair)); rbt->style->freeer[HCL_RBT_VAL] (rbt, VPTR(pair), VLEN(pair));
HCL_MMGR_FREE (rbt->hcl->mmgr, pair); hcl_freemem (rbt->hcl, pair);
} }
static hcl_rbt_style_t style[] = static hcl_rbt_style_t style[] =
@ -195,12 +195,12 @@ hcl_rbt_t* hcl_rbt_open (hcl_t* hcl, hcl_oow_t xtnsize, int kscale, int vscale)
{ {
hcl_rbt_t* rbt; hcl_rbt_t* rbt;
rbt = (hcl_rbt_t*) HCL_MMGR_ALLOC (hcl->mmgr, HCL_SIZEOF(hcl_rbt_t) + xtnsize); rbt = (hcl_rbt_t*)hcl_allocmem(hcl, HCL_SIZEOF(hcl_rbt_t) + xtnsize);
if (rbt == HCL_NULL) return HCL_NULL; if (!rbt) return HCL_NULL;
if (hcl_rbt_init (rbt, hcl, kscale, vscale) <= -1) if (hcl_rbt_init(rbt, hcl, kscale, vscale) <= -1)
{ {
HCL_MMGR_FREE (hcl->mmgr, rbt); hcl_freemem (hcl, rbt);
return HCL_NULL; return HCL_NULL;
} }
@ -211,7 +211,7 @@ hcl_rbt_t* hcl_rbt_open (hcl_t* hcl, hcl_oow_t xtnsize, int kscale, int vscale)
void hcl_rbt_close (hcl_rbt_t* rbt) void hcl_rbt_close (hcl_rbt_t* rbt)
{ {
hcl_rbt_fini (rbt); hcl_rbt_fini (rbt);
HCL_MMGR_FREE (rbt->hcl->mmgr, rbt); hcl_freemem (rbt->hcl, rbt);
} }
int hcl_rbt_init (hcl_rbt_t* rbt, hcl_t* hcl, int kscale, int vscale) int hcl_rbt_init (hcl_rbt_t* rbt, hcl_t* hcl, int kscale, int vscale)

View File

@ -2398,7 +2398,7 @@ void hcl_detachio (hcl_t* hcl)
prev = hcl->c->curinp->includer; prev = hcl->c->curinp->includer;
HCL_ASSERT (hcl, hcl->c->curinp->name != HCL_NULL); HCL_ASSERT (hcl, hcl->c->curinp->name != HCL_NULL);
HCL_MMGR_FREE (hcl->mmgr, hcl->c->curinp); hcl_freemem (hcl, hcl->c->curinp);
hcl->c->curinp = prev; hcl->c->curinp = prev;
} }

View File

@ -725,7 +725,7 @@ int hcl_convbtouchars (hcl_t* hcl, const hcl_bch_t* bcs, hcl_oow_t* bcslen, hcl_
/* length bound */ /* length bound */
int n; int n;
n = hcl_conv_bchars_to_uchars_with_cmgr(bcs, bcslen, ucs, ucslen, hcl->cmgr, 0); n = hcl_conv_bchars_to_uchars_with_cmgr(bcs, bcslen, ucs, ucslen, hcl_getcmgr(hcl), 0);
if (n <= -1) if (n <= -1)
{ {
@ -741,7 +741,7 @@ int hcl_convutobchars (hcl_t* hcl, const hcl_uch_t* ucs, hcl_oow_t* ucslen, hcl_
/* length bound */ /* length bound */
int n; int n;
n = hcl_conv_uchars_to_bchars_with_cmgr(ucs, ucslen, bcs, bcslen, hcl->cmgr); n = hcl_conv_uchars_to_bchars_with_cmgr(ucs, ucslen, bcs, bcslen, hcl_getcmgr(hcl));
if (n <= -1) if (n <= -1)
{ {
@ -756,7 +756,7 @@ int hcl_convbtoucstr (hcl_t* hcl, const hcl_bch_t* bcs, hcl_oow_t* bcslen, hcl_u
/* null-terminated. */ /* null-terminated. */
int n; int n;
n = hcl_conv_bcstr_to_ucstr_with_cmgr(bcs, bcslen, ucs, ucslen, hcl->cmgr, 0); n = hcl_conv_bcstr_to_ucstr_with_cmgr(bcs, bcslen, ucs, ucslen, hcl_getcmgr(hcl), 0);
if (n <= -1) if (n <= -1)
{ {
@ -771,7 +771,7 @@ int hcl_convutobcstr (hcl_t* hcl, const hcl_uch_t* ucs, hcl_oow_t* ucslen, hcl_b
/* null-terminated */ /* null-terminated */
int n; int n;
n = hcl_conv_ucstr_to_bcstr_with_cmgr(ucs, ucslen, bcs, bcslen, hcl->cmgr); n = hcl_conv_ucstr_to_bcstr_with_cmgr(ucs, ucslen, bcs, bcslen, hcl_getcmgr(hcl));
if (n <= -1) if (n <= -1)
{ {