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.
This commit is contained in:
hujianwei 2022-11-05 13:31:32 +00:00
parent d17262c6ea
commit 55cae69aa1
4 changed files with 48 additions and 2 deletions

View file

@ -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.

View file

@ -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

24
fns.c
View file

@ -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. */

2
seat.c
View file

@ -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;
}