105b261ecSmrg/*********************************************************** 205b261ecSmrg 305b261ecSmrgCopyright 1987, 1998 The Open Group 405b261ecSmrg 505b261ecSmrgPermission to use, copy, modify, distribute, and sell this software and its 605b261ecSmrgdocumentation for any purpose is hereby granted without fee, provided that 705b261ecSmrgthe above copyright notice appear in all copies and that both that 805b261ecSmrgcopyright notice and this permission notice appear in supporting 905b261ecSmrgdocumentation. 1005b261ecSmrg 1105b261ecSmrgThe above copyright notice and this permission notice shall be included in 1205b261ecSmrgall copies or substantial portions of the Software. 1305b261ecSmrg 1405b261ecSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1505b261ecSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1605b261ecSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1705b261ecSmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 1805b261ecSmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 1905b261ecSmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2005b261ecSmrg 2105b261ecSmrgExcept as contained in this notice, the name of The Open Group shall not be 2205b261ecSmrgused in advertising or otherwise to promote the sale, use or other dealings 2305b261ecSmrgin this Software without prior written authorization from The Open Group. 2405b261ecSmrg 2505b261ecSmrgCopyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. 2605b261ecSmrg 2705b261ecSmrg All Rights Reserved 2805b261ecSmrg 2935c4bbdfSmrgPermission to use, copy, modify, and distribute this software and its 3035c4bbdfSmrgdocumentation for any purpose and without fee is hereby granted, 3105b261ecSmrgprovided that the above copyright notice appear in all copies and that 3235c4bbdfSmrgboth that copyright notice and this permission notice appear in 3305b261ecSmrgsupporting documentation, and that the name of Digital not be 3405b261ecSmrgused in advertising or publicity pertaining to distribution of the 3535c4bbdfSmrgsoftware without specific, written prior permission. 3605b261ecSmrg 3705b261ecSmrgDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 3805b261ecSmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 3905b261ecSmrgDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 4005b261ecSmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 4105b261ecSmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 4205b261ecSmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 4305b261ecSmrgSOFTWARE. 4405b261ecSmrg 4505b261ecSmrgCopyright 1992, 1993 Data General Corporation; 4635c4bbdfSmrgCopyright 1992, 1993 OMRON Corporation 4705b261ecSmrg 4805b261ecSmrgPermission to use, copy, modify, distribute, and sell this software and its 4905b261ecSmrgdocumentation for any purpose is hereby granted without fee, provided that the 5005b261ecSmrgabove copyright notice appear in all copies and that both that copyright 5105b261ecSmrgnotice and this permission notice appear in supporting documentation, and that 5205b261ecSmrgneither the name OMRON or DATA GENERAL be used in advertising or publicity 5305b261ecSmrgpertaining to distribution of the software without specific, written prior 5435c4bbdfSmrgpermission of the party whose name is to be used. Neither OMRON or 5505b261ecSmrgDATA GENERAL make any representation about the suitability of this software 5635c4bbdfSmrgfor any purpose. It is provided "as is" without express or implied warranty. 5705b261ecSmrg 5805b261ecSmrgOMRON AND DATA GENERAL EACH DISCLAIM ALL WARRANTIES WITH REGARD TO THIS 5905b261ecSmrgSOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, 6005b261ecSmrgIN NO EVENT SHALL OMRON OR DATA GENERAL BE LIABLE FOR ANY SPECIAL, INDIRECT 6105b261ecSmrgOR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 6205b261ecSmrgDATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 6305b261ecSmrgTORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 6405b261ecSmrgOF THIS SOFTWARE. 6505b261ecSmrg 6605b261ecSmrg******************************************************************/ 6705b261ecSmrg#ifndef MISC_H 6805b261ecSmrg#define MISC_H 1 6905b261ecSmrg/* 7035c4bbdfSmrg * X internal definitions 7105b261ecSmrg * 7205b261ecSmrg */ 7305b261ecSmrg 7405b261ecSmrg#include <X11/Xosdefs.h> 7505b261ecSmrg#include <X11/Xfuncproto.h> 7605b261ecSmrg#include <X11/Xmd.h> 7705b261ecSmrg#include <X11/X.h> 7805b261ecSmrg#include <X11/Xdefs.h> 7905b261ecSmrg 8005b261ecSmrg#include <stddef.h> 8135c4bbdfSmrg#include <stdint.h> 821b5d61b8Smrg#include <pthread.h> 8305b261ecSmrg 8405b261ecSmrg#ifndef MAXSCREENS 8505b261ecSmrg#define MAXSCREENS 16 8605b261ecSmrg#endif 8735c4bbdfSmrg#ifndef MAXGPUSCREENS 8835c4bbdfSmrg#define MAXGPUSCREENS 16 8935c4bbdfSmrg#endif 901b5d61b8Smrg#define MAXCLIENTS 2048 9135c4bbdfSmrg#define LIMITCLIENTS 256 /* Must be a power of 2 and <= MAXCLIENTS */ 924642e01fSmrg#define MAXEXTENSIONS 128 9305b261ecSmrg#define MAXFORMATS 8 94ed6184dfSmrg#ifndef MAXDEVICES 955a7dfde8Smrg#define MAXDEVICES 256 /* input devices */ 96ed6184dfSmrg#endif 9735c4bbdfSmrg#define GPU_SCREEN_OFFSET 256 984642e01fSmrg 9935c4bbdfSmrg/* 128 event opcodes for core + extension events, excluding GE */ 10035c4bbdfSmrg#define MAXEVENTS 128 1014642e01fSmrg#define EXTENSION_EVENT_BASE 64 1024642e01fSmrg#define EXTENSION_BASE 128 10305b261ecSmrg 10435c4bbdfSmrgtypedef uint32_t ATOM; 10505b261ecSmrg 10605b261ecSmrg#ifndef TRUE 10705b261ecSmrg#define TRUE 1 10805b261ecSmrg#define FALSE 0 10905b261ecSmrg#endif 11005b261ecSmrg 11105b261ecSmrg#ifndef _XTYPEDEF_CALLBACKLISTPTR 11235c4bbdfSmrgtypedef struct _CallbackList *CallbackListPtr; /* also in dix.h */ 11335c4bbdfSmrg 11405b261ecSmrg#define _XTYPEDEF_CALLBACKLISTPTR 11505b261ecSmrg#endif 11605b261ecSmrg 11705b261ecSmrgtypedef struct _xReq *xReqPtr; 11805b261ecSmrg 11935c4bbdfSmrg#include "os.h" /* for ALLOCATE_LOCAL and DEALLOCATE_LOCAL */ 12035c4bbdfSmrg#include <X11/Xfuncs.h> /* for bcopy, bzero, and bcmp */ 12105b261ecSmrg 12205b261ecSmrg#define NullBox ((BoxPtr)0) 12305b261ecSmrg#define MILLI_PER_MIN (1000 * 60) 12405b261ecSmrg#define MILLI_PER_SECOND (1000) 12505b261ecSmrg 12605b261ecSmrg /* this next is used with None and ParentRelative to tell 12705b261ecSmrg PaintWin() what to use to paint the background. Also used 12805b261ecSmrg in the macro IS_VALID_PIXMAP */ 12905b261ecSmrg 13005b261ecSmrg#define USE_BACKGROUND_PIXEL 3 13105b261ecSmrg#define USE_BORDER_PIXEL 3 13205b261ecSmrg 13305b261ecSmrg#undef min 13405b261ecSmrg#undef max 13505b261ecSmrg 13605b261ecSmrg#define min(a, b) (((a) < (b)) ? (a) : (b)) 13705b261ecSmrg#define max(a, b) (((a) > (b)) ? (a) : (b)) 13805b261ecSmrg/* abs() is a function, not a macro; include the file declaring 13905b261ecSmrg * it in case we haven't done that yet. 14005b261ecSmrg */ 14105b261ecSmrg#include <stdlib.h> 14205b261ecSmrg#define sign(x) ((x) < 0 ? -1 : ((x) > 0 ? 1 : 0)) 14305b261ecSmrg/* this assumes b > 0 */ 14405b261ecSmrg#define modulus(a, b, d) if (((d) = (a) % (b)) < 0) (d) += (b) 14505b261ecSmrg/* 14605b261ecSmrg * return the least significant bit in x which is set 14705b261ecSmrg * 14805b261ecSmrg * This works on 1's complement and 2's complement machines. 14905b261ecSmrg * If you care about the extra instruction on 2's complement 15005b261ecSmrg * machines, change to ((x) & (-(x))) 15105b261ecSmrg */ 15205b261ecSmrg#define lowbit(x) ((x) & (~(x) + 1)) 15305b261ecSmrg 15405b261ecSmrg/* XXX Not for modules */ 15505b261ecSmrg#include <limits.h> 15605b261ecSmrg#if !defined(MAXSHORT) || !defined(MINSHORT) || \ 15705b261ecSmrg !defined(MAXINT) || !defined(MININT) 15805b261ecSmrg/* 15905b261ecSmrg * Some implementations #define these through <math.h>, so preclude 16005b261ecSmrg * #include'ing it later. 16105b261ecSmrg */ 16205b261ecSmrg 16305b261ecSmrg#include <math.h> 16405b261ecSmrg#undef MAXSHORT 16505b261ecSmrg#define MAXSHORT SHRT_MAX 16605b261ecSmrg#undef MINSHORT 16705b261ecSmrg#define MINSHORT SHRT_MIN 16805b261ecSmrg#undef MAXINT 16905b261ecSmrg#define MAXINT INT_MAX 17005b261ecSmrg#undef MININT 17105b261ecSmrg#define MININT INT_MIN 17205b261ecSmrg 17305b261ecSmrg#include <assert.h> 17405b261ecSmrg#include <ctype.h> 17535c4bbdfSmrg#include <stdio.h> /* for fopen, etc... */ 17635c4bbdfSmrg 17735c4bbdfSmrg#endif 17805b261ecSmrg 17935c4bbdfSmrg#ifndef PATH_MAX 18035c4bbdfSmrg#include <sys/param.h> 18135c4bbdfSmrg#ifndef PATH_MAX 18235c4bbdfSmrg#ifdef MAXPATHLEN 18335c4bbdfSmrg#define PATH_MAX MAXPATHLEN 18435c4bbdfSmrg#else 18535c4bbdfSmrg#define PATH_MAX 1024 18635c4bbdfSmrg#endif 18735c4bbdfSmrg#endif 18805b261ecSmrg#endif 18905b261ecSmrg 1906747b715Smrg/** 1916747b715Smrg * Calculate the number of bytes needed to hold bits. 1926747b715Smrg * @param bits The minimum number of bits needed. 1936747b715Smrg * @return The number of bytes needed to hold bits. 1946747b715Smrg */ 1956747b715Smrgstatic inline int 19635c4bbdfSmrgbits_to_bytes(const int bits) 19735c4bbdfSmrg{ 1986747b715Smrg return ((bits + 7) >> 3); 1996747b715Smrg} 20035c4bbdfSmrg 2016747b715Smrg/** 2026747b715Smrg * Calculate the number of 4-byte units needed to hold the given number of 2036747b715Smrg * bytes. 2046747b715Smrg * @param bytes The minimum number of bytes needed. 2056747b715Smrg * @return The number of 4-byte units needed to hold bytes. 2066747b715Smrg */ 2076747b715Smrgstatic inline int 20835c4bbdfSmrgbytes_to_int32(const int bytes) 20935c4bbdfSmrg{ 2106747b715Smrg return (((bytes) + 3) >> 2); 2116747b715Smrg} 2126747b715Smrg 2136747b715Smrg/** 2146747b715Smrg * Calculate the number of bytes (in multiples of 4) needed to hold bytes. 2156747b715Smrg * @param bytes The minimum number of bytes needed. 2166747b715Smrg * @return The closest multiple of 4 that is equal or higher than bytes. 2176747b715Smrg */ 2186747b715Smrgstatic inline int 21935c4bbdfSmrgpad_to_int32(const int bytes) 22035c4bbdfSmrg{ 2216747b715Smrg return (((bytes) + 3) & ~3); 2226747b715Smrg} 2236747b715Smrg 22435c4bbdfSmrg/** 22535c4bbdfSmrg * Calculate padding needed to bring the number of bytes to an even 22635c4bbdfSmrg * multiple of 4. 22735c4bbdfSmrg * @param bytes The minimum number of bytes needed. 22835c4bbdfSmrg * @return The bytes of padding needed to arrive at the closest multiple of 4 22935c4bbdfSmrg * that is equal or higher than bytes. 23035c4bbdfSmrg */ 23135c4bbdfSmrgstatic inline int 23235c4bbdfSmrgpadding_for_int32(const int bytes) 23335c4bbdfSmrg{ 23435c4bbdfSmrg return ((-bytes) & 3); 23535c4bbdfSmrg} 23635c4bbdfSmrg 23735c4bbdfSmrg 2381b5d61b8Smrgextern _X_EXPORT char **xstrtokenize(const char *str, const char *separators); 23935c4bbdfSmrgextern void FormatInt64(int64_t num, char *string); 24035c4bbdfSmrgextern void FormatUInt64(uint64_t num, char *string); 24135c4bbdfSmrgextern void FormatUInt64Hex(uint64_t num, char *string); 24235c4bbdfSmrgextern void FormatDouble(double dbl, char *string); 24335c4bbdfSmrg 24435c4bbdfSmrg/** 24535c4bbdfSmrg * Compare the two version numbers comprising of major.minor. 24635c4bbdfSmrg * 24735c4bbdfSmrg * @return A value less than 0 if a is less than b, 0 if a is equal to b, 24835c4bbdfSmrg * or a value greater than 0 24935c4bbdfSmrg */ 25035c4bbdfSmrgstatic inline int 25135c4bbdfSmrgversion_compare(uint32_t a_major, uint32_t a_minor, 25235c4bbdfSmrg uint32_t b_major, uint32_t b_minor) 25335c4bbdfSmrg{ 25435c4bbdfSmrg if (a_major > b_major) 25535c4bbdfSmrg return 1; 25635c4bbdfSmrg if (a_major < b_major) 25735c4bbdfSmrg return -1; 25835c4bbdfSmrg if (a_minor > b_minor) 25935c4bbdfSmrg return 1; 26035c4bbdfSmrg if (a_minor < b_minor) 26135c4bbdfSmrg return -1; 26235c4bbdfSmrg 26335c4bbdfSmrg return 0; 26435c4bbdfSmrg} 2656747b715Smrg 26605b261ecSmrg/* some macros to help swap requests, replies, and events */ 26705b261ecSmrg 26805b261ecSmrg#define LengthRestB(stuff) \ 26905b261ecSmrg ((client->req_len << 2) - sizeof(*stuff)) 27005b261ecSmrg 27105b261ecSmrg#define LengthRestS(stuff) \ 27205b261ecSmrg ((client->req_len << 1) - (sizeof(*stuff) >> 1)) 27305b261ecSmrg 27405b261ecSmrg#define LengthRestL(stuff) \ 27505b261ecSmrg (client->req_len - (sizeof(*stuff) >> 2)) 27605b261ecSmrg 27705b261ecSmrg#define SwapRestS(stuff) \ 27805b261ecSmrg SwapShorts((short *)(stuff + 1), LengthRestS(stuff)) 27905b261ecSmrg 28005b261ecSmrg#define SwapRestL(stuff) \ 28105b261ecSmrg SwapLongs((CARD32 *)(stuff + 1), LengthRestL(stuff)) 28205b261ecSmrg 28335c4bbdfSmrg#if defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) 28435c4bbdfSmrgvoid __attribute__ ((error("wrong sized variable passed to swap"))) 28535c4bbdfSmrgwrong_size(void); 28635c4bbdfSmrg#else 28735c4bbdfSmrgstatic inline void 28835c4bbdfSmrgwrong_size(void) 28935c4bbdfSmrg{ 29035c4bbdfSmrg} 29135c4bbdfSmrg#endif 29235c4bbdfSmrg 29335c4bbdfSmrg#if !(defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590))) 29435c4bbdfSmrgstatic inline int 29535c4bbdfSmrg__builtin_constant_p(int x) 29635c4bbdfSmrg{ 29735c4bbdfSmrg return 0; 29835c4bbdfSmrg} 29935c4bbdfSmrg#endif 30035c4bbdfSmrg 3011b5d61b8Smrgstatic inline uint64_t 3021b5d61b8Smrgbswap_64(uint64_t x) 30335c4bbdfSmrg{ 3041b5d61b8Smrg return (((x & 0xFF00000000000000ull) >> 56) | 3051b5d61b8Smrg ((x & 0x00FF000000000000ull) >> 40) | 3061b5d61b8Smrg ((x & 0x0000FF0000000000ull) >> 24) | 3071b5d61b8Smrg ((x & 0x000000FF00000000ull) >> 8) | 3081b5d61b8Smrg ((x & 0x00000000FF000000ull) << 8) | 3091b5d61b8Smrg ((x & 0x0000000000FF0000ull) << 24) | 3101b5d61b8Smrg ((x & 0x000000000000FF00ull) << 40) | 3111b5d61b8Smrg ((x & 0x00000000000000FFull) << 56)); 31235c4bbdfSmrg} 31335c4bbdfSmrg 31435c4bbdfSmrg#define swapll(x) do { \ 31535c4bbdfSmrg if (sizeof(*(x)) != 8) \ 31635c4bbdfSmrg wrong_size(); \ 3171b5d61b8Smrg *(x) = bswap_64(*(x)); \ 31835c4bbdfSmrg } while (0) 31935c4bbdfSmrg 3201b5d61b8Smrgstatic inline uint32_t 3211b5d61b8Smrgbswap_32(uint32_t x) 3221b5d61b8Smrg{ 3231b5d61b8Smrg return (((x & 0xFF000000) >> 24) | 3241b5d61b8Smrg ((x & 0x00FF0000) >> 8) | 3251b5d61b8Smrg ((x & 0x0000FF00) << 8) | 3261b5d61b8Smrg ((x & 0x000000FF) << 24)); 3271b5d61b8Smrg} 3281b5d61b8Smrg 3291b5d61b8Smrgstatic inline Bool 3301b5d61b8Smrgchecked_int64_add(int64_t *out, int64_t a, int64_t b) 3311b5d61b8Smrg{ 3321b5d61b8Smrg /* Do the potentially overflowing math as uint64_t, as signed 3331b5d61b8Smrg * integers in C are undefined on overflow (and the compiler may 3341b5d61b8Smrg * optimize out our overflow check below, otherwise) 3351b5d61b8Smrg */ 3361b5d61b8Smrg int64_t result = (uint64_t)a + (uint64_t)b; 3371b5d61b8Smrg /* signed addition overflows if operands have the same sign, and 3381b5d61b8Smrg * the sign of the result doesn't match the sign of the inputs. 3391b5d61b8Smrg */ 3401b5d61b8Smrg Bool overflow = (a < 0) == (b < 0) && (a < 0) != (result < 0); 3411b5d61b8Smrg 3421b5d61b8Smrg *out = result; 3431b5d61b8Smrg 3441b5d61b8Smrg return overflow; 3451b5d61b8Smrg} 3461b5d61b8Smrg 3471b5d61b8Smrgstatic inline Bool 3481b5d61b8Smrgchecked_int64_subtract(int64_t *out, int64_t a, int64_t b) 34935c4bbdfSmrg{ 3501b5d61b8Smrg int64_t result = (uint64_t)a - (uint64_t)b; 3511b5d61b8Smrg Bool overflow = (a < 0) != (b < 0) && (a < 0) != (result < 0); 3521b5d61b8Smrg 3531b5d61b8Smrg *out = result; 35435c4bbdfSmrg 3551b5d61b8Smrg return overflow; 35635c4bbdfSmrg} 35735c4bbdfSmrg 35835c4bbdfSmrg#define swapl(x) do { \ 35935c4bbdfSmrg if (sizeof(*(x)) != 4) \ 36035c4bbdfSmrg wrong_size(); \ 3611b5d61b8Smrg *(x) = bswap_32(*(x)); \ 36235c4bbdfSmrg } while (0) 36335c4bbdfSmrg 3641b5d61b8Smrgstatic inline uint16_t 3651b5d61b8Smrgbswap_16(uint16_t x) 36635c4bbdfSmrg{ 3671b5d61b8Smrg return (((x & 0xFF00) >> 8) | 3681b5d61b8Smrg ((x & 0x00FF) << 8)); 36935c4bbdfSmrg} 37035c4bbdfSmrg 37135c4bbdfSmrg#define swaps(x) do { \ 37235c4bbdfSmrg if (sizeof(*(x)) != 2) \ 37335c4bbdfSmrg wrong_size(); \ 3741b5d61b8Smrg *(x) = bswap_16(*(x)); \ 37535c4bbdfSmrg } while (0) 37605b261ecSmrg 37705b261ecSmrg/* copy 32-bit value from src to dst byteswapping on the way */ 37835c4bbdfSmrg#define cpswapl(src, dst) do { \ 37935c4bbdfSmrg if (sizeof((src)) != 4 || sizeof((dst)) != 4) \ 38035c4bbdfSmrg wrong_size(); \ 3811b5d61b8Smrg (dst) = bswap_32((src)); \ 38235c4bbdfSmrg } while (0) 38305b261ecSmrg 38405b261ecSmrg/* copy short from src to dst byteswapping on the way */ 38535c4bbdfSmrg#define cpswaps(src, dst) do { \ 38635c4bbdfSmrg if (sizeof((src)) != 2 || sizeof((dst)) != 2) \ 38735c4bbdfSmrg wrong_size(); \ 3881b5d61b8Smrg (dst) = bswap_16((src)); \ 38935c4bbdfSmrg } while (0) 39005b261ecSmrg 39135c4bbdfSmrgextern _X_EXPORT void SwapLongs(CARD32 *list, unsigned long count); 39205b261ecSmrg 39335c4bbdfSmrgextern _X_EXPORT void SwapShorts(short *list, unsigned long count); 39405b261ecSmrg 3956747b715Smrgextern _X_EXPORT void MakePredeclaredAtoms(void); 39605b261ecSmrg 39735c4bbdfSmrgextern _X_EXPORT int Ones(unsigned long /*mask */ ); 39805b261ecSmrg 39905b261ecSmrgtypedef struct _xPoint *DDXPointPtr; 40005b261ecSmrgtypedef struct pixman_box16 *BoxPtr; 40105b261ecSmrgtypedef struct _xEvent *xEventPtr; 40205b261ecSmrgtypedef struct _xRectangle *xRectanglePtr; 40305b261ecSmrgtypedef struct _GrabRec *GrabPtr; 40405b261ecSmrg 40505b261ecSmrg/* typedefs from other places - duplicated here to minimize the amount 40605b261ecSmrg * of unnecessary junk that one would normally have to include to get 40705b261ecSmrg * these symbols defined 40805b261ecSmrg */ 40905b261ecSmrg 41005b261ecSmrg#ifndef _XTYPEDEF_CHARINFOPTR 41135c4bbdfSmrgtypedef struct _CharInfo *CharInfoPtr; /* also in fonts/include/font.h */ 41235c4bbdfSmrg 41305b261ecSmrg#define _XTYPEDEF_CHARINFOPTR 41405b261ecSmrg#endif 41505b261ecSmrg 4166747b715Smrgextern _X_EXPORT unsigned long globalSerialNumber; 4176747b715Smrgextern _X_EXPORT unsigned long serverGeneration; 4186747b715Smrg 41935c4bbdfSmrg/* Don't use this directly, use BUG_WARN or BUG_WARN_MSG instead */ 42035c4bbdfSmrg#define __BUG_WARN_MSG(cond, with_msg, ...) \ 42135c4bbdfSmrg do { if (cond) { \ 42235c4bbdfSmrg ErrorFSigSafe("BUG: triggered 'if (" #cond ")'\n"); \ 42335c4bbdfSmrg ErrorFSigSafe("BUG: %s:%u in %s()\n", \ 42435c4bbdfSmrg __FILE__, __LINE__, __func__); \ 42535c4bbdfSmrg if (with_msg) ErrorFSigSafe(__VA_ARGS__); \ 42635c4bbdfSmrg xorg_backtrace(); \ 42735c4bbdfSmrg } } while(0) 42835c4bbdfSmrg 42935c4bbdfSmrg#define BUG_WARN_MSG(cond, ...) \ 43035c4bbdfSmrg __BUG_WARN_MSG(cond, 1, __VA_ARGS__) 43135c4bbdfSmrg 43235c4bbdfSmrg#define BUG_WARN(cond) __BUG_WARN_MSG(cond, 0, NULL) 43335c4bbdfSmrg 43435c4bbdfSmrg#define BUG_RETURN(cond) \ 43535c4bbdfSmrg do { if (cond) { __BUG_WARN_MSG(cond, 0, NULL); return; } } while(0) 43635c4bbdfSmrg 43735c4bbdfSmrg#define BUG_RETURN_MSG(cond, ...) \ 43835c4bbdfSmrg do { if (cond) { __BUG_WARN_MSG(cond, 1, __VA_ARGS__); return; } } while(0) 43935c4bbdfSmrg 44035c4bbdfSmrg#define BUG_RETURN_VAL(cond, val) \ 44135c4bbdfSmrg do { if (cond) { __BUG_WARN_MSG(cond, 0, NULL); return (val); } } while(0) 44235c4bbdfSmrg 44335c4bbdfSmrg#define BUG_RETURN_VAL_MSG(cond, val, ...) \ 44435c4bbdfSmrg do { if (cond) { __BUG_WARN_MSG(cond, 1, __VA_ARGS__); return (val); } } while(0) 44535c4bbdfSmrg 44635c4bbdfSmrg#endif /* MISC_H */ 447