Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ install(FILES ${CMAKE_BINARY_DIR}/etc/gitinfo.txt DESTINATION ${CMAKE_INSTALL_SY

#---Recurse into the given subdirectories. This does not actually cause another cmake executable
# to run. The same process will walk through the project's entire directory structure.
add_subdirectory (builtins/clib) # hard coded builtin for core
add_subdirectory (core)
add_subdirectory (builtins/zip) # hard coded builtin for core/zip
add_subdirectory (math)
Expand Down
68 changes: 68 additions & 0 deletions builtins/clib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Copyright (C) 1995-2019, Rene Brun and Fons Rademakers.
# All rights reserved.
#
# For the licensing terms see $ROOTSYS/LICENSE.
# For the list of contributors see $ROOTSYS/README/CREDITS.

############################################################################
# CMakeLists.txt file for building ROOT core/clib package
############################################################################

add_library(ROOTclib STATIC)

target_sources(ROOTclib PUBLIC
inc/strlcpy.h # custom ROOT file (https://github.com/root-project/root/blob/b48975de4dcbcd5f1ecf7f60c3f8e39c38a1f6e3/core/clib/inc/strlcpy.h)
inc/strtok.h # custom ROOT file (https://github.com/root-project/root/blob/d39c9211ba045c0b9aaa780ec76a32666e04cd1e/core/clib/inc/strtok.h)
)

target_sources(ROOTclib PRIVATE
# All this code below is LGPL (GNU Lesser General Public License was called at that time GNU Library General Public License)
src/attach.c # forked in 1999 from gdb-4 (https://github.com/root-project/root/blob/852600061bcacd9b255d44f6312c96b6b1e00a2d/clib/src/attach.c vs https://github.com/gnutools/binutils-gdb/blob/c906108c21474dfb4ed285bcc0ac6fe02cd400cc/mmalloc/attach.c)
src/detach.c # forked in 1999 from gdb-4 (https://github.com/root-project/root/blob/852600061bcacd9b255d44f6312c96b6b1e00a2d/clib/src/detach.c vs https://github.com/gnutools/binutils-gdb/blob/c906108c21474dfb4ed285bcc0ac6fe02cd400cc/mmalloc/detach.c)
src/getpagesize.c # forked in 1999 from gdb-4 (https://github.com/root-project/root/blob/852600061bcacd9b255d44f6312c96b6b1e00a2d/clib/src/getpagesize.c vs https://github.com/gnutools/binutils-gdb/blob/c906108c21474dfb4ed285bcc0ac6fe02cd400cc/mmalloc/mvalloc.c)
src/keys.c # forked in 1999 from gdb-4 (https://github.com/root-project/root/blob/852600061bcacd9b255d44f6312c96b6b1e00a2d/clib/src/keys.c vs https://github.com/gnutools/binutils-gdb/blob/c906108c21474dfb4ed285bcc0ac6fe02cd400cc/mmalloc/keys.c)
src/mcalloc.c # forked in 1999 from gdb-4 (https://github.com/root-project/root/blob/852600061bcacd9b255d44f6312c96b6b1e00a2d/clib/src/mcalloc.c vs https://github.com/gnutools/binutils-gdb/blob/c906108c21474dfb4ed285bcc0ac6fe02cd400cc/mmalloc/mcalloc.c)
src/mfree.c # forked in 1999 from gdb-4 (https://github.com/root-project/root/blob/852600061bcacd9b255d44f6312c96b6b1e00a2d/clib/src/mfree.c vs https://github.com/gnutools/binutils-gdb/blob/c906108c21474dfb4ed285bcc0ac6fe02cd400cc/mmalloc/mfree.c)
src/mmalloc.c # forked in 1999 from gdb-4 (https://github.com/root-project/root/blob/852600061bcacd9b255d44f6312c96b6b1e00a2d/clib/src/mmalloc.c vs https://github.com/gnutools/binutils-gdb/blob/c906108c21474dfb4ed285bcc0ac6fe02cd400cc/mmalloc/mmalloc.c)
src/mmapsup.c # forked in 1999 from gdb-4 (https://github.com/root-project/root/blob/852600061bcacd9b255d44f6312c96b6b1e00a2d/clib/src/mmapsup.c vs https://github.com/gnutools/binutils-gdb/blob/c906108c21474dfb4ed285bcc0ac6fe02cd400cc/mmalloc/mmap-sup.c)
src/mmcheck.c # forked in 1999 from gdb-4 (https://github.com/root-project/root/blob/852600061bcacd9b255d44f6312c96b6b1e00a2d/clib/src/mmcheck.c vs https://github.com/gnutools/binutils-gdb/blob/c906108c21474dfb4ed285bcc0ac6fe02cd400cc/mmalloc/mmcheck.c)
src/mrealloc.c # forked in 1999 from gdb-4 (https://github.com/root-project/root/blob/852600061bcacd9b255d44f6312c96b6b1e00a2d/clib/src/mrealloc.c vs https://github.com/gnutools/binutils-gdb/blob/c906108c21474dfb4ed285bcc0ac6fe02cd400cc/mmalloc/mrealloc.c)
src/sbrksup.c # forked in 1999 from gdb-4 (https://github.com/root-project/root/blob/852600061bcacd9b255d44f6312c96b6b1e00a2d/clib/src/sbrksup.c vs https://github.com/gnutools/binutils-gdb/blob/c906108c21474dfb4ed285bcc0ac6fe02cd400cc/mmalloc/sbrk-sup.c)
src/strlcat.c # forked in 2010 from OpenBSD (https://github.com/root-project/root/blob/b48975de4dcbcd5f1ecf7f60c3f8e39c38a1f6e3/core/clib/src/strlcat.c vs https://github.com/libressl/openbsd/blob/032d9a965adfb74e42b18dc939b34fcda2cf740e/src/lib/libc/string/strlcat.c)
src/strlcpy.c # forked in 2010 from OpenBSD (https://github.com/root-project/root/blob/b48975de4dcbcd5f1ecf7f60c3f8e39c38a1f6e3/core/clib/src/strlcpy.c vs https://github.com/libressl/openbsd/blob/032d9a965adfb74e42b18dc939b34fcda2cf740e/src/lib/libc/string/strlcpy.c)
# res/mmalloc.h (https://github.com/root-project/root/blob/852600061bcacd9b255d44f6312c96b6b1e00a2d/clib/inc/mmalloc.h vs https://github.com/gnutools/binutils-gdb/blob/c906108c21474dfb4ed285bcc0ac6fe02cd400cc/mmalloc/mmalloc.h)
# res/mmconfig.h # custom ROOT file (https://github.com/root-project/root/blob/852600061bcacd9b255d44f6312c96b6b1e00a2d/clib/inc/mmconfig.h)
# res/mmprivate.h # forked in 1999 from gdb-4 (https://github.com/root-project/root/blob/852600061bcacd9b255d44f6312c96b6b1e00a2d/clib/inc/mmprivate.c vs https://github.com/gnutools/binutils-gdb/blob/c906108c21474dfb4ed285bcc0ac6fe02cd400cc/mmalloc/mmprivate.c)
)

include(CheckSourceCompiles)
check_source_compiles(C
"#include <string.h>
int main() {
char dst[10];
strlcpy(dst, \"a\", 10);
return 0;
}"
HAS_STRLCPY
)


target_compile_definitions(ROOTclib PUBLIC $<$<BOOL:${HAS_STRLCPY}>:HAS_STRLCPY>)
if (NOT WIN32)
target_compile_definitions(ROOTclib PRIVATE INVALID_HANDLE_VALUE=-1)
endif()
if (UNIX)
target_compile_definitions(ROOTclib PRIVATE R__HAVE_UNISTD_H)
endif()
target_compile_definitions(ROOTclib PRIVATE R__HAVE_MMAP)
target_compile_definitions(ROOTclib PRIVATE NO_SBRK_MALLOC)
target_compile_definitions(ROOTclib PRIVATE $<$<PLATFORM_ID:LynxOS>:R__LYNXOS>)
target_compile_definitions(ROOTclib PRIVATE $<$<PLATFORM_ID:GNU>:R__HURD>)

target_include_directories(ROOTclib
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/inc>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/res> # New requires those publicly
)
set_property(TARGET ROOTclib PROPERTY POSITION_INDEPENDENT_CODE ON)
target_link_options(ROOTclib PRIVATE -fvisibility=hidden)
6 changes: 2 additions & 4 deletions core/clib/inc/strlcpy.h → builtins/clib/inc/strlcpy.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@
/* Author: Fons Rademakers 20/9/2010 */

/*
Inlcude file for strlcpy and strlcat. They are in string.h on systems
Include file for strlcpy and strlcat. They are in string.h on systems
that have these function (BSD based systems).
*/

#ifndef ROOT_strlcpy
#define ROOT_strlcpy

#include <ROOT/RConfig.hxx>

#ifndef HAS_STRLCPY

#ifndef WIN32
#ifndef _WIN32
# include <unistd.h>
#else
# include <sys/types.h>
Expand Down
6 changes: 2 additions & 4 deletions core/clib/inc/strtok.h → builtins/clib/inc/strtok.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#ifndef ROOT_strtok
#define ROOT_strtok

#include <ROOT/RConfig.hxx>

#include <cstring>
#include <string.h>

// On Windows strtok_r does not exist: the function is called strtok_s.
inline char *R__STRTOK_R(char *str, const char *delim, char **saveptr)
{
#if defined(R__WIN32)
#if defined(_WIN32)
return strtok_s(str, delim, saveptr);
#else
return strtok_r(str, delim, saveptr);
Expand Down
18 changes: 5 additions & 13 deletions core/clib/res/mmalloc.h → builtins/clib/res/mmalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,17 @@
#ifndef MMALLOC_H
#define MMALLOC_H 1

/* FIXME: If <stddef.h> doesn't exist, you'll need to do something
to define size_t before including this file. Like upgrading
to a system with an ANSI C environment. */

#include "mmconfig.h"

#ifdef WIN32
#ifdef _WIN32
# include <windows.h>
#endif

#ifdef R__HAVE_STDDEF_H
# include <stddef.h>
#endif

#define PTR void *
#define PARAMS(paramlist) paramlist

#ifdef WIN32
extern struct mmstats_t mmstats PARAMS ((PTR));
#ifdef _WIN32
extern struct mmstats_t mmstats PARAMS((PTR));
#endif

#ifdef __cplusplus
Expand Down Expand Up @@ -80,8 +72,8 @@ include/mmalloc.h:73:25: warning: 'mmstats' has C-linkage specified, but returns
*/
// extern struct mmstats_t mmstats PARAMS ((PTR));

#ifndef WIN32
extern PTR mmalloc_attach PARAMS ((int, PTR, int));
#ifndef _WIN32
extern PTR mmalloc_attach PARAMS((int, PTR, int));
#else
extern PTR mmalloc_attach PARAMS ((HANDLE, PTR, int));
#endif
Expand Down
25 changes: 5 additions & 20 deletions core/clib/res/mmprivate.h → builtins/clib/res/mmprivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,12 @@

#include "mmalloc.h"

#ifdef R__HAVE_LIMITS_H
# include <limits.h>
#else
# ifndef CHAR_BIT
# define CHAR_BIT 8
# endif
#endif

#ifdef R__HAVE_STDDEF_H
# include <stddef.h>
#else
# include <sys/types.h> /* hope for the best -- ANSI C is your friend */
#endif

#include <limits.h>
#include <stddef.h>
#ifdef R__HAVE_UNISTD_H
# include <unistd.h>
#include <unistd.h>
#endif
#ifdef R__HAVE_STDLIB_H
# include <stdlib.h>
#endif

#include <stdlib.h>
#include <stdint.h>

#ifndef MIN
Expand Down Expand Up @@ -303,7 +288,7 @@ struct mdesc
by default if no open file is supplied by the client. Also note that
it may change each time the region is mapped and unmapped. */

#ifndef WIN32
#ifndef _WIN32
int fd;
#else
HANDLE fd;
Expand Down
33 changes: 18 additions & 15 deletions core/clib/src/attach.c → builtins/clib/src/attach.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */


#ifndef _WIN32
#include <unistd.h>
#include <stdlib.h>
#endif
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
Expand All @@ -32,7 +35,7 @@ Boston, MA 02111-1307, USA. */
#include <string.h>
#include "mmprivate.h"

#ifndef WIN32
#ifndef _WIN32
# include <sys/mman.h>
#else
# include <io.h>
Expand All @@ -47,7 +50,7 @@ Boston, MA 02111-1307, USA. */

/* Forward declarations/prototypes for local functions */

#ifndef WIN32
#ifndef _WIN32
static struct mdesc *reuse PARAMS ((int));
#else
static struct mdesc *reuse PARAMS ((HANDLE));
Expand Down Expand Up @@ -85,7 +88,7 @@ Boston, MA 02111-1307, USA. */
On failure returns NULL. */

PTR
#ifndef WIN32
#ifndef _WIN32
mmalloc_attach (int fd, PTR baseaddr, int minsize)
#else
mmalloc_attach (HANDLE fd, PTR baseaddr, int minsize)
Expand All @@ -95,7 +98,7 @@ mmalloc_attach (HANDLE fd, PTR baseaddr, int minsize)
struct mdesc *mdp;
PTR mbase;
int coresize;
#ifndef WIN32
#ifndef _WIN32
struct stat sbuf;
#else
BY_HANDLE_FILE_INFORMATION sbuf;
Expand All @@ -108,7 +111,7 @@ mmalloc_attach (HANDLE fd, PTR baseaddr, int minsize)
obsolete version, or any other reason, then we fail to attach to
this file. */

#ifndef WIN32
#ifndef _WIN32
if (fd >= 0)
{
if (fstat (fd, &sbuf) < 0)
Expand All @@ -132,7 +135,7 @@ mmalloc_attach (HANDLE fd, PTR baseaddr, int minsize)
return ((PTR) reuse (fd));
}
}
#endif /* WIN32 */
#endif /* _WIN32 */

/* We start off with the malloc descriptor allocated on the stack, until
we build it up enough to call _mmalloc_mmap_morecore() to allocate the
Expand All @@ -151,7 +154,7 @@ mmalloc_attach (HANDLE fd, PTR baseaddr, int minsize)
/* If we have not been passed a valid open file descriptor for the file
to map to, then open /dev/zero and use that to map to. */

#ifndef WIN32
#ifndef _WIN32
if (mdp -> fd < 0)
{
if ((mdp -> fd = open ("/dev/zero", O_RDWR)) < 0)
Expand All @@ -165,7 +168,7 @@ mmalloc_attach (HANDLE fd, PTR baseaddr, int minsize)
}
#else
if (mdp -> fd == (HANDLE)0xffffffff) mdp -> flags |= MMALLOC_DEVZERO;
#endif /* WIN32 */
#endif /* _WIN32 */

/* Now try to map in the first page, copy the malloc descriptor structure
there, and arrange to return a pointer to this new copy. If the mapping
Expand All @@ -181,7 +184,7 @@ mmalloc_attach (HANDLE fd, PTR baseaddr, int minsize)
{
mdp->breakval = mdp->base + sizeof(mtemp);
memcpy (mbase, mdp, sizeof (mtemp));
#ifndef WIN32
#ifndef _WIN32
# ifndef VMS
# ifndef R__LYNXOS
# ifndef R__HURD
Expand All @@ -197,7 +200,7 @@ mmalloc_attach (HANDLE fd, PTR baseaddr, int minsize)
{
if (mdp -> flags & MMALLOC_DEVZERO)
{
#ifndef WIN32
#ifndef _WIN32
close (mdp -> fd);
#else
CloseHandle (mdp -> fd);
Expand Down Expand Up @@ -233,7 +236,7 @@ mmalloc_attach (HANDLE fd, PTR baseaddr, int minsize)
unsuccessful for some reason. */

static struct mdesc *
#ifndef WIN32
#ifndef _WIN32
reuse(int cfd)
#else
reuse(HANDLE cfd)
Expand All @@ -242,7 +245,7 @@ reuse(HANDLE cfd)
struct mdesc *mtemp = (struct mdesc*) malloc(sizeof(struct mdesc));
struct mdesc *mdp = NULL;

#ifdef WIN32
#ifdef _WIN32
int rdonly = 0;
BY_HANDLE_FILE_INFORMATION FileInformation;
DWORD lbuf;
Expand Down Expand Up @@ -289,7 +292,7 @@ reuse(HANDLE cfd)
if (mtemp->offset != 0) goto end;
mdp = (struct mdesc *) mtemp->base;
mdp -> fd = cfd;
#ifndef WIN32
#ifndef _WIN32
# ifndef VMS
# ifndef R__LYNXOS
# ifndef R__HURD
Expand Down Expand Up @@ -328,7 +331,7 @@ reuse(HANDLE cfd)
mmalloc_attach (fd, baseaddr)
#endif

#ifndef WIN32
#ifndef _WIN32
int fd;
#else
HANDLE fd;
Expand Down
5 changes: 4 additions & 1 deletion core/clib/src/detach.c → builtins/clib/src/detach.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */

#ifndef _WIN32
#include <unistd.h>
#endif
#include <sys/types.h>
#include <fcntl.h> /* After sys/types.h, at least for dpx/2. */
#include "mmprivate.h"
Expand Down Expand Up @@ -63,7 +66,7 @@ PTR mmalloc_detach(PTR md)
{
if (mtemp.flags & MMALLOC_DEVZERO)
{
#ifndef WIN32
#ifndef _WIN32
close (mtemp.fd);
#else
CloseHandle(mtemp.fd);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* @(#)root/clib:$Id$ */
/* Author: */
#ifdef WIN32
#ifdef _WIN32
#include <windows.h>
#include "mmalloc.h"

Expand Down
6 changes: 3 additions & 3 deletions core/clib/src/keys.c → builtins/clib/src/keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ Boston, MA 02111-1307, USA. */
can be an unlimited number of keys, possibly using a multilevel access
scheme of some sort. */

#ifndef WIN32
#ifndef _WIN32
# include <sys/types.h>
# include <sys/mman.h>
#endif /* WIN32 */
#endif /* _WIN32 */

#include "mmprivate.h"

Expand All @@ -49,7 +49,7 @@ int mmalloc_setkey(PTR md, int keynum, PTR key)
if ((mdp != NULL) && (keynum >= 0) && (keynum < MMALLOC_KEYS))
{
mdp -> keys [keynum] = key;
#ifndef WIN32
#ifndef _WIN32
#ifndef VMS
#ifndef R__LYNXOS
#ifndef R__HURD
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading
Loading