misc.h revision 5a7dfde8
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 945a7dfde8Smrg#define MAXDEVICES 256 /* input devices */ 9535c4bbdfSmrg#define GPU_SCREEN_OFFSET 256 964642e01fSmrg 9735c4bbdfSmrg/* 128 event opcodes for core + extension events, excluding GE */ 9835c4bbdfSmrg#define MAXEVENTS 128 994642e01fSmrg#define EXTENSION_EVENT_BASE 64 1004642e01fSmrg#define EXTENSION_BASE 128 10105b261ecSmrg 10235c4bbdfSmrgtypedef uint32_t ATOM; 10305b261ecSmrg 10405b261ecSmrg#ifndef TRUE 10505b261ecSmrg#define TRUE 1 10605b261ecSmrg#define FALSE 0 10705b261ecSmrg#endif 10805b261ecSmrg 10905b261ecSmrg#ifndef _XTYPEDEF_CALLBACKLISTPTR 11035c4bbdfSmrgtypedef struct _CallbackList *CallbackListPtr; /* also in dix.h */ 11135c4bbdfSmrg 11205b261ecSmrg#define _XTYPEDEF_CALLBACKLISTPTR 11305b261ecSmrg#endif 11405b261ecSmrg 11505b261ecSmrgtypedef struct _xReq *xReqPtr; 11605b261ecSmrg 11735c4bbdfSmrg#include "os.h" /* for ALLOCATE_LOCAL and DEALLOCATE_LOCAL */ 11835c4bbdfSmrg#include <X11/Xfuncs.h> /* for bcopy, bzero, and bcmp */ 11905b261ecSmrg 12005b261ecSmrg#define NullBox ((BoxPtr)0) 12105b261ecSmrg#define MILLI_PER_MIN (1000 * 60) 12205b261ecSmrg#define MILLI_PER_SECOND (1000) 12305b261ecSmrg 12405b261ecSmrg /* this next is used with None and ParentRelative to tell 12505b261ecSmrg PaintWin() what to use to paint the background. Also used 12605b261ecSmrg in the macro IS_VALID_PIXMAP */ 12705b261ecSmrg 12805b261ecSmrg#define USE_BACKGROUND_PIXEL 3 12905b261ecSmrg#define USE_BORDER_PIXEL 3 13005b261ecSmrg 13105b261ecSmrg#undef min 13205b261ecSmrg#undef max 13305b261ecSmrg 13405b261ecSmrg#define min(a, b) (((a) < (b)) ? (a) : (b)) 13505b261ecSmrg#define max(a, b) (((a) > (b)) ? (a) : (b)) 13605b261ecSmrg/* abs() is a function, not a macro; include the file declaring 13705b261ecSmrg * it in case we haven't done that yet. 13805b261ecSmrg */ 13905b261ecSmrg#include <stdlib.h> 14005b261ecSmrg#define sign(x) ((x) < 0 ? -1 : ((x) > 0 ? 1 : 0)) 14105b261ecSmrg/* this assumes b > 0 */ 14205b261ecSmrg#define modulus(a, b, d) if (((d) = (a) % (b)) < 0) (d) += (b) 14305b261ecSmrg/* 14405b261ecSmrg * return the least significant bit in x which is set 14505b261ecSmrg * 14605b261ecSmrg * This works on 1's complement and 2's complement machines. 14705b261ecSmrg * If you care about the extra instruction on 2's complement 14805b261ecSmrg * machines, change to ((x) & (-(x))) 14905b261ecSmrg */ 15005b261ecSmrg#define lowbit(x) ((x) & (~(x) + 1)) 15105b261ecSmrg 15205b261ecSmrg/* XXX Not for modules */ 15305b261ecSmrg#include <limits.h> 15405b261ecSmrg#if !defined(MAXSHORT) || !defined(MINSHORT) || \ 15505b261ecSmrg !defined(MAXINT) || !defined(MININT) 15605b261ecSmrg/* 15705b261ecSmrg * Some implementations #define these through <math.h>, so preclude 15805b261ecSmrg * #include'ing it later. 15905b261ecSmrg */ 16005b261ecSmrg 16105b261ecSmrg#include <math.h> 16205b261ecSmrg#undef MAXSHORT 16305b261ecSmrg#define MAXSHORT SHRT_MAX 16405b261ecSmrg#undef MINSHORT 16505b261ecSmrg#define MINSHORT SHRT_MIN 16605b261ecSmrg#undef MAXINT 16705b261ecSmrg#define MAXINT INT_MAX 16805b261ecSmrg#undef MININT 16905b261ecSmrg#define MININT INT_MIN 17005b261ecSmrg 17105b261ecSmrg#include <assert.h> 17205b261ecSmrg#include <ctype.h> 17335c4bbdfSmrg#include <stdio.h> /* for fopen, etc... */ 17435c4bbdfSmrg 17535c4bbdfSmrg#endif 17605b261ecSmrg 17735c4bbdfSmrg#ifndef PATH_MAX 17835c4bbdfSmrg#include <sys/param.h> 17935c4bbdfSmrg#ifndef PATH_MAX 18035c4bbdfSmrg#ifdef MAXPATHLEN 18135c4bbdfSmrg#define PATH_MAX MAXPATHLEN 18235c4bbdfSmrg#else 18335c4bbdfSmrg#define PATH_MAX 1024 18435c4bbdfSmrg#endif 18535c4bbdfSmrg#endif 18605b261ecSmrg#endif 18705b261ecSmrg 1886747b715Smrg/** 1896747b715Smrg * Calculate the number of bytes needed to hold bits. 1906747b715Smrg * @param bits The minimum number of bits needed. 1916747b715Smrg * @return The number of bytes needed to hold bits. 1926747b715Smrg */ 1936747b715Smrgstatic inline int 19435c4bbdfSmrgbits_to_bytes(const int bits) 19535c4bbdfSmrg{ 1966747b715Smrg return ((bits + 7) >> 3); 1976747b715Smrg} 19835c4bbdfSmrg 1996747b715Smrg/** 2006747b715Smrg * Calculate the number of 4-byte units needed to hold the given number of 2016747b715Smrg * bytes. 2026747b715Smrg * @param bytes The minimum number of bytes needed. 2036747b715Smrg * @return The number of 4-byte units needed to hold bytes. 2046747b715Smrg */ 2056747b715Smrgstatic inline int 20635c4bbdfSmrgbytes_to_int32(const int bytes) 20735c4bbdfSmrg{ 2086747b715Smrg return (((bytes) + 3) >> 2); 2096747b715Smrg} 2106747b715Smrg 2116747b715Smrg/** 2126747b715Smrg * Calculate the number of bytes (in multiples of 4) needed to hold bytes. 2136747b715Smrg * @param bytes The minimum number of bytes needed. 2146747b715Smrg * @return The closest multiple of 4 that is equal or higher than bytes. 2156747b715Smrg */ 2166747b715Smrgstatic inline int 21735c4bbdfSmrgpad_to_int32(const int bytes) 21835c4bbdfSmrg{ 2196747b715Smrg return (((bytes) + 3) & ~3); 2206747b715Smrg} 2216747b715Smrg 22235c4bbdfSmrg/** 22335c4bbdfSmrg * Calculate padding needed to bring the number of bytes to an even 22435c4bbdfSmrg * multiple of 4. 22535c4bbdfSmrg * @param bytes The minimum number of bytes needed. 22635c4bbdfSmrg * @return The bytes of padding needed to arrive at the closest multiple of 4 22735c4bbdfSmrg * that is equal or higher than bytes. 22835c4bbdfSmrg */ 22935c4bbdfSmrgstatic inline int 23035c4bbdfSmrgpadding_for_int32(const int bytes) 23135c4bbdfSmrg{ 23235c4bbdfSmrg return ((-bytes) & 3); 23335c4bbdfSmrg} 23435c4bbdfSmrg 23535c4bbdfSmrg 2361b5d61b8Smrgextern _X_EXPORT char **xstrtokenize(const char *str, const char *separators); 23735c4bbdfSmrgextern void FormatInt64(int64_t num, char *string); 23835c4bbdfSmrgextern void FormatUInt64(uint64_t num, char *string); 23935c4bbdfSmrgextern void FormatUInt64Hex(uint64_t num, char *string); 24035c4bbdfSmrgextern void FormatDouble(double dbl, char *string); 24135c4bbdfSmrg 24235c4bbdfSmrg/** 24335c4bbdfSmrg * Compare the two version numbers comprising of major.minor. 24435c4bbdfSmrg * 24535c4bbdfSmrg * @return A value less than 0 if a is less than b, 0 if a is equal to b, 24635c4bbdfSmrg * or a value greater than 0 24735c4bbdfSmrg */ 24835c4bbdfSmrgstatic inline int 24935c4bbdfSmrgversion_compare(uint32_t a_major, uint32_t a_minor, 25035c4bbdfSmrg uint32_t b_major, uint32_t b_minor) 25135c4bbdfSmrg{ 25235c4bbdfSmrg if (a_major > b_major) 25335c4bbdfSmrg return 1; 25435c4bbdfSmrg if (a_major < b_major) 25535c4bbdfSmrg return -1; 25635c4bbdfSmrg if (a_minor > b_minor) 25735c4bbdfSmrg return 1; 25835c4bbdfSmrg if (a_minor < b_minor) 25935c4bbdfSmrg return -1; 26035c4bbdfSmrg 26135c4bbdfSmrg return 0; 26235c4bbdfSmrg} 2636747b715Smrg 26405b261ecSmrg/* some macros to help swap requests, replies, and events */ 26505b261ecSmrg 26605b261ecSmrg#define LengthRestB(stuff) \ 26705b261ecSmrg ((client->req_len << 2) - sizeof(*stuff)) 26805b261ecSmrg 26905b261ecSmrg#define LengthRestS(stuff) \ 27005b261ecSmrg ((client->req_len << 1) - (sizeof(*stuff) >> 1)) 27105b261ecSmrg 27205b261ecSmrg#define LengthRestL(stuff) \ 27305b261ecSmrg (client->req_len - (sizeof(*stuff) >> 2)) 27405b261ecSmrg 27505b261ecSmrg#define SwapRestS(stuff) \ 27605b261ecSmrg SwapShorts((short *)(stuff + 1), LengthRestS(stuff)) 27705b261ecSmrg 27805b261ecSmrg#define SwapRestL(stuff) \ 27905b261ecSmrg SwapLongs((CARD32 *)(stuff + 1), LengthRestL(stuff)) 28005b261ecSmrg 28135c4bbdfSmrg#if defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) 28235c4bbdfSmrgvoid __attribute__ ((error("wrong sized variable passed to swap"))) 28335c4bbdfSmrgwrong_size(void); 28435c4bbdfSmrg#else 28535c4bbdfSmrgstatic inline void 28635c4bbdfSmrgwrong_size(void) 28735c4bbdfSmrg{ 28835c4bbdfSmrg} 28935c4bbdfSmrg#endif 29035c4bbdfSmrg 29135c4bbdfSmrg#if !(defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590))) 29235c4bbdfSmrgstatic inline int 29335c4bbdfSmrg__builtin_constant_p(int x) 29435c4bbdfSmrg{ 29535c4bbdfSmrg return 0; 29635c4bbdfSmrg} 29735c4bbdfSmrg#endif 29835c4bbdfSmrg 2991b5d61b8Smrgstatic inline uint64_t 3001b5d61b8Smrgbswap_64(uint64_t x) 30135c4bbdfSmrg{ 3021b5d61b8Smrg return (((x & 0xFF00000000000000ull) >> 56) | 3031b5d61b8Smrg ((x & 0x00FF000000000000ull) >> 40) | 3041b5d61b8Smrg ((x & 0x0000FF0000000000ull) >> 24) | 3051b5d61b8Smrg ((x & 0x000000FF00000000ull) >> 8) | 3061b5d61b8Smrg ((x & 0x00000000FF000000ull) << 8) | 3071b5d61b8Smrg ((x & 0x0000000000FF0000ull) << 24) | 3081b5d61b8Smrg ((x & 0x000000000000FF00ull) << 40) | 3091b5d61b8Smrg ((x & 0x00000000000000FFull) << 56)); 31035c4bbdfSmrg} 31135c4bbdfSmrg 31235c4bbdfSmrg#define swapll(x) do { \ 31335c4bbdfSmrg if (sizeof(*(x)) != 8) \ 31435c4bbdfSmrg wrong_size(); \ 3151b5d61b8Smrg *(x) = bswap_64(*(x)); \ 31635c4bbdfSmrg } while (0) 31735c4bbdfSmrg 3181b5d61b8Smrgstatic inline uint32_t 3191b5d61b8Smrgbswap_32(uint32_t x) 3201b5d61b8Smrg{ 3211b5d61b8Smrg return (((x & 0xFF000000) >> 24) | 3221b5d61b8Smrg ((x & 0x00FF0000) >> 8) | 3231b5d61b8Smrg ((x & 0x0000FF00) << 8) | 3241b5d61b8Smrg ((x & 0x000000FF) << 24)); 3251b5d61b8Smrg} 3261b5d61b8Smrg 3271b5d61b8Smrgstatic inline Bool 3281b5d61b8Smrgchecked_int64_add(int64_t *out, int64_t a, int64_t b) 3291b5d61b8Smrg{ 3301b5d61b8Smrg /* Do the potentially overflowing math as uint64_t, as signed 3311b5d61b8Smrg * integers in C are undefined on overflow (and the compiler may 3321b5d61b8Smrg * optimize out our overflow check below, otherwise) 3331b5d61b8Smrg */ 3341b5d61b8Smrg int64_t result = (uint64_t)a + (uint64_t)b; 3351b5d61b8Smrg /* signed addition overflows if operands have the same sign, and 3361b5d61b8Smrg * the sign of the result doesn't match the sign of the inputs. 3371b5d61b8Smrg */ 3381b5d61b8Smrg Bool overflow = (a < 0) == (b < 0) && (a < 0) != (result < 0); 3391b5d61b8Smrg 3401b5d61b8Smrg *out = result; 3411b5d61b8Smrg 3421b5d61b8Smrg return overflow; 3431b5d61b8Smrg} 3441b5d61b8Smrg 3451b5d61b8Smrgstatic inline Bool 3461b5d61b8Smrgchecked_int64_subtract(int64_t *out, int64_t a, int64_t b) 34735c4bbdfSmrg{ 3481b5d61b8Smrg int64_t result = (uint64_t)a - (uint64_t)b; 3491b5d61b8Smrg Bool overflow = (a < 0) != (b < 0) && (a < 0) != (result < 0); 3501b5d61b8Smrg 3511b5d61b8Smrg *out = result; 35235c4bbdfSmrg 3531b5d61b8Smrg return overflow; 35435c4bbdfSmrg} 35535c4bbdfSmrg 35635c4bbdfSmrg#define swapl(x) do { \ 35735c4bbdfSmrg if (sizeof(*(x)) != 4) \ 35835c4bbdfSmrg wrong_size(); \ 3591b5d61b8Smrg *(x) = bswap_32(*(x)); \ 36035c4bbdfSmrg } while (0) 36135c4bbdfSmrg 3621b5d61b8Smrgstatic inline uint16_t 3631b5d61b8Smrgbswap_16(uint16_t x) 36435c4bbdfSmrg{ 3651b5d61b8Smrg return (((x & 0xFF00) >> 8) | 3661b5d61b8Smrg ((x & 0x00FF) << 8)); 36735c4bbdfSmrg} 36835c4bbdfSmrg 36935c4bbdfSmrg#define swaps(x) do { \ 37035c4bbdfSmrg if (sizeof(*(x)) != 2) \ 37135c4bbdfSmrg wrong_size(); \ 3721b5d61b8Smrg *(x) = bswap_16(*(x)); \ 37335c4bbdfSmrg } while (0) 37405b261ecSmrg 37505b261ecSmrg/* copy 32-bit value from src to dst byteswapping on the way */ 37635c4bbdfSmrg#define cpswapl(src, dst) do { \ 37735c4bbdfSmrg if (sizeof((src)) != 4 || sizeof((dst)) != 4) \ 37835c4bbdfSmrg wrong_size(); \ 3791b5d61b8Smrg (dst) = bswap_32((src)); \ 38035c4bbdfSmrg } while (0) 38105b261ecSmrg 38205b261ecSmrg/* copy short from src to dst byteswapping on the way */ 38335c4bbdfSmrg#define cpswaps(src, dst) do { \ 38435c4bbdfSmrg if (sizeof((src)) != 2 || sizeof((dst)) != 2) \ 38535c4bbdfSmrg wrong_size(); \ 3861b5d61b8Smrg (dst) = bswap_16((src)); \ 38735c4bbdfSmrg } while (0) 38805b261ecSmrg 38935c4bbdfSmrgextern _X_EXPORT void SwapLongs(CARD32 *list, unsigned long count); 39005b261ecSmrg 39135c4bbdfSmrgextern _X_EXPORT void SwapShorts(short *list, unsigned long count); 39205b261ecSmrg 3936747b715Smrgextern _X_EXPORT void MakePredeclaredAtoms(void); 39405b261ecSmrg 39535c4bbdfSmrgextern _X_EXPORT int Ones(unsigned long /*mask */ ); 39605b261ecSmrg 39705b261ecSmrgtypedef struct _xPoint *DDXPointPtr; 39805b261ecSmrgtypedef struct pixman_box16 *BoxPtr; 39905b261ecSmrgtypedef struct _xEvent *xEventPtr; 40005b261ecSmrgtypedef struct _xRectangle *xRectanglePtr; 40105b261ecSmrgtypedef struct _GrabRec *GrabPtr; 40205b261ecSmrg 40305b261ecSmrg/* typedefs from other places - duplicated here to minimize the amount 40405b261ecSmrg * of unnecessary junk that one would normally have to include to get 40505b261ecSmrg * these symbols defined 40605b261ecSmrg */ 40705b261ecSmrg 40805b261ecSmrg#ifndef _XTYPEDEF_CHARINFOPTR 40935c4bbdfSmrgtypedef struct _CharInfo *CharInfoPtr; /* also in fonts/include/font.h */ 41035c4bbdfSmrg 41105b261ecSmrg#define _XTYPEDEF_CHARINFOPTR 41205b261ecSmrg#endif 41305b261ecSmrg 4146747b715Smrgextern _X_EXPORT unsigned long globalSerialNumber; 4156747b715Smrgextern _X_EXPORT unsigned long serverGeneration; 4166747b715Smrg 41735c4bbdfSmrg/* Don't use this directly, use BUG_WARN or BUG_WARN_MSG instead */ 41835c4bbdfSmrg#define __BUG_WARN_MSG(cond, with_msg, ...) \ 41935c4bbdfSmrg do { if (cond) { \ 42035c4bbdfSmrg ErrorFSigSafe("BUG: triggered 'if (" #cond ")'\n"); \ 42135c4bbdfSmrg ErrorFSigSafe("BUG: %s:%u in %s()\n", \ 42235c4bbdfSmrg __FILE__, __LINE__, __func__); \ 42335c4bbdfSmrg if (with_msg) ErrorFSigSafe(__VA_ARGS__); \ 42435c4bbdfSmrg xorg_backtrace(); \ 42535c4bbdfSmrg } } while(0) 42635c4bbdfSmrg 42735c4bbdfSmrg#define BUG_WARN_MSG(cond, ...) \ 42835c4bbdfSmrg __BUG_WARN_MSG(cond, 1, __VA_ARGS__) 42935c4bbdfSmrg 43035c4bbdfSmrg#define BUG_WARN(cond) __BUG_WARN_MSG(cond, 0, NULL) 43135c4bbdfSmrg 43235c4bbdfSmrg#define BUG_RETURN(cond) \ 43335c4bbdfSmrg do { if (cond) { __BUG_WARN_MSG(cond, 0, NULL); return; } } while(0) 43435c4bbdfSmrg 43535c4bbdfSmrg#define BUG_RETURN_MSG(cond, ...) \ 43635c4bbdfSmrg do { if (cond) { __BUG_WARN_MSG(cond, 1, __VA_ARGS__); return; } } while(0) 43735c4bbdfSmrg 43835c4bbdfSmrg#define BUG_RETURN_VAL(cond, val) \ 43935c4bbdfSmrg do { if (cond) { __BUG_WARN_MSG(cond, 0, NULL); return (val); } } while(0) 44035c4bbdfSmrg 44135c4bbdfSmrg#define BUG_RETURN_VAL_MSG(cond, val, ...) \ 44235c4bbdfSmrg do { if (cond) { __BUG_WARN_MSG(cond, 1, __VA_ARGS__); return (val); } } while(0) 44335c4bbdfSmrg 44435c4bbdfSmrg#endif /* MISC_H */ 445