diff --git a/qse/Makefile.in b/qse/Makefile.in index 83d14b98..127cb8e0 100644 --- a/qse/Makefile.in +++ b/qse/Makefile.in @@ -80,12 +80,12 @@ host_triplet = @host@ subdir = . DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \ $(top_srcdir)/configure $(am__configure_deps) \ - $(srcdir)/README.in README ac/ar-lib ac/compile \ - ac/config.guess ac/config.sub ac/depcomp ac/install-sh \ - ac/missing ac/ltmain.sh $(top_srcdir)/ac/ar-lib \ - $(top_srcdir)/ac/compile $(top_srcdir)/ac/config.guess \ - $(top_srcdir)/ac/config.sub $(top_srcdir)/ac/install-sh \ - $(top_srcdir)/ac/ltmain.sh $(top_srcdir)/ac/missing + $(srcdir)/README.in ac/ar-lib ac/compile ac/config.guess \ + ac/config.sub ac/depcomp ac/install-sh ac/missing ac/ltmain.sh \ + $(top_srcdir)/ac/ar-lib $(top_srcdir)/ac/compile \ + $(top_srcdir)/ac/config.guess $(top_srcdir)/ac/config.sub \ + $(top_srcdir)/ac/install-sh $(top_srcdir)/ac/ltmain.sh \ + $(top_srcdir)/ac/missing ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/argz.m4 \ $(top_srcdir)/m4/ax_check_sign.m4 \ diff --git a/qse/configure b/qse/configure index 996c19ff..a677746c 100755 --- a/qse/configure +++ b/qse/configure @@ -18534,7 +18534,7 @@ fi done -for ac_header in ifaddrs.h tiuser.h linux/netfilter_ipv4.h netinet/sctp.h +for ac_header in ifaddrs.h tiuser.h linux/netfilter_ipv4.h netinet/sctp.h netpacket/packet.h do : as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default" diff --git a/qse/configure.ac b/qse/configure.ac index 0dc2745d..d5b59de6 100644 --- a/qse/configure.ac +++ b/qse/configure.ac @@ -125,7 +125,7 @@ AC_CHECK_HEADERS([time.h sys/time.h utime.h spawn.h execinfo.h ucontext.h]) AC_CHECK_HEADERS([sys/resource.h sys/wait.h sys/syscall.h sys/ioctl.h]) AC_CHECK_HEADERS([sys/sendfile.h sys/epoll.h sys/event.h]) AC_CHECK_HEADERS([sys/sysctl.h sys/socket.h sys/sockio.h sys/un.h]) -AC_CHECK_HEADERS([ifaddrs.h tiuser.h linux/netfilter_ipv4.h netinet/sctp.h]) +AC_CHECK_HEADERS([ifaddrs.h tiuser.h linux/netfilter_ipv4.h netinet/sctp.h netpacket/packet.h]) AC_CHECK_HEADERS([net/if.h net/if_dl.h], [], [], [ #include #include ]) diff --git a/qse/include/qse/config.h.in b/qse/include/qse/config.h.in index b35aa52d..04b765a5 100644 --- a/qse/include/qse/config.h.in +++ b/qse/include/qse/config.h.in @@ -401,6 +401,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_NETINET_SCTP_H +/* Define to 1 if you have the header file. */ +#undef HAVE_NETPACKET_PACKET_H + /* Define to 1 if you have the header file. */ #undef HAVE_NET_IF_DL_H diff --git a/qse/include/qse/macros.h b/qse/include/qse/macros.h index d202e98a..8586f33a 100644 --- a/qse/include/qse/macros.h +++ b/qse/include/qse/macros.h @@ -126,6 +126,28 @@ #define QSE_ALIGNOF(type) QSE_OFFSETOF(struct { qse_uint8_t d1; type d2; }, d2) /*(sizeof(struct { qse_uint8_t d1; type d2; }) - sizeof(type))*/ +/** + * The QSE_ALIGNTO() macro rounds up a positive integer to the nearest + * multiple of 'align'. + */ +#define QSE_ALIGNTO(num,align) ((((num) + (align) - 1) / (align)) * (align)) + +#if 0 +/** + * Round up a number, both positive and negative, to the nearest multiple of 'align' + */ +#define QSE_ALIGNTO(num,align) ((((num) + (num >= 0? 1: -1) * (align) - 1) / (align)) * (align)) +#endif + +/** + * The QSE_ALIGNTO_POW2() macro rounds up a positive integer to to the + * nearest multiple of 'align' which should be a multiple of a power of 2 + */ +#define QSE_ALIGNTO_POW2(num,align) ((((num) + (align) - 1)) & ~((align) - 1)) + +#define QSE_IS_UNALIGNED_POW2(num,align) ((num) & ((align) - 1)) +#define QSE_IS_ALIGNED_POW2(num,align) (!QSE_IS_UNALIGNED_POW2(num,align)) + /** * The QSE_TYPE_IS_SIGNED() macro determines if a type is signed. * \code diff --git a/qse/lib/cmn/mem.c b/qse/lib/cmn/mem.c index ff9ba1c7..d62b6916 100644 --- a/qse/lib/cmn/mem.c +++ b/qse/lib/cmn/mem.c @@ -43,8 +43,8 @@ #define SPU_VUC_SIZE QSE_SIZEOF(vector unsigned char) #endif -/*#define IS_UNALIGNED(ptr) (((qse_size_t)ptr)%QSE_SIZEOF(qse_size_t))*/ -#define IS_UNALIGNED(ptr) (((qse_size_t)ptr)&(QSE_SIZEOF(qse_size_t)-1)) +#define IS_UNALIGNED(ptr) \ + QSE_IS_UNALIGNED_POW2((qse_size_t)ptr, QSE_SIZEOF(qse_size_t)) #define IS_ALIGNED(ptr) (!IS_UNALIGNED(ptr)) #define IS_EITHER_UNALIGNED(ptr1,ptr2) \ diff --git a/qse/lib/cmn/xma.c b/qse/lib/cmn/xma.c index 38744370..0769f7e8 100644 --- a/qse/lib/cmn/xma.c +++ b/qse/lib/cmn/xma.c @@ -27,7 +27,7 @@ #include #include "mem.h" -#define ALIGN QSE_SIZEOF(qse_size_t) +#define ALIGN QSE_SIZEOF(qse_size_t) /* this must be a power of 2 */ #define HDRSIZE QSE_SIZEOF(qse_xma_blk_t) #define MINBLKLEN (HDRSIZE + ALIGN) @@ -144,7 +144,7 @@ int qse_xma_init (qse_xma_t* xma, qse_mmgr_t* mmgr, qse_size_t zonesize) qse_size_t xfi; /* round 'zonesize' to be the multiples of ALIGN */ - zonesize = ((zonesize + ALIGN - 1) / ALIGN) * ALIGN; + zonesize = QSE_ALIGNTO_POW2(zonesize, ALIGN); /* adjust 'zonesize' to be large enough to hold a single smallest block */ if (zonesize < MINBLKLEN) zonesize = MINBLKLEN; @@ -332,8 +332,7 @@ void* qse_xma_alloc (qse_xma_t* xma, qse_size_t size) if (size <= 0) size = 1; /* round up 'size' to the multiples of ALIGN */ - /*size = (size + ALIGN - 1) & ~(ALIGN - 1); */ - size = ((size + ALIGN - 1) / ALIGN) * ALIGN; + size = QSE_ALIGNTO_POW2(size, ALIGN); QSE_ASSERT (size >= ALIGN); xfi = getxfi(xma,size); @@ -402,7 +401,7 @@ static void* _realloc_merge (qse_xma_t* xma, void* b, qse_size_t size) qse_xma_blk_t* blk = USR_TO_SYS(b); /* rounds up 'size' to be multiples of ALIGN */ - size = ((size + ALIGN - 1) / ALIGN) * ALIGN; + size = QSE_ALIGNTO_POW2 (size, ALIGN); if (size > blk->size) { diff --git a/qse/lib/sys/mux.c b/qse/lib/sys/mux.c index 061bf2d8..27f6a631 100644 --- a/qse/lib/sys/mux.c +++ b/qse/lib/sys/mux.c @@ -464,8 +464,6 @@ qse_mux_errnum_t qse_mux_geterrnum (qse_mux_t* mux) return mux->errnum; } -#define ALIGN_TO(num,align) ((((num) + (align) - 1) / (align)) * (align)) - int qse_mux_insert (qse_mux_t* mux, const qse_mux_evt_t* evt) { #if defined(USE_SELECT) @@ -499,7 +497,7 @@ int qse_mux_insert (qse_mux_t* mux, const qse_mux_evt_t* evt) int ubound; ubound = evt->hnd + 1; - ubound = ALIGN_TO (ubound, 128); + ubound = QSE_ALIGNTO_POW2 (ubound, 128); tmp = QSE_MMGR_REALLOC (mux->mmgr, mux->me.ptr, QSE_SIZEOF(*mux->me.ptr) * ubound); if (tmp == QSE_NULL) @@ -557,7 +555,7 @@ int qse_mux_insert (qse_mux_t* mux, const qse_mux_evt_t* evt) int ubound; ubound = evt->hnd + 1; - ubound = ALIGN_TO (ubound, 128); + ubound = QSE_ALIGNTO_POW2 (ubound, 128); tmp = QSE_MMGR_REALLOC (mux->mmgr, mux->me.ptr, QSE_SIZEOF(*mux->me.ptr) * ubound); if (tmp == QSE_NULL) @@ -606,7 +604,7 @@ int qse_mux_insert (qse_mux_t* mux, const qse_mux_evt_t* evt) int ubound; ubound = evt->hnd + 1; - ubound = ALIGN_TO (ubound, 128); + ubound = QSE_ALIGNTO_POW2 (ubound, 128); tmp = QSE_MMGR_REALLOC (mux->mmgr, mux->me.ptr, QSE_SIZEOF(*mux->me.ptr) * ubound); if (tmp == QSE_NULL) @@ -639,7 +637,7 @@ int qse_mux_insert (qse_mux_t* mux, const qse_mux_evt_t* evt) qse_size_t newcapa; newcapa = (mux->ee.capa + 1) * 2; - newcapa = ALIGN_TO (newcapa, 256); + newcapa = QSE_ALIGNTO_POW2 (newcapa, 256); tmp = QSE_MMGR_REALLOC ( mux->mmgr, mux->ee.ptr, @@ -673,7 +671,7 @@ int qse_mux_insert (qse_mux_t* mux, const qse_mux_evt_t* evt) int ubound; ubound = evt->hnd + 1; - ubound = ALIGN_TO (ubound, 128); + ubound = QSE_ALIGNTO_POW2 (ubound, 128); tmp = QSE_MMGR_REALLOC (mux->mmgr, mux->me.ptr, QSE_SIZEOF(*mux->me.ptr) * ubound); if (tmp == QSE_NULL)