* device/include/string.h: added size_t typedef, changed
authorepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 7 Sep 2003 07:50:07 +0000 (07:50 +0000)
committerepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 7 Sep 2003 07:50:07 +0000 (07:50 +0000)
prototypes to use size_t, eliminated separate reentrant and
non-reentrant declarations, added _memmove declaration
* device/lib/_memcpy.c: changed to use size_t instead of int,
changed /4 to >>2 to avoid division library call
* device/lib/_memcmp.c,
* device/lib/_memset.c,
* device/lib/_strncat.c,
* device/lib/_strncpy.c,
* device/lib/_strncmp.c: changed to use size_t instead of int
* device/lib/_memmove.c: new file (fixed bug #772294)
* device/lib/Makefile.in: added _memmove.c
* device/lib/z80/asm_strings.s: fixed bug #772290
* support/regression/tests/bitfields.c: attempt to fix host assertion
failure on amd64-unknown-linux2.2

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2881 4a8a32a2-be11-0410-ad9d-d568d2c75423

12 files changed:
ChangeLog
device/include/string.h
device/lib/Makefile.in
device/lib/_memcmp.c
device/lib/_memcpy.c
device/lib/_memmove.c [new file with mode: 0644]
device/lib/_memset.c
device/lib/_strncat.c
device/lib/_strncmp.c
device/lib/_strncpy.c
device/lib/z80/asm_strings.s
support/regression/tests/bitfields.c

index 0fa92ba517a957597b98467adb1aef38a0ffdc4c..6f0bdfb038a30fc758ff49e62e5cc4d6989366db 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,23 @@
+2003-09-07  Erik Petrich <epetrich@ivorytower.norman.ok.us>
+
+       * device/include/string.h: added size_t typedef, changed
+       prototypes to use size_t, eliminated separate reentrant and
+       non-reentrant declarations, added _memmove declaration
+       * device/lib/_memcpy.c: changed to use size_t instead of int,
+       changed /4 to >>2 to avoid division library call
+       * device/lib/_memcmp.c,
+       * device/lib/_memset.c,
+       * device/lib/_strncat.c,
+       * device/lib/_strncpy.c,
+       * device/lib/_strncmp.c: changed to use size_t instead of int
+       * device/lib/_memmove.c: new file (fixed bug #772294)
+       * device/lib/Makefile.in: added _memmove.c
+       * device/lib/z80/asm_strings.s: fixed bug #772290
+       * support/regression/tests/bitfields.c: attempt to fix host assertion
+       failure on amd64-unknown-linux2.2
+
 2003-09-06  Erik Petrich <epetrich@ivorytower.norman.ok.us>
+
        * src/z80/gen.c (aopPut, spillPairReg): fixed bug #800998
        * src/z80/gen.c (genFunction, genEndFunction): fixed "bug" #774700
        * as/z80/asmain.c (main): fixed bug #801766
        compilers
 
 2003-09-05  Erik Petrich <epetrich@ivorytower.norman.ok.us>
+
        * src/SDCCast.c (isConformingBody): fixed loop reversal bug
        reported in bug #800609
 
 2003-09-04  Vangelis Rokas <vrokas@otenet.gr>
+
        * Top header beautifications in src/pic16 directory:
          device.c, device.h, gen.c, gen.h, genarith.c, glue.c, pcode.c,
          pcodeflow.c, pcodeflow.h, pcode.h, pcodepeep.c, pcoderegs.c,
@@ -34,6 +55,7 @@
        aren't part of the nRegs tally. 
 
 2003-08-31  Vangelis Rokas <vrokas@otenet.gr>
+
        * src/pic16/main.c: corrected offsets of interrupt vectors in _pic16_genIVT()
        * src/pic16/pcode.c: fix to disable inserting BANKSEL directive
          before instructions that use the _STATUS register
index 9e0da877823f0017495e073f842150c84cab6239..2800db732f20b22a5e5966386f070d54980686e6 100644 (file)
 #ifndef __SDC51_STRING_H
 #define __SDC51_STRING_H 1
 
-#if !defined(SDCC_mcs51) && !defined(SDCC_ds390)
-#define reentrant
-#endif
-
 #ifndef NULL
 # define NULL (void *)0
 #endif
 
-#define memmove memcpy
-
-#ifdef SDCC_STACK_AUTO
-
-extern char *strcpy (char *, char *) reentrant ;
-extern char *strncpy(char *, char *,int ) reentrant ;
-extern char *strcat (char *, char *) reentrant ;
-extern char *strncat(char *, char *,int ) reentrant ;
-extern int   strcmp (char *, char *) reentrant ;
-extern int   strncmp(char *, char *,int ) reentrant ;
-extern char *strchr (char *, char  ) reentrant ;
-extern char *strrchr(char *, char  ) reentrant ;
-extern int   strspn (char *, char *) reentrant ;
-extern int   strcspn(char *, char *) reentrant ;
-extern char *strpbrk(char *, char *) reentrant ;
-extern char *strstr (char *, char *) reentrant ;
-extern int   strlen (char *        ) reentrant ;
-extern char *strtok (char *, char *) reentrant ;
-extern void *memcpy (void *, void *, int ) reentrant ;
-extern int   memcmp (void *, void *, int ) reentrant ;
-extern void *memset (void *, unsigned char  , int ) reentrant ;
-#else
+#ifndef _SIZE_T_DEFINED
+# define _SIZE_T_DEFINED
+  typedef unsigned int size_t;
+#endif
 
 extern char *strcpy (char *, char *)  ;
-extern char *strncpy(char *, char *,int )  ;
+extern char *strncpy(char *, char *, size_t )  ;
 extern char *strcat (char *, char *)  ;
-extern char *strncat(char *, char *,int )  ;
+extern char *strncat(char *, char *, size_t )  ;
 extern int   strcmp (char *, char *)  ;
-extern int   strncmp(char *, char *,int )  ;
+extern int   strncmp(char *, char *, size_t )  ;
 extern char *strchr (char *, char  )  ;
 extern char *strrchr(char *, char  )  ;
 extern int   strspn (char *, char *)  ;
@@ -72,14 +49,14 @@ extern char *strpbrk(char *, char *)  ;
 extern char *strstr (char *, char *)  ;
 extern int   strlen (char *  )  ;
 extern char *strtok (char *, char *)  ;
-extern void *memcpy (void *, void *, int )  ;
-extern int   memcmp (void *, void *, int )  ;
-extern void *memset (void *, unsigned char  , int )  ;
+extern void *memcpy (void *, void *, size_t )  ;
+extern int   memcmp (void *, void *, size_t )  ;
+extern void *memset (void *, unsigned char  , size_t )  ;
+extern void *memmove (void *, void *, size_t )  ;
 
 #if SDCC_ds390
 extern void xdata * memcpyx(void xdata *, void xdata *, int) _naked;
 #endif
 
-#endif
 
 #endif
index fe0bc318b052495715581edbd4339093ad741458..54fd5c0530a6c271cab5247571e488579e6c0844 100644 (file)
@@ -52,7 +52,7 @@ SOURCES               = _atof.c _atoi.c _atol.c _autobaud.c _bp.c _schar2fs.c \
                  _islower.c _isprint.c _ispunct.c _isspace.c \
                  _isupper.c _isxdigit.c _itoa.c _ltoa.c \
                   _slong2fs.c _memcmp.c \
-                 _memcpy.c _memset.c _modsint.c _modslong.c \
+                 _memcpy.c _memmove.c _memset.c _modsint.c _modslong.c \
                  _moduint.c _modulong.c _mulint.c _mullong.c \
                  _ser.c _setjmp.c \
                  _spx.c _startup.c _strchr.c _strcmp.c _strcpy.c \
@@ -73,7 +73,7 @@ Z80SOURCES      = _atof.c _atoi.c \
                  _iscntrl.c _isdigit.c _isgraph.c \
                  _islower.c _isprint.c _ispunct.c _isspace.c \
                  _isupper.c _isxdigit.c _memcmp.c \
-                 _memcpy.c _memset.c \
+                 _memcpy.c _memmove.c _memset.c \
                  _startup.c _strchr.c _strcmp.c _strcpy.c \
                  _strcspn.c _strlen.c _strncat.c _strncmp.c \
                  _strncpy.c _strpbrk.c _strrchr.c _strspn.c \
@@ -103,7 +103,7 @@ XA51SOURCES      = _atof.c _atoi.c _atol.c _schar2fs.c \
                  _sint2fs.c _iscntrl.c _isdigit.c _isgraph.c \
                  _islower.c _isprint.c _ispunct.c _isspace.c \
                  _isupper.c _isxdigit.c _slong2fs.c _memcmp.c \
-                 _memcpy.c _memset.c _modsint.c _modslong.c \
+                 _memcpy.c _memmove.c _memset.c _modsint.c _modslong.c \
                  _moduint.c _modulong.c _mulint.c _mullong.c \
                  _strchr.c _strcmp.c _strcpy.c \
                  _strcspn.c _strlen.c _strncat.c _strncmp.c \
index 8a2cac860b2f2a71229bce4e011bfa54146c9e3d..08b06347e5e7089bb93ad6e763eda6fb082904d5 100644 (file)
@@ -26,7 +26,7 @@
 int memcmp (
        void * buf1,
        void * buf2,
-       int count
+       size_t count
        ) 
 {
        if (!count)
index 38d01ad8047d790ea0aa48a75e1aef4224330e73..38681c84e8598d673a676fa3aabcb30295478dab 100644 (file)
@@ -29,7 +29,7 @@
 void * memcpy (
        void * dst,
        void * src,
-       int acount
+       size_t acount
        ) 
 {
 #if _SDCC_Z80_STYLE_LIB_OPT
@@ -39,7 +39,7 @@ void * memcpy (
        char * d = dst;
        char * s = src;
        /* PENDING: Divide first to get around sign problems */
-       int count = -(acount/4);
+       int count = -(acount >> 2);
 
         while (count) {
                *d++ = *s++;
diff --git a/device/lib/_memmove.c b/device/lib/_memmove.c
new file mode 100644 (file)
index 0000000..5144e3b
--- /dev/null
@@ -0,0 +1,124 @@
+/*-------------------------------------------------------------------------
+  _memmove.c - part of string library functions
+
+             Adapted By -  Erik Petrich  . epetrich@users.sourceforge.net
+             from _memcpy.c which was originally
+             Written By -  Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+   This library is free software; you can redistribute it and/or modify it
+   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!  
+-------------------------------------------------------------------------*/
+#include "string.h" 
+#include <sdcc-lib.h>
+
+#ifndef _SDCC_PORT_PROVIDES_MEMMOVE
+#define _SDCC_PORT_PROVIDES_MEMMOVE 0
+#endif
+
+#if !_SDCC_PORT_PROVIDES_MEMMOVE
+
+void * memmove (
+       void * dst,
+       void * src,
+       size_t acount
+       ) 
+{
+#if _SDCC_Z80_STYLE_LIB_OPT
+
+#pragma NOINDUCTION
+
+       char * d;
+       char * s;
+       /* PENDING: Divide first to get around sign problems */
+       int count = -(acount >> 2);
+
+       if (((int)src < (int)dst) && ((((int)src)+acount) > (int)dst)) {
+               /*
+                * copy from higher addresses to lower addresses
+                */
+               d = ((char *)dst)+acount-1;
+               s = ((char *)src)+acount-1;
+               while (count) {
+                       *d-- = *s--;
+                       *d-- = *s--;
+                       *d-- = *s--;
+                       *d-- = *s--;
+                       count++;
+               }
+
+               if (acount & 2) {
+                       *d-- = *s--;
+                       *d-- = *s--;
+               }
+               if (acount & 1) {
+                       *d-- = *s--;
+               }
+       }
+       else {
+               /*
+                * copy from lower addresses to higher addresses
+                */
+               d = dst;
+               s = src;
+               while (count) {
+                       *d++ = *s++;
+                       *d++ = *s++;
+                       *d++ = *s++;
+                       *d++ = *s++;
+                       count++;
+               }
+
+               if (acount & 2) {
+                       *d++ = *s++; 
+                       *d++ = *s++;
+               }
+               if (acount & 1) {
+                       *d++ = *s++;
+               }
+       }
+       return dst;
+#else
+       void * ret = dst;
+       char * d;
+       char * s;
+
+       if (((int)src < (int)dst) && ((((int)src)+acount) > (int)dst)) {
+               /*
+                * copy from higher addresses to lower addresses
+                */
+               d = ((char *)dst)+acount-1;
+               s = ((char *)src)+acount-1;
+               while (acount--) {
+                       *d-- = *s--;
+               }
+       }
+       else {
+               /*
+                * copy from lower addresses to higher addresses
+                */
+               d = dst;
+               s = src;
+               while (acount--) {
+                       *d++ = *s++;
+               }
+       }
+
+       return(ret);
+#endif
+}
+#endif
index 9d903d2cf8732b9a31f5cc03109e2af7c19ee3a2..9bd603edf3e42eb4566dc5c837376f569e1ebe6f 100644 (file)
@@ -26,7 +26,7 @@
 void * memset (
        void * buf,
        unsigned char ch ,
-       int count) 
+       size_t count) 
 {
        register unsigned char * ret = buf;
 
index 9aae0ff2446cecfdf389136481ac42fce8c25dad..826858806f2d6411d9cd0bb8d48f9d2dac670105 100644 (file)
@@ -26,7 +26,7 @@
 char * strncat (
        char * front,
        char * back,
-       int count
+       size_t count
        ) 
 {
        char *start = front;
index c55b5fa600abdf53f9db2d43d1996c60d7fd2514..f22ed3b96695cd5d7ef37eedf1e333ccac7b0629 100644 (file)
@@ -26,7 +26,7 @@
 int strncmp (
        char * first,
        char * last,
-       int count
+       size_t count
        ) 
 {
        if (!count)
index 19b8a1a0bde002a76cff91b1ea461e0a32a7e90a..fd5f445c15403eb77d9c763fc7f6653e607b99df 100644 (file)
@@ -26,7 +26,7 @@
 char *strncpy (
        char * d,
        char * s,
-       int n ) 
+       size_t n ) 
 {
        register char * d1 =  d;
 
index a6527fb97f5adb1575db4194b69055aa5d0c5d87..1796b4a57017f580289701ea007a989c4517baae 100644 (file)
@@ -51,29 +51,21 @@ __memcpy_rrx_s::
         ;; LDIR:        do; *DE = *HL; HL++; BC--; while BC != 0
         
         ;; All registers are already saved.
-        ld      hl,#2
-        add     hl,sp
-        ld      e,(hl)
-        inc     hl
-        ld      d,(hl)
-        inc     hl
-        ld      a,(hl)
-        inc     hl
-        ld      b,(hl)
-        inc     hl
-        ld      c,(hl)
-        inc     hl
-        ld      h,(hl)
-        ld      l,a
-        ld      a,h
-        ld      h,b
-        ld      b,a
-
-        ;; Pending: could optimise this check to occur earlier.
-        or      c
-        ret     z
-
-        ldir
+       pop     iy      ; iy = return address
+       pop     de      ; de = destination pointer
+       pop     hl      ; hl = source pointer
+       pop     bc      ; bc = count
+       push    bc
+       push    hl
+       push    de
+       ld      a,b
+       or      c
+       jr      z,1$
+       ldir
+1$:
+       pop     hl      ; return hl = original destination pointer
+       push    hl
+       jp      (iy)
         ret
 
 ; int strcmp(const char *s1, const char *s2) 
index cf7d004bc8e573aebb7bff977541ec1cb0ac2abf..76b9df18c2a9f16b6276ca9a23af0ae481ede100 100644 (file)
@@ -100,7 +100,7 @@ testBitfieldSizeof(void)
   ASSERT( sizeof(size2c_bf) >= 2);
   ASSERT( sizeof(size2d_bf) >= 2);
   ASSERT( sizeof(size3a_bf) >= 2);
-  ASSERT( sizeof(size1a_bf) == sizeof(size1b_bf));
+  ASSERT( sizeof(size1a_bf) <= sizeof(size1b_bf));
   ASSERT( sizeof(size1a_bf) < sizeof(size2a_bf));
 
   /* Some SDCC specific assertions. SDCC uses 8 bit storage units.