mescc: drop naive realloc.

* mlibc/libc-gcc.c (free, memcpy): Move from libc-mes+tcc.c.
  (realloc): Use realloc from libc-mes+tcc.c
* mlibc/libc-gcc+tcc.c (free, memcpy, realloc): Remove.
* mlibc/libc-mes+tcc.c (free, memcpy, realloc): Remove.
* scaffold/tests/79-int-array.c (test): Update.
* scaffold/tests/7a-struct-char-array.c (test): Update.
This commit is contained in:
Jan Nieuwenhuizen 2017-08-01 11:08:14 +02:00
parent 1e37c9d9ea
commit c23a9ee01f
6 changed files with 48 additions and 71 deletions

View file

@ -18,7 +18,6 @@
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#define FULL_MALLOC 1
#include <libc-gcc.c>
#include <libc-mes+tcc.c>

View file

@ -174,11 +174,9 @@ fputc (int c, int fd)
return 0;
}
int
putchar (int c)
void
free (void *ptr)
{
write (STDOUT, (char*)&c, 1);
return 0;
}
char *g_brk = 0;
@ -195,14 +193,33 @@ malloc (size_t size)
return p;
}
#if !FULL_MALLOC
void *
realloc (void *p, size_t size)
memcpy (void *dest, void const *src, size_t n)
{
brk (g_brk + size);
return g_brk;
char* p = dest;
char* q = src;
while (n--) *p++ = *q++;
return dest;
}
int
putchar (int c)
{
write (STDOUT, (char*)&c, 1);
return 0;
}
void *
realloc (void *ptr, size_t size)
{
void *new = malloc (size);
if (ptr && new)
{
memcpy (new, ptr, size);
free (ptr);
}
return new;
}
#endif
size_t
strlen (char const* s)

View file

@ -30,7 +30,6 @@
#include <unistd.h>
#if !__GNUC__
#define FULL_MALLOC 1
#include <libc-mes.c>
int errno;
@ -139,11 +138,6 @@ fread (void *ptr, size_t size, size_t nmemb, FILE *stream)
return 0;
}
void
free (void *ptr)
{
}
int
fseek (FILE *stream, long offset, int whence)
{
@ -184,15 +178,6 @@ longjmp (jmp_buf env, int val)
eputs ("longjmp stub\n");
}
void *
memcpy (void *dest, void const *src, size_t n)
{
char* p = dest;
char* q = src;
while (n--) *p++ = *q++;
return dest;
}
void *
memmove (void *dest, void const *src, size_t n)
{
@ -363,18 +348,6 @@ calloc (size_t nmemb, size_t size)
return p;
}
void *
realloc (void *ptr, size_t size)
{
void *new = malloc (size);
if (ptr && new)
{
memcpy (new, ptr, size);
free (ptr);
}
return new;
}
int
vfprintf (FILE* f, char const* format, va_list ap)
{

View file

@ -224,6 +224,11 @@ fgetc (int fd)
return c == 1 ? c : (-1);
}
void
free (void *ptr)
{
}
//#define assert(x) ((x) ? (void)0 : assert_fail (#x))
int
ungetc (int c, int fd)
@ -328,14 +333,26 @@ malloc (size_t size)
return p;
}
#if !FULL_MALLOC
void *
realloc (void *p, size_t size)
memcpy (void *dest, void const *src, size_t n)
{
brk (g_brk + size);
return g_brk;
char* p = dest;
char* q = src;
while (n--) *p++ = *q++;
return dest;
}
void *
realloc (void *ptr, size_t size)
{
void *new = malloc (size);
if (ptr && new)
{
memcpy (new, ptr, size);
free (ptr);
}
return new;
}
#endif
int
strncmp (char const* a, char const* b, int length)

View file

@ -29,15 +29,6 @@ struct foo {
struct foo f;
void *
memcpy (void *dest, void const *src, size_t n)
{
char* p = dest;
char* q = src;
while (n--) *p++ = *q++;
return dest;
}
int bla[6] = {0,0,11223344, 55667788,0,0};
int g_c[2] = {101, 111};

View file

@ -38,26 +38,6 @@ int fill7;
int fill8;
int fill9;
void *
memcpy (void *dest, void const *src, int n)
{
char* p = dest;
char* q = src;
while (n--) *p++ = *q++;
return dest;
}
#if __MESC__
char *
strcpy (char *dest, char const *src)
{
char *p = dest;
while (*src) *p++ = *src++;
*p = 0;
return dest;
}
#endif
int
test ()
{