From ed27bb9f3b9f6f2d6eaafa77e2145098f6f73ac3 Mon Sep 17 00:00:00 2001 From: Erwin Janssen Date: Mon, 31 Oct 2016 22:32:36 +0100 Subject: [PATCH] Assume `atexit()` can be used, part of standard C The `atexit()` function is part of standard C, so it can be assumed that it available. The fallback machanism with `onexit()` is therefore not needed, which results in less code and defines. --- lib/sfio/features/sfio | 2 - lib/sfio/sfexit.c | 67 ----------------------------- lib/vmalloc/Makefile.am | 2 +- lib/vmalloc/features/vmalloc | 2 - lib/vmalloc/vmalloc.vcxproj | 1 - lib/vmalloc/vmalloc.vcxproj.filters | 3 -- lib/vmalloc/vmexit.c | 67 ----------------------------- windows/include/FEATURE/sfio | 1 - windows/include/FEATURE/vmalloc | 3 -- 9 files changed, 1 insertion(+), 147 deletions(-) delete mode 100644 lib/vmalloc/vmexit.c diff --git a/lib/sfio/features/sfio b/lib/sfio/features/sfio index f1d7be152..8dd3450b2 100644 --- a/lib/sfio/features/sfio +++ b/lib/sfio/features/sfio @@ -11,8 +11,6 @@ lib qfrexp lib qldexp hdr unistd -lib atexit -lib onexit lib ftruncate diff --git a/lib/sfio/sfexit.c b/lib/sfio/sfexit.c index 0be4d1a28..33cc4639d 100644 --- a/lib/sfio/sfexit.c +++ b/lib/sfio/sfexit.c @@ -18,73 +18,6 @@ ** Written by Kiem-Phong Vo */ -#if !_lib_atexit -#if _lib_onexit - -int atexit(void (*exitf) (void)) -{ -#if _lib_onexit - return onexit(exitf); -#endif -} - -#else /* !_lib_onexit */ - -typedef struct _exit_s { - struct _exit_s *next; - void (*exitf) (void); -} Exit_t; -static Exit_t *Exit; - -atexit(void (*exitf) (void)) -{ - Exit_t *e; - int rv; - - vtmtxlock(_Sfmutex); - - if (!(e = (Exit_t *) malloc(sizeof(Exit_t)))) - rv = -1; - else { - e->exitf = exitf; - e->next = Exit; - Exit = e; - rv = 0; - } - - vtmtxunlock(_Sfmutex); - - return rv; -} - -#if _exit_cleanup -/* since exit() calls _cleanup(), we only need to redefine _cleanup() */ -_cleanup(void) -{ - Exit_t *e; - for (e = Exit; e; e = e->next) - (*e->exitf) (); - if (_Sfcleanup) - (*_Sfcleanup) (); -} - -#else - -/* in this case, we have to redefine exit() itself */ -exit(int type) -{ - Exit_t *e; - for (e = Exit; e; e = e->next) - (*e->exitf) (); - _exit(type); - return type; -} -#endif /* _exit_cleanup */ - -#endif /* _lib_onexit */ - -#endif /* !_lib_atexit */ - #if _lib_waitpid int _Sf_no_need_for_waitpid; #else diff --git a/lib/vmalloc/Makefile.am b/lib/vmalloc/Makefile.am index 6305fa2f3..5edd20ae1 100644 --- a/lib/vmalloc/Makefile.am +++ b/lib/vmalloc/Makefile.am @@ -5,7 +5,7 @@ noinst_HEADERS = vmalloc.h vmhdr.h noinst_LTLIBRARIES = libvmalloc_C.la libvmalloc_C_la_SOURCES = malloc.c vmbest.c vmclear.c vmclose.c vmdcheap.c \ - vmdebug.c vmdisc.c vmexit.c vmlast.c vmopen.c vmpool.c vmprivate.c \ + vmdebug.c vmdisc.c vmlast.c vmopen.c vmpool.c vmprivate.c \ vmprofile.c vmregion.c vmsegment.c vmset.c vmstat.c vmstrdup.c \ vmtrace.c vmwalk.c diff --git a/lib/vmalloc/features/vmalloc b/lib/vmalloc/features/vmalloc index 7d6cfb3f6..10d62a8e8 100644 --- a/lib/vmalloc/features/vmalloc +++ b/lib/vmalloc/features/vmalloc @@ -5,8 +5,6 @@ # Written by Kiem-Phong Vo (08/15/95). #################################################################### -lib atexit -lib onexit lib getpagesize hdr stat hdr stdlib diff --git a/lib/vmalloc/vmalloc.vcxproj b/lib/vmalloc/vmalloc.vcxproj index 10239f8cd..b3fbe8a2a 100644 --- a/lib/vmalloc/vmalloc.vcxproj +++ b/lib/vmalloc/vmalloc.vcxproj @@ -97,7 +97,6 @@ - diff --git a/lib/vmalloc/vmalloc.vcxproj.filters b/lib/vmalloc/vmalloc.vcxproj.filters index 4bb4441e2..13ae3d594 100644 --- a/lib/vmalloc/vmalloc.vcxproj.filters +++ b/lib/vmalloc/vmalloc.vcxproj.filters @@ -41,9 +41,6 @@ Source Files - - Source Files - Source Files diff --git a/lib/vmalloc/vmexit.c b/lib/vmalloc/vmexit.c deleted file mode 100644 index 05837911b..000000000 --- a/lib/vmalloc/vmexit.c +++ /dev/null @@ -1,67 +0,0 @@ -/* $Id$ $Revision$ */ -/* vim:set shiftwidth=4 ts=8: */ - -/************************************************************************* - * Copyright (c) 2011 AT&T Intellectual Property - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: See CVS logs. Details at http://www.graphviz.org/ - *************************************************************************/ - -#include "vmhdr.h" - -/* -** Any required functions for process exiting. -** Written by Kiem-Phong Vo, kpv@research.att.com (05/25/93). -*/ -#if _lib_atexit -int Vm_atexit_already_defined; -#else - -#if _lib_onexit - -int atexit(void (*exitf) (void)) -{ - return onexit(exitf); -} - -#else /*!_lib_onexit */ - -typedef struct _exit_s { - struct _exit_s *next; - void (*exitf)(void); -} Exit_t; -static Exit_t *Exit; - -atexit(void (*exitf) (void)) -{ - Exit_t *e; - - if (!(e = (Exit_t *) malloc(sizeof(Exit_t)))) - return -1; - e->exitf = exitf; - e->next = Exit; - Exit = e; - return 0; -} - -void exit(int type) -{ - Exit_t *e; - - for (e = Exit; e; e = e->next) - (*e->exitf) (); - -#if _exit_cleanup - _cleanup(); -#endif - - _exit(type); -} - -#endif /* _lib_onexit || _lib_on_exit */ - -#endif /*_lib_atexit */ diff --git a/windows/include/FEATURE/sfio b/windows/include/FEATURE/sfio index 39962b803..dd5c10b34 100644 --- a/windows/include/FEATURE/sfio +++ b/windows/include/FEATURE/sfio @@ -4,7 +4,6 @@ #define _sys_types 1 /* #include ok */ #define _hdr_math 1 /* #include ok */ //#define _hdr_unistd 1 /* #include ok */ -#define _lib_atexit 1 /* atexit() in default lib(s) */ #define _lib_ftruncate 0 /* ftruncate() in default lib(s) */ #define _lib_lseek64 1 /* lseek64() in default lib(s) */ #define _typ_off64_t 1 /* off64_t is a type */ diff --git a/windows/include/FEATURE/vmalloc b/windows/include/FEATURE/vmalloc index 9aa620cfb..21638933f 100644 --- a/windows/include/FEATURE/vmalloc +++ b/windows/include/FEATURE/vmalloc @@ -5,9 +5,6 @@ #undef _sys_types #define _sys_types 1 /* #include ok */ -#undef _lib_atexit -#define _lib_atexit 1 /* atexit() in default lib(s) */ - #undef _lib_getpagesize #define _lib_getpagesize 0 /* getpagesize() in default lib(s) */ -- 2.40.0