misc.h revision 35c4bbdf
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> 8205b261ecSmrg 8305b261ecSmrg#ifndef MAXSCREENS 8405b261ecSmrg#define MAXSCREENS 16 8505b261ecSmrg#endif 8635c4bbdfSmrg#ifndef MAXGPUSCREENS 8735c4bbdfSmrg#define MAXGPUSCREENS 16 8835c4bbdfSmrg#endif 8935c4bbdfSmrg#define MAXCLIENTS 512 9035c4bbdfSmrg#define LIMITCLIENTS 256 /* Must be a power of 2 and <= MAXCLIENTS */ 914642e01fSmrg#define MAXEXTENSIONS 128 9205b261ecSmrg#define MAXFORMATS 8 9335c4bbdfSmrg#define MAXDEVICES 40 /* input devices */ 9435c4bbdfSmrg#define GPU_SCREEN_OFFSET 256 954642e01fSmrg 9635c4bbdfSmrg/* 128 event opcodes for core + extension events, excluding GE */ 9735c4bbdfSmrg#define MAXEVENTS 128 984642e01fSmrg#define EXTENSION_EVENT_BASE 64 994642e01fSmrg#define EXTENSION_BASE 128 10005b261ecSmrg 10135c4bbdfSmrgtypedef uint32_t ATOM; 10205b261ecSmrg 10305b261ecSmrg#ifndef TRUE 10405b261ecSmrg#define TRUE 1 10505b261ecSmrg#define FALSE 0 10605b261ecSmrg#endif 10705b261ecSmrg 10805b261ecSmrg#ifndef _XTYPEDEF_CALLBACKLISTPTR 10935c4bbdfSmrgtypedef struct _CallbackList *CallbackListPtr; /* also in dix.h */ 11035c4bbdfSmrg 11105b261ecSmrg#define _XTYPEDEF_CALLBACKLISTPTR 11205b261ecSmrg#endif 11305b261ecSmrg 11405b261ecSmrgtypedef struct _xReq *xReqPtr; 11505b261ecSmrg 11635c4bbdfSmrg#include "os.h" /* for ALLOCATE_LOCAL and DEALLOCATE_LOCAL */ 11735c4bbdfSmrg#include <X11/Xfuncs.h> /* for bcopy, bzero, and bcmp */ 11805b261ecSmrg 11905b261ecSmrg#define NullBox ((BoxPtr)0) 12005b261ecSmrg#define MILLI_PER_MIN (1000 * 60) 12105b261ecSmrg#define MILLI_PER_SECOND (1000) 12205b261ecSmrg 12305b261ecSmrg /* this next is used with None and ParentRelative to tell 12405b261ecSmrg PaintWin() what to use to paint the background. Also used 12505b261ecSmrg in the macro IS_VALID_PIXMAP */ 12605b261ecSmrg 12705b261ecSmrg#define USE_BACKGROUND_PIXEL 3 12805b261ecSmrg#define USE_BORDER_PIXEL 3 12905b261ecSmrg 13005b261ecSmrg/* byte swap a 32-bit literal */ 13135c4bbdfSmrgstatic inline uint32_t 13235c4bbdfSmrglswapl(uint32_t x) 13335c4bbdfSmrg{ 13435c4bbdfSmrg return ((x & 0xff) << 24) | 13535c4bbdfSmrg ((x & 0xff00) << 8) | ((x & 0xff0000) >> 8) | ((x >> 24) & 0xff); 13635c4bbdfSmrg} 13705b261ecSmrg 13835c4bbdfSmrg/* byte swap a 16-bit literal */ 13935c4bbdfSmrgstatic inline uint16_t 14035c4bbdfSmrglswaps(uint16_t x) 14135c4bbdfSmrg{ 14235c4bbdfSmrg return (uint16_t)((x & 0xff) << 8) | ((x >> 8) & 0xff); 14335c4bbdfSmrg} 14405b261ecSmrg 14505b261ecSmrg#undef min 14605b261ecSmrg#undef max 14705b261ecSmrg 14805b261ecSmrg#define min(a, b) (((a) < (b)) ? (a) : (b)) 14905b261ecSmrg#define max(a, b) (((a) > (b)) ? (a) : (b)) 15005b261ecSmrg/* abs() is a function, not a macro; include the file declaring 15105b261ecSmrg * it in case we haven't done that yet. 15205b261ecSmrg */ 15305b261ecSmrg#include <stdlib.h> 15405b261ecSmrg#define sign(x) ((x) < 0 ? -1 : ((x) > 0 ? 1 : 0)) 15505b261ecSmrg/* this assumes b > 0 */ 15605b261ecSmrg#define modulus(a, b, d) if (((d) = (a) % (b)) < 0) (d) += (b) 15705b261ecSmrg/* 15805b261ecSmrg * return the least significant bit in x which is set 15905b261ecSmrg * 16005b261ecSmrg * This works on 1's complement and 2's complement machines. 16105b261ecSmrg * If you care about the extra instruction on 2's complement 16205b261ecSmrg * machines, change to ((x) & (-(x))) 16305b261ecSmrg */ 16405b261ecSmrg#define lowbit(x) ((x) & (~(x) + 1)) 16505b261ecSmrg 16605b261ecSmrg/* XXX Not for modules */ 16705b261ecSmrg#include <limits.h> 16805b261ecSmrg#if !defined(MAXSHORT) || !defined(MINSHORT) || \ 16905b261ecSmrg !defined(MAXINT) || !defined(MININT) 17005b261ecSmrg/* 17105b261ecSmrg * Some implementations #define these through <math.h>, so preclude 17205b261ecSmrg * #include'ing it later. 17305b261ecSmrg */ 17405b261ecSmrg 17505b261ecSmrg#include <math.h> 17605b261ecSmrg#undef MAXSHORT 17705b261ecSmrg#define MAXSHORT SHRT_MAX 17805b261ecSmrg#undef MINSHORT 17905b261ecSmrg#define MINSHORT SHRT_MIN 18005b261ecSmrg#undef MAXINT 18105b261ecSmrg#define MAXINT INT_MAX 18205b261ecSmrg#undef MININT 18305b261ecSmrg#define MININT INT_MIN 18405b261ecSmrg 18505b261ecSmrg#include <assert.h> 18605b261ecSmrg#include <ctype.h> 18735c4bbdfSmrg#include <stdio.h> /* for fopen, etc... */ 18835c4bbdfSmrg 18935c4bbdfSmrg#endif 19005b261ecSmrg 19135c4bbdfSmrg#ifndef PATH_MAX 19235c4bbdfSmrg#include <sys/param.h> 19335c4bbdfSmrg#ifndef PATH_MAX 19435c4bbdfSmrg#ifdef MAXPATHLEN 19535c4bbdfSmrg#define PATH_MAX MAXPATHLEN 19635c4bbdfSmrg#else 19735c4bbdfSmrg#define PATH_MAX 1024 19835c4bbdfSmrg#endif 19935c4bbdfSmrg#endif 20005b261ecSmrg#endif 20105b261ecSmrg 2026747b715Smrg/** 2036747b715Smrg * Calculate the number of bytes needed to hold bits. 2046747b715Smrg * @param bits The minimum number of bits needed. 2056747b715Smrg * @return The number of bytes needed to hold bits. 2066747b715Smrg */ 2076747b715Smrgstatic inline int 20835c4bbdfSmrgbits_to_bytes(const int bits) 20935c4bbdfSmrg{ 2106747b715Smrg return ((bits + 7) >> 3); 2116747b715Smrg} 21235c4bbdfSmrg 2136747b715Smrg/** 2146747b715Smrg * Calculate the number of 4-byte units needed to hold the given number of 2156747b715Smrg * bytes. 2166747b715Smrg * @param bytes The minimum number of bytes needed. 2176747b715Smrg * @return The number of 4-byte units needed to hold bytes. 2186747b715Smrg */ 2196747b715Smrgstatic inline int 22035c4bbdfSmrgbytes_to_int32(const int bytes) 22135c4bbdfSmrg{ 2226747b715Smrg return (((bytes) + 3) >> 2); 2236747b715Smrg} 2246747b715Smrg 2256747b715Smrg/** 2266747b715Smrg * Calculate the number of bytes (in multiples of 4) needed to hold bytes. 2276747b715Smrg * @param bytes The minimum number of bytes needed. 2286747b715Smrg * @return The closest multiple of 4 that is equal or higher than bytes. 2296747b715Smrg */ 2306747b715Smrgstatic inline int 23135c4bbdfSmrgpad_to_int32(const int bytes) 23235c4bbdfSmrg{ 2336747b715Smrg return (((bytes) + 3) & ~3); 2346747b715Smrg} 2356747b715Smrg 23635c4bbdfSmrg/** 23735c4bbdfSmrg * Calculate padding needed to bring the number of bytes to an even 23835c4bbdfSmrg * multiple of 4. 23935c4bbdfSmrg * @param bytes The minimum number of bytes needed. 24035c4bbdfSmrg * @return The bytes of padding needed to arrive at the closest multiple of 4 24135c4bbdfSmrg * that is equal or higher than bytes. 24235c4bbdfSmrg */ 24335c4bbdfSmrgstatic inline int 24435c4bbdfSmrgpadding_for_int32(const int bytes) 24535c4bbdfSmrg{ 24635c4bbdfSmrg return ((-bytes) & 3); 24735c4bbdfSmrg} 24835c4bbdfSmrg 24935c4bbdfSmrg 25035c4bbdfSmrgextern char **xstrtokenize(const char *str, const char *separators); 25135c4bbdfSmrgextern void FormatInt64(int64_t num, char *string); 25235c4bbdfSmrgextern void FormatUInt64(uint64_t num, char *string); 25335c4bbdfSmrgextern void FormatUInt64Hex(uint64_t num, char *string); 25435c4bbdfSmrgextern void FormatDouble(double dbl, char *string); 25535c4bbdfSmrg 25635c4bbdfSmrg/** 25735c4bbdfSmrg * Compare the two version numbers comprising of major.minor. 25835c4bbdfSmrg * 25935c4bbdfSmrg * @return A value less than 0 if a is less than b, 0 if a is equal to b, 26035c4bbdfSmrg * or a value greater than 0 26135c4bbdfSmrg */ 26235c4bbdfSmrgstatic inline int 26335c4bbdfSmrgversion_compare(uint32_t a_major, uint32_t a_minor, 26435c4bbdfSmrg uint32_t b_major, uint32_t b_minor) 26535c4bbdfSmrg{ 26635c4bbdfSmrg if (a_major > b_major) 26735c4bbdfSmrg return 1; 26835c4bbdfSmrg if (a_major < b_major) 26935c4bbdfSmrg return -1; 27035c4bbdfSmrg if (a_minor > b_minor) 27135c4bbdfSmrg return 1; 27235c4bbdfSmrg if (a_minor < b_minor) 27335c4bbdfSmrg return -1; 27435c4bbdfSmrg 27535c4bbdfSmrg return 0; 27635c4bbdfSmrg} 2776747b715Smrg 27805b261ecSmrg/* some macros to help swap requests, replies, and events */ 27905b261ecSmrg 28005b261ecSmrg#define LengthRestB(stuff) \ 28105b261ecSmrg ((client->req_len << 2) - sizeof(*stuff)) 28205b261ecSmrg 28305b261ecSmrg#define LengthRestS(stuff) \ 28405b261ecSmrg ((client->req_len << 1) - (sizeof(*stuff) >> 1)) 28505b261ecSmrg 28605b261ecSmrg#define LengthRestL(stuff) \ 28705b261ecSmrg (client->req_len - (sizeof(*stuff) >> 2)) 28805b261ecSmrg 28905b261ecSmrg#define SwapRestS(stuff) \ 29005b261ecSmrg SwapShorts((short *)(stuff + 1), LengthRestS(stuff)) 29105b261ecSmrg 29205b261ecSmrg#define SwapRestL(stuff) \ 29305b261ecSmrg SwapLongs((CARD32 *)(stuff + 1), LengthRestL(stuff)) 29405b261ecSmrg 29535c4bbdfSmrg#if defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) 29635c4bbdfSmrgvoid __attribute__ ((error("wrong sized variable passed to swap"))) 29735c4bbdfSmrgwrong_size(void); 29835c4bbdfSmrg#else 29935c4bbdfSmrgstatic inline void 30035c4bbdfSmrgwrong_size(void) 30135c4bbdfSmrg{ 30235c4bbdfSmrg} 30335c4bbdfSmrg#endif 30435c4bbdfSmrg 30535c4bbdfSmrg#if !(defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590))) 30635c4bbdfSmrgstatic inline int 30735c4bbdfSmrg__builtin_constant_p(int x) 30835c4bbdfSmrg{ 30935c4bbdfSmrg return 0; 31035c4bbdfSmrg} 31135c4bbdfSmrg#endif 31235c4bbdfSmrg 31335c4bbdfSmrg/* byte swap a 64-bit value */ 31435c4bbdfSmrgstatic inline void 31535c4bbdfSmrgswap_uint64(uint64_t *x) 31635c4bbdfSmrg{ 31735c4bbdfSmrg char n; 31835c4bbdfSmrg 31935c4bbdfSmrg n = ((char *) x)[0]; 32035c4bbdfSmrg ((char *) x)[0] = ((char *) x)[7]; 32135c4bbdfSmrg ((char *) x)[7] = n; 32235c4bbdfSmrg 32335c4bbdfSmrg n = ((char *) x)[1]; 32435c4bbdfSmrg ((char *) x)[1] = ((char *) x)[6]; 32535c4bbdfSmrg ((char *) x)[6] = n; 32635c4bbdfSmrg 32735c4bbdfSmrg n = ((char *) x)[2]; 32835c4bbdfSmrg ((char *) x)[2] = ((char *) x)[5]; 32935c4bbdfSmrg ((char *) x)[5] = n; 33035c4bbdfSmrg 33135c4bbdfSmrg n = ((char *) x)[3]; 33235c4bbdfSmrg ((char *) x)[3] = ((char *) x)[4]; 33335c4bbdfSmrg ((char *) x)[4] = n; 33435c4bbdfSmrg} 33535c4bbdfSmrg 33635c4bbdfSmrg#define swapll(x) do { \ 33735c4bbdfSmrg if (sizeof(*(x)) != 8) \ 33835c4bbdfSmrg wrong_size(); \ 33935c4bbdfSmrg swap_uint64((uint64_t *)(x)); \ 34035c4bbdfSmrg } while (0) 34135c4bbdfSmrg 34205b261ecSmrg/* byte swap a 32-bit value */ 34335c4bbdfSmrgstatic inline void 34435c4bbdfSmrgswap_uint32(uint32_t * x) 34535c4bbdfSmrg{ 34635c4bbdfSmrg char n = ((char *) x)[0]; 34735c4bbdfSmrg 34835c4bbdfSmrg ((char *) x)[0] = ((char *) x)[3]; 34935c4bbdfSmrg ((char *) x)[3] = n; 35035c4bbdfSmrg n = ((char *) x)[1]; 35135c4bbdfSmrg ((char *) x)[1] = ((char *) x)[2]; 35235c4bbdfSmrg ((char *) x)[2] = n; 35335c4bbdfSmrg} 35435c4bbdfSmrg 35535c4bbdfSmrg#define swapl(x) do { \ 35635c4bbdfSmrg if (sizeof(*(x)) != 4) \ 35735c4bbdfSmrg wrong_size(); \ 35835c4bbdfSmrg if (__builtin_constant_p((uintptr_t)(x) & 3) && ((uintptr_t)(x) & 3) == 0) \ 35935c4bbdfSmrg *(x) = lswapl(*(x)); \ 36035c4bbdfSmrg else \ 36135c4bbdfSmrg swap_uint32((uint32_t *)(x)); \ 36235c4bbdfSmrg } while (0) 36335c4bbdfSmrg 36435c4bbdfSmrg/* byte swap a 16-bit value */ 36535c4bbdfSmrgstatic inline void 36635c4bbdfSmrgswap_uint16(uint16_t * x) 36735c4bbdfSmrg{ 36835c4bbdfSmrg char n = ((char *) x)[0]; 36935c4bbdfSmrg 37035c4bbdfSmrg ((char *) x)[0] = ((char *) x)[1]; 37135c4bbdfSmrg ((char *) x)[1] = n; 37235c4bbdfSmrg} 37335c4bbdfSmrg 37435c4bbdfSmrg#define swaps(x) do { \ 37535c4bbdfSmrg if (sizeof(*(x)) != 2) \ 37635c4bbdfSmrg wrong_size(); \ 37735c4bbdfSmrg if (__builtin_constant_p((uintptr_t)(x) & 1) && ((uintptr_t)(x) & 1) == 0) \ 37835c4bbdfSmrg *(x) = lswaps(*(x)); \ 37935c4bbdfSmrg else \ 38035c4bbdfSmrg swap_uint16((uint16_t *)(x)); \ 38135c4bbdfSmrg } while (0) 38205b261ecSmrg 38305b261ecSmrg/* copy 32-bit value from src to dst byteswapping on the way */ 38435c4bbdfSmrg#define cpswapl(src, dst) do { \ 38535c4bbdfSmrg if (sizeof((src)) != 4 || sizeof((dst)) != 4) \ 38635c4bbdfSmrg wrong_size(); \ 38735c4bbdfSmrg (dst) = lswapl((src)); \ 38835c4bbdfSmrg } while (0) 38905b261ecSmrg 39005b261ecSmrg/* copy short from src to dst byteswapping on the way */ 39135c4bbdfSmrg#define cpswaps(src, dst) do { \ 39235c4bbdfSmrg if (sizeof((src)) != 2 || sizeof((dst)) != 2) \ 39335c4bbdfSmrg wrong_size(); \ 39435c4bbdfSmrg (dst) = lswaps((src)); \ 39535c4bbdfSmrg } while (0) 39605b261ecSmrg 39735c4bbdfSmrgextern _X_EXPORT void SwapLongs(CARD32 *list, unsigned long count); 39805b261ecSmrg 39935c4bbdfSmrgextern _X_EXPORT void SwapShorts(short *list, unsigned long count); 40005b261ecSmrg 4016747b715Smrgextern _X_EXPORT void MakePredeclaredAtoms(void); 40205b261ecSmrg 40335c4bbdfSmrgextern _X_EXPORT int Ones(unsigned long /*mask */ ); 40405b261ecSmrg 40505b261ecSmrgtypedef struct _xPoint *DDXPointPtr; 40605b261ecSmrgtypedef struct pixman_box16 *BoxPtr; 40705b261ecSmrgtypedef struct _xEvent *xEventPtr; 40805b261ecSmrgtypedef struct _xRectangle *xRectanglePtr; 40905b261ecSmrgtypedef struct _GrabRec *GrabPtr; 41005b261ecSmrg 41105b261ecSmrg/* typedefs from other places - duplicated here to minimize the amount 41205b261ecSmrg * of unnecessary junk that one would normally have to include to get 41305b261ecSmrg * these symbols defined 41405b261ecSmrg */ 41505b261ecSmrg 41605b261ecSmrg#ifndef _XTYPEDEF_CHARINFOPTR 41735c4bbdfSmrgtypedef struct _CharInfo *CharInfoPtr; /* also in fonts/include/font.h */ 41835c4bbdfSmrg 41905b261ecSmrg#define _XTYPEDEF_CHARINFOPTR 42005b261ecSmrg#endif 42105b261ecSmrg 4226747b715Smrgextern _X_EXPORT unsigned long globalSerialNumber; 4236747b715Smrgextern _X_EXPORT unsigned long serverGeneration; 4246747b715Smrg 42535c4bbdfSmrg/* Don't use this directly, use BUG_WARN or BUG_WARN_MSG instead */ 42635c4bbdfSmrg#define __BUG_WARN_MSG(cond, with_msg, ...) \ 42735c4bbdfSmrg do { if (cond) { \ 42835c4bbdfSmrg ErrorFSigSafe("BUG: triggered 'if (" #cond ")'\n"); \ 42935c4bbdfSmrg ErrorFSigSafe("BUG: %s:%u in %s()\n", \ 43035c4bbdfSmrg __FILE__, __LINE__, __func__); \ 43135c4bbdfSmrg if (with_msg) ErrorFSigSafe(__VA_ARGS__); \ 43235c4bbdfSmrg xorg_backtrace(); \ 43335c4bbdfSmrg } } while(0) 43435c4bbdfSmrg 43535c4bbdfSmrg#define BUG_WARN_MSG(cond, ...) \ 43635c4bbdfSmrg __BUG_WARN_MSG(cond, 1, __VA_ARGS__) 43735c4bbdfSmrg 43835c4bbdfSmrg#define BUG_WARN(cond) __BUG_WARN_MSG(cond, 0, NULL) 43935c4bbdfSmrg 44035c4bbdfSmrg#define BUG_RETURN(cond) \ 44135c4bbdfSmrg do { if (cond) { __BUG_WARN_MSG(cond, 0, NULL); return; } } while(0) 44235c4bbdfSmrg 44335c4bbdfSmrg#define BUG_RETURN_MSG(cond, ...) \ 44435c4bbdfSmrg do { if (cond) { __BUG_WARN_MSG(cond, 1, __VA_ARGS__); return; } } while(0) 44535c4bbdfSmrg 44635c4bbdfSmrg#define BUG_RETURN_VAL(cond, val) \ 44735c4bbdfSmrg do { if (cond) { __BUG_WARN_MSG(cond, 0, NULL); return (val); } } while(0) 44835c4bbdfSmrg 44935c4bbdfSmrg#define BUG_RETURN_VAL_MSG(cond, val, ...) \ 45035c4bbdfSmrg do { if (cond) { __BUG_WARN_MSG(cond, 1, __VA_ARGS__); return (val); } } while(0) 45135c4bbdfSmrg 45235c4bbdfSmrg#endif /* MISC_H */ 453