From 5f91536a3860337da314e2e89fc9b7ba76857726 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Fri, 22 Dec 2023 11:53:29 +0900 Subject: [PATCH] code cleanup --- lib/gc.c | 2 +- lib/hcl-cmn.h | 19 ++++++++------- lib/hcl-dos.h | 2 +- lib/heap.c | 6 ++--- lib/std.c | 65 +++++++++++++++++---------------------------------- 5 files changed, 37 insertions(+), 57 deletions(-) diff --git a/lib/gc.c b/lib/gc.c index e73ddff..03476d9 100644 --- a/lib/gc.c +++ b/lib/gc.c @@ -745,7 +745,7 @@ hcl_oop_t hcl_shallowcopy (hcl_t* hcl, hcl_oop_t oop) total_bytes = HCL_SIZEOF(hcl_obj_t) + hcl_getobjpayloadbytes(hcl, oop); hcl_pushvolat (hcl, &oop); - z = (hcl_oop_t)hcl_allocbytes (hcl, total_bytes); + z = (hcl_oop_t)hcl_allocbytes(hcl, total_bytes); hcl_popvolat(hcl); HCL_MEMCPY (z, oop, total_bytes); diff --git a/lib/hcl-cmn.h b/lib/hcl-cmn.h index 1f2fe71..27808a5 100644 --- a/lib/hcl-cmn.h +++ b/lib/hcl-cmn.h @@ -35,7 +35,10 @@ # include #elif defined(__OS2__) # include -#elif defined(__DOS__) +#elif defined(__DOS__) || defined(__MSDOS__) +# if defined(__MSDOS__) && !defined(__DOS__) +# define __DOS__ __MSDOS__ +# endif # include #elif defined(macintosh) # include /* classic mac os */ @@ -756,28 +759,28 @@ typedef void (*hcl_mmgr_free_t) (hcl_mmgr_t* mmgr, void* ptr); */ struct hcl_mmgr_t { - hcl_mmgr_alloc_t alloc; /**< allocation function */ - hcl_mmgr_realloc_t realloc; /**< resizing function */ - hcl_mmgr_free_t free; /**< disposal function */ - void* ctx; /**< user-defined data pointer */ + hcl_mmgr_alloc_t allocmem; /**< allocation function */ + hcl_mmgr_realloc_t reallocmem; /**< resizing function */ + hcl_mmgr_free_t freemem; /**< disposal function */ + void* ctx; /**< user-defined data pointer */ }; /** * The HCL_MMGR_ALLOC() macro allocates a memory block of the \a size bytes * using the \a mmgr memory manager. */ -#define HCL_MMGR_ALLOC(mmgr,size) ((mmgr)->alloc(mmgr,size)) +#define HCL_MMGR_ALLOC(mmgr,size) ((mmgr)->allocmem(mmgr,size)) /** * The HCL_MMGR_REALLOC() macro resizes a memory block pointed to by \a ptr * to the \a size bytes using the \a mmgr memory manager. */ -#define HCL_MMGR_REALLOC(mmgr,ptr,size) ((mmgr)->realloc(mmgr,ptr,size)) +#define HCL_MMGR_REALLOC(mmgr,ptr,size) ((mmgr)->reallocmem(mmgr,ptr,size)) /** * The HCL_MMGR_FREE() macro deallocates the memory block pointed to by \a ptr. */ -#define HCL_MMGR_FREE(mmgr,ptr) ((mmgr)->free(mmgr,ptr)) +#define HCL_MMGR_FREE(mmgr,ptr) ((mmgr)->freemem(mmgr,ptr)) /* ========================================================================= diff --git a/lib/hcl-dos.h b/lib/hcl-dos.h index 1867496..cac7b94 100644 --- a/lib/hcl-dos.h +++ b/lib/hcl-dos.h @@ -79,7 +79,7 @@ # define HCL_SIZEOF_MBSTATE_T HCL_SIZEOF_LONG # define HCL_MBLEN_MAX 8 -#elif defined(__TURBOC__) +#elif defined(__TURBOC__) || defined(_MSC_VER) /* TODO: be more version specific wchar_t may be available in newer BCC */ # define HCL_SIZEOF_CHAR 1 # define HCL_SIZEOF_SHORT 2 diff --git a/lib/heap.c b/lib/heap.c index a9ab2e8..879147f 100644 --- a/lib/heap.c +++ b/lib/heap.c @@ -93,9 +93,9 @@ hcl_heap_t* hcl_makeheap (hcl_t* hcl, hcl_oow_t size) return HCL_NULL; } - heap->xmmgr.alloc = xma_alloc; - heap->xmmgr.realloc = xma_realloc; - heap->xmmgr.free = xma_free; + heap->xmmgr.allocmem = xma_alloc; + heap->xmmgr.reallocmem = xma_realloc; + heap->xmmgr.freemem = xma_free; heap->xmmgr.ctx = heap->xma; } diff --git a/lib/std.c b/lib/std.c index f6d0e3f..636c03b 100644 --- a/lib/std.c +++ b/lib/std.c @@ -108,10 +108,14 @@ # include # include /* inp, outp */ +# define DOS_EXIT 0x4C # if defined(_INTELC32_) -# define DOS_EXIT 0x4C # include # include +# elif defined(_MSC_VER) +# include +# define malloc(x) halloc(x, 1) +# define free(x) hfree(x) # else # include # endif @@ -413,26 +417,26 @@ struct xtn_t * BASIC MEMORY MANAGER * ----------------------------------------------------------------- */ -static void* sys_alloc (hcl_mmgr_t* mmgr, hcl_oow_t size) +static void* sys_allocmem (hcl_mmgr_t* mmgr, hcl_oow_t size) { return malloc(size); } -static void* sys_realloc (hcl_mmgr_t* mmgr, void* ptr, hcl_oow_t size) +static void* sys_reallocmem (hcl_mmgr_t* mmgr, void* ptr, hcl_oow_t size) { return realloc(ptr, size); } -static void sys_free (hcl_mmgr_t* mmgr, void* ptr) +static void sys_freemem (hcl_mmgr_t* mmgr, void* ptr) { free (ptr); } static hcl_mmgr_t sys_mmgr = { - sys_alloc, - sys_realloc, - sys_free, + sys_allocmem, + sys_reallocmem, + sys_freemem, HCL_NULL }; @@ -923,38 +927,6 @@ static void _assertfail (hcl_t* hcl, const hcl_bch_t* expr, const hcl_bch_t* fil * SYSTEM DEPENDENT HEADERS * -------------------------------------------------------------------------- */ -#if defined(_WIN32) -# include -# include -#elif defined(__OS2__) - -# define INCL_DOSERRORS -# include -#elif defined(__DOS__) -# include -# if defined(_INTELC32_) -# define DOS_EXIT 0x4C -# else -# include -# endif -# include -#elif defined(vms) || defined(__vms) -# define __NEW_STARLET 1 -# include /* (SYS$...) */ -# include /* (SS$...) */ -# include /* (lib$...) */ -#elif defined(macintosh) -# include -# include -# include -# include -#else -# include -# include -# include -# include -#endif - #if defined(HCL_ENABLE_LIBUNWIND) #include static void backtrace_stack_frames (hcl_t* hcl) @@ -1219,9 +1191,9 @@ void vm_gettime (hcl_t* hcl, hcl_ntime_t* now) bigmsec -= HCL_SEC_TO_MSEC(bigsec); HCL_INIT_NTIME (now, bigsec, HCL_MSEC_TO_NSEC(bigmsec)); #else - hcl_uint32_t bigsec, bigmsec; + hcl_uint32_t bigsec, bigmsec; - DosQuerySysInfo (QSV_MS_COUNT, QSV_MS_COUNT, &msec, HCL_SIZEOF(msec)); + DosQuerySysInfo (QSV_MS_COUNT, QSV_MS_COUNT, &msec, HCL_SIZEOF(msec)); bigsec = HCL_MSEC_TO_SEC(msec); bigmsec = msec - HCL_SEC_TO_MSEC(bigsec); if (msec < xtn->tc_last) @@ -1245,11 +1217,11 @@ void vm_gettime (hcl_t* hcl, hcl_ntime_t* now) HCL_INIT_NTIME (now, bigsec, HCL_MSEC_TO_NSEC(bigmsec)); #endif -#elif defined(__DOS__) && (defined(_INTELC32_) || defined(__WATCOMC__)) +#elif defined(__DOS__) clock_t c; /* TODO: handle overflow?? */ - c = clock (); + c = clock(); now->sec = c / CLOCKS_PER_SEC; #if (CLOCKS_PER_SEC == 100) now->nsec = HCL_MSEC_TO_NSEC((c % CLOCKS_PER_SEC) * 10); @@ -2277,6 +2249,8 @@ static void vm_muxwait (hcl_t* hcl, const hcl_ntime_t* dur, hcl_vmprim_muxwait_c # elif defined(__WATCOMC__) void _halt_cpu (void); # pragma aux _halt_cpu = "hlt" +# elif defined(_MSC_VER) + static void _halt_cpu (void) { _asm { hlt } } # endif #endif @@ -2307,7 +2281,7 @@ static int vm_sleep (hcl_t* hcl, const hcl_ntime_t* dur) /* TODO: ... */ -#elif defined(__DOS__) && (defined(_INTELC32_) || defined(__WATCOMC__)) +#elif defined(__DOS__) clock_t c; @@ -2862,6 +2836,9 @@ static int open_pipes (hcl_t* hcl, int p[2]) hcl_seterrbfmtwithsyserr (hcl, 2, sock_errno(), "unable to create pipes"); return -1; } +#elif defined(__DOS__) + hcl_seterrbfmt (hcl, HCL_ENOIMPL, "unable to create pipes - not supported"); + return -1; #elif defined(HAVE_PIPE2) && defined(O_CLOEXEC) && defined(O_NONBLOCK) if (pipe2(p, O_CLOEXEC | O_NONBLOCK) == -1) {