diff --git a/ase/awk/awk.c b/ase/awk/awk.c index 1c887b0d..2ada3640 100644 --- a/ase/awk/awk.c +++ b/ase/awk/awk.c @@ -1,5 +1,5 @@ /* - * $Id: awk.c,v 1.70 2006-08-13 16:04:32 bacon Exp $ + * $Id: awk.c,v 1.71 2006-08-31 04:21:03 bacon Exp $ */ #include @@ -11,16 +11,21 @@ static void __free_afn (void* awk, void* afn); -xp_awk_t* xp_awk_open (xp_awk_thrlks_t* thrlks) +xp_awk_t* xp_awk_open (xp_awk_syscas_t* syscas) { xp_awk_t* awk; - awk = (xp_awk_t*) xp_malloc (xp_sizeof(xp_awk_t)); + if (syscas == XP_NULL || + syscas->malloc == XP_NULL || + syscas->free == XP_NULL) return XP_NULL; + + awk = (xp_awk_t*) syscas->malloc ( + xp_sizeof(xp_awk_t), syscas->custom_data); if (awk == XP_NULL) return XP_NULL; if (xp_str_open (&awk->token.name, 128) == XP_NULL) { - xp_free (awk); + syscas->free (awk, syscas->custom_data); return XP_NULL; } @@ -29,7 +34,7 @@ xp_awk_t* xp_awk_open (xp_awk_thrlks_t* thrlks) &awk->tree.afns, awk, 256, __free_afn) == XP_NULL) { xp_str_close (&awk->token.name); - xp_free (awk); + syscas->free (awk, syscas->custom_data); return XP_NULL; } @@ -37,7 +42,7 @@ xp_awk_t* xp_awk_open (xp_awk_thrlks_t* thrlks) { xp_str_close (&awk->token.name); xp_awk_map_close (&awk->tree.afns); - xp_free (awk); + syscas->free (awk, syscas->custom_data); return XP_NULL; } @@ -46,7 +51,7 @@ xp_awk_t* xp_awk_open (xp_awk_thrlks_t* thrlks) xp_str_close (&awk->token.name); xp_awk_map_close (&awk->tree.afns); xp_awk_tab_close (&awk->parse.globals); - xp_free (awk); + syscas->free (awk, syscas->custom_data); return XP_NULL; } @@ -56,7 +61,7 @@ xp_awk_t* xp_awk_open (xp_awk_thrlks_t* thrlks) xp_awk_map_close (&awk->tree.afns); xp_awk_tab_close (&awk->parse.globals); xp_awk_tab_close (&awk->parse.locals); - xp_free (awk); + syscas->free (awk, syscas->custom_data); return XP_NULL; } @@ -92,7 +97,7 @@ xp_awk_t* xp_awk_open (xp_awk_thrlks_t* thrlks) awk->run.count = 0; awk->run.ptr = XP_NULL; - awk->thr.lks = thrlks; + awk->syscas = syscas; return awk; } @@ -108,7 +113,7 @@ int xp_awk_close (xp_awk_t* awk) xp_awk_tab_close (&awk->parse.params); xp_str_close (&awk->token.name); - xp_free (awk); + awk->syscas->free (awk, awk->syscas->custom_data); return 0; } diff --git a/ase/awk/awk.h b/ase/awk/awk.h index fcd002bb..1c6d5e95 100644 --- a/ase/awk/awk.h +++ b/ase/awk/awk.h @@ -1,5 +1,5 @@ /* - * $Id: awk.h,v 1.103 2006-08-29 15:01:44 bacon Exp $ + * $Id: awk.h,v 1.104 2006-08-31 04:21:03 bacon Exp $ */ #ifndef _XP_AWK_AWK_H_ @@ -12,7 +12,7 @@ typedef struct xp_awk_t xp_awk_t; typedef struct xp_awk_val_t xp_awk_val_t; typedef struct xp_awk_extio_t xp_awk_extio_t; -typedef struct xp_awk_thrlks_t xp_awk_thrlks_t; +typedef struct xp_awk_syscas_t xp_awk_syscas_t; typedef struct xp_awk_srcios_t xp_awk_srcios_t; typedef struct xp_awk_runios_t xp_awk_runios_t; typedef struct xp_awk_runcbs_t xp_awk_runcbs_t; @@ -40,12 +40,27 @@ struct xp_awk_extio_t xp_awk_extio_t* next; }; +/* struct xp_awk_thrlks_t { xp_awk_lk_t lock; xp_awk_lk_t unlock; void* custom_data; }; +*/ +struct xp_awk_syscas_t +{ + /* memory */ + void* (*malloc) (xp_size_t n, void* custom_data); + void* (*realloc) (void* ptr, xp_size_t n, void* custom_data); + void (*free) (void* ptr, void* custom_data); + + /* thread lock */ + xp_awk_lk_t lock; + xp_awk_lk_t unlock; + + void* custom_data; +}; struct xp_awk_srcios_t { @@ -69,6 +84,7 @@ struct xp_awk_runcbs_t void* custom_data; }; + /* io function commands */ enum { @@ -258,7 +274,7 @@ enum extern "C" { #endif -xp_awk_t* xp_awk_open (xp_awk_thrlks_t* thrlks); +xp_awk_t* xp_awk_open (xp_awk_syscas_t* syscas); int xp_awk_close (xp_awk_t* awk); int xp_awk_clear (xp_awk_t* awk); diff --git a/ase/awk/awk_i.h b/ase/awk/awk_i.h index 5204f84d..2e35894d 100644 --- a/ase/awk/awk_i.h +++ b/ase/awk/awk_i.h @@ -1,5 +1,5 @@ /* - * $Id: awk_i.h,v 1.47 2006-08-29 15:01:44 bacon Exp $ + * $Id: awk_i.h,v 1.48 2006-08-31 04:21:03 bacon Exp $ */ #ifndef _XP_AWK_AWKI_H_ @@ -127,10 +127,7 @@ struct xp_awk_t xp_awk_run_t* ptr; } run; - struct - { - xp_awk_thrlks_t* lks; - } thr; + xp_awk_syscas_t* syscas; /* housekeeping */ int errnum; diff --git a/ase/awk/run.c b/ase/awk/run.c index fc555cd8..01148842 100644 --- a/ase/awk/run.c +++ b/ase/awk/run.c @@ -1,5 +1,5 @@ /* - * $Id: run.c,v 1.185 2006-08-30 14:25:33 bacon Exp $ + * $Id: run.c,v 1.186 2006-08-31 04:21:03 bacon Exp $ */ #include @@ -363,8 +363,8 @@ int xp_awk_stop (xp_awk_t* awk, void* run) xp_awk_run_t* r; int n = 0; - if (awk->thr.lks != XP_NULL) - awk->thr.lks->lock (awk, awk->thr.lks->custom_data); + if (awk->syscas != XP_NULL && awk->syscas->lock != XP_NULL) + awk->syscas->lock (awk, awk->syscas->custom_data); /* check if the run handle given is valid */ for (r = awk->run.ptr; r != XP_NULL; r = r->next) @@ -385,8 +385,8 @@ int xp_awk_stop (xp_awk_t* awk, void* run) n = -1; } - if (awk->thr.lks != XP_NULL) - awk->thr.lks->unlock (awk, awk->thr.lks->custom_data); + if (awk->syscas != XP_NULL && awk->syscas->unlock != XP_NULL) + awk->syscas->unlock (awk, awk->syscas->custom_data); return n; } @@ -395,16 +395,16 @@ void xp_awk_stopall (xp_awk_t* awk) { xp_awk_run_t* r; - if (awk->thr.lks != XP_NULL) - awk->thr.lks->lock (awk, awk->thr.lks->custom_data); + if (awk->syscas != XP_NULL && awk->syscas->lock != XP_NULL) + awk->syscas->lock (awk, awk->syscas->custom_data); for (r = awk->run.ptr; r != XP_NULL; r = r->next) { r->exit_level = EXIT_ABORT; } - if (awk->thr.lks != XP_NULL) - awk->thr.lks->unlock (awk, awk->thr.lks->custom_data); + if (awk->syscas != XP_NULL && awk->syscas->unlock != XP_NULL) + awk->syscas->unlock (awk, awk->syscas->custom_data); } int xp_awk_getrunerrnum (xp_awk_t* awk, void* run, int* errnum) @@ -412,8 +412,8 @@ int xp_awk_getrunerrnum (xp_awk_t* awk, void* run, int* errnum) xp_awk_run_t* r; int n = 0; - if (awk->thr.lks != XP_NULL) - awk->thr.lks->lock (awk, awk->thr.lks->custom_data); + if (awk->syscas != XP_NULL && awk->syscas->lock != XP_NULL) + awk->syscas->lock (awk, awk->syscas->custom_data); for (r = awk->run.ptr; r != XP_NULL; r = r->next) { @@ -431,8 +431,8 @@ int xp_awk_getrunerrnum (xp_awk_t* awk, void* run, int* errnum) n = -1; } - if (awk->thr.lks != XP_NULL) - awk->thr.lks->unlock (awk, awk->thr.lks->custom_data); + if (awk->syscas != XP_NULL && awk->syscas->unlock != XP_NULL) + awk->syscas->unlock (awk, awk->syscas->custom_data); return n; } @@ -444,8 +444,8 @@ static void __free_namedval (void* run, void* val) static void __add_run (xp_awk_t* awk, xp_awk_run_t* run) { - if (awk->thr.lks != XP_NULL) - awk->thr.lks->lock (awk, awk->thr.lks->custom_data); + if (awk->syscas != XP_NULL && awk->syscas->lock != XP_NULL) + awk->syscas->lock (awk, awk->syscas->custom_data); run->awk = awk; run->prev = XP_NULL; @@ -454,14 +454,14 @@ static void __add_run (xp_awk_t* awk, xp_awk_run_t* run) awk->run.ptr = run; awk->run.count++; - if (awk->thr.lks != XP_NULL) - awk->thr.lks->unlock (awk, awk->thr.lks->custom_data); + if (awk->syscas != XP_NULL && awk->syscas->unlock != XP_NULL) + awk->syscas->unlock (awk, awk->syscas->custom_data); } static void __del_run (xp_awk_t* awk, xp_awk_run_t* run) { - if (awk->thr.lks != XP_NULL) - awk->thr.lks->lock (awk, awk->thr.lks->custom_data); + if (awk->syscas != XP_NULL && awk->syscas->lock != XP_NULL) + awk->syscas->lock (awk, awk->syscas->custom_data); xp_assert (awk->run.ptr != XP_NULL); @@ -479,8 +479,8 @@ static void __del_run (xp_awk_t* awk, xp_awk_run_t* run) run->awk = XP_NULL; awk->run.count--; - if (awk->thr.lks != XP_NULL) - awk->thr.lks->unlock (awk, awk->thr.lks->custom_data); + if (awk->syscas != XP_NULL && awk->syscas->unlock != XP_NULL) + awk->syscas->unlock (awk, awk->syscas->custom_data); } static int __init_run ( diff --git a/ase/awk/sa.h b/ase/awk/sa.h index 4f9fe69d..3cc7cf30 100644 --- a/ase/awk/sa.h +++ b/ase/awk/sa.h @@ -1,5 +1,5 @@ /* - * $Id: sa.h,v 1.33 2006-08-30 14:23:19 bacon Exp $ + * $Id: sa.h,v 1.34 2006-08-31 04:21:04 bacon Exp $ */ #ifndef _XP_AWK_SA_H_ @@ -26,7 +26,9 @@ #define xp_memset(dst,fill,len) RtlFillMemory(dst,len,fill) #define xp_memcpy(dst,src,len) RtlCopyMemory(dst,src,len) - #define xp_memcmp(src1,src2,len) RtlCompareMemory(src1,src2,len); + #define xp_memmove(dst,src,len) RtlMoveMemory(dst,src,len) + #define xp_memcmp(src1,src2,len) RtlCompareMemory(src1,src2,len) + #define xp_memzero(dst,len) RtlZeroMemory(dst,len) #else #include #include @@ -53,7 +55,9 @@ #define xp_memset(dst,fill,len) memset(dst,fill,len) #define xp_memcpy(dst,src,len) memcpy(dst,src,len) - #define xp_memcmp(src1,src2,len) memcmp(src1,src2,len); + #define xp_memmove(dst,src,len) memmove(dst,src,len) + #define xp_memcmp(src1,src2,len) memcmp(src1,src2,len) + #define xp_memzero(dst,len) memset(dst,0,len) #ifdef XP_CHAR_IS_MCHAR #define xp_isdigit isdigit diff --git a/ase/test/awk/awk.c b/ase/test/awk/awk.c index f256b784..583c550a 100644 --- a/ase/test/awk/awk.c +++ b/ase/test/awk/awk.c @@ -1,5 +1,5 @@ /* - * $Id: awk.c,v 1.79 2006-08-30 07:15:14 bacon Exp $ + * $Id: awk.c,v 1.80 2006-08-31 04:21:04 bacon Exp $ */ #include @@ -548,6 +548,39 @@ static void __on_run_end (xp_awk_t* awk, void* handle, int errnum, void* arg) app_run = NULL; } +typedef struct syscas_data_t syscas_data_t; +struct syscas_data_t +{ + HANDLE heap; +}; + +static void* __awk_malloc (xp_size_t n, void* custom_data) +{ +#ifdef _WIN32 + return HeapAlloc (((syscas_data_t*)custom_data)->heap, 0, n); +#else + return malloc (n); +#endif +} + +static void* __awk_realloc (void* ptr, xp_size_t n, void* custom_data) +{ +#ifdef _WIN32 + return HeapReAlloc (((syscas_data_t*)custom_data)->heap, 0, ptr, n); +#else + return realloc (ptr, n); +#endif +} + +static void __awk_free (void* ptr, void* custom_data) +{ +#ifdef _WIN32 + HeapFree (((syscas_data_t*)custom_data)->heap, 0, ptr); +#else + free (ptr); +#endif +} + #if defined(__STAND_ALONE) && !defined(_WIN32) static int __main (int argc, char* argv[]) #else @@ -558,14 +591,12 @@ static int __main (int argc, xp_char_t* argv[]) xp_awk_srcios_t srcios; xp_awk_runcbs_t runcbs; xp_awk_runios_t runios; + xp_awk_syscas_t syscas; struct src_io src_io = { NULL, NULL }; int opt, i, file_count = 0; - - if ((awk = xp_awk_open(XP_NULL)) == XP_NULL) - { - xp_printf (XP_T("Error: cannot open awk\n")); - return -1; - } +#ifdef _WIN32 + syscas_data_t syscas_data; +#endif opt = XP_AWK_EXPLICIT | XP_AWK_UNIQUE | XP_AWK_HASHSIGN | /*XP_AWK_DBLSLASHES |*/ @@ -607,6 +638,33 @@ static int __main (int argc, xp_char_t* argv[]) } } + memset (&syscas, 0, sizeof(syscas)); + syscas.malloc = __awk_malloc; + syscas.realloc = NULL; + syscas.free = __awk_free; + syscas.lock = NULL; + syscas.unlock = NULL; + +#ifdef _WIN32 + syscas_data.heap = HeapCreate (0, 640 * 1024, 640 * 1024); + if (syscas_data.heap == NULL) + { + xp_printf (XP_T("Error: cannot create an awk heap\n")); + return -1; + } + + syscas.custom_data = &syscas_data; +#endif + + if ((awk = xp_awk_open(&syscas)) == XP_NULL) + { +#ifdef _WIN32 + HeapDestroy (syscas_data.heap); +#endif + xp_printf (XP_T("Error: cannot open awk\n")); + return -1; + } + xp_awk_setopt (awk, opt); srcios.in = process_source; @@ -664,6 +722,9 @@ static int __main (int argc, xp_char_t* argv[]) } xp_awk_close (awk); +#ifdef _WIN32 + HeapDestroy (syscas_data.heap); +#endif return 0; }