diff options
| author | Mikhail Gusarov <dottedmag@dottedmag.net> | 2010-05-07 20:22:20 +0000 |
|---|---|---|
| committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2010-05-07 18:48:12 -0700 |
| commit | 996d92d2710f9dc740351f4d9cbe14af64569689 (patch) | |
| tree | 0e3fe578b2119bf22e62ee0fb8ca22b3f56d50fd | |
| parent | 2a51e57425e1b4062a459a19b1860c9c9721d9ea (diff) | |
Get rid of Xalloc/Xrealloc/Xfree from X server or Xlib
alloc/realloc/free calls are encapsulated in libXdmcp, so
there is no need to wrap allocation functions even under Windows
Signed-off-by: Mikhail Gusarov <dottedmag@dottedmag.net>
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
| -rw-r--r-- | Alloc.c | 74 | ||||
| -rw-r--r-- | Array.c | 45 | ||||
| -rw-r--r-- | Fill.c | 5 | ||||
| -rw-r--r-- | Makefile.am | 1 | ||||
| -rw-r--r-- | Read.c | 27 | ||||
| -rw-r--r-- | Write.c | 5 | ||||
| -rw-r--r-- | include/X11/Xdmcp.h | 6 |
7 files changed, 52 insertions, 111 deletions
diff --git a/Alloc.c b/Alloc.c deleted file mode 100644 index f180eaf..0000000 --- a/Alloc.c +++ /dev/null @@ -1,74 +0,0 @@ -/* -Copyright 1989, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - * * - * Author: Keith Packard, MIT X Consortium - */ - -/* stubs for use when Xalloc, Xrealloc and Xfree are not defined */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <X11/Xos.h> -#include <X11/X.h> -#include <X11/Xmd.h> -#include <X11/Xdmcp.h> -#include <stdlib.h> - -/* this probably works for Mach-O too, but probably not for PE */ -#if defined(__ELF__) && defined(__GNUC__) && (__GNUC__ >= 3) -#define weak __attribute__((weak)) -#else -#define weak -#endif - -#ifdef __SUNPRO_C -#pragma weak Xalloc -#pragma weak Xrealloc -#pragma weak Xfree -#endif - -weak void * -Xalloc (unsigned long amount) -{ - if (amount == 0) - amount = 1; - return malloc (amount); -} - -weak void * -Xrealloc (void *old, unsigned long amount) -{ - if (amount == 0) - amount = 1; - if (!old) - return malloc (amount); - return realloc ((char *) old, amount); -} - -weak void -Xfree (void *old) -{ - if (old) - free ((char *) old); -} @@ -32,6 +32,25 @@ in this Software without prior written authorization from The Open Group. #include <X11/Xmd.h> #include <X11/Xdmcp.h> #include <stdint.h> +#include <stdlib.h> + +/* + * This variant of malloc does not return NULL if zero size is passed into. + */ +static void * +xmalloc(size_t size) +{ + return malloc(size ? size : 1); +} + +/* + * This variant of realloc does not return NULL if zero size is passed into + */ +static void * +xrealloc(void *ptr, size_t size) +{ + return realloc(ptr, size ? size : 1); +} int XdmcpAllocARRAY8 (ARRAY8Ptr array, int length) @@ -42,7 +61,7 @@ XdmcpAllocARRAY8 (ARRAY8Ptr array, int length) if (length > UINT16_MAX) return FALSE; - newData = (CARD8Ptr) Xalloc (length * sizeof (CARD8)); + newData = (CARD8Ptr) xmalloc(length * sizeof (CARD8)); if (!newData) return FALSE; array->length = (CARD16) length; @@ -59,7 +78,7 @@ XdmcpAllocARRAY16 (ARRAY16Ptr array, int length) if (length > UINT8_MAX) return FALSE; - newData = (CARD16Ptr) Xalloc (length * sizeof (CARD16)); + newData = (CARD16Ptr) xmalloc(length * sizeof (CARD16)); if (!newData) return FALSE; array->length = (CARD8) length; @@ -76,7 +95,7 @@ XdmcpAllocARRAY32 (ARRAY32Ptr array, int length) if (length > UINT8_MAX) return FALSE; - newData = (CARD32Ptr) Xalloc (length * sizeof (CARD32)); + newData = (CARD32Ptr) xmalloc(length * sizeof (CARD32)); if (!newData) return FALSE; array->length = (CARD8) length; @@ -93,7 +112,7 @@ XdmcpAllocARRAYofARRAY8 (ARRAYofARRAY8Ptr array, int length) if (length > UINT8_MAX) return FALSE; - newData = (ARRAY8Ptr) Xalloc (length * sizeof (ARRAY8)); + newData = (ARRAY8Ptr) xmalloc(length * sizeof (ARRAY8)); if (!newData) return FALSE; array->length = (CARD8) length; @@ -115,7 +134,7 @@ int XdmcpCopyARRAY8 (const ARRAY8Ptr src, ARRAY8Ptr dst) { dst->length = src->length; - dst->data = (CARD8 *) Xalloc (dst->length * sizeof (CARD8)); + dst->data = (CARD8 *) xmalloc(dst->length * sizeof (CARD8)); if (!dst->data) return FALSE; memmove (dst->data, src->data, src->length * sizeof (CARD8)); @@ -131,7 +150,7 @@ XdmcpReallocARRAY8 (ARRAY8Ptr array, int length) if (length > UINT16_MAX) return FALSE; - newData = (CARD8Ptr) Xrealloc (array->data, length * sizeof (CARD8)); + newData = (CARD8Ptr) xrealloc(array->data, length * sizeof (CARD8)); if (!newData) return FALSE; array->length = (CARD16) length; @@ -148,7 +167,7 @@ XdmcpReallocARRAYofARRAY8 (ARRAYofARRAY8Ptr array, int length) if (length > UINT8_MAX) return FALSE; - newData = (ARRAY8Ptr) Xrealloc (array->data, length * sizeof (ARRAY8)); + newData = (ARRAY8Ptr) xrealloc(array->data, length * sizeof (ARRAY8)); if (!newData) return FALSE; array->length = (CARD8) length; @@ -164,7 +183,7 @@ XdmcpReallocARRAY16 (ARRAY16Ptr array, int length) /* length defined in ARRAY16 struct is a CARD8 */ if (length > UINT8_MAX) return FALSE; - newData = (CARD16Ptr) Xrealloc (array->data, length * sizeof (CARD16)); + newData = (CARD16Ptr) xrealloc(array->data, length * sizeof (CARD16)); if (!newData) return FALSE; array->length = (CARD8) length; @@ -181,7 +200,7 @@ XdmcpReallocARRAY32 (ARRAY32Ptr array, int length) if (length > UINT8_MAX) return FALSE; - newData = (CARD32Ptr) Xrealloc (array->data, length * sizeof (CARD32)); + newData = (CARD32Ptr) xrealloc(array->data, length * sizeof (CARD32)); if (!newData) return FALSE; array->length = (CARD8) length; @@ -192,7 +211,7 @@ XdmcpReallocARRAY32 (ARRAY32Ptr array, int length) void XdmcpDisposeARRAY8 (ARRAY8Ptr array) { - if (array->data != NULL) Xfree (array->data); + free(array->data); array->length = 0; array->data = NULL; } @@ -200,7 +219,7 @@ XdmcpDisposeARRAY8 (ARRAY8Ptr array) void XdmcpDisposeARRAY16 (ARRAY16Ptr array) { - if (array->data != NULL) Xfree (array->data); + free(array->data); array->length = 0; array->data = NULL; } @@ -208,7 +227,7 @@ XdmcpDisposeARRAY16 (ARRAY16Ptr array) void XdmcpDisposeARRAY32 (ARRAY32Ptr array) { - if (array->data != NULL) Xfree (array->data); + free(array->data); array->length = 0; array->data = NULL; } @@ -221,7 +240,7 @@ XdmcpDisposeARRAYofARRAY8 (ARRAYofARRAY8Ptr array) if (array->data != NULL) { for (i = 0; i < (int)array->length; i++) XdmcpDisposeARRAY8 (&array->data[i]); - Xfree (array->data); + free(array->data); } array->length = 0; array->data = NULL; @@ -34,6 +34,7 @@ in this Software without prior written authorization from The Open Group. #include <X11/X.h> #include <X11/Xmd.h> #include <X11/Xdmcp.h> +#include <stdlib.h> #ifdef STREAMSCONN #include <tiuser.h> @@ -56,10 +57,10 @@ XdmcpFill (int fd, XdmcpBufferPtr buffer, XdmcpNetaddr from, int *fromlen) if (buffer->size < XDM_MAX_MSGLEN) { - newBuf = (BYTE *) Xalloc (XDM_MAX_MSGLEN); + newBuf = (BYTE *) malloc(XDM_MAX_MSGLEN); if (newBuf) { - Xfree (buffer->data); + free(buffer->data); buffer->data = newBuf; buffer->size = XDM_MAX_MSGLEN; } diff --git a/Makefile.am b/Makefile.am index 4a55544..244a0c2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -8,7 +8,6 @@ AM_CFLAGS = \ libXdmcp_la_LDFLAGS = -version-number 6:0:0 -no-undefined libXdmcp_la_LIBADD = $(XDMCP_LIBS) libXdmcp_la_SOURCES = \ - Alloc.c \ Array.c \ Fill.c \ Flush.c \ @@ -31,6 +31,7 @@ in this Software without prior written authorization from The Open Group. #include <X11/X.h> #include <X11/Xmd.h> #include <X11/Xdmcp.h> +#include <stdlib.h> int XdmcpReadHeader (XdmcpBufferPtr buffer, XdmcpHeaderPtr header) @@ -56,7 +57,7 @@ XdmcpReadARRAY8 (XdmcpBufferPtr buffer, ARRAY8Ptr array) if (!XdmcpReadCARD16 (buffer, &array->length)) { /* Must set array->data to NULL to guarantee safe call of - * XdmcpDisposeARRAY*(array) (which calls Xfree(array->data)); + * XdmcpDisposeARRAY*(array) (which calls free(array->data)); * see defect 7329 */ array->data = NULL; return FALSE; @@ -66,14 +67,14 @@ XdmcpReadARRAY8 (XdmcpBufferPtr buffer, ARRAY8Ptr array) array->data = NULL; return TRUE; } - array->data = (CARD8 *) Xalloc (array->length * sizeof (CARD8)); + array->data = (CARD8 *) malloc(array->length * sizeof (CARD8)); if (!array->data) return FALSE; for (i = 0; i < (int)array->length; i++) { if (!XdmcpReadCARD8 (buffer, &array->data[i])) { - Xfree (array->data); + free(array->data); array->data = NULL; array->length = 0; return FALSE; @@ -90,7 +91,7 @@ XdmcpReadARRAY16 (XdmcpBufferPtr buffer, ARRAY16Ptr array) if (!XdmcpReadCARD8 (buffer, &array->length)) { /* Must set array->data to NULL to guarantee safe call of - * XdmcpDisposeARRAY*(array) (which calls Xfree(array->data)); + * XdmcpDisposeARRAY*(array) (which calls free(array->data)); * see defect 7329 */ array->data = NULL; return FALSE; @@ -100,14 +101,14 @@ XdmcpReadARRAY16 (XdmcpBufferPtr buffer, ARRAY16Ptr array) array->data = NULL; return TRUE; } - array->data = (CARD16 *) Xalloc (array->length * sizeof (CARD16)); + array->data = (CARD16 *) malloc(array->length * sizeof (CARD16)); if (!array->data) return FALSE; for (i = 0; i < (int)array->length; i++) { if (!XdmcpReadCARD16 (buffer, &array->data[i])) { - Xfree (array->data); + free(array->data); array->data = NULL; array->length = 0; return FALSE; @@ -124,7 +125,7 @@ XdmcpReadARRAY32 (XdmcpBufferPtr buffer, ARRAY32Ptr array) if (!XdmcpReadCARD8 (buffer, &array->length)) { /* Must set array->data to NULL to guarantee safe call of - * XdmcpDisposeARRAY*(array) (which calls Xfree(array->data)); + * XdmcpDisposeARRAY*(array) (which calls free(array->data)); * see defect 7329 */ array->data = NULL; return FALSE; @@ -134,14 +135,14 @@ XdmcpReadARRAY32 (XdmcpBufferPtr buffer, ARRAY32Ptr array) array->data = NULL; return TRUE; } - array->data = (CARD32 *) Xalloc (array->length * sizeof (CARD32)); + array->data = (CARD32 *) malloc(array->length * sizeof (CARD32)); if (!array->data) return FALSE; for (i = 0; i < (int)array->length; i++) { if (!XdmcpReadCARD32 (buffer, &array->data[i])) { - Xfree (array->data); + free(array->data); array->data = NULL; array->length = 0; return FALSE; @@ -158,8 +159,8 @@ XdmcpReadARRAYofARRAY8 (XdmcpBufferPtr buffer, ARRAYofARRAY8Ptr array) if (!XdmcpReadCARD8 (buffer, &array->length)) { /* Must set array->data to NULL to guarantee safe call of - * XdmcpDisposeARRAY*(array) (which calls Xfree(array->data)); - * see defect 7329 */ + * XdmcpDisposeARRAY*(array) (which calls free(array->data)); + * see defect 7329 */ array->data = NULL; return FALSE; } @@ -168,7 +169,7 @@ XdmcpReadARRAYofARRAY8 (XdmcpBufferPtr buffer, ARRAYofARRAY8Ptr array) array->data = NULL; return TRUE; } - array->data = (ARRAY8 *) Xalloc (array->length * sizeof (ARRAY8)); + array->data = (ARRAY8 *) malloc(array->length * sizeof (ARRAY8)); if (!array->data) return FALSE; for (i = 0; i < array->length; i++) @@ -178,7 +179,7 @@ XdmcpReadARRAYofARRAY8 (XdmcpBufferPtr buffer, ARRAYofARRAY8Ptr array) /* All arrays allocated thus far in the loop must be freed * if there is an error in the read. - * See Defect 7328 */ + * See Defect 7328 */ array->length = i; XdmcpDisposeARRAYofARRAY8(array); return FALSE; @@ -31,6 +31,7 @@ in this Software without prior written authorization from The Open Group. #include <X11/X.h> #include <X11/Xmd.h> #include <X11/Xdmcp.h> +#include <stdlib.h> int XdmcpWriteHeader ( @@ -41,10 +42,10 @@ XdmcpWriteHeader ( if ((int)buffer->size < 6 + (int)header->length) { - newData = (BYTE *) Xalloc (XDM_MAX_MSGLEN * sizeof (BYTE)); + newData = (BYTE *) malloc(XDM_MAX_MSGLEN * sizeof (BYTE)); if (!newData) return FALSE; - Xfree ((unsigned long *)(buffer->data)); + free((unsigned long *)(buffer->data)); buffer->data = newData; buffer->size = XDM_MAX_MSGLEN; } diff --git a/include/X11/Xdmcp.h b/include/X11/Xdmcp.h index 266f407..74ae4b3 100644 --- a/include/X11/Xdmcp.h +++ b/include/X11/Xdmcp.h @@ -164,12 +164,6 @@ extern void XdmcpUnwrap(unsigned char *input, unsigned char *wrapper, unsigned c #define FALSE 0 #endif -#if !defined(Xalloc) && !defined(xalloc) && !defined(Xrealloc) -extern void *Xalloc (unsigned long amount); -extern void *Xrealloc (void *old, unsigned long amount); -extern void Xfree(void *old); -#endif - extern int XdmcpCompareKeys (const XdmAuthKeyPtr a, const XdmAuthKeyPtr b); extern int XdmcpAllocARRAY16 (ARRAY16Ptr array, int length); |
