code touch-up for recent c language standard
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
9271fae745
commit
f928ce5ec8
@ -31,6 +31,13 @@
|
||||
#include <hawk-xma.h>
|
||||
#include <hawk-glob.h>
|
||||
|
||||
#if !defined(_GNU_SOURCE)
|
||||
# define _GNU_SOURCE
|
||||
#endif
|
||||
#if !defined(_XOPEN_SOURCE)
|
||||
# define _XOPEN_SOURCE 700
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
@ -38,7 +45,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <locale.h>
|
||||
|
||||
// #define ENABLE_CALLBACK TODO: enable this back
|
||||
/* #define ENABLE_CALLBACK TODO: enable this back */
|
||||
#define ABORT(label) goto label
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
@ -31,6 +31,13 @@
|
||||
#include <hawk-utl.h>
|
||||
#include <hawk-std.h>
|
||||
|
||||
#if !defined(_GNU_SOURCE)
|
||||
# define _GNU_SOURCE
|
||||
#endif
|
||||
#if !defined(_XOPEN_SOURCE)
|
||||
# define _XOPEN_SOURCE 700
|
||||
#endif
|
||||
|
||||
#include <locale.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
@ -31,6 +31,9 @@
|
||||
#elif defined(__DOS__)
|
||||
/* TODO: */
|
||||
#else
|
||||
# if !defined(_GNU_SOURCE)
|
||||
# define _GNU_SOURCE
|
||||
# endif
|
||||
# include "syscall.h"
|
||||
# include <sys/socket.h>
|
||||
# if defined(HAVE_SYS_IOCTL_H)
|
||||
@ -152,7 +155,7 @@ int hawk_gem_bcstrtoifindex (hawk_gem_t* gem, const hawk_bch_t* ptr, unsigned in
|
||||
|
||||
if (x >= 0)
|
||||
{
|
||||
#if defined(HAVE_STRUCT_IFREQ_IFR_IFINDEX)
|
||||
#if defined(HAVE_STRUCT_IFREQ_IFR_IFINDEX) || defined(ifr_ifindex)
|
||||
*index = ifr.ifr_ifindex;
|
||||
#else
|
||||
*index = ifr.ifr_index;
|
||||
@ -242,7 +245,7 @@ int hawk_gem_bcharstoifindex (hawk_gem_t* gem, const hawk_bch_t* ptr, hawk_oow_t
|
||||
|
||||
if (x >= 0)
|
||||
{
|
||||
#if defined(HAVE_STRUCT_IFREQ_IFR_IFINDEX)
|
||||
#if defined(HAVE_STRUCT_IFREQ_IFR_IFINDEX) || defined(ifr_ifindex)
|
||||
*index = ifr.ifr_ifindex;
|
||||
#else
|
||||
*index = ifr.ifr_index;
|
||||
@ -326,7 +329,7 @@ int hawk_gem_ucstrtoifindex (hawk_gem_t* gem, const hawk_uch_t* ptr, unsigned in
|
||||
|
||||
if (x >= 0)
|
||||
{
|
||||
#if defined(HAVE_STRUCT_IFREQ_IFR_IFINDEX)
|
||||
#if defined(HAVE_STRUCT_IFREQ_IFR_IFINDEX) || defined(ifr_ifindex)
|
||||
*index = ifr.ifr_ifindex;
|
||||
#else
|
||||
*index = ifr.ifr_index;
|
||||
@ -419,7 +422,7 @@ int hawk_gem_ucharstoifindex (hawk_gem_t* gem, const hawk_uch_t* ptr, hawk_oow_t
|
||||
|
||||
if (x >= 0)
|
||||
{
|
||||
#if defined(HAVE_STRUCT_IFREQ_IFR_IFINDEX)
|
||||
#if defined(HAVE_STRUCT_IFREQ_IFR_IFINDEX) || defined(ifr_ifindex)
|
||||
*index = ifr.ifr_ifindex;
|
||||
#else
|
||||
*index = ifr.ifr_index;
|
||||
@ -506,7 +509,7 @@ int hawk_gem_ifindextobcstr (hawk_gem_t* gem, unsigned int index, hawk_bch_t* bu
|
||||
}
|
||||
|
||||
HAWK_MEMSET (&ifr, 0, HAWK_SIZEOF(ifr));
|
||||
#if defined(HAVE_STRUCT_IFREQ_IFR_IFINDEX)
|
||||
#if defined(HAVE_STRUCT_IFREQ_IFR_IFINDEX) || defined(ifr_ifindex)
|
||||
ifr.ifr_ifindex = index;
|
||||
#else
|
||||
ifr.ifr_index = index;
|
||||
@ -587,7 +590,7 @@ int hawk_gem_ifindextoucstr (hawk_gem_t* gem, unsigned int index, hawk_uch_t* bu
|
||||
}
|
||||
|
||||
HAWK_MEMSET (&ifr, 0, HAWK_SIZEOF(ifr));
|
||||
#if defined(HAVE_STRUCT_IFREQ_IFR_IFINDEX)
|
||||
#if defined(HAVE_STRUCT_IFREQ_IFR_IFINDEX) || defined(ifr_ifindex)
|
||||
ifr.ifr_ifindex = index;
|
||||
#else
|
||||
ifr.ifr_index = index;
|
||||
|
@ -23,6 +23,8 @@
|
||||
*/
|
||||
|
||||
#if 1
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include "hawk-prv.h"
|
||||
#include "skad-prv.h"
|
||||
#include <hawk-sio.h>
|
||||
@ -50,6 +52,9 @@
|
||||
#elif defined(__DOS__)
|
||||
/* TODO: */
|
||||
#else
|
||||
# if !defined(_GNU_SOURCE)
|
||||
# define _GNU_SOURCE
|
||||
# endif
|
||||
# include "syscall.h"
|
||||
# include <sys/socket.h>
|
||||
# include <netinet/in.h>
|
||||
@ -639,7 +644,7 @@ static int get_ifcfg (hawk_gem_t* gem, int s, hawk_ifcfg_t* cfg, struct ifreq* i
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if defined(HAVE_STRUCT_IFREQ_IFR_IFINDEX)
|
||||
#if defined(HAVE_STRUCT_IFREQ_IFR_IFINDEX) || defined(ifr_ifindex)
|
||||
cfg->index = ifr->ifr_ifindex;
|
||||
#else
|
||||
cfg->index = ifr->ifr_index;
|
||||
|
@ -122,6 +122,10 @@
|
||||
# define HAWK_UNUSED
|
||||
#endif
|
||||
|
||||
#if !defined(__has_builtin)
|
||||
# define __has_builtin(v) 0
|
||||
#endif
|
||||
|
||||
/* =========================================================================
|
||||
* STATIC ASSERTION
|
||||
* =========================================================================*/
|
||||
@ -729,8 +733,16 @@ struct hawk_ntime_t
|
||||
* The HAWK_ALIGNOF() macro returns the alignment size of a structure.
|
||||
* Note that this macro may not work reliably depending on the type given.
|
||||
*/
|
||||
#define HAWK_ALIGNOF(type) HAWK_OFFSETOF(struct { hawk_uint8_t d1; type d2; }, d2)
|
||||
/*(sizeof(struct { hawk_uint8_t d1; type d2; }) - sizeof(type))*/
|
||||
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L) /* C23 */
|
||||
#define HAWK_ALIGNOF(type) alignof(type)
|
||||
#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) /* C11 */
|
||||
#define HAWK_ALIGNOF(type) _Alignof(type)
|
||||
#elif defined(__cplusplus) && (__cplusplus >= 201103L) /* C++11 */
|
||||
#define HAWK_ALIGNOF(type) alignof(type)
|
||||
#else
|
||||
#define HAWK_ALIGNOF(type) HAWK_OFFSETOF(struct { hcl_uint8_t d1; type d2; }, d2)
|
||||
/*(sizeof(struct { hcl_uint8_t d1; type d2; }) - sizeof(type))*/
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
# if (__cplusplus >= 201103L) /* C++11 */
|
||||
@ -1222,6 +1234,16 @@ typedef enum hawk_log_mask_t hawk_log_mask_t;
|
||||
#define HAWK_IS_UNALIGNED_POW2(x,y) ((x) & ((y) - 1))
|
||||
#define HAWK_IS_ALIGNED_POW2(x,y) (!HAWK_IS_UNALIGNED_POW2(x,y))
|
||||
|
||||
#if defined(__cplusplus) || (defined(__STDC_VERSION__) && (__STDC_VERSION__>=199901L))
|
||||
/* array index */
|
||||
#define HAWK_AID(x) [x]=
|
||||
/* struct field name */
|
||||
#define HAWK_SFN(x) .x=
|
||||
#else
|
||||
#define HAWK_AID(x)
|
||||
#define HAWK_SFN(x)
|
||||
#endif
|
||||
|
||||
/* =========================================================================
|
||||
* COMPILER FEATURE TEST MACROS
|
||||
* =========================================================================*/
|
||||
|
@ -598,11 +598,10 @@ static HAWK_INLINE void HAWK_RTX_STACK_POP (hawk_rtx_t* rtx)
|
||||
#define HAWK_RTX_STACK_POP(rtx) ((rtx)->stack_top--)
|
||||
#endif
|
||||
|
||||
|
||||
#define HAWK_RTX_INIT_REF_VAL(refval, _id, _adr, _nrefs) \
|
||||
do { \
|
||||
(refval)->v_type = HAWK_VAL_REF; \
|
||||
(refval)->v_refs = (_nrefs); \
|
||||
(refval)->v_type = HAWK_VAL_REF; \
|
||||
(refval)->v_static = 0; \
|
||||
(refval)->v_nstr = 0; \
|
||||
(refval)->v_gc = 0; \
|
||||
|
22
lib/hawk.h
22
lib/hawk.h
@ -157,26 +157,40 @@ static HAWK_INLINE hawk_gch_t* hawk_val_to_gch(hawk_val_t* v)
|
||||
/**
|
||||
* The #HAWK_VAL_HDR defines the common header for a value.
|
||||
* Three common fields are:
|
||||
* - v_type - type of a value from #hawk_val_type_t
|
||||
* - v_refs - reference count
|
||||
* - v_type - type of a value from #hawk_val_type_t
|
||||
* - v_static - static value indicator
|
||||
* - v_nstr - numeric string marker, 1 -> integer, 2 -> floating-point number
|
||||
* - v_gc - used for garbage collection together with v_refs
|
||||
*
|
||||
* [IMPORTANT]
|
||||
* if you change the order of these fields, you must ensure that statically
|
||||
* defined values follow this order strictly. for example, hawk_nil, hawk_zls,
|
||||
* hawk_zlbs are defined statically in val.c
|
||||
*/
|
||||
/*
|
||||
#define HAWK_VAL_HDR \
|
||||
unsigned int v_type: 4; \
|
||||
unsigned int v_refs: 24; \
|
||||
unsigned int v_type: 4; \
|
||||
unsigned int v_static: 1; \
|
||||
unsigned int v_nstr: 2; \
|
||||
unsigned int v_gc: 1
|
||||
*/
|
||||
|
||||
#define HAWK_VAL_HDR \
|
||||
hawk_uintptr_t v_type: 4; \
|
||||
hawk_uintptr_t v_refs: ((HAWK_SIZEOF_UINTPTR_T * 8) - 8); \
|
||||
hawk_uintptr_t v_type: 4; \
|
||||
hawk_uintptr_t v_static: 1; \
|
||||
hawk_uintptr_t v_nstr: 2; \
|
||||
hawk_uintptr_t v_gc: 1
|
||||
*/
|
||||
|
||||
/* regardless of architecture, use 4-byte reference count */
|
||||
#define HAWK_VAL_HDR \
|
||||
hawk_uint32_t v_refs; \
|
||||
hawk_uint8_t v_type: 4; \
|
||||
hawk_uint8_t v_static: 1; \
|
||||
hawk_uint8_t v_nstr: 2; \
|
||||
hawk_uint8_t v_gc: 1
|
||||
|
||||
/**
|
||||
* The hawk_val_t type is an abstract value type. A value commonly contains:
|
||||
|
@ -25,6 +25,9 @@
|
||||
#include "mod-math.h"
|
||||
#include "hawk-prv.h"
|
||||
|
||||
#if !defined(_GNU_SOURCE)
|
||||
# define _GNU_SOURCE
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
#include <math.h>
|
||||
|
@ -40,6 +40,9 @@
|
||||
/* implement this */
|
||||
|
||||
#else
|
||||
# if !defined(_GNU_SOURCE)
|
||||
# define _GNU_SOURCE
|
||||
# endif
|
||||
# include "syscall.h"
|
||||
# if defined(AIX) && defined(__GNUC__)
|
||||
typedef int crid_t;
|
||||
|
@ -37,6 +37,9 @@
|
||||
# include <io.h>
|
||||
# include <errno.h>
|
||||
#else
|
||||
# if !defined(_GNU_SOURCE)
|
||||
# define _GNU_SOURCE
|
||||
# endif
|
||||
# include "syscall.h"
|
||||
# if defined(HAVE_SPAWN_H)
|
||||
# include <spawn.h>
|
||||
|
@ -39,6 +39,9 @@
|
||||
# include <dos.h>
|
||||
# include <time.h>
|
||||
#else
|
||||
# if !defined(_GNU_SOURCE)
|
||||
# define _GNU_SOURCE
|
||||
# endif
|
||||
# include "syscall.h"
|
||||
# if defined(HAVE_SYS_TIME_H)
|
||||
# include <sys/time.h>
|
||||
|
46
lib/val.c
46
lib/val.c
@ -26,11 +26,35 @@
|
||||
|
||||
#define CHUNKSIZE HAWK_VAL_CHUNK_SIZE
|
||||
|
||||
static hawk_val_nil_t hawk_nil = { HAWK_VAL_NIL, 0, 1, 0, 0 };
|
||||
/* this isn't necessary as the implemenation is context(rtx)-centric
|
||||
* leave it here for experiment.
|
||||
#define USE_ATOMIC_REFCNT */
|
||||
|
||||
static hawk_val_nil_t hawk_nil = {
|
||||
HAWK_SFN(v_refs) 0,
|
||||
HAWK_SFN(v_type) HAWK_VAL_NIL,
|
||||
HAWK_SFN(v_static) 1,
|
||||
HAWK_SFN(v_nstr) 0,
|
||||
HAWK_SFN(v_gc) 0
|
||||
};
|
||||
/* zero-length string */
|
||||
static hawk_val_str_t hawk_zls = { HAWK_VAL_STR, 0, 1, 0, 0, { HAWK_T(""), 0 } };
|
||||
static hawk_val_str_t hawk_zls = {
|
||||
HAWK_SFN(v_refs) 0,
|
||||
HAWK_SFN(v_type) HAWK_VAL_STR,
|
||||
HAWK_SFN(v_static) 1,
|
||||
HAWK_SFN(v_nstr) 0,
|
||||
HAWK_SFN(v_gc) 0,
|
||||
HAWK_SFN(val) { HAWK_T(""), 0 }
|
||||
};
|
||||
/* zero-length byte string */
|
||||
static hawk_val_mbs_t hawk_zlbs = { HAWK_VAL_MBS, 0, 1, 0, 0, { HAWK_BT(""), 0 } };
|
||||
static hawk_val_mbs_t hawk_zlbs = {
|
||||
HAWK_SFN(v_refs) 0,
|
||||
HAWK_SFN(v_type) HAWK_VAL_MBS,
|
||||
HAWK_SFN(v_static) 1,
|
||||
HAWK_SFN(v_nstr) 0,
|
||||
HAWK_SFN(v_gc) 0,
|
||||
HAWK_SFN(val) { HAWK_BT(""), 0 }
|
||||
};
|
||||
|
||||
hawk_val_t* hawk_val_nil = (hawk_val_t*)&hawk_nil;
|
||||
hawk_val_t* hawk_val_zls = (hawk_val_t*)&hawk_zls;
|
||||
@ -1635,7 +1659,12 @@ void hawk_rtx_refupval (hawk_rtx_t* rtx, hawk_val_t* val)
|
||||
#if defined(DEBUG_VAL)
|
||||
hawk_logfmt (hawk_rtx_gethawk(rtx), HAWK_LOG_STDERR, HAWK_T("ref up [ptr=%p] [count=%d] - [%O]\n"), val, (int)val->v_refs, val);
|
||||
#endif
|
||||
|
||||
#if defined(USE_ATOMIC_REFCNT) && __has_builtin(__atomic_fetch_add)
|
||||
__atomic_fetch_add(&val->v_refs, 1, __ATOMIC_RELAXED);
|
||||
#else
|
||||
val->v_refs++;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -1652,11 +1681,18 @@ void hawk_rtx_refdownval (hawk_rtx_t* rtx, hawk_val_t* val)
|
||||
/* 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->v_refs > 0);
|
||||
|
||||
#if defined(USE_ATOMIC_REFCNT) && __has_builtin(__atomic_fetch_sub)
|
||||
if (__atomic_fetch_sub(&val->v_refs, 1, __ATOMIC_RELAXED) == 1)
|
||||
{
|
||||
hawk_rtx_freeval (rtx, val, HAWK_RTX_FREEVAL_CACHE);
|
||||
}
|
||||
#else
|
||||
val->v_refs--;
|
||||
if (val->v_refs <= 0)
|
||||
{
|
||||
hawk_rtx_freeval (rtx, val, HAWK_RTX_FREEVAL_CACHE);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -1669,7 +1705,11 @@ void hawk_rtx_refdownval_nofree (hawk_rtx_t* rtx, hawk_val_t* val)
|
||||
/* 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->v_refs > 0);
|
||||
|
||||
#if defined(USE_ATOMIC_REFCNT) && __has_builtin(__atomic_fetch_sub)
|
||||
__atomic_fetch_sub(&val->v_refs, 1, __ATOMIC_RELAXED);
|
||||
#else
|
||||
val->v_refs--;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user