From 55cae69aa1635d9ea3d6e613fee6bb42abec5008 Mon Sep 17 00:00:00 2001 From: hujianwei Date: Sat, 5 Nov 2022 13:31:32 +0000 Subject: [PATCH] Add some initial wrapping for ports * Imakefile (EXTRA_DEFINES, DEPEND_DEFINES, ANALYZE, OPTIMIZE): Make port and compiler specific. * compositor.h: Update compiler-specific defines. * fns.c (PortPopcount): New function. * seat.c (MaskPopCount): Use Popcount macro. --- Imakefile | 12 +++++++++++- compositor.h | 12 ++++++++++++ fns.c | 24 ++++++++++++++++++++++++ seat.c | 2 +- 4 files changed, 48 insertions(+), 2 deletions(-) diff --git a/Imakefile b/Imakefile index b99b519..cc574d3 100644 --- a/Imakefile +++ b/Imakefile @@ -22,7 +22,13 @@ DependSubdirs($(SUBDIRS)) OBJS = 12to11.o run.o alloc.o fns.o output.o compositor.o surface.o region.o shm.o atoms.o subcompositor.o positioner.o xdg_wm.o xdg_surface.o xdg_toplevel.o frame_clock.o xerror.o ewmh.o timer.o subsurface.o seat.o data_device.o xdg_popup.o dmabuf.o buffer.o select.o xdata.o xsettings.o dnd.o icon_surface.o primary_selection.o renderer.o picture_renderer.o explicit_synchronization.o transform.o wp_viewporter.o decoration.o text_input.o single_pixel_buffer.o drm_lease.o pointer_constraints.o time.o relative_pointer.o keyboard_shortcuts_inhibit.o idle_inhibit.o process.o fence_ring.o pointer_gestures.o test.o buffer_release.o GENHEADERS = transfer_atoms.h drm_modifiers.h HEADER = $(GENHEADERS) compositor.h - EXTRA_DEFINES := -D_GNU_SOURCE -U_BSD_SOURCE -U_SVID_SOURCE + +#if defined LinuxArchitecture || define GNUArchitecture + EXTRA_DEFINES := -DPortFile=\"port_gnu.h\" -D_GNU_SOURCE -U_BSD_SOURCE -U_SVID_SOURCE + DEPEND_DEFINES := -DPortFile=\"port_gnu.h\" +#else +# error "The protocol translator was not ported to your system" +#endif #ifdef HaveEglSupport @@ -46,8 +52,12 @@ cleandir:: #endif OPTIMIZE = -O0 +#if GccMajorVersion >= 10 ANALYZE = -fanalyzer +#endif +#if GccMajorVersion >= 7 CDEBUGFLAGS := -fno-common -Wall -Warith-conversion -Wdate-time -Wdisabled-optimization -Wdouble-promotion -Wduplicated-cond -Wextra -Wformat-signedness -Winit-self -Winvalid-pch -Wlogical-op -Wmissing-declarations -Wmissing-include-dirs -Wmissing-prototypes -Wnested-externs -Wnull-dereference -Wold-style-definition -Wopenmp-simd -Wpacked -Wpointer-arith -Wstrict-prototypes -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wsuggest-final-methods -Wsuggest-final-types -Wuninitialized -Wunknown-pragmas -Wunused-macros -Wvariadic-macros -Wvector-operation-performance -Wwrite-strings -Warray-bounds=2 -Wattribute-alias=2 -Wformat=2 -Wformat-truncation=2 -Wimplicit-fallthrough=5 -Wshift-overflow=2 -Wuse-after-free=3 -Wvla-larger-than=4031 -Wredundant-decls -Wno-missing-field-initializers -Wno-override-init -Wno-sign-compare -Wno-type-limits -Wno-unused-parameter -Wno-format-nonliteral -g3 $(OPTIMIZE) $(ANALYZE) +#endif short_types.txt: media_types.txt XCOMM Remove all data types starting with application/vnd. diff --git a/compositor.h b/compositor.h index e43f4d1..86eec72 100644 --- a/compositor.h +++ b/compositor.h @@ -1853,10 +1853,16 @@ extern void ReleaseBufferWithHelper (BufferReleaseHelper *, ExtBuffer *, ? (t) -1 \ : ((((t) 1 << (TypeWidth (t) - 2)) - 1) * 2 + 1))) +#if __GNUC__ >= 7 + #define IntAddWrapv(a, b, r) __builtin_add_overflow (a, b, r) #define IntSubtractWrapv(a, b, r) __builtin_sub_overflow (a, b, r) #define IntMultiplyWrapv(a, b, r) __builtin_mul_overflow (a, b, r) +#define Popcount(number) __builtin_popcount (number) + +#endif + /* This is a macro in order to be more static analyzer friendly. */ #define XLAssert(cond) (!(cond) ? abort () : ((void) 0)) @@ -1872,3 +1878,9 @@ struct _Rectangle /* The width and height. */ int width, height; }; + +/* port.h may override ports here. */ + +#ifdef PortFile +#include PortFile +#endif diff --git a/fns.c b/fns.c index 0fad5e7..daf97e2 100644 --- a/fns.c +++ b/fns.c @@ -891,3 +891,27 @@ XLAddFdFlag (int fd, int flag, Bool abort_on_error) return True; } + +/* Functions for ports. */ + +#ifdef NeedPortPopcount + +int +PortPopcount (unsigned long long int big) +{ + int num_bits; + + num_bits = 0; + + while (big) + { + if (big & 1) + ++num_bits; + + big >>= 1; + } + + return num_bits; +} + +#endif /* NeedPortPopcount. */ diff --git a/seat.c b/seat.c index 2520548..35fc8f7 100644 --- a/seat.c +++ b/seat.c @@ -3063,7 +3063,7 @@ MaskPopCount (XIButtonState *mask) population = 0; for (i = 0; i < mask->mask_len; ++i) - population += __builtin_popcount (mask->mask[i]); + population += Popcount (mask->mask[i]); return population; }