From 8763c3cf88e4b89c8fb9a352df605282468c3f13 Mon Sep 17 00:00:00 2001 From: wlestes Date: Wed, 21 Mar 2012 18:36:28 +0000 Subject: provide malloc() and realloc() for systems that do not have satisfactory versions; resolves #1899047 --- Makefile.am | 4 ++++ configure.in | 2 ++ lib/Makefile.am | 4 ++++ lib/lib.c | 7 +++++++ lib/malloc.c | 17 +++++++++++++++++ lib/realloc.c | 27 +++++++++++++++++++++++++++ 6 files changed, 61 insertions(+) create mode 100644 lib/Makefile.am create mode 100644 lib/lib.c create mode 100755 lib/malloc.c create mode 100644 lib/realloc.c diff --git a/Makefile.am b/Makefile.am index cf28658..a354699 100644 --- a/Makefile.am +++ b/Makefile.am @@ -66,6 +66,9 @@ flex_SOURCES = \ filter.c \ regex.c + +LDADD = lib/libcompat.a + libfl_a_SOURCES = \ libmain.c \ libyywrap.c @@ -113,6 +116,7 @@ BUILT_SOURCES = \ skel.c SUBDIRS = \ + lib \ . \ doc \ examples \ diff --git a/configure.in b/configure.in index cbbb754..1563137 100644 --- a/configure.in +++ b/configure.in @@ -29,6 +29,7 @@ AC_INIT([the fast lexical analyser generator], [2.5.36], AC_CONFIG_SRCDIR([scan.l]) AM_INIT_AUTOMAKE([gnits dist-bzip2 1.10]) AC_CONFIG_HEADER([config.h:conf.in]) +AC_CONFIG_LIBOBJ_DIR([lib]) # checks for programs @@ -112,6 +113,7 @@ doc/Makefile examples/Makefile examples/fastwc/Makefile examples/manual/Makefile +lib/Makefile po/Makefile.in tools/Makefile tests/Makefile diff --git a/lib/Makefile.am b/lib/Makefile.am new file mode 100644 index 0000000..53b4d48 --- /dev/null +++ b/lib/Makefile.am @@ -0,0 +1,4 @@ +noinst_LIBRARIES = libcompat.a +libcompat_a_SOURCES = lib.c +libcompat_a_LIBADD = $(LIBOBJS) + diff --git a/lib/lib.c b/lib/lib.c new file mode 100644 index 0000000..a8ff70f --- /dev/null +++ b/lib/lib.c @@ -0,0 +1,7 @@ +/* Since building an empty library could cause problems, we provide a + * function to go into the library. We could make this non-trivial by + * moving something that flex treats as a library function into this + * directory. */ + +void do_nothing(){ return;} + diff --git a/lib/malloc.c b/lib/malloc.c new file mode 100755 index 0000000..d4c605f --- /dev/null +++ b/lib/malloc.c @@ -0,0 +1,17 @@ + #include + #undef malloc + + #include + + void *malloc (); + + /* Allocate an N-byte block of memory from the heap. + If N is zero, allocate a 1-byte block. */ + + void * + rpl_malloc (size_t n) + { + if (n == 0) + n = 1; + return malloc (n); + } diff --git a/lib/realloc.c b/lib/realloc.c new file mode 100644 index 0000000..d7bb629 --- /dev/null +++ b/lib/realloc.c @@ -0,0 +1,27 @@ +#include + +#include + +#include + +void * rpl_realloc (void *p, size_t n) +{ + void *result; + + if (n == 0) + { + n = 1; + } + + if (p == NULL) + { + result = malloc (n); + } + else + result = realloc (p, n); + + if (result == NULL) + errno = ENOMEM; + + return result; +} -- cgit v1.2.1