From: bernhardheld Date: Sun, 2 Feb 2003 20:36:49 +0000 (+0000) Subject: * introduced NULL in the headers X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=993302259ccd79c62b7ca67697eb886e145397be;p=fw%2Fsdcc * introduced NULL in the headers git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2203 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index 32313a47..171008c0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,29 @@ +2003-02-02 Bernhard Held + + * device/include/malloc.h: introduced NULL + * device/include/string.h: introduced NULL + * device/include/stdlib.h: introduced NULL + * device/lib/_memcpy.c: removed NULL + * device/lib/_strcat.c: removed NULL + * device/lib/_strchr.c: removed NULL + * device/lib/_strcmp.c: removed NULL + * device/lib/_strcpy.c: removed NULL + * device/lib/_strcspn.c: removed NULL + * device/lib/_strlen.c: removed NULL + * device/lib/_strncat.c: removed NULL + * device/lib/_strncmp.c: removed NULL + * device/lib/_strncpy.c: removed NULL + * device/lib/_strpbrk.c: removed NULL + * device/lib/_strrchr.c: removed NULL + * device/lib/_strspn.c: removed NULL + * device/lib/_strstr.c: removed NULL + * device/lib/_strtok.c: removed NULL + * device/lib/malloc.c: removed NULL, include own header + * device/lib/_strspn.c: removed NULL + * device/lib/_strspn.c: removed NULL + * device/lib/_strspn.c: removed NULL + + 2003-02-02 * src/mcs51/ralloc.c (packForPush): fixed bug #631653, maybe other ports need this too? At least now some new alerts in SDCCBBlock.c and SDCCicode.c gives an early warning @@ -46,7 +72,7 @@ 2003-01-28 Bernhard Held * src/ds390/gen.c: fix deps by replacing with "common.h" - * src/SDCC.lex: rename P_OVERLAY to P_OVERLAY_ for cross-gcc 3.2 MINGW32 + * src/SDCC.lex: rename P_OVERLAY to P_OVERLAY_ for cross-gcc 3.2 MINGW32 2003-01-27 diff --git a/device/include/malloc.h b/device/include/malloc.h index 05055bbf..261e56c1 100644 --- a/device/include/malloc.h +++ b/device/include/malloc.h @@ -7,25 +7,29 @@ under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - + In other words, you are welcome to use, share and improve this program. You are forbidden to forbid anyone else to use, share and improve - what you give them. Help stamp out software-hoarding! + what you give them. Help stamp out software-hoarding! -------------------------------------------------------------------------*/ /* malloc.h */ #ifndef __SDCC51_MALLOC_H #define __SDCC51_MALLOC_H #include +#ifndef NULL +# define NULL (void *)0 +#endif + #if _SDCC_MALLOC_TYPE_MLH void *malloc (unsigned int); void free(void *p); @@ -47,7 +51,7 @@ MEMHEADER extern void init_dynamic_memory(MEMHEADER xdata * , unsigned int ) reentrant; extern void xdata * malloc (unsigned int ) reentrant; -extern void free (void * xdata p) reentrant; +extern void free (void xdata * p) reentrant; #else diff --git a/device/include/stdlib.h b/device/include/stdlib.h index 828c41c4..17043cd2 100644 --- a/device/include/stdlib.h +++ b/device/include/stdlib.h @@ -1,30 +1,34 @@ /*------------------------------------------------------------------------- stdlib.h - ANSI functions forward declarations - + Written By - Sandeep Dutta . sandeep.dutta@usa.net (1998) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - + In other words, you are welcome to use, share and improve this program. You are forbidden to forbid anyone else to use, share and improve - what you give them. Help stamp out software-hoarding! + what you give them. Help stamp out software-hoarding! -------------------------------------------------------------------------*/ #ifndef __SDC51_STDLIB_H #define __SDC51_STDLIB_H 1 +#ifndef +# define NULL (void *)0 +#endif + extern int atoi (char *); extern long atol (char *); @@ -34,9 +38,3 @@ extern void _itoa(unsigned int, char*, unsigned char); extern void _ultoa(unsigned long, char*, unsigned char); extern void _ltoa(unsigned long, char*, unsigned char); #endif - - - - - - diff --git a/device/include/string.h b/device/include/string.h index c220664c..5909896e 100644 --- a/device/include/string.h +++ b/device/include/string.h @@ -30,6 +30,10 @@ #define reentrant #endif +#ifndef NULL +# define NULL (void *)0 +#endif + #define memmove memcpy #ifdef SDCC_STACK_AUTO diff --git a/device/lib/_memcpy.c b/device/lib/_memcpy.c index aebbbb9c..38d01ad8 100644 --- a/device/lib/_memcpy.c +++ b/device/lib/_memcpy.c @@ -26,8 +26,6 @@ #if !_SDCC_PORT_PROVIDES_MEMCPY -#define NULL (void *)0 - void * memcpy ( void * dst, void * src, diff --git a/device/lib/_strcat.c b/device/lib/_strcat.c index f4cb9631..f1c4b0ec 100644 --- a/device/lib/_strcat.c +++ b/device/lib/_strcat.c @@ -7,22 +7,22 @@ under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. - + You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - + In other words, you are welcome to use, share and improve this program. You are forbidden to forbid anyone else to use, share and improve - what you give them. Help stamp out software-hoarding! + what you give them. Help stamp out software-hoarding! -------------------------------------------------------------------------*/ -#include "string.h" -#define NULL (void *)0 +#include "string.h" + char * strcat ( char * dst, char * src diff --git a/device/lib/_strchr.c b/device/lib/_strchr.c index ce9c0908..8f4e4cbb 100644 --- a/device/lib/_strchr.c +++ b/device/lib/_strchr.c @@ -7,22 +7,21 @@ under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. - + You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - + In other words, you are welcome to use, share and improve this program. You are forbidden to forbid anyone else to use, share and improve - what you give them. Help stamp out software-hoarding! + what you give them. Help stamp out software-hoarding! -------------------------------------------------------------------------*/ -#include "string.h" -#define NULL (void *)0 +#include "string.h" char * strchr ( char * string, diff --git a/device/lib/_strcmp.c b/device/lib/_strcmp.c index 47681961..eeceb8ba 100644 --- a/device/lib/_strcmp.c +++ b/device/lib/_strcmp.c @@ -7,27 +7,25 @@ under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. - + You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - + In other words, you are welcome to use, share and improve this program. You are forbidden to forbid anyone else to use, share and improve - what you give them. Help stamp out software-hoarding! + what you give them. Help stamp out software-hoarding! -------------------------------------------------------------------------*/ -#include "string.h" +#include "string.h" #include #if !_SDCC_PORT_PROVIDES_STRCMP -#define NULL (void *)0 - int strcmp ( char * asrc, char * adst diff --git a/device/lib/_strcpy.c b/device/lib/_strcpy.c index 5e7c1cdb..1ee5052e 100644 --- a/device/lib/_strcpy.c +++ b/device/lib/_strcpy.c @@ -7,27 +7,25 @@ under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. - + You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - + In other words, you are welcome to use, share and improve this program. You are forbidden to forbid anyone else to use, share and improve - what you give them. Help stamp out software-hoarding! + what you give them. Help stamp out software-hoarding! -------------------------------------------------------------------------*/ -#include "string.h" +#include "string.h" #include #if !_SDCC_PORT_PROVIDES_STRCPY -#define NULL (void *)0 - char * strcpy ( char * d, char * s) diff --git a/device/lib/_strcspn.c b/device/lib/_strcspn.c index b011e1b8..0beaf752 100644 --- a/device/lib/_strcspn.c +++ b/device/lib/_strcspn.c @@ -7,22 +7,21 @@ under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. - + You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - + In other words, you are welcome to use, share and improve this program. You are forbidden to forbid anyone else to use, share and improve - what you give them. Help stamp out software-hoarding! + what you give them. Help stamp out software-hoarding! -------------------------------------------------------------------------*/ -#include "string.h" -#define NULL (void *)0 +#include "string.h" int strcspn ( char * string , diff --git a/device/lib/_strlen.c b/device/lib/_strlen.c index d9c546cc..6d0e9acd 100644 --- a/device/lib/_strlen.c +++ b/device/lib/_strlen.c @@ -7,22 +7,21 @@ under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. - + You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - + In other words, you are welcome to use, share and improve this program. You are forbidden to forbid anyone else to use, share and improve - what you give them. Help stamp out software-hoarding! + what you give them. Help stamp out software-hoarding! -------------------------------------------------------------------------*/ -#include "string.h" -#define NULL (void *)0 +#include "string.h" int strlen ( char * str ) { diff --git a/device/lib/_strncat.c b/device/lib/_strncat.c index ec28bf44..9aae0ff2 100644 --- a/device/lib/_strncat.c +++ b/device/lib/_strncat.c @@ -7,22 +7,21 @@ under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. - + You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - + In other words, you are welcome to use, share and improve this program. You are forbidden to forbid anyone else to use, share and improve - what you give them. Help stamp out software-hoarding! + what you give them. Help stamp out software-hoarding! -------------------------------------------------------------------------*/ -#include "string.h" -#define NULL (void *)0 +#include "string.h" char * strncat ( char * front, diff --git a/device/lib/_strncmp.c b/device/lib/_strncmp.c index 2b7e9904..c55b5fa6 100644 --- a/device/lib/_strncmp.c +++ b/device/lib/_strncmp.c @@ -7,22 +7,21 @@ under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. - + You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - + In other words, you are welcome to use, share and improve this program. You are forbidden to forbid anyone else to use, share and improve - what you give them. Help stamp out software-hoarding! + what you give them. Help stamp out software-hoarding! -------------------------------------------------------------------------*/ -#include "string.h" -#define NULL (void *)0 +#include "string.h" int strncmp ( char * first, diff --git a/device/lib/_strncpy.c b/device/lib/_strncpy.c index 1fe12f6f..19b8a1a0 100644 --- a/device/lib/_strncpy.c +++ b/device/lib/_strncpy.c @@ -7,22 +7,21 @@ under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. - + You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - + In other words, you are welcome to use, share and improve this program. You are forbidden to forbid anyone else to use, share and improve - what you give them. Help stamp out software-hoarding! + what you give them. Help stamp out software-hoarding! -------------------------------------------------------------------------*/ -#include "string.h" -#define NULL (void *)0 +#include "string.h" char *strncpy ( char * d, diff --git a/device/lib/_strpbrk.c b/device/lib/_strpbrk.c index 76e2a08c..cddd369f 100644 --- a/device/lib/_strpbrk.c +++ b/device/lib/_strpbrk.c @@ -7,22 +7,21 @@ under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. - + You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - + In other words, you are welcome to use, share and improve this program. You are forbidden to forbid anyone else to use, share and improve - what you give them. Help stamp out software-hoarding! + what you give them. Help stamp out software-hoarding! -------------------------------------------------------------------------*/ #include -#define NULL (void *)0 char * strpbrk ( char * string , diff --git a/device/lib/_strrchr.c b/device/lib/_strrchr.c index 3ed636e4..5d6a6deb 100644 --- a/device/lib/_strrchr.c +++ b/device/lib/_strrchr.c @@ -7,22 +7,21 @@ under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. - + You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - + In other words, you are welcome to use, share and improve this program. You are forbidden to forbid anyone else to use, share and improve - what you give them. Help stamp out software-hoarding! + what you give them. Help stamp out software-hoarding! -------------------------------------------------------------------------*/ -#include "string.h" -#define NULL (void *)0 +#include "string.h" char * strrchr ( char * string, diff --git a/device/lib/_strspn.c b/device/lib/_strspn.c index 377aeed9..fae51a6f 100644 --- a/device/lib/_strspn.c +++ b/device/lib/_strspn.c @@ -22,7 +22,6 @@ what you give them. Help stamp out software-hoarding! -------------------------------------------------------------------------*/ #include "string.h" -#define NULL (void *)0 int strspn ( char * string, diff --git a/device/lib/_strstr.c b/device/lib/_strstr.c index 13d36e5c..272ad164 100644 --- a/device/lib/_strstr.c +++ b/device/lib/_strstr.c @@ -22,7 +22,6 @@ what you give them. Help stamp out software-hoarding! -------------------------------------------------------------------------*/ #include "string.h" -#define NULL (void *)0 char * strstr ( char * str1, diff --git a/device/lib/_strtok.c b/device/lib/_strtok.c index 7f00370a..82a09c3a 100644 --- a/device/lib/_strtok.c +++ b/device/lib/_strtok.c @@ -22,7 +22,6 @@ what you give them. Help stamp out software-hoarding! -------------------------------------------------------------------------*/ #include "string.h" -#define NULL (void *)0 #if defined(SDCC_MODEL_LARGE) || defined (SDCC_MODEL_FLAT24) #pragma NOINDUCTION diff --git a/device/lib/malloc.c b/device/lib/malloc.c index 22f813c5..00439285 100644 --- a/device/lib/malloc.c +++ b/device/lib/malloc.c @@ -1,7 +1,7 @@ #include +#include #if _SDCC_MALLOC_TYPE_MLH -#include typedef struct _MEMHEADER MEMHEADER; @@ -14,7 +14,6 @@ struct _MEMHEADER }; #define HEADER_SIZE (sizeof(MEMHEADER)-sizeof(char)) -#define NULL 0 /* These veriables are defined through the crt0 functions. */ /* Base of this variable is the first byte of the heap. */ @@ -22,7 +21,7 @@ extern MEMHEADER _sdcc_heap_start; /* Address of this variable is the last byte of the heap. */ extern char _sdcc_heap_end; -void +void _sdcc_heap_init(void) { MEMHEADER *pbase = &_sdcc_heap_start; @@ -91,7 +90,7 @@ malloc (unsigned int size) } } -void +void free (void *p) { MEMHEADER *prev_header, *pthis; @@ -103,12 +102,12 @@ free (void *p) { prev_header = pthis->prev; prev_header->next = pthis->next; - if (pthis->next) + if (pthis->next) { pthis->next->prev = prev_header; } } - else + else { pthis->len = 0; //For the first header } @@ -140,8 +139,6 @@ free (void *p) }; #define HEADER_SIZE (sizeof(MEMHEADER)-1) - #define NULL (void xdata * ) 0 - //Static here means: can be accessed from this module only static MEMHEADER xdata * FIRST_MEMORY_HEADER_PTR; @@ -175,8 +172,8 @@ free (void *p) FIRST_MEMORY_HEADER_PTR = array; //Reserve a mem for last header array->next = (MEMHEADER xdata * )(((char xdata * ) array) + size - HEADER_SIZE); - array->next->next = NULL; //And mark it as last - array->prev = NULL; //and mark first as first + array->next->next = (void xdata * ) NULL; //And mark it as last + array->prev = (void xdata * ) NULL; //and mark first as first array->len = 0; //Empty and ready. } @@ -185,7 +182,7 @@ free (void *p) register MEMHEADER xdata * current_header; register MEMHEADER xdata * new_header; - if (size>(0xFFFF-HEADER_SIZE)) return NULL; //To prevent overflow in next line + if (size>(0xFFFF-HEADER_SIZE)) return (void xdata *) NULL; //To prevent overflow in next line size += HEADER_SIZE; //We need a memory for header too current_header = FIRST_MEMORY_HEADER_PTR; while (1) @@ -202,7 +199,7 @@ free (void *p) ((unsigned int)current_header) - current_header->len) >= size) break; //if spare is more than need current_header = current_header->next; //else try next - if (!current_header->next) return NULL; //if end_of_list reached + if (!current_header->next) return (void xdata *) NULL; //if end_of_list reached } if (!current_header->len) { //This code works only for first_header in the list and only @@ -218,21 +215,21 @@ free (void *p) return ((xdata *)&(new_header->mem)); } - void free (MEMHEADER xdata * p) + void free (void xdata * p) { register MEMHEADER xdata * prev_header; if ( p ) //For allocated pointers only! { p = (MEMHEADER xdata * )((char xdata *) p - HEADER_SIZE); //to start of header - if ( p->prev ) // For the regular header + if ( ((MEMHEADER xdata * ) p)->prev ) // For the regular header { - prev_header = p->prev; - prev_header->next = p->next; - if (p->next) p->next->prev = prev_header; + prev_header = ((MEMHEADER xdata * ) p)->prev; + prev_header->next = ((MEMHEADER xdata * ) p)->next; + if (((MEMHEADER xdata * ) p)->next) + ((MEMHEADER xdata * ) p)->next->prev = prev_header; } - else p->len = 0; //For the first header + else ((MEMHEADER xdata * ) p)->len = 0; //For the first header } } //END OF MODULE - #endif