changed the doubly linked list to circular in idmap-imp.h

started writing some code to implement gc
This commit is contained in:
hyung-hwan 2020-03-18 08:30:40 +00:00
parent bc87c486da
commit 1285d77c1e
11 changed files with 345 additions and 155 deletions

View File

@ -1,7 +1,7 @@
# Hawk # Hawk
- [Language](#language) - [Language](#language)
- [Basic Modules](#basic-modules) - [Modules](#modules)
- [Embedding Guide](#embedding-guide) - [Embedding Guide](#embedding-guide)
## Language <a name="language"></a> ## Language <a name="language"></a>
@ -289,7 +289,7 @@ and represents the value of 0.
0b # 0b0 but not desirable. 0b # 0b0 but not desirable.
### Module ### Modules <a name="modules"></a>
Hawk supports various modules. Hawk supports various modules.
@ -545,6 +545,44 @@ Socket functions are available.
sys::close (s); sys::close (s);
} }
### ffi
### mysql
BEGIN {
mysql = mysql::open();
if (mysql::connect(mysql, "10.30.1.219", "pdns", "pdns", "pdns") <= -1)
{
print "connect error -", mysql::errmsg();
}
if (mysql::query(mysql, "select * from records") <= -1)
{
print "query error -", mysql::errmsg();
}
result = mysql::store_result(mysql);
if (result <= -1)
{
print "store result error - ", mysql::errmsg();
}
while (mysql::fetch_row(result, row) > 0)
{
ncols = length(row);
for (i = 0; i < ncols; i++) print row[i];
print "----";
}
mysql::free_result(result);
mysql::close(mysql);
}
### Incompatibility with AWK ### Incompatibility with AWK
#### Parameter passing #### Parameter passing
@ -577,14 +615,6 @@ There are subtle differences when you put an expression for a position variable.
| $(++$(++i)) | OK | syntax error | | $(++$(++i)) | OK | syntax error |
## Basic Modules <a name="basic-modules"></a>
### sys
### ffi
### mysql
## Embedding Guide <a name="embedding-guide"></a> ## Embedding Guide <a name="embedding-guide"></a>
To use hawk in your program, do the followings: To use hawk in your program, do the followings:

View File

@ -80,6 +80,7 @@ libhawk_la_SOURCES = \
gem-nwif2.c \ gem-nwif2.c \
hawk-prv.h \ hawk-prv.h \
hawk.c \ hawk.c \
idmap-imp.h \
mb8.c \ mb8.c \
misc-prv.h \ misc-prv.h \
misc.c \ misc.c \
@ -184,7 +185,6 @@ if ENABLE_STATIC_MODULE
# STATIC MODULES BUILT INTO MAIN LIBRARY # STATIC MODULES BUILT INTO MAIN LIBRARY
################################################## ##################################################
libhawk_la_SOURCES += \ libhawk_la_SOURCES += \
imap-imp.h \
mod-math.c mod-math.h \ mod-math.c mod-math.h \
mod-str.c mod-str.h \ mod-str.c mod-str.h \
mod-sys.c mod-sys.h mod-sys.c mod-sys.h

View File

@ -100,7 +100,6 @@ host_triplet = @host@
# STATIC MODULES BUILT INTO MAIN LIBRARY # STATIC MODULES BUILT INTO MAIN LIBRARY
################################################## ##################################################
@ENABLE_STATIC_MODULE_TRUE@am__append_9 = \ @ENABLE_STATIC_MODULE_TRUE@am__append_9 = \
@ENABLE_STATIC_MODULE_TRUE@ imap-imp.h \
@ENABLE_STATIC_MODULE_TRUE@ mod-math.c mod-math.h \ @ENABLE_STATIC_MODULE_TRUE@ mod-math.c mod-math.h \
@ENABLE_STATIC_MODULE_TRUE@ mod-str.c mod-str.h \ @ENABLE_STATIC_MODULE_TRUE@ mod-str.c mod-str.h \
@ENABLE_STATIC_MODULE_TRUE@ mod-sys.c mod-sys.h @ENABLE_STATIC_MODULE_TRUE@ mod-sys.c mod-sys.h
@ -207,9 +206,9 @@ am__libhawk_la_SOURCES_DIST = hawk.h hawk-arr.h hawk-chr.h hawk-cmn.h \
hawk-tre.h hawk-unpack.h Hawk.hpp HawkStd.hpp arr.c chr.c \ hawk-tre.h hawk-unpack.h Hawk.hpp HawkStd.hpp arr.c chr.c \
dir.c ecs-imp.h ecs.c err-prv.h err.c err-sys.c fmt-imp.h \ dir.c ecs-imp.h ecs.c err-prv.h err.c err-sys.c fmt-imp.h \
fmt.c fnc-prv.h fnc.c htb.c gem.c gem-skad.c gem-nwif.c \ fmt.c fnc-prv.h fnc.c htb.c gem.c gem-skad.c gem-nwif.c \
gem-nwif2.c hawk-prv.h hawk.c mb8.c misc-prv.h misc.c \ gem-nwif2.c hawk-prv.h hawk.c idmap-imp.h mb8.c misc-prv.h \
parse-prv.h parse.c rbt.c rec.c rio-prv.h rio.c run-prv.h \ misc.c parse-prv.h parse.c rbt.c rec.c rio-prv.h rio.c \
run.c tre-prv.h tre-ast.c tre-ast.h tre-compile.c \ run-prv.h run.c tre-prv.h tre-ast.c tre-ast.h tre-compile.c \
tre-compile.h tre-match-bt.c tre-match-pa.c tre-match-ut.h \ tre-compile.h tre-match-bt.c tre-match-pa.c tre-match-ut.h \
tre-mem.c tre-mem.h tre-parse.c tre-parse.h tre-stack.h \ tre-mem.c tre-mem.h tre-parse.c tre-parse.h tre-stack.h \
tre-stack.c tre.c tree-prv.h tree.c uch-prop.h uch-case.h \ tre-stack.c tre.c tree-prv.h tree.c uch-prop.h uch-case.h \
@ -217,8 +216,8 @@ am__libhawk_la_SOURCES_DIST = hawk.h hawk-arr.h hawk-chr.h hawk-cmn.h \
utl-str.c utl-sys.c utl.c val-prv.h val.c hawk-cli.h \ utl-str.c utl-sys.c utl.c val-prv.h val.c hawk-cli.h \
hawk-fio.h hawk-mtx.h hawk-pio.h hawk-sio.h hawk-tio.h \ hawk-fio.h hawk-mtx.h hawk-pio.h hawk-sio.h hawk-tio.h \
cli-imp.h cli.c fio.c mtx.c pio.c sio.c syscall.h tio.c \ cli-imp.h cli.c fio.c mtx.c pio.c sio.c syscall.h tio.c \
std-prv.h std.c Hawk.cpp HawkStd.cpp imap-imp.h mod-math.c \ std-prv.h std.c Hawk.cpp HawkStd.cpp mod-math.c mod-math.h \
mod-math.h mod-str.c mod-str.h mod-sys.c mod-sys.h mod-str.c mod-str.h mod-sys.c mod-sys.h
am__objects_1 = am__objects_1 =
am__objects_2 = $(am__objects_1) am__objects_2 = $(am__objects_1)
@ENABLE_CXX_TRUE@am__objects_3 = libhawk_la-Hawk.lo \ @ENABLE_CXX_TRUE@am__objects_3 = libhawk_la-Hawk.lo \
@ -576,14 +575,14 @@ pkglib_LTLIBRARIES = libhawk.la $(am__append_15)
libhawk_la_SOURCES = $(pkginclude_HEADERS) arr.c chr.c dir.c ecs-imp.h \ libhawk_la_SOURCES = $(pkginclude_HEADERS) arr.c chr.c dir.c ecs-imp.h \
ecs.c err-prv.h err.c err-sys.c fmt-imp.h fmt.c fnc-prv.h \ ecs.c err-prv.h err.c err-sys.c fmt-imp.h fmt.c fnc-prv.h \
fnc.c htb.c gem.c gem-skad.c gem-nwif.c gem-nwif2.c hawk-prv.h \ fnc.c htb.c gem.c gem-skad.c gem-nwif.c gem-nwif2.c hawk-prv.h \
hawk.c mb8.c misc-prv.h misc.c parse-prv.h parse.c rbt.c rec.c \ hawk.c idmap-imp.h mb8.c misc-prv.h misc.c parse-prv.h parse.c \
rio-prv.h rio.c run-prv.h run.c tre-prv.h tre-ast.c tre-ast.h \ rbt.c rec.c rio-prv.h rio.c run-prv.h run.c tre-prv.h \
tre-compile.c tre-compile.h tre-match-bt.c tre-match-pa.c \ tre-ast.c tre-ast.h tre-compile.c tre-compile.h tre-match-bt.c \
tre-match-ut.h tre-mem.c tre-mem.h tre-parse.c tre-parse.h \ tre-match-pa.c tre-match-ut.h tre-mem.c tre-mem.h tre-parse.c \
tre-stack.h tre-stack.c tre.c tree-prv.h tree.c uch-prop.h \ tre-parse.h tre-stack.h tre-stack.c tre.c tree-prv.h tree.c \
uch-case.h utf16.c utf8.c utl-ass.c utl-skad.c utl-skad.h \ uch-prop.h uch-case.h utf16.c utf8.c utl-ass.c utl-skad.c \
utl-sort.c utl-str.c utl-sys.c utl.c val-prv.h val.c \ utl-skad.h utl-sort.c utl-str.c utl-sys.c utl.c val-prv.h \
hawk-cli.h hawk-fio.h hawk-mtx.h hawk-pio.h hawk-sio.h \ val.c hawk-cli.h hawk-fio.h hawk-mtx.h hawk-pio.h hawk-sio.h \
hawk-tio.h cli-imp.h cli.c fio.c mtx.c pio.c sio.c syscall.h \ hawk-tio.h cli-imp.h cli.c fio.c mtx.c pio.c sio.c syscall.h \
tio.c std-prv.h std.c $(am__append_8) $(am__append_9) tio.c std-prv.h std.c $(am__append_8) $(am__append_9)
libhawk_la_CPPFLAGS = $(CPPFLAGS_ALL_COMMON) $(CPPFLAGS_PFMOD) \ libhawk_la_CPPFLAGS = $(CPPFLAGS_ALL_COMMON) $(CPPFLAGS_PFMOD) \

View File

@ -492,8 +492,8 @@ struct hawk_mod_data_t
#define HAWK_RTX_INIT_REF_VAL(refval, _id, _adr, _nrefs) \ #define HAWK_RTX_INIT_REF_VAL(refval, _id, _adr, _nrefs) \
do { \ do { \
(refval)->v_type = HAWK_VAL_REF; \ (refval)->v_type = HAWK_VAL_REF; \
(refval)->ref = (_nrefs); \ (refval)->v_refs = (_nrefs); \
(refval)->stat = 0; \ (refval)->v_static = 0; \
(refval)->nstr = 0; \ (refval)->nstr = 0; \
(refval)->fcb = 0; \ (refval)->fcb = 0; \
(refval)->id = (_id); \ (refval)->id = (_id); \

View File

@ -127,26 +127,51 @@ struct hawk_rtx_alt_t
HAWK_RTX_HDR; HAWK_RTX_HDR;
}; };
/* ------------------------------------------------------------------------ */
typedef struct hawk_gc_info_t hawk_gc_info_t;
struct hawk_gc_info_t
{
hawk_gc_info_t* gc_prev;
hawk_gc_info_t* gc_next;
hawk_uintptr_t gc_refs;
};
#if defined(HAWK_HAVE_INLINE)
static HAWK_INLINE hawk_gc_info_t* hawk_val_to_gcinfo(hawk_val_t* v)
{
return ((hawk_gc_info_t*)v) - 1;
}
static HAWK_INLINE hawk_val_t* hawk_gcinfo_to_val(hawk_gc_info_t* gci)
{
return (hawk_val_t*)(gci + 1);
}
#else
# defined hawk_val_to_gcinfo(v) (((hawk_gc_info_t*)(v)) - 1)
# defined hawk_gcinfo_to_val(gci) ((hawk_val_t*)(((hawk_gc_info_t*)(gci)) + 1))
#endif
/** /**
* The #HAWK_VAL_HDR defines the common header for a value. * The #HAWK_VAL_HDR defines the common header for a value.
* Three common fields are: * Three common fields are:
* - type - type of a value from #hawk_val_type_t * - v_type - type of a value from #hawk_val_type_t
* - ref - reference count * - v_refs - reference count
* - stat - static value * - v_static - static value indicator
* - nstr - numeric string marker, 1 -> integer, 2 -> floating-point number * - nstr - numeric string marker, 1 -> integer, 2 -> floating-point number
*/ */
/* /*
#define HAWK_VAL_HDR \ #define HAWK_VAL_HDR \
unsigned int type: 4; \ unsigned int v_type: 4; \
unsigned int ref: 24; \ unsigned int v_refs: 24; \
unsigned int stat: 1; \ unsigned int v_static: 1; \
unsigned int nstr: 2; \ unsigned int nstr: 2; \
unsigned int fcb: 1 unsigned int fcb: 1
*/ */
#define HAWK_VAL_HDR \ #define HAWK_VAL_HDR \
hawk_uintptr_t v_type: 4; \ hawk_uintptr_t v_type: 4; \
hawk_uintptr_t ref: ((HAWK_SIZEOF_UINTPTR_T * 8) - 8); \ hawk_uintptr_t v_refs: ((HAWK_SIZEOF_UINTPTR_T * 8) - 8); \
hawk_uintptr_t stat: 1; \ hawk_uintptr_t v_static: 1; \
hawk_uintptr_t nstr: 2; \ hawk_uintptr_t nstr: 2; \
hawk_uintptr_t fcb: 1 hawk_uintptr_t fcb: 1

View File

@ -604,7 +604,7 @@ int hawk_htb_delete (hawk_htb_t* htb, const void* kptr, hawk_oow_t klen)
while (pair != HAWK_NULL) while (pair != HAWK_NULL)
{ {
if (htb->style->comper (htb, KPTR(pair), KLEN(pair), kptr, klen) == 0) if (htb->style->comper(htb, KPTR(pair), KLEN(pair), kptr, klen) == 0)
{ {
if (prev == HAWK_NULL) if (prev == HAWK_NULL)
htb->bucket[hc] = NEXT(pair); htb->bucket[hc] = NEXT(pair);

View File

@ -26,46 +26,70 @@
/* THIS FILE IS SUPPOSED TO BE INCLUDED BY MODULE SOURCE THAT MAINTAINS MAPPING BETWEEN ID AND DATA */ /* THIS FILE IS SUPPOSED TO BE INCLUDED BY MODULE SOURCE THAT MAINTAINS MAPPING BETWEEN ID AND DATA */
typedef struct __IMAP_NODE_T __IMAP_NODE_T; typedef struct __IDMAP_NODE_T __IDMAP_NODE_T;
struct __IMAP_NODE_T struct __IDMAP_NODE_T
{ {
__IMAP_NODE_T* prev; __IDMAP_NODE_T* prev;
__IMAP_NODE_T* next; __IDMAP_NODE_T* next;
int id; int id;
__IMAP_NODE_T_DATA __IDMAP_NODE_T_DATA
}; };
typedef struct __IMAP_LIST_T __IMAP_LIST_T; typedef struct __IDMAP_LIST_T __IDMAP_LIST_T;
struct __IMAP_LIST_T struct __IDMAP_LIST_T
{ {
__IMAP_NODE_T* head; #if defined(__IDMAP_AVOID_CIRCULAR_LIST)
__IMAP_NODE_T* tail; __IDMAP_NODE_T* head;
__IMAP_NODE_T* free; __IDMAP_NODE_T* tail;
__IDMAP_NODE_T* free;
#else
struct
{
__IDMAP_NODE_T* prev;
__IDMAP_NODE_T* next;
} used;
struct
{
__IDMAP_NODE_T* prev;
__IDMAP_NODE_T* next;
} free;
#endif
/* mapping table to map 'id' to 'node' */ /* mapping table to map 'id' to 'node' */
struct struct
{ {
__IMAP_NODE_T** tab; __IDMAP_NODE_T** tab;
int capa; int capa;
int high; int high;
} map; } map;
__IMAP_LIST_T_DATA __IDMAP_LIST_T_DATA
}; };
static __IMAP_NODE_T* __MAKE_IMAP_NODE (hawk_rtx_t* rtx, __IMAP_LIST_T* list)
static __IDMAP_NODE_T* __MAKE_IDMAP_NODE (hawk_rtx_t* rtx, __IDMAP_LIST_T* list)
{ {
/* create a new context node and append it to the list tail */ /* create a new context node and append it to the list tail */
__IMAP_NODE_T* node; __IDMAP_NODE_T* node;
node = HAWK_NULL; node = HAWK_NULL;
#if defined(__IDMAP_AVOID_CIRCULAR_LIST)
if (list->free) if (list->free)
{ {
node = list->free; node = list->free;
list->free = node->next; list->free = node->next;
} }
#else
if (list->free.next != (__IDMAP_NODE_T*)&list->free)
{
/* remove a node from a free list */
node = list->free.next;
node->prev->next = node->next;
node->next->prev = node->prev;
}
#endif
else else
{ {
node = hawk_rtx_callocmem(rtx, HAWK_SIZEOF(*node)); node = hawk_rtx_callocmem(rtx, HAWK_SIZEOF(*node));
@ -74,7 +98,7 @@ static __IMAP_NODE_T* __MAKE_IMAP_NODE (hawk_rtx_t* rtx, __IMAP_LIST_T* list)
if (list->map.high <= list->map.capa) if (list->map.high <= list->map.capa)
{ {
hawk_oow_t newcapa, inc; hawk_oow_t newcapa, inc;
__IMAP_NODE_T** tmp; __IDMAP_NODE_T** tmp;
inc = HAWK_TYPE_MAX(int) - list->map.capa; inc = HAWK_TYPE_MAX(int) - list->map.capa;
if (inc == 0) goto oops; /* too many nodes */ if (inc == 0) goto oops; /* too many nodes */
@ -82,7 +106,7 @@ static __IMAP_NODE_T* __MAKE_IMAP_NODE (hawk_rtx_t* rtx, __IMAP_LIST_T* list)
if (inc > 64) inc = 64; if (inc > 64) inc = 64;
newcapa = (hawk_oow_t)list->map.capa + inc; newcapa = (hawk_oow_t)list->map.capa + inc;
tmp = (__IMAP_NODE_T**)hawk_rtx_reallocmem(rtx, list->map.tab, HAWK_SIZEOF(*tmp) * newcapa); tmp = (__IDMAP_NODE_T**)hawk_rtx_reallocmem(rtx, list->map.tab, HAWK_SIZEOF(*tmp) * newcapa);
if (!tmp) goto oops; if (!tmp) goto oops;
HAWK_MEMSET (&tmp[list->map.capa], 0, HAWK_SIZEOF(*tmp) * (newcapa - list->map.capa)); HAWK_MEMSET (&tmp[list->map.capa], 0, HAWK_SIZEOF(*tmp) * (newcapa - list->map.capa));
@ -98,12 +122,20 @@ static __IMAP_NODE_T* __MAKE_IMAP_NODE (hawk_rtx_t* rtx, __IMAP_LIST_T* list)
HAWK_ASSERT (list->map.tab[node->id] == HAWK_NULL); HAWK_ASSERT (list->map.tab[node->id] == HAWK_NULL);
list->map.tab[node->id] = node; list->map.tab[node->id] = node;
#if defined(__IDMAP_AVOID_CIRCULAR_LIST)
/* append it to the tail */ /* append it to the tail */
node->next = HAWK_NULL; node->next = HAWK_NULL;
node->prev = list->tail; node->prev = list->tail;
if (list->tail) list->tail->next = node; if (list->tail) list->tail->next = node;
else list->head = node; else list->head = node;
list->tail = node; list->tail = node;
#else
/* append it */
node->next = (__IDMAP_NODE_T*)&list->used;
node->prev = list->used.prev;
node->prev->next = node;
list->used.prev = node;
#endif
return node; return node;
@ -112,12 +144,17 @@ oops:
return HAWK_NULL; return HAWK_NULL;
} }
static void __FREE_IMAP_NODE (hawk_rtx_t* rtx, __IMAP_LIST_T* list, __IMAP_NODE_T* node) static void __FREE_IDMAP_NODE (hawk_rtx_t* rtx, __IDMAP_LIST_T* list, __IDMAP_NODE_T* node)
{ {
#if defined(__IDMAP_AVOID_CIRCULAR_LIST)
if (node->prev) node->prev->next = node->next; if (node->prev) node->prev->next = node->next;
if (node->next) node->next->prev = node->prev; if (node->next) node->next->prev = node->prev;
if (list->head == node) list->head = node->next; if (list->head == node) list->head = node->next;
if (list->tail == node) list->tail = node->prev; if (list->tail == node) list->tail = node->prev;
#else
node->prev->next = node->next;
node->next->prev = node->prev;
#endif
list->map.tab[node->id] = HAWK_NULL; list->map.tab[node->id] = HAWK_NULL;
@ -131,15 +168,23 @@ static void __FREE_IMAP_NODE (hawk_rtx_t* rtx, __IMAP_LIST_T* list, __IMAP_NODE_
else else
{ {
/* otherwise, chain the node to the free list */ /* otherwise, chain the node to the free list */
#if defined(__IDMAP_AVOID_CIRCULAR_LIST)
node->next = list->free; node->next = list->free;
list->free = node; list->free = node;
#else
node->next = (__IDMAP_NODE_T*)&list->free;
node->prev = list->free.prev;
node->prev->next = node;
list->free.prev = node;
#endif
} }
/* however, i destroy the whole free list when all the nodes are /* however, i destroy the whole free list when all the nodes are
* chanined to the free list */ * chanined to the free list */
#if defined(__IDMAP_AVOID_CIRCULAR_LIST)
if (list->head == HAWK_NULL) if (list->head == HAWK_NULL)
{ {
__IMAP_NODE_T* curnode; __IDMAP_NODE_T* curnode;
while (list->free) while (list->free)
{ {
@ -153,4 +198,75 @@ static void __FREE_IMAP_NODE (hawk_rtx_t* rtx, __IMAP_LIST_T* list, __IMAP_NODE_
list->map.capa = 0; list->map.capa = 0;
list->map.tab = HAWK_NULL; list->map.tab = HAWK_NULL;
} }
#else
if (list->used.next == (__IDMAP_NODE_T*)&list->used)
{
__IDMAP_NODE_T* node;
while (list->free.next != (__IDMAP_NODE_T*)&list->free)
{
node = list->free.next;
node->prev->next = node->next;
node->next->prev = node->prev;
hawk_rtx_freemem (rtx, node);
}
hawk_rtx_freemem (rtx, list->map.tab);
list->map.high = 0;
list->map.capa = 0;
list->map.tab = HAWK_NULL;
}
#endif
}
static void __INIT_IDMAP_LIST (hawk_rtx_t* rtx, __IDMAP_LIST_T* list)
{
#if defined(__IDMAP_AVOID_CIRCULAR_LIST)
/* nothing */
#else
list->used.next = (__IDMAP_NODE_T*)&list->used;
list->used.prev = (__IDMAP_NODE_T*)&list->used;
list->free.next = (__IDMAP_NODE_T*)&list->free;
list->free.prev = (__IDMAP_NODE_T*)&list->free;
#endif
}
static void __FINI_IDMAP_LIST (hawk_rtx_t* rtx, __IDMAP_LIST_T* list)
{
#if defined(__IDMAP_AVOID_CIRCULAR_LIST)
__IDMAP_NODE_T* node, * next;
node = data->list->head;
while (node)
{
next = node->next;
__FREE_IDMAP_NODE (rtx, list, node);
node = next;
}
node = data->list->free;
while (node)
{
next = node->next;
__FREE_IDMAP_NODE (rtx, list, node);
node = next;
}
#else
__IDMAP_NODE_T* node;
while (list->used.next != (__IDMAP_NODE_T*)&list->used)
{
node = list->used.next;
node->prev->next = node->next;
node->next->prev = node->prev;
__FREE_IDMAP_NODE (rtx, list, node);
}
while (list->free.next != (__IDMAP_NODE_T*)&list->free)
{
node = list->free.next;
node->prev->next = node->next;
node->next->prev = node->prev;
__FREE_IDMAP_NODE (rtx, list, node);
}
#endif
} }

View File

@ -166,13 +166,15 @@ struct sys_list_data_t
}; };
typedef struct sys_list_data_t sys_list_data_t; typedef struct sys_list_data_t sys_list_data_t;
#define __IMAP_NODE_T_DATA sys_node_data_t ctx; #define __IDMAP_NODE_T_DATA sys_node_data_t ctx;
#define __IMAP_LIST_T_DATA sys_list_data_t ctx; #define __IDMAP_LIST_T_DATA sys_list_data_t ctx;
#define __IMAP_LIST_T sys_list_t #define __IDMAP_LIST_T sys_list_t
#define __IMAP_NODE_T sys_node_t #define __IDMAP_NODE_T sys_node_t
#define __MAKE_IMAP_NODE __new_sys_node #define __INIT_IDMAP_LIST __init_sys_list
#define __FREE_IMAP_NODE __free_sys_node #define __FINI_IDMAP_LIST __fini_sys_list
#include "imap-imp.h" #define __MAKE_IDMAP_NODE __new_sys_node
#define __FREE_IDMAP_NODE __free_sys_node
#include "idmap-imp.h"
struct rtx_data_t struct rtx_data_t
{ {
@ -713,7 +715,7 @@ static int fnc_write (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
{ {
hawk_bch_t* dptr; hawk_bch_t* dptr;
hawk_oow_t dlen; hawk_oow_t dlen;
hawk_ooi_t startpos = 0, maxlen = HAWK_TYPE_MAX(hawk_ooi_t); hawk_int_t startpos = 0, maxlen = HAWK_TYPE_MAX(hawk_int_t);
hawk_val_t* a1; hawk_val_t* a1;
if (hawk_rtx_getnargs(rtx) >= 3 && (hawk_rtx_valtoint(rtx, hawk_rtx_getarg(rtx, 2), &startpos) <= -1 || startpos < 0)) startpos = 0; if (hawk_rtx_getnargs(rtx) >= 3 && (hawk_rtx_valtoint(rtx, hawk_rtx_getarg(rtx, 2), &startpos) <= -1 || startpos < 0)) startpos = 0;
@ -4762,14 +4764,19 @@ static int query (hawk_mod_t* mod, hawk_t* awk, const hawk_ooch_t* name, hawk_mo
static int init (hawk_mod_t* mod, hawk_rtx_t* rtx) static int init (hawk_mod_t* mod, hawk_rtx_t* rtx)
{ {
mod_ctx_t* mctx = (mod_ctx_t*)mod->ctx; mod_ctx_t* mctx = (mod_ctx_t*)mod->ctx;
rtx_data_t data; rtx_data_t data, * datap;
hawk_rbt_pair_t* pair;
mctx->log.type = SYSLOG_LOCAL; mctx->log.type = SYSLOG_LOCAL;
mctx->log.syslog_opened = 0; mctx->log.syslog_opened = 0;
mctx->log.sck = -1; mctx->log.sck = -1;
HAWK_MEMSET (&data, 0, HAWK_SIZEOF(data)); HAWK_MEMSET (&data, 0, HAWK_SIZEOF(data));
if (hawk_rbt_insert(mctx->rtxtab, &rtx, HAWK_SIZEOF(rtx), &data, HAWK_SIZEOF(data)) == HAWK_NULL) return -1; pair = hawk_rbt_insert(mctx->rtxtab, &rtx, HAWK_SIZEOF(rtx), &data, HAWK_SIZEOF(data));
if (HAWK_UNLIKELY(!pair)) return -1;
datap = (rtx_data_t*)HAWK_RBT_VPTR(pair);
__init_sys_list (rtx, &datap->sys_list);
return 0; return 0;
} }
@ -4789,24 +4796,19 @@ static void fini (hawk_mod_t* mod, hawk_rtx_t* rtx)
if (pair) if (pair)
{ {
rtx_data_t* data; rtx_data_t* data;
sys_node_t* sys_node, * sys_next;
data = (rtx_data_t*)HAWK_RBT_VPTR(pair); data = (rtx_data_t*)HAWK_RBT_VPTR(pair);
sys_node = data->sys_list.head;
while (sys_node)
{
sys_next = sys_node->next;
free_sys_node (rtx, &data->sys_list, sys_node);
sys_node = sys_next;
}
if (data->sys_list.ctx.readbuf) if (data->sys_list.ctx.readbuf)
{ {
hawk_rtx_freemem (rtx, data->sys_list.ctx.readbuf); hawk_rtx_freemem (rtx, data->sys_list.ctx.readbuf);
data->sys_list.ctx.readbuf = HAWK_NULL; data->sys_list.ctx.readbuf = HAWK_NULL;
data->sys_list.ctx.readbuf_capa = 0; data->sys_list.ctx.readbuf_capa = 0;
} }
__fini_sys_list (rtx, &data->sys_list);
hawk_rbt_delete (mctx->rtxtab, &rtx, HAWK_SIZEOF(rtx)); hawk_rbt_delete (mctx->rtxtab, &rtx, HAWK_SIZEOF(rtx));
} }

View File

@ -68,7 +68,7 @@ struct hawk_val_rchunk_t
#define IS_STATICVAL(val) ((val) == HAWK_NULL || (val) == hawk_val_nil || (val) == hawk_val_zls || (val) == hawk_val_zlm) #define IS_STATICVAL(val) ((val) == HAWK_NULL || (val) == hawk_val_nil || (val) == hawk_val_zls || (val) == hawk_val_zlm)
*/ */
#define IS_STATICVAL(val) ((val)->stat) #define IS_STATICVAL(val) ((val)->v_static)
/* hawk_val_t pointer encoding assumes the pointer is an even number. /* hawk_val_t pointer encoding assumes the pointer is an even number.

View File

@ -36,6 +36,22 @@ hawk_val_t* hawk_val_nil = (hawk_val_t*)&awk_nil;
hawk_val_t* hawk_val_zls = (hawk_val_t*)&awk_zls; hawk_val_t* hawk_val_zls = (hawk_val_t*)&awk_zls;
hawk_val_t* hawk_val_zlm = (hawk_val_t*)&awk_zlm; hawk_val_t* hawk_val_zlm = (hawk_val_t*)&awk_zlm;
/* --------------------------------------------------------------------- */
/* TOOD: */
static hawk_val_t* gc_calloc (hawk_rtx_t* rtx, hawk_oow_t size)
{
hawk_gc_info_t* gci;
gci = (hawk_gc_info_t*)hawk_rtx_callocmem(rtx, HAWK_SIZEOF(*gci) + size);
if (HAWK_UNLIKELY(!gci)) return HAWK_NULL;
return hawk_gcinfo_to_val(gci);
}
/* --------------------------------------------------------------------- */
hawk_val_t* hawk_get_awk_nil_val (void) hawk_val_t* hawk_get_awk_nil_val (void)
{ {
return (hawk_val_t*)&awk_nil; return (hawk_val_t*)&awk_nil;
@ -95,8 +111,8 @@ hawk_val_t* hawk_rtx_makeintval (hawk_rtx_t* rtx, hawk_int_t v)
rtx->vmgr.ifree = (hawk_val_int_t*)val->nde; rtx->vmgr.ifree = (hawk_val_int_t*)val->nde;
val->v_type = HAWK_VAL_INT; val->v_type = HAWK_VAL_INT;
val->ref = 0; val->v_refs = 0;
val->stat = 0; val->v_static = 0;
val->nstr = 0; val->nstr = 0;
val->fcb = 0; val->fcb = 0;
val->i_val = v; val->i_val = v;
@ -146,8 +162,8 @@ hawk_val_t* hawk_rtx_makefltval (hawk_rtx_t* rtx, hawk_flt_t v)
rtx->vmgr.rfree = (hawk_val_flt_t*)val->nde; rtx->vmgr.rfree = (hawk_val_flt_t*)val->nde;
val->v_type = HAWK_VAL_FLT; val->v_type = HAWK_VAL_FLT;
val->ref = 0; val->v_refs = 0;
val->stat = 0; val->v_static = 0;
val->nstr = 0; val->nstr = 0;
val->fcb = 0; val->fcb = 0;
val->val = v; val->val = v;
@ -189,8 +205,8 @@ static HAWK_INLINE hawk_val_t* make_str_val (hawk_rtx_t* rtx, const hawk_ooch_t*
init: init:
#endif #endif
val->v_type = HAWK_VAL_STR; val->v_type = HAWK_VAL_STR;
val->ref = 0; val->v_refs = 0;
val->stat = 0; val->v_static = 0;
val->nstr = 0; val->nstr = 0;
val->fcb = 0; val->fcb = 0;
val->val.len = len1 + len2; val->val.len = len1 + len2;
@ -337,8 +353,7 @@ hawk_val_t* hawk_rtx_makenstrvalwithuchars (hawk_rtx_t* rtx, const hawk_uch_t* p
x = hawk_uchars_to_num(HAWK_OOCHARS_TO_NUM_MAKE_OPTION(1, 0, HAWK_RTX_IS_STRIPSTRSPC_ON(rtx), 0), ptr, len, &l, &r); x = hawk_uchars_to_num(HAWK_OOCHARS_TO_NUM_MAKE_OPTION(1, 0, HAWK_RTX_IS_STRIPSTRSPC_ON(rtx), 0), ptr, len, &l, &r);
v = hawk_rtx_makestrvalwithuchars(rtx, ptr, len); v = hawk_rtx_makestrvalwithuchars(rtx, ptr, len);
if (HAWK_UNLIKELY(!v)) return HAWK_NULL;
if (!v) return HAWK_NULL;
if (x >= 0) if (x >= 0)
{ {
@ -360,8 +375,7 @@ hawk_val_t* hawk_rtx_makenstrvalwithbchars (hawk_rtx_t* rtx, const hawk_bch_t* p
x = hawk_bchars_to_num(HAWK_OOCHARS_TO_NUM_MAKE_OPTION(1, 0, HAWK_RTX_IS_STRIPSTRSPC_ON(rtx), 0), ptr, len, &l, &r); x = hawk_bchars_to_num(HAWK_OOCHARS_TO_NUM_MAKE_OPTION(1, 0, HAWK_RTX_IS_STRIPSTRSPC_ON(rtx), 0), ptr, len, &l, &r);
v = hawk_rtx_makestrvalwithbchars(rtx, ptr, len); v = hawk_rtx_makestrvalwithbchars(rtx, ptr, len);
if (HAWK_UNLIKELY(!v)) return HAWK_NULL;
if (!v) return HAWK_NULL;
if (x >= 0) if (x >= 0)
{ {
@ -410,8 +424,8 @@ hawk_val_t* hawk_rtx_makembsvalwithbchars (hawk_rtx_t* rtx, const hawk_bch_t* pt
if (HAWK_UNLIKELY(!val)) return HAWK_NULL; if (HAWK_UNLIKELY(!val)) return HAWK_NULL;
val->v_type = HAWK_VAL_MBS; val->v_type = HAWK_VAL_MBS;
val->ref = 0; val->v_refs = 0;
val->stat = 0; val->v_static = 0;
val->nstr = 0; val->nstr = 0;
val->fcb = 0; val->fcb = 0;
val->val.len = len; val->val.len = len;
@ -496,8 +510,8 @@ hawk_val_t* hawk_rtx_makerexval (hawk_rtx_t* rtx, const hawk_oocs_t* str, hawk_t
if (HAWK_UNLIKELY(!val)) return HAWK_NULL; if (HAWK_UNLIKELY(!val)) return HAWK_NULL;
val->v_type = HAWK_VAL_REX; val->v_type = HAWK_VAL_REX;
val->ref = 0; val->v_refs = 0;
val->stat = 0; val->v_static = 0;
val->nstr = 0; val->nstr = 0;
val->fcb = 0; val->fcb = 0;
val->str.len = str->len; val->str.len = str->len;
@ -549,17 +563,19 @@ hawk_val_t* hawk_rtx_makemapval (hawk_rtx_t* rtx)
}, },
HAWK_MAP_COMPER_DEFAULT, HAWK_MAP_COMPER_DEFAULT,
same_mapval, same_mapval,
#if defined(HAWK_MAP_IS_HTB)
HAWK_MAP_SIZER_DEFAULT, HAWK_MAP_SIZER_DEFAULT,
HAWK_MAP_HASHER_DEFAULT HAWK_MAP_HASHER_DEFAULT
#endif
}; };
hawk_val_map_t* val; hawk_val_map_t* val;
val = (hawk_val_map_t*)hawk_rtx_callocmem(rtx, HAWK_SIZEOF(hawk_val_map_t) + HAWK_SIZEOF(hawk_map_t) + HAWK_SIZEOF(rtx)); val = (hawk_val_map_t*)hawk_rtx_callocmem(rtx, HAWK_SIZEOF(hawk_val_map_t) + HAWK_SIZEOF(hawk_map_t) + HAWK_SIZEOF(rtx));
if (!val) return HAWK_NULL; if (HAWK_UNLIKELY(!val)) return HAWK_NULL;
val->v_type = HAWK_VAL_MAP; val->v_type = HAWK_VAL_MAP;
val->ref = 0; val->v_refs = 0;
val->stat = 0; val->v_static = 0;
val->nstr = 0; val->nstr = 0;
val->fcb = 0; val->fcb = 0;
val->map = (hawk_map_t*)(val + 1); val->map = (hawk_map_t*)(val + 1);
@ -734,8 +750,8 @@ hawk_val_t* hawk_rtx_makefunval (hawk_rtx_t* rtx, const hawk_fun_t* fun)
if (HAWK_UNLIKELY(!val)) return HAWK_NULL; if (HAWK_UNLIKELY(!val)) return HAWK_NULL;
val->v_type = HAWK_VAL_FUN; val->v_type = HAWK_VAL_FUN;
val->ref = 0; val->v_refs = 0;
val->stat = 0; val->v_static = 0;
val->nstr = 0; val->nstr = 0;
val->fcb = 0; val->fcb = 0;
val->fun = (hawk_fun_t*)fun; val->fun = (hawk_fun_t*)fun;
@ -888,9 +904,9 @@ void hawk_rtx_refupval (hawk_rtx_t* rtx, hawk_val_t* val)
if (IS_STATICVAL(val)) return; if (IS_STATICVAL(val)) return;
#if defined(DEBUG_VAL) #if defined(DEBUG_VAL)
hawk_logfmt (hawk_rtx_gethawk(rtx), HAWK_T("ref up [ptr=%p] [count=%d] - [%O]\n"), val, (int)val->ref, val); hawk_logfmt (hawk_rtx_gethawk(rtx), HAWK_T("ref up [ptr=%p] [count=%d] - [%O]\n"), val, (int)val->v_refs, val);
#endif #endif
val->ref++; val->v_refs++;
} }
} }
@ -901,15 +917,14 @@ void hawk_rtx_refdownval (hawk_rtx_t* rtx, hawk_val_t* val)
if (IS_STATICVAL(val)) return; if (IS_STATICVAL(val)) return;
#if defined(DEBUG_VAL) #if defined(DEBUG_VAL)
hawk_logfmt (hawk_rtx_gethawk(rtx), HAWK_T("ref down [ptr=%p] [count=%d] - [%O]\n"), val, (int)val->ref, val); hawk_logfmt (hawk_rtx_gethawk(rtx), HAWK_T("ref down [ptr=%p] [count=%d] - [%O]\n"), val, (int)val->v_refs, val);
#endif #endif
/* the reference count of a value should be greater than zero for it to be decremented. check the source code for any bugs */ /* the reference count of a value should be greater than zero for it to be decremented. check the source code for any bugs */
HAWK_ASSERT (val->ref > 0); HAWK_ASSERT (val->v_refs > 0);
val->ref--; val->v_refs--;
if (val->ref <= 0) if (val->v_refs <= 0)
{ {
hawk_rtx_freeval(rtx, val, 1); hawk_rtx_freeval(rtx, val, 1);
} }
@ -923,9 +938,9 @@ void hawk_rtx_refdownval_nofree (hawk_rtx_t* rtx, hawk_val_t* val)
if (IS_STATICVAL(val)) return; if (IS_STATICVAL(val)) return;
/* the reference count of a value should be greater than zero for it to be decremented. check the source code for any bugs */ /* the reference count of a value should be greater than zero for it to be decremented. check the source code for any bugs */
HAWK_ASSERT (val->ref > 0); HAWK_ASSERT (val->v_refs > 0);
val->ref--; val->v_refs--;
} }
} }

View File

@ -49,43 +49,53 @@ struct param_data_t
typedef struct param_data_t param_data_t; typedef struct param_data_t param_data_t;
typedef struct param_data_t res_data_t; typedef struct param_data_t res_data_t;
#define __IMAP_NODE_T_DATA MYSQL* mysql; int connect_ever_attempted; #define __IDMAP_NODE_T_DATA MYSQL* mysql; int connect_ever_attempted;
#define __IMAP_LIST_T_DATA int errnum; hawk_ooch_t errmsg[256]; #define __IDMAP_LIST_T_DATA int errnum; hawk_ooch_t errmsg[256];
#define __IMAP_LIST_T sql_list_t #define __IDMAP_LIST_T sql_list_t
#define __IMAP_NODE_T sql_node_t #define __IDMAP_NODE_T sql_node_t
#define __MAKE_IMAP_NODE __new_sql_node #define __INIT_IDMAP_LIST __init_sql_list
#define __FREE_IMAP_NODE __free_sql_node #define __FINI_IDMAP_LIST __fini_sql_list
#include "../lib/imap-imp.h" #define __MAKE_IDMAP_NODE __new_sql_node
#define __FREE_IDMAP_NODE __free_sql_node
#include "../lib/idmap-imp.h"
#undef __IMAP_NODE_T_DATA #undef __IDMAP_NODE_T_DATA
#undef __IMAP_LIST_T_DATA #undef __IDMAP_LIST_T_DATA
#undef __IMAP_LIST_T #undef __IDMAP_LIST_T
#undef __IMAP_NODE_T #undef __IDMAP_NODE_T
#undef __MAKE_IMAP_NODE #undef __INIT_IDMAP_LIST
#undef __FREE_IMAP_NODE #undef __FINI_IDMAP_LIST
#undef __MAKE_IDMAP_NODE
#undef __FREE_IDMAP_NODE
#define __IMAP_NODE_T_DATA MYSQL_RES* res; unsigned int num_fields; #define __IDMAP_NODE_T_DATA MYSQL_RES* res; unsigned int num_fields;
#define __IMAP_LIST_T_DATA /* int errnum; */ #define __IDMAP_LIST_T_DATA /* int errnum; */
#define __IMAP_LIST_T res_list_t #define __IDMAP_LIST_T res_list_t
#define __IMAP_NODE_T res_node_t #define __IDMAP_NODE_T res_node_t
#define __MAKE_IMAP_NODE __new_res_node #define __INIT_IDMAP_LIST __init_res_list
#define __FREE_IMAP_NODE __free_res_node #define __FINI_IDMAP_LIST __fini_res_list
#include "../lib/imap-imp.h" #define __MAKE_IDMAP_NODE __new_res_node
#define __FREE_IDMAP_NODE __free_res_node
#include "../lib/idmap-imp.h"
#undef __IMAP_NODE_T_DATA #undef __IDMAP_NODE_T_DATA
#undef __IMAP_LIST_T_DATA #undef __IDMAP_LIST_T_DATA
#undef __IMAP_LIST_T #undef __IDMAP_LIST_T
#undef __IMAP_NODE_T #undef __IDMAP_NODE_T
#undef __MAKE_IMAP_NODE #undef __INIT_IDMAP_LIST
#undef __FREE_IMAP_NODE #undef __FINI_IDMAP_LIST
#undef __MAKE_IDMAP_NODE
#undef __FREE_IDMAP_NODE
#define __IMAP_NODE_T_DATA MYSQL_STMT* stmt; MYSQL_BIND* param_binds; param_data_t* param_data; hawk_oow_t param_capa; MYSQL_BIND* res_binds; res_data_t* res_data; hawk_oow_t res_capa; #define __IDMAP_NODE_T_DATA MYSQL_STMT* stmt; MYSQL_BIND* param_binds; param_data_t* param_data; hawk_oow_t param_capa; MYSQL_BIND* res_binds; res_data_t* res_data; hawk_oow_t res_capa;
#define __IMAP_LIST_T_DATA /* int errnum; */ #define __IDMAP_LIST_T_DATA /* int errnum; */
#define __IMAP_LIST_T stmt_list_t #define __IDMAP_LIST_T stmt_list_t
#define __IMAP_NODE_T stmt_node_t #define __IDMAP_NODE_T stmt_node_t
#define __MAKE_IMAP_NODE __new_stmt_node #define __INIT_IDMAP_LIST __init_stmt_list
#define __FREE_IMAP_NODE __free_stmt_node #define __FINI_IDMAP_LIST __fini_stmt_list
#include "../lib/imap-imp.h" #define __MAKE_IDMAP_NODE __new_stmt_node
#define __FREE_IDMAP_NODE __free_stmt_node
#include "../lib/idmap-imp.h"
struct rtx_data_t struct rtx_data_t
{ {
@ -1832,12 +1842,19 @@ static int query (hawk_mod_t* mod, hawk_t* awk, const hawk_ooch_t* name, hawk_mo
static int init (hawk_mod_t* mod, hawk_rtx_t* rtx) static int init (hawk_mod_t* mod, hawk_rtx_t* rtx)
{ {
hawk_rbt_t* rbt; hawk_rbt_t* rbt;
rtx_data_t data; rtx_data_t data, * datap;
hawk_rbt_pair_t* pair;
rbt = (hawk_rbt_t*)mod->ctx; rbt = (hawk_rbt_t*)mod->ctx;
HAWK_MEMSET (&data, 0, HAWK_SIZEOF(data)); HAWK_MEMSET (&data, 0, HAWK_SIZEOF(data));
if (hawk_rbt_insert(rbt, &rtx, HAWK_SIZEOF(rtx), &data, HAWK_SIZEOF(data)) == HAWK_NULL) return -1; pair = hawk_rbt_insert(rbt, &rtx, HAWK_SIZEOF(rtx), &data, HAWK_SIZEOF(data));
if (HAWK_UNLIKELY(!pair)) return -1;
datap = (rtx_data_t*)HAWK_RBT_VPTR(pair);
__init_sql_list (rtx, &datap->sql_list);
__init_res_list (rtx, &datap->res_list);
__init_stmt_list (rtx, &datap->stmt_list);
return 0; return 0;
} }
@ -1854,26 +1871,12 @@ static void fini (hawk_mod_t* mod, hawk_rtx_t* rtx)
if (pair) if (pair)
{ {
rtx_data_t* data; rtx_data_t* data;
sql_node_t* sql_node, * sql_next;
res_node_t* res_node, * res_next;
data = (rtx_data_t*)HAWK_RBT_VPTR(pair); data = (rtx_data_t*)HAWK_RBT_VPTR(pair);
res_node = data->res_list.head; __fini_stmt_list (rtx, &data->stmt_list);
while (res_node) __fini_res_list (rtx, &data->res_list);
{ __fini_sql_list (rtx, &data->sql_list);
res_next = res_node->next;
free_res_node (rtx, &data->res_list, res_node);
res_node = res_next;
}
sql_node = data->sql_list.head;
while (sql_node)
{
sql_next = sql_node->next;
free_sql_node (rtx, &data->sql_list, sql_node);
sql_node = sql_next;
}
hawk_rbt_delete (rbt, &rtx, HAWK_SIZEOF(rtx)); hawk_rbt_delete (rbt, &rtx, HAWK_SIZEOF(rtx));
} }
@ -1901,7 +1904,7 @@ int hawk_mod_mysql (hawk_mod_t* mod, hawk_t* hawk)
mod->fini = fini; mod->fini = fini;
rbt = hawk_rbt_open(hawk_getgem(hawk), 0, 1, 1); rbt = hawk_rbt_open(hawk_getgem(hawk), 0, 1, 1);
if (rbt == HAWK_NULL) return -1; if (HAWK_UNLIKELY(!rbt)) return -1;
hawk_rbt_setstyle (rbt, hawk_get_rbt_style(HAWK_RBT_STYLE_INLINE_COPIERS)); hawk_rbt_setstyle (rbt, hawk_get_rbt_style(HAWK_RBT_STYLE_INLINE_COPIERS));