Changeset 6d44da1 for libcfa


Ignore:
Timestamp:
Sep 25, 2018, 11:35:34 AM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
Children:
c6bbcdb
Parents:
341bb80 (diff), 7428ad9 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into shared_library

Location:
libcfa
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • libcfa/Makefile.in

    r341bb80 r6d44da1  
    238238CFLAGS = @CFLAGS@
    239239CONFIGURATION = @CONFIGURATION@
     240CONFIG_BUILDLIB = @CONFIG_BUILDLIB@
    240241CONFIG_CFAFLAGS = @CONFIG_CFAFLAGS@
    241242CONFIG_CFLAGS = @CONFIG_CFLAGS@
  • libcfa/configure

    r341bb80 r6d44da1  
    701701CFA_PREFIX
    702702CFA_NAME
     703BUILDLIB_FALSE
     704BUILDLIB_TRUE
     705CONFIG_BUILDLIB
    703706CONFIG_CFAFLAGS
    704707CONFIG_CFLAGS
     
    23762379
    23772380
     2381
    23782382am__api_version='1.15'
    23792383
     
    29472951                CONFIG_CFLAGS="-O0 -g"
    29482952                CONFIG_CFAFLAGS="-debug"
     2953                CONFIG_BUILDLIB="yes"
    29492954        ;;
    29502955        "nodebug" )
    29512956                CONFIG_CFLAGS="-O2 -s"
    29522957                CONFIG_CFAFLAGS="-nodebug"
     2958                CONFIG_BUILDLIB="yes"
    29532959        ;;
    29542960        "nolib"   )
    2955                 CONFIG_CFLAGS=""
    2956                 CONFIG_CFAFLAGS=""
     2961                CONFIG_CFLAGS="-O2 -s"
     2962                CONFIG_CFAFLAGS="-nodebug"
     2963                CONFIG_BUILDLIB="no"
    29572964        ;;
    29582965esac
    29592966
    29602967
     2968
     2969
     2970
     2971 if test "x${CONFIG_BUILDLIB}" = "xyes"; then
     2972  BUILDLIB_TRUE=
     2973  BUILDLIB_FALSE='#'
     2974else
     2975  BUILDLIB_TRUE='#'
     2976  BUILDLIB_FALSE=
     2977fi
    29612978
    29622979
     
    1694416961fi
    1694516962
     16963if test -z "${BUILDLIB_TRUE}" && test -z "${BUILDLIB_FALSE}"; then
     16964  as_fn_error $? "conditional \"BUILDLIB\" was never defined.
     16965Usually this means the macro was only invoked conditionally." "$LINENO" 5
     16966fi
    1694616967if test -z "${AMDEP_TRUE}" && test -z "${AMDEP_FALSE}"; then
    1694716968  as_fn_error $? "conditional \"AMDEP\" was never defined.
  • libcfa/configure.ac

    r341bb80 r6d44da1  
    4242                CONFIG_CFLAGS="-O0 -g"
    4343                CONFIG_CFAFLAGS="-debug"
     44                CONFIG_BUILDLIB="yes"
    4445        ;;
    4546        "nodebug" )
    4647                CONFIG_CFLAGS="-O2 -s"
    4748                CONFIG_CFAFLAGS="-nodebug"
     49                CONFIG_BUILDLIB="yes"
    4850        ;;
    4951        "nolib"   )
    50                 CONFIG_CFLAGS=""
    51                 CONFIG_CFAFLAGS=""
     52                CONFIG_CFLAGS="-O2 -s"
     53                CONFIG_CFAFLAGS="-nodebug"
     54                CONFIG_BUILDLIB="no"
    5255        ;;
    5356esac
     
    5558AC_SUBST(CONFIG_CFLAGS)
    5659AC_SUBST(CONFIG_CFAFLAGS)
     60AC_SUBST(CONFIG_BUILDLIB)
     61
     62AM_CONDITIONAL([BUILDLIB], [test "x${CONFIG_BUILDLIB}" = "xyes"])
    5763
    5864#==============================================================================
  • libcfa/prelude/Makefile.am

    r341bb80 r6d44da1  
    2121# put into lib for now
    2222cfalibdir = ${CFA_LIBDIR}
    23 cfalib_DATA = gcc-builtins.cf builtins.cf extras.cf prelude.cf bootloader.c
    24 noinst_DATA = ../src/prelude.c
     23cfalib_DATA = gcc-builtins.cf builtins.cf extras.cf prelude.cfa bootloader.c
    2524
    2625CC = @CFACC@
     
    4544        ${AM_V_GEN}gcc -I${srcdir} -E ${srcdir}/prototypes.c | awk -f ${srcdir}/prototypes.awk > $@
    4645
    47 prelude.cf : prelude-gen.cc
     46prelude.cfa : prelude-gen.cc
    4847        ${AM_V_GEN}${CXX} ${AM_CXXFLAGS} ${CXXFLAGS} ${AM_CFLAGS} ${<} -o prelude-gen -Wall -Wextra -O2 -g -std=c++14
    4948        @./prelude-gen > $@
     
    6160include $(DEPDIR)/builtins.Po
    6261
    63 ../src/prelude.c : prelude.cf extras.cf gcc-builtins.cf builtins.cf @CFACPP@
    64         ${AM_V_GEN}@CFACPP@ --prelude-dir=${builddir} -l prelude.cf $@  # use src/cfa-cpp as not in lib until after install
    65 
    66 bootloader.c : ${srcdir}/bootloader.cf prelude.cf extras.cf gcc-builtins.cf builtins.cf @CFACPP@
     62bootloader.c : ${srcdir}/bootloader.cf prelude.cfa extras.cf gcc-builtins.cf builtins.cf @CFACPP@
    6763        ${AM_V_GEN}@CFACPP@ --prelude-dir=${builddir} -tpm ${srcdir}/bootloader.cf $@  # use src/cfa-cpp as not in lib until after install
    6864
     
    7066        rm -rf $(DEPDIR)
    7167
    72 MOSTLYCLEANFILES = bootloader.c builtins.cf extras.cf gcc-builtins.c gcc-builtins.cf prelude.cf
     68MOSTLYCLEANFILES = bootloader.c builtins.cf extras.cf gcc-builtins.c gcc-builtins.cf prelude.cfa
    7369MAINTAINERCLEANFILES = ${addprefix ${libdir}/,${cfalib_DATA}} ${addprefix ${libdir}/,${lib_LIBRARIES}}
  • libcfa/prelude/Makefile.in

    r341bb80 r6d44da1  
    153153  }
    154154am__installdirs = "$(DESTDIR)$(cfalibdir)"
    155 DATA = $(cfalib_DATA) $(noinst_DATA)
     155DATA = $(cfalib_DATA)
    156156am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
    157157am__DIST_COMMON = $(srcdir)/Makefile.in
     
    181181CFLAGS = @CFLAGS@
    182182CONFIGURATION = @CONFIGURATION@
     183CONFIG_BUILDLIB = @CONFIG_BUILDLIB@
    183184CONFIG_CFAFLAGS = @CONFIG_CFAFLAGS@
    184185CONFIG_CFLAGS = @CONFIG_CFLAGS@
     
    301302# put into lib for now
    302303cfalibdir = ${CFA_LIBDIR}
     304<<<<<<< HEAD
    303305cfalib_DATA = gcc-builtins.cf builtins.cf extras.cf prelude.cf bootloader.c
    304306noinst_DATA = ../src/prelude.c
    305307AM_CFLAGS = -g -Wall -Wno-unused-function -fPIC @ARCH_FLAGS@ @CONFIG_CFLAGS@
     308=======
     309cfalib_DATA = gcc-builtins.cf builtins.cf extras.cf prelude.cfa bootloader.c
     310AM_CFLAGS = -g -Wall -Wno-unused-function @ARCH_FLAGS@ @CONFIG_CFLAGS@
     311>>>>>>> master
    306312AM_CFAFLAGS = @CONFIG_CFAFLAGS@
    307 MOSTLYCLEANFILES = bootloader.c builtins.cf extras.cf gcc-builtins.c gcc-builtins.cf prelude.cf
     313MOSTLYCLEANFILES = bootloader.c builtins.cf extras.cf gcc-builtins.c gcc-builtins.cf prelude.cfa
    308314MAINTAINERCLEANFILES = ${addprefix ${libdir}/,${cfalib_DATA}} ${addprefix ${libdir}/,${lib_LIBRARIES}}
    309315all: all-am
     
    544550        ${AM_V_GEN}gcc -I${srcdir} -E ${srcdir}/prototypes.c | awk -f ${srcdir}/prototypes.awk > $@
    545551
    546 prelude.cf : prelude-gen.cc
     552prelude.cfa : prelude-gen.cc
    547553        ${AM_V_GEN}${CXX} ${AM_CXXFLAGS} ${CXXFLAGS} ${AM_CFLAGS} ${<} -o prelude-gen -Wall -Wextra -O2 -g -std=c++14
    548554        @./prelude-gen > $@
     
    560566include $(DEPDIR)/builtins.Po
    561567
    562 ../src/prelude.c : prelude.cf extras.cf gcc-builtins.cf builtins.cf @CFACPP@
    563         ${AM_V_GEN}@CFACPP@ --prelude-dir=${builddir} -l prelude.cf $@  # use src/cfa-cpp as not in lib until after install
    564 
    565 bootloader.c : ${srcdir}/bootloader.cf prelude.cf extras.cf gcc-builtins.cf builtins.cf @CFACPP@
     568bootloader.c : ${srcdir}/bootloader.cf prelude.cfa extras.cf gcc-builtins.cf builtins.cf @CFACPP@
    566569        ${AM_V_GEN}@CFACPP@ --prelude-dir=${builddir} -tpm ${srcdir}/bootloader.cf $@  # use src/cfa-cpp as not in lib until after install
    567570
  • libcfa/prelude/prelude-gen.cc

    r341bb80 r6d44da1  
    142142
    143143int main() {
    144         cout << "# 2 \"prelude.cf\"  // needed for error messages from this file" << endl;
     144        cout << "# 2 \"prelude.cfa\"  // needed for error messages from this file" << endl;
    145145        cout << "trait sized(dtype T) {};" << endl;
    146146
  • libcfa/src/Makefile.am

    r341bb80 r6d44da1  
    2525lib_LTLIBRARIES =  libcfa.la
    2626
     27VPATH += :../prelude
     28
    2729# AM_CFLAGS for all cfa source
    2830# AM_CFAFLAGS for only cfa source
    2931# use -no-include-stdhdr to prevent rebuild cycles
    3032# The built sources must not depend on the installed headers
    31 AM_CFAFLAGS = -quiet -in-tree -imacros prelude.c -I$(srcdir)/stdhdr @CONFIG_CFAFLAGS@
     33AM_CFAFLAGS = -quiet -in-tree -I$(srcdir)/stdhdr @CONFIG_CFAFLAGS@
    3234AM_CFLAGS = -g -Wall -Wno-unused-function -fPIC @ARCH_FLAGS@ @CONFIG_CFLAGS@
    3335AM_CCASFLAGS = -g -Wall -Wno-unused-function @ARCH_FLAGS@ @CONFIG_CFLAGS@
     
    3537
    3638#----------------------------------------------------------------------------------------------------------------
     39if BUILDLIB
    3740headers = fstream.hfa iostream.hfa iterator.hfa limits.hfa rational.hfa time.hfa stdlib.hfa common.hfa \
    3841          containers/maybe.hfa containers/pair.hfa containers/result.hfa containers/vector.hfa
     42
     43headers_nosrc = math.hfa gmp.hfa time_t.hfa bits/align.hfa bits/containers.hfa bits/defs.hfa bits/debug.hfa bits/locks.hfa
    3944
    4045# not all platforms support concurrency, add option do disable it
    4146headers += concurrency/coroutine.hfa concurrency/thread.hfa concurrency/kernel.hfa concurrency/monitor.hfa concurrency/mutex.hfa
    4247
     48headers_nosrc += concurrency/invoke.h
     49
    4350libobjs = ${headers:.hfa=.lo}
    44 libsrc = prelude.c startup.cfa interpose.cfa bits/debug.cfa assert.cfa exception.c virtual.c heap.cfa \
    45         ${headers:.hfa=.cfa}
     51libsrc = startup.cfa interpose.cfa bits/debug.cfa assert.cfa exception.c virtual.c heap.cfa ${headers:.hfa=.cfa}
    4652
    4753# not all platforms support concurrency, add option do disable it
    4854libsrc += concurrency/CtxSwitch-@ARCHITECTURE@.S concurrency/alarm.cfa concurrency/invoke.c concurrency/preemption.cfa
     55else
     56headers =
     57headers_nosrc =
     58libsrc =
     59endif
     60
    4961
    5062#----------------------------------------------------------------------------------------------------------------
    5163# add dependency to cfa-cpp so all libraries are rebuilt with new translator
    52 ${libobjs} : ${cfalib_DATA}
     64#@CFACC@ @CFACPP@ prelude.cfa
    5365
    54 libcfa_la_SOURCES = ${libsrc}
     66# add dependency of cfa files
     67libobjs = $(addsuffix .lo, $(basename $(filter %.cfa,$(libsrc))))
     68$(libobjs) : @CFACC@ @CFACPP@ prelude.cfa
     69
     70
     71# .deps inclusion is not done automatically by automake for new languages
     72libdeps = $(join \
     73        $(addsuffix $(DEPDIR)/ , $(dir $(libobjs) ) ), \
     74        $(notdir ${libobjs:.lo=.Po}) \
     75)
     76
     77-include $(libdeps)
     78
     79prelude.lo : prelude.cfa extras.cf gcc-builtins.cf builtins.cf @CFACC@ @CFACPP@
     80        ${AM_V_GEN}@CFACC@ ${AM_CFLAGS} ${CFLAGS} -quiet -in-tree -XCFA -l ${<} -c -o ${@}
     81
     82
     83
     84#----------------------------------------------------------------------------------------------------------------
     85libcfa_la_SOURCES = prelude.cfa ${libsrc}
    5586
    5687stdhdr = $(shell find $(srcdir)/stdhdr -type f -printf "%p ")
    5788
    5889cfa_includedir = $(CFA_INCDIR)
    59 nobase_cfa_include_HEADERS = \
    60         ${headers}             \
    61         ${stdhdr}              \
    62         math.hfa               \
    63         gmp.hfa                \
    64         time_t.hfa             \
    65         bits/align.hfa         \
    66         bits/containers.hfa    \
    67         bits/defs.hfa          \
    68         bits/debug.hfa         \
    69         bits/locks.hfa         \
    70         concurrency/invoke.h
    71 
    72 MOSTLYCLEANFILES = prelude.c
     90nobase_cfa_include_HEADERS = ${stdhdr} ${headers} ${headers_nosrc}
    7391
    7492#----------------------------------------------------------------------------------------------------------------
    7593maintainer-clean-local:
    7694        -rm -rf ${CFA_INCDIR} ${CFA_LIBDIR}
     95
     96
     97# $(AM_V_CFA)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
     98#       $(CFACOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\
     99#       $(am__mv) $$depbase.Tpo $$depbase.Po
  • libcfa/src/Makefile.in

    r341bb80 r6d44da1  
    1919
    2020
    21 VPATH = @srcdir@
    2221am__is_gnu_make = { \
    2322  if test -z '$(MAKELEVEL)'; then \
     
    103102am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
    104103        $(ACLOCAL_M4)
    105 DIST_COMMON = $(srcdir)/Makefile.am $(nobase_cfa_include_HEADERS) \
    106         $(am__DIST_COMMON)
     104DIST_COMMON = $(srcdir)/Makefile.am \
     105        $(am__nobase_cfa_include_HEADERS_DIST) $(am__DIST_COMMON)
    107106mkinstalldirs = $(install_sh) -d
    108107CONFIG_CLEAN_FILES =
     
    136135  }
    137136am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(cfa_includedir)"
     137<<<<<<< HEAD
    138138LTLIBRARIES = $(lib_LTLIBRARIES)
    139139libcfa_la_LIBADD =
     
    155155am__v_lt_0 = --silent
    156156am__v_lt_1 =
     157=======
     158LIBRARIES = $(lib_LIBRARIES)
     159AR = ar
     160AM_V_AR = $(am__v_AR_@AM_V@)
     161am__v_AR_ = $(am__v_AR_@AM_DEFAULT_V@)
     162am__v_AR_0 = @echo "  AR      " $@;
     163am__v_AR_1 =
     164libcfa_a_AR = $(AR) $(ARFLAGS)
     165libcfa_a_LIBADD =
     166am__libcfa_a_SOURCES_DIST = prelude.cfa startup.cfa interpose.cfa \
     167        bits/debug.cfa assert.cfa exception.c virtual.c heap.cfa \
     168        fstream.cfa iostream.cfa iterator.cfa limits.cfa rational.cfa \
     169        time.cfa stdlib.cfa common.cfa containers/maybe.cfa \
     170        containers/pair.cfa containers/result.cfa \
     171        containers/vector.cfa concurrency/coroutine.cfa \
     172        concurrency/thread.cfa concurrency/kernel.cfa \
     173        concurrency/monitor.cfa concurrency/mutex.cfa \
     174        concurrency/CtxSwitch-@ARCHITECTURE@.S concurrency/alarm.cfa \
     175        concurrency/invoke.c concurrency/preemption.cfa
     176am__dirstamp = $(am__leading_dot)dirstamp
     177@BUILDLIB_TRUE@am__objects_1 = fstream.$(OBJEXT) iostream.$(OBJEXT) \
     178@BUILDLIB_TRUE@ iterator.$(OBJEXT) limits.$(OBJEXT) \
     179@BUILDLIB_TRUE@ rational.$(OBJEXT) time.$(OBJEXT) \
     180@BUILDLIB_TRUE@ stdlib.$(OBJEXT) common.$(OBJEXT) \
     181@BUILDLIB_TRUE@ containers/maybe.$(OBJEXT) \
     182@BUILDLIB_TRUE@ containers/pair.$(OBJEXT) \
     183@BUILDLIB_TRUE@ containers/result.$(OBJEXT) \
     184@BUILDLIB_TRUE@ containers/vector.$(OBJEXT) \
     185@BUILDLIB_TRUE@ concurrency/coroutine.$(OBJEXT) \
     186@BUILDLIB_TRUE@ concurrency/thread.$(OBJEXT) \
     187@BUILDLIB_TRUE@ concurrency/kernel.$(OBJEXT) \
     188@BUILDLIB_TRUE@ concurrency/monitor.$(OBJEXT) \
     189@BUILDLIB_TRUE@ concurrency/mutex.$(OBJEXT)
     190@BUILDLIB_TRUE@am__objects_2 = startup.$(OBJEXT) interpose.$(OBJEXT) \
     191@BUILDLIB_TRUE@ bits/debug.$(OBJEXT) assert.$(OBJEXT) \
     192@BUILDLIB_TRUE@ exception.$(OBJEXT) virtual.$(OBJEXT) \
     193@BUILDLIB_TRUE@ heap.$(OBJEXT) $(am__objects_1) \
     194@BUILDLIB_TRUE@ concurrency/CtxSwitch-@ARCHITECTURE@.$(OBJEXT) \
     195@BUILDLIB_TRUE@ concurrency/alarm.$(OBJEXT) \
     196@BUILDLIB_TRUE@ concurrency/invoke.$(OBJEXT) \
     197@BUILDLIB_TRUE@ concurrency/preemption.$(OBJEXT)
     198am_libcfa_a_OBJECTS = prelude.$(OBJEXT) $(am__objects_2)
     199libcfa_a_OBJECTS = $(am_libcfa_a_OBJECTS)
     200>>>>>>> master
    157201AM_V_P = $(am__v_P_@AM_V@)
    158202am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
     
    199243am__v_CCLD_0 = @echo "  CCLD    " $@;
    200244am__v_CCLD_1 =
     245<<<<<<< HEAD
    201246SOURCES = $(libcfa_la_SOURCES)
    202247DIST_SOURCES = $(libcfa_la_SOURCES)
     248=======
     249SOURCES = $(libcfa_a_SOURCES)
     250DIST_SOURCES = $(am__libcfa_a_SOURCES_DIST)
     251>>>>>>> master
    203252am__can_run_installinfo = \
    204253  case $$AM_UPDATE_INFO_DIR in \
     
    206255    *) (install-info --version) >/dev/null 2>&1;; \
    207256  esac
     257am__nobase_cfa_include_HEADERS_DIST = ${shell find ${srcdir}/stdhdr \
     258        -type f -printf "%p "} fstream.hfa iostream.hfa iterator.hfa \
     259        limits.hfa rational.hfa time.hfa stdlib.hfa common.hfa \
     260        containers/maybe.hfa containers/pair.hfa containers/result.hfa \
     261        containers/vector.hfa concurrency/coroutine.hfa \
     262        concurrency/thread.hfa concurrency/kernel.hfa \
     263        concurrency/monitor.hfa concurrency/mutex.hfa math.hfa gmp.hfa \
     264        time_t.hfa bits/align.hfa bits/containers.hfa bits/defs.hfa \
     265        bits/debug.hfa bits/locks.hfa concurrency/invoke.h
    208266HEADERS = $(nobase_cfa_include_HEADERS)
    209267am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
     
    229287        $(top_srcdir)/automake/depcomp
    230288DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
     289VPATH = @srcdir@ :../prelude
    231290ACLOCAL = @ACLOCAL@
    232291AMTAR = @AMTAR@
     
    253312CFLAGS = @CFLAGS@
    254313CONFIGURATION = @CONFIGURATION@
     314CONFIG_BUILDLIB = @CONFIG_BUILDLIB@
    255315CONFIG_CFAFLAGS = @CONFIG_CFAFLAGS@
    256316CONFIG_CFLAGS = @CONFIG_CFLAGS@
     
    369429# create object files in directory with source files
    370430AUTOMAKE_OPTIONS = foreign subdir-objects
     431<<<<<<< HEAD
    371432ACLOCAL_AMFLAGS = -I automake
     433=======
     434>>>>>>> master
    372435ARFLAGS = cr
    373436CFACOMPILE = $(CFACC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CFAFLAGS) $(CFAFLAGS) $(AM_CFLAGS) $(CFLAGS)
     
    387450# use -no-include-stdhdr to prevent rebuild cycles
    388451# The built sources must not depend on the installed headers
     452<<<<<<< HEAD
    389453AM_CFAFLAGS = -quiet -in-tree -imacros prelude.c -I$(srcdir)/stdhdr @CONFIG_CFAFLAGS@
    390454AM_CFLAGS = -g -Wall -Wno-unused-function -fPIC @ARCH_FLAGS@ @CONFIG_CFLAGS@
     455=======
     456AM_CFAFLAGS = -quiet -in-tree -I$(srcdir)/stdhdr @CONFIG_CFAFLAGS@
     457AM_CFLAGS = -g -Wall -Wno-unused-function @ARCH_FLAGS@ @CONFIG_CFLAGS@
     458>>>>>>> master
    391459AM_CCASFLAGS = -g -Wall -Wno-unused-function @ARCH_FLAGS@ @CONFIG_CFLAGS@
     460@BUILDLIB_FALSE@headers =
    392461
    393462#----------------------------------------------------------------------------------------------------------------
    394463
    395464# not all platforms support concurrency, add option do disable it
     465<<<<<<< HEAD
    396466headers = fstream.hfa iostream.hfa iterator.hfa limits.hfa \
    397467        rational.hfa time.hfa stdlib.hfa common.hfa \
     
    409479libcfa_la_SOURCES = ${libsrc}
    410480stdhdr = $(shell find $(srcdir)/stdhdr -type f -printf "%p ")
     481=======
     482@BUILDLIB_TRUE@headers = fstream.hfa iostream.hfa iterator.hfa \
     483@BUILDLIB_TRUE@ limits.hfa rational.hfa time.hfa stdlib.hfa \
     484@BUILDLIB_TRUE@ common.hfa containers/maybe.hfa \
     485@BUILDLIB_TRUE@ containers/pair.hfa containers/result.hfa \
     486@BUILDLIB_TRUE@ containers/vector.hfa concurrency/coroutine.hfa \
     487@BUILDLIB_TRUE@ concurrency/thread.hfa concurrency/kernel.hfa \
     488@BUILDLIB_TRUE@ concurrency/monitor.hfa concurrency/mutex.hfa
     489@BUILDLIB_FALSE@headers_nosrc =
     490@BUILDLIB_TRUE@headers_nosrc = math.hfa gmp.hfa time_t.hfa \
     491@BUILDLIB_TRUE@ bits/align.hfa bits/containers.hfa \
     492@BUILDLIB_TRUE@ bits/defs.hfa bits/debug.hfa bits/locks.hfa \
     493@BUILDLIB_TRUE@ concurrency/invoke.h
     494@BUILDLIB_FALSE@libsrc =
     495
     496# not all platforms support concurrency, add option do disable it
     497@BUILDLIB_TRUE@libsrc = startup.cfa interpose.cfa bits/debug.cfa \
     498@BUILDLIB_TRUE@ assert.cfa exception.c virtual.c heap.cfa \
     499@BUILDLIB_TRUE@ ${headers:.hfa=.cfa} \
     500@BUILDLIB_TRUE@ concurrency/CtxSwitch-@ARCHITECTURE@.S \
     501@BUILDLIB_TRUE@ concurrency/alarm.cfa concurrency/invoke.c \
     502@BUILDLIB_TRUE@ concurrency/preemption.cfa
     503
     504#----------------------------------------------------------------------------------------------------------------
     505# add dependency to cfa-cpp so all libraries are rebuilt with new translator
     506#@CFACC@ @CFACPP@ prelude.cfa
     507
     508# add dependency of cfa files
     509libobjs = $(addsuffix .o, $(basename $(filter %.cfa,$(libsrc))))
     510
     511# .deps inclusion is not done automatically by automake for new languages
     512libdeps = $(join \
     513        $(addsuffix $(DEPDIR)/ , $(dir $(libobjs) ) ), \
     514        $(notdir ${libobjs:.o=.Po}) \
     515)
     516
     517
     518#----------------------------------------------------------------------------------------------------------------
     519libcfa_a_SOURCES = prelude.cfa ${libsrc}
     520stdhdr = ${shell find ${srcdir}/stdhdr -type f -printf "%p "}
     521>>>>>>> master
    411522cfa_includedir = $(CFA_INCDIR)
    412 nobase_cfa_include_HEADERS = \
    413         ${headers}             \
    414         ${stdhdr}              \
    415         math.hfa               \
    416         gmp.hfa                \
    417         time_t.hfa             \
    418         bits/align.hfa         \
    419         bits/containers.hfa    \
    420         bits/defs.hfa          \
    421         bits/debug.hfa         \
    422         bits/locks.hfa         \
    423         concurrency/invoke.h
    424 
    425 MOSTLYCLEANFILES = prelude.c
     523nobase_cfa_include_HEADERS = ${stdhdr} ${headers} ${headers_nosrc}
    426524all: all-am
    427525
     
    554652        -rm -f *.tab.c
    555653
     654<<<<<<< HEAD
    556655@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/exception.Plo@am__quote@
    557656@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/prelude.Plo@am__quote@
     
    559658@AMDEP_TRUE@@am__include@ @am__quote@concurrency/$(DEPDIR)/CtxSwitch-@ARCHITECTURE@.Plo@am__quote@
    560659@AMDEP_TRUE@@am__include@ @am__quote@concurrency/$(DEPDIR)/invoke.Plo@am__quote@
     660=======
     661@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/exception.Po@am__quote@
     662@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/virtual.Po@am__quote@
     663@AMDEP_TRUE@@am__include@ @am__quote@concurrency/$(DEPDIR)/CtxSwitch-@ARCHITECTURE@.Po@am__quote@
     664@AMDEP_TRUE@@am__include@ @am__quote@concurrency/$(DEPDIR)/invoke.Po@am__quote@
     665>>>>>>> master
    561666
    562667.S.o:
     
    750855        fi
    751856mostlyclean-generic:
    752         -test -z "$(MOSTLYCLEANFILES)" || rm -f $(MOSTLYCLEANFILES)
    753857
    754858clean-generic:
     
    861965
    862966
    863 .cfa.o: $(CFACC) $(CFACPP)
     967.cfa.o:
    864968        $(AM_V_CFA)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
    865969        $(CFACOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\
    866970        $(am__mv) $$depbase.Tpo $$depbase.Po
    867 
     971$(libobjs) : @CFACC@ @CFACPP@ prelude.cfa
     972
     973<<<<<<< HEAD
    868974.cfa.lo:
    869975        $(AM_V_CFA)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.lo$$||'`;\
     
    874980# add dependency to cfa-cpp so all libraries are rebuilt with new translator
    875981${libobjs} : ${cfalib_DATA}
     982=======
     983-include $(libdeps)
     984
     985prelude.o : prelude.cfa extras.cf gcc-builtins.cf builtins.cf @CFACC@ @CFACPP@
     986        ${AM_V_GEN}@CFACC@ ${AM_CFLAGS} ${CFLAGS} -quiet -in-tree -XCFA -l ${<} -c -o ${@}
     987>>>>>>> master
    876988
    877989#----------------------------------------------------------------------------------------------------------------
     
    879991        -rm -rf ${CFA_INCDIR} ${CFA_LIBDIR}
    880992
     993# $(AM_V_CFA)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
     994#       $(CFACOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\
     995#       $(am__mv) $$depbase.Tpo $$depbase.Po
     996
    881997# Tell versions [3.59,3.63) of GNU make to not export all variables.
    882998# Otherwise a system limit (for SysV at least) may be exceeded.
  • libcfa/src/heap.cfa

    r341bb80 r6d44da1  
    1 // #comment TD : this file uses both spaces and tabs for indentation
    2 
    31//
    42// Cforall Version 1.0.0 Copyright (C) 2017 University of Waterloo
     
    1210// Created On       : Tue Dec 19 21:58:35 2017
    1311// Last Modified By : Peter A. Buhr
    14 // Last Modified On : Sat Aug 11 08:22:16 2018
    15 // Update Count     : 495
     12// Last Modified On : Thu Sep  6 09:01:30 2018
     13// Update Count     : 513
    1614//
    1715
     
    2523
    2624// #comment TD : Many of these should be merged into math I believe
    27 #include "bits/align.hfa"                                                                       // libPow2
    28 #include "bits/defs.hfa"                                                                        // likely, unlikely
    29 #include "bits/locks.hfa"                                                                       // __spinlock_t
     25#include "bits/align.hfa"                                                               // libPow2
     26#include "bits/defs.hfa"                                                                // likely, unlikely
     27#include "bits/locks.hfa"                                                               // __spinlock_t
    3028#include "startup.hfa"                                                                  // STARTUP_PRIORITY_MEMORY
    31 #include "stdlib.hfa"                                                                           // bsearchl
     29#include "stdlib.hfa"                                                                   // bsearchl
    3230#include "malloc.h"
    3331
     
    151149
    152150extern "C" {
    153 void heapAppStart() {                                                                   // called by __cfaabi_appready_startup
    154         allocFree = 0;
    155 } // heapAppStart
    156 
    157 void heapAppStop() {                                                                    // called by __cfaabi_appready_startdown
    158         fclose( stdin ); fclose( stdout );
    159         checkUnfreed();
    160 } // heapAppStop
     151        void heapAppStart() {                                                           // called by __cfaabi_appready_startup
     152                allocFree = 0;
     153        } // heapAppStart
     154
     155        void heapAppStop() {                                                            // called by __cfaabi_appready_startdown
     156                fclose( stdin ); fclose( stdout );
     157                checkUnfreed();
     158        } // heapAppStop
    161159} // extern "C"
    162160#endif // __CFA_DEBUG__
     
    167165
    168166        struct Storage {
    169             struct Header {                                                                     // header
     167                struct Header {                                                                 // header
    170168                        union Kind {
    171169                                struct RealHeader {
    172170                                        union {
    173                                                 // #comment TD : this code use byte size but the comment uses bit size
    174 
    175                                                 struct {                                                // 32-bit word => 64-bit header, 64-bit word => 128-bit header
     171                                                struct {                                                // 4-byte word => 8-byte header, 8-byte word => 16-byte header
    176172                                                        #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ && __SIZEOF_POINTER__ == 4
    177173                                                        uint32_t padding;                       // unused, force home/blocksize to overlay alignment in fake header
    178                                                         #endif // __ORDER_BIG_ENDIAN__ && __U_WORDSIZE__ == 32
     174                                                        #endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ && __SIZEOF_POINTER__ == 4
    179175
    180176                                                        union {
     
    189185                                                        #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ && __SIZEOF_POINTER__ == 4
    190186                                                        uint32_t padding;                       // unused, force home/blocksize to overlay alignment in fake header
    191                                                         #endif // __ORDER_LITTLE_ENDIAN__ && __U_WORDSIZE__ == 32
    192 
     187                                                        #endif // __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ && __SIZEOF_POINTER__ == 4
    193188                                                };
    194 
    195                                                 // #comment TD : C++ code
     189                                                // future code
    196190                                                #if BUCKLOCK == LOCKFREE
    197191                                                Stack<Storage>::Link next;              // freed block points next freed block of same size (double-wide)
     
    211205                                } fake; // FakeHeader
    212206                        } kind; // Kind
    213             } header; // Header
    214             char pad[ALIGN - sizeof( Header )];
    215             char data[0];                                                                       // storage
     207                } header; // Header
     208                char pad[ALIGN - sizeof( Header )];
     209                char data[0];                                                                   // storage
    216210        }; // Storage
    217211
     
    220214        struct FreeHeader {
    221215                #if BUCKLOCK == SPINLOCK
    222             __spinlock_t lock;                                                          // must be first field for alignment
    223             Storage * freeList;
     216                __spinlock_t lock;                                                              // must be first field for alignment
     217                Storage * freeList;
    224218                #elif BUCKLOCK == LOCKFREE
    225                 // #comment TD : C++ code
    226             StackLF<Storage> freeList;
     219                // future code
     220                StackLF<Storage> freeList;
    227221                #else
    228                         #error undefined lock type for bucket lock
     222                #error undefined lock type for bucket lock
    229223                #endif // SPINLOCK
    230             size_t blockSize;                                                           // size of allocations on this list
     224                size_t blockSize;                                                               // size of allocations on this list
    231225        }; // FreeHeader
    232226
     
    249243static unsigned int maxBucketsUsed;                                             // maximum number of buckets in use
    250244
    251 // #comment TD : This array is not const but it feels like it should be
    252245// Powers of 2 are common allocation sizes, so make powers of 2 generate the minimum required size.
    253 static unsigned int bucketSizes[NoBucketSizes] @= {             // different bucket sizes
     246static const unsigned int bucketSizes[NoBucketSizes] @= { // different bucket sizes
    254247        16, 32, 48, 64,
    255248        64 + sizeof(HeapManager.Storage), 96, 112, 128, 128 + sizeof(HeapManager.Storage), 160, 192, 224,
     
    279272// #comment TD : The return type of this function should be commented
    280273static inline bool setMmapStart( size_t value ) {
    281         if ( value < pageSize || bucketSizes[NoBucketSizes - 1] < value ) return true;
     274  if ( value < pageSize || bucketSizes[NoBucketSizes - 1] < value ) return true;
    282275        mmapStart = value;                                                                      // set global
    283276
     
    313306        sbrk( (char *)libCeiling( (long unsigned int)End, libAlign() ) - End ); // move start of heap to multiple of alignment
    314307        heapBegin = heapEnd = sbrk( 0 );                                        // get new start point
    315 } // HeapManager
     308                           } // HeapManager
    316309
    317310
     
    323316        // } // if
    324317        #endif // __STATISTICS__
    325 } // ~HeapManager
     318                                } // ~HeapManager
    326319
    327320
     
    329322void memory_startup( void ) {
    330323        #ifdef __CFA_DEBUG__
    331         if ( unlikely( heapBoot ) ) {                                   // check for recursion during system boot
     324        if ( unlikely( heapBoot ) ) {                                           // check for recursion during system boot
    332325                // DO NOT USE STREAMS AS THEY MAY BE UNAVAILABLE AT THIS POINT.
    333326                abort( "boot() : internal error, recursively invoked during system boot." );
     
    336329        #endif // __CFA_DEBUG__
    337330
    338         // #comment TD : This assertion seems redundent with the above code
    339         assert( heapManager.heapBegin == 0 );
    340         heapManager{};
     331        //assert( heapManager.heapBegin != 0 );
     332        //heapManager{};
     333        if ( heapManager.heapBegin == 0 ) heapManager{};
    341334} // memory_startup
    342335
     
    374367        char helpText[512];
    375368        __cfaabi_dbg_bits_print_buffer( helpText, sizeof(helpText),
    376                         "\nHeap statistics:\n"
    377                         "  malloc: calls %u / storage %llu\n"
    378                         "  calloc: calls %u / storage %llu\n"
    379                         "  memalign: calls %u / storage %llu\n"
    380                         "  cmemalign: calls %u / storage %llu\n"
    381                         "  realloc: calls %u / storage %llu\n"
    382                         "  free: calls %u / storage %llu\n"
    383                         "  mmap: calls %u / storage %llu\n"
    384                         "  munmap: calls %u / storage %llu\n"
    385                         "  sbrk: calls %u / storage %llu\n",
    386                         malloc_calls, malloc_storage,
    387                         calloc_calls, calloc_storage,
    388                         memalign_calls, memalign_storage,
    389                         cmemalign_calls, cmemalign_storage,
    390                         realloc_calls, realloc_storage,
    391                         free_calls, free_storage,
    392                         mmap_calls, mmap_storage,
    393                         munmap_calls, munmap_storage,
    394                         sbrk_calls, sbrk_storage
     369                                                                        "\nHeap statistics:\n"
     370                                                                        "  malloc: calls %u / storage %llu\n"
     371                                                                        "  calloc: calls %u / storage %llu\n"
     372                                                                        "  memalign: calls %u / storage %llu\n"
     373                                                                        "  cmemalign: calls %u / storage %llu\n"
     374                                                                        "  realloc: calls %u / storage %llu\n"
     375                                                                        "  free: calls %u / storage %llu\n"
     376                                                                        "  mmap: calls %u / storage %llu\n"
     377                                                                        "  munmap: calls %u / storage %llu\n"
     378                                                                        "  sbrk: calls %u / storage %llu\n",
     379                                                                        malloc_calls, malloc_storage,
     380                                                                        calloc_calls, calloc_storage,
     381                                                                        memalign_calls, memalign_storage,
     382                                                                        cmemalign_calls, cmemalign_storage,
     383                                                                        realloc_calls, realloc_storage,
     384                                                                        free_calls, free_storage,
     385                                                                        mmap_calls, mmap_storage,
     386                                                                        munmap_calls, munmap_storage,
     387                                                                        sbrk_calls, sbrk_storage
    395388                );
    396389} // printStats
    397390
    398 // #comment TD : Why do we have this?
    399 static int printStatsXML( FILE * stream ) {
     391static int printStatsXML( FILE * stream ) {                             // see malloc_info
    400392        char helpText[512];
    401393        int len = snprintf( helpText, sizeof(helpText),
     
    431423static inline void noMemory() {
    432424        abort( "Heap memory exhausted at %zu bytes.\n"
    433                         "Possible cause is very large memory allocation and/or large amount of unfreed storage allocated by the program or system/library routines.",
    434                         ((char *)(sbrk( 0 )) - (char *)(heapManager.heapBegin)) );
     425                   "Possible cause is very large memory allocation and/or large amount of unfreed storage allocated by the program or system/library routines.",
     426                   ((char *)(sbrk( 0 )) - (char *)(heapManager.heapBegin)) );
    435427} // noMemory
    436428
     
    444436
    445437static inline bool setHeapExpand( size_t value ) {
    446         if ( heapExpand < pageSize ) return true;
     438  if ( heapExpand < pageSize ) return true;
    447439        heapExpand = value;
    448440        return false;
     
    453445        if ( unlikely( check ) ) {                                                      // bad address ?
    454446                abort( "Attempt to %s storage %p with address outside the heap.\n"
    455                                 "Possible cause is duplicate free on same block or overwriting of memory.",
    456                                 name, addr );
     447                           "Possible cause is duplicate free on same block or overwriting of memory.",
     448                           name, addr );
    457449        } // if
    458450} // checkHeader
     
    484476
    485477        #ifdef __CFA_DEBUG__
    486                         checkHeader( addr < heapBegin || header < (HeapManager.Storage.Header *)heapBegin, name, addr ); // bad low address ?
     478        checkHeader( addr < heapBegin || header < (HeapManager.Storage.Header *)heapBegin, name, addr ); // bad low address ?
    487479        #endif // __CFA_DEBUG__
    488480
     
    490482        //               It's called as the first statement of both branches of the last if, with the same parameters in all cases
    491483
    492                 // header may be safe to dereference
    493                 fakeHeader( header, size, alignment );
     484        // header may be safe to dereference
     485        fakeHeader( header, size, alignment );
    494486        #ifdef __CFA_DEBUG__
    495                         checkHeader( header < (HeapManager.Storage.Header *)heapBegin || (HeapManager.Storage.Header *)heapEnd < header, name, addr ); // bad address ? (offset could be + or -)
     487        checkHeader( header < (HeapManager.Storage.Header *)heapBegin || (HeapManager.Storage.Header *)heapEnd < header, name, addr ); // bad address ? (offset could be + or -)
    496488        #endif // __CFA_DEBUG__
    497489
    498                 freeElem = (HeapManager.FreeHeader *)((size_t)header->kind.real.home & -3);
     490        freeElem = (HeapManager.FreeHeader *)((size_t)header->kind.real.home & -3);
    499491        #ifdef __CFA_DEBUG__
    500                         if ( freeElem < &freeLists[0] || &freeLists[NoBucketSizes] <= freeElem ) {
    501                         abort( "Attempt to %s storage %p with corrupted header.\n"
    502                                 "Possible cause is duplicate free on same block or overwriting of header information.",
    503                                         name, addr );
    504                         } // if
     492        if ( freeElem < &freeLists[0] || &freeLists[NoBucketSizes] <= freeElem ) {
     493                abort( "Attempt to %s storage %p with corrupted header.\n"
     494                          "Possible cause is duplicate free on same block or overwriting of header information.",
     495                           name, addr );
     496        } // if
    505497        #endif // __CFA_DEBUG__
    506                 size = freeElem->blockSize;
    507                 return false;
     498        size = freeElem->blockSize;
     499        return false;
    508500} // headers
    509501
     
    521513                        return 0;
    522514                } // if
    523 #ifdef __STATISTICS__
     515                #ifdef __STATISTICS__
    524516                sbrk_calls += 1;
    525517                sbrk_storage += increase;
    526 #endif // __STATISTICS__
    527 #ifdef __CFA_DEBUG__
     518                #endif // __STATISTICS__
     519                #ifdef __CFA_DEBUG__
    528520                // Set new memory to garbage so subsequent uninitialized usages might fail.
    529521                memset( (char *)heapEnd + heapRemaining, '\377', increase );
    530 #endif // __CFA_DEBUG__
     522                #endif // __CFA_DEBUG__
    531523                rem = heapRemaining + increase - size;
    532524        } // if
     
    560552
    561553                #if defined( SPINLOCK )
    562                         lock( freeElem->lock __cfaabi_dbg_ctx2 );
    563                         block = freeElem->freeList;                                             // remove node from stack
     554                lock( freeElem->lock __cfaabi_dbg_ctx2 );
     555                block = freeElem->freeList;                                             // remove node from stack
    564556                #else
    565                         block = freeElem->freeList.pop();
     557                block = freeElem->freeList.pop();
    566558                #endif // SPINLOCK
    567559                if ( unlikely( block == 0 ) ) {                                 // no free block ?
     
    569561                        unlock( freeElem->lock );
    570562                        #endif // SPINLOCK
     563
    571564                        // Freelist for that size was empty, so carve it out of the heap if there's enough left, or get some more
    572565                        // and then carve it off.
    573566
    574567                        block = (HeapManager.Storage *)extend( tsize ); // mutual exclusion on call
    575                         if ( unlikely( block == 0 ) ) return 0;
     568  if ( unlikely( block == 0 ) ) return 0;
    576569                        #if defined( SPINLOCK )
    577570                } else {
     
    582575
    583576                block->header.kind.real.home = freeElem;                // pointer back to free list of apropriate size
    584                 } else {                                                                                        // large size => mmap
     577        } else {                                                                                        // large size => mmap
    585578                tsize = libCeiling( tsize, pageSize );                  // must be multiple of page size
    586579                #ifdef __STATISTICS__
    587                         __atomic_add_fetch( &mmap_calls, 1, __ATOMIC_SEQ_CST );
    588                         __atomic_add_fetch( &mmap_storage, tsize, __ATOMIC_SEQ_CST );
     580                __atomic_add_fetch( &mmap_calls, 1, __ATOMIC_SEQ_CST );
     581                __atomic_add_fetch( &mmap_storage, tsize, __ATOMIC_SEQ_CST );
    589582                #endif // __STATISTICS__
    590583                block = (HeapManager.Storage *)mmap( 0, tsize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, mmapFd, 0 );
     
    593586                        abort( "(HeapManager &)0x%p.doMalloc() : internal error, mmap failure, size:%zu error:%d.", &heapManager, tsize, errno );
    594587                } // if
    595 #ifdef __CFA_DEBUG__
     588                #ifdef __CFA_DEBUG__
    596589                // Set new memory to garbage so subsequent uninitialized usages might fail.
    597590                memset( block, '\377', tsize );
    598 #endif // __CFA_DEBUG__
     591                #endif // __CFA_DEBUG__
    599592                block->header.kind.real.blockSize = tsize;              // storage size for munmap
    600                 } // if
    601 
    602                 void * area = &(block->data);                                           // adjust off header to user bytes
     593        } // if
     594
     595        void * area = &(block->data);                                           // adjust off header to user bytes
    603596
    604597        #ifdef __CFA_DEBUG__
    605                         assert( ((uintptr_t)area & (libAlign() - 1)) == 0 ); // minimum alignment ?
    606                         __atomic_add_fetch( &allocFree, tsize, __ATOMIC_SEQ_CST );
    607                 if ( traceHeap() ) {
    608                         enum { BufferSize = 64 };
    609                         char helpText[BufferSize];
    610                         int len = snprintf( helpText, BufferSize, "%p = Malloc( %zu ) (allocated %zu)\n", area, size, tsize );
    611                         // int len = snprintf( helpText, BufferSize, "Malloc %p %zu\n", area, size );
    612                         __cfaabi_dbg_bits_write( helpText, len );
    613                 } // if
     598        assert( ((uintptr_t)area & (libAlign() - 1)) == 0 ); // minimum alignment ?
     599        __atomic_add_fetch( &allocFree, tsize, __ATOMIC_SEQ_CST );
     600        if ( traceHeap() ) {
     601                enum { BufferSize = 64 };
     602                char helpText[BufferSize];
     603                int len = snprintf( helpText, BufferSize, "%p = Malloc( %zu ) (allocated %zu)\n", area, size, tsize );
     604                // int len = snprintf( helpText, BufferSize, "Malloc %p %zu\n", area, size );
     605                __cfaabi_dbg_bits_write( helpText, len );
     606        } // if
    614607        #endif // __CFA_DEBUG__
    615608
     
    620613static inline void doFree( void * addr ) with ( heapManager ) {
    621614        #ifdef __CFA_DEBUG__
    622                 if ( unlikely( heapManager.heapBegin == 0 ) ) {
    623                         abort( "doFree( %p ) : internal error, called before heap is initialized.", addr );
    624                 } // if
     615        if ( unlikely( heapManager.heapBegin == 0 ) ) {
     616                abort( "doFree( %p ) : internal error, called before heap is initialized.", addr );
     617        } // if
    625618        #endif // __CFA_DEBUG__
    626619
     
    631624        if ( headers( "free", addr, header, freeElem, size, alignment ) ) { // mmapped ?
    632625                #ifdef __STATISTICS__
    633                         __atomic_add_fetch( &munmap_calls, 1, __ATOMIC_SEQ_CST );
    634                         __atomic_add_fetch( &munmap_storage, size, __ATOMIC_SEQ_CST );
     626                __atomic_add_fetch( &munmap_calls, 1, __ATOMIC_SEQ_CST );
     627                __atomic_add_fetch( &munmap_storage, size, __ATOMIC_SEQ_CST );
    635628                #endif // __STATISTICS__
    636629                if ( munmap( header, size ) == -1 ) {
    637630                        #ifdef __CFA_DEBUG__
    638631                        abort( "Attempt to deallocate storage %p not allocated or with corrupt header.\n"
    639                                         "Possible cause is invalid pointer.",
    640                                         addr );
     632                                   "Possible cause is invalid pointer.",
     633                                   addr );
    641634                        #endif // __CFA_DEBUG__
    642635                } // if
    643                 } else {
     636        } else {
    644637                #ifdef __CFA_DEBUG__
    645                         // Set free memory to garbage so subsequent usages might fail.
    646                         memset( ((HeapManager.Storage *)header)->data, '\377', freeElem->blockSize - sizeof( HeapManager.Storage ) );
     638                // Set free memory to garbage so subsequent usages might fail.
     639                memset( ((HeapManager.Storage *)header)->data, '\377', freeElem->blockSize - sizeof( HeapManager.Storage ) );
    647640                #endif // __CFA_DEBUG__
    648641
    649642                #ifdef __STATISTICS__
    650                         free_storage += size;
     643                free_storage += size;
    651644                #endif // __STATISTICS__
    652645                #if defined( SPINLOCK )
    653                         lock( freeElem->lock __cfaabi_dbg_ctx2 );               // acquire spin lock
    654                         header->kind.real.next = freeElem->freeList;    // push on stack
    655                         freeElem->freeList = (HeapManager.Storage *)header;
    656                         unlock( freeElem->lock );                                               // release spin lock
     646                lock( freeElem->lock __cfaabi_dbg_ctx2 );               // acquire spin lock
     647                header->kind.real.next = freeElem->freeList;    // push on stack
     648                freeElem->freeList = (HeapManager.Storage *)header;
     649                unlock( freeElem->lock );                                               // release spin lock
    657650                #else
    658                         freeElem->freeList.push( *(HeapManager.Storage *)header );
     651                freeElem->freeList.push( *(HeapManager.Storage *)header );
    659652                #endif // SPINLOCK
    660                 } // if
     653        } // if
    661654
    662655        #ifdef __CFA_DEBUG__
    663                  __atomic_add_fetch( &allocFree, -size, __ATOMIC_SEQ_CST );
    664                 if ( traceHeap() ) {
    665                         char helpText[64];
    666                         int len = snprintf( helpText, sizeof(helpText), "Free( %p ) size:%zu\n", addr, size );
    667                         __cfaabi_dbg_bits_write( helpText, len );
    668                 } // if
     656        __atomic_add_fetch( &allocFree, -size, __ATOMIC_SEQ_CST );
     657        if ( traceHeap() ) {
     658                char helpText[64];
     659                int len = snprintf( helpText, sizeof(helpText), "Free( %p ) size:%zu\n", addr, size );
     660                __cfaabi_dbg_bits_write( helpText, len );
     661        } // if
    669662        #endif // __CFA_DEBUG__
    670663} // doFree
     
    674667        size_t total = 0;
    675668        #ifdef __STATISTICS__
    676                 __cfaabi_dbg_bits_acquire();
    677                 __cfaabi_dbg_bits_print_nolock( "\nBin lists (bin size : free blocks on list)\n" );
     669        __cfaabi_dbg_bits_acquire();
     670        __cfaabi_dbg_bits_print_nolock( "\nBin lists (bin size : free blocks on list)\n" );
    678671        #endif // __STATISTICS__
    679672        for ( unsigned int i = 0; i < maxBucketsUsed; i += 1 ) {
     
    695688
    696689                #ifdef __STATISTICS__
    697                         __cfaabi_dbg_bits_print_nolock( "%7zu, %-7u  ", size, N );
    698                         if ( (i + 1) % 8 == 0 ) __cfaabi_dbg_bits_print_nolock( "\n" );
     690                __cfaabi_dbg_bits_print_nolock( "%7zu, %-7u  ", size, N );
     691                if ( (i + 1) % 8 == 0 ) __cfaabi_dbg_bits_print_nolock( "\n" );
    699692                #endif // __STATISTICS__
    700693        } // for
    701694        #ifdef __STATISTICS__
    702                 __cfaabi_dbg_bits_print_nolock( "\ntotal free blocks:%zu\n", total );
    703                 __cfaabi_dbg_bits_release();
     695        __cfaabi_dbg_bits_print_nolock( "\ntotal free blocks:%zu\n", total );
     696        __cfaabi_dbg_bits_release();
    704697        #endif // __STATISTICS__
    705698        return (char *)heapEnd - (char *)heapBegin - total;
    706699} // checkFree
    707700
    708 // #comment TD : This is not a good name, plus this feels like it could easily be folded into doMalloc
    709 static inline void * malloc2( size_t size ) {                   // necessary for malloc statistics
    710         assert( heapManager.heapBegin != 0 );
     701
     702static inline void * mallocNoStats( size_t size ) {             // necessary for malloc statistics
     703        //assert( heapManager.heapBegin != 0 );
     704        if ( unlikely( heapManager.heapBegin == 0 ) ) heapManager{}; // called before memory_startup ?
    711705        void * area = doMalloc( size );
    712706        if ( unlikely( area == 0 ) ) errno = ENOMEM;            // POSIX
    713707        return area;
    714 } // malloc2
    715 
    716 
    717 static inline void * memalign2( size_t alignment, size_t size ) { // necessary for malloc statistics
    718 #ifdef __CFA_DEBUG__
     708} // mallocNoStats
     709
     710
     711static inline void * memalignNoStats( size_t alignment, size_t size ) { // necessary for malloc statistics
     712        #ifdef __CFA_DEBUG__
    719713        checkAlign( alignment );                                                        // check alignment
    720 #endif // __CFA_DEBUG__
     714        #endif // __CFA_DEBUG__
    721715
    722716        // if alignment <= default alignment, do normal malloc as two headers are unnecessary
    723         if ( unlikely( alignment <= libAlign() ) ) return malloc2( size );
     717  if ( unlikely( alignment <= libAlign() ) ) return mallocNoStats( size );
    724718
    725719        // Allocate enough storage to guarantee an address on the alignment boundary, and sufficient space before it for
     
    732726        // subtract libAlign() because it is already the minimum alignment
    733727        // add sizeof(Storage) for fake header
    734         // #comment TD : this is the only place that calls doMalloc without calling malloc2, why ?
     728        // #comment TD : this is the only place that calls doMalloc without calling mallocNoStats, why ?
    735729        char * area = (char *)doMalloc( size + alignment - libAlign() + sizeof(HeapManager.Storage) );
    736         if ( unlikely( area == 0 ) ) return area;
     730  if ( unlikely( area == 0 ) ) return area;
    737731
    738732        // address in the block of the "next" alignment address
     
    749743
    750744        return user;
    751 } // memalign2
     745} // memalignNoStats
    752746
    753747
    754748extern "C" {
    755         // The malloc() function allocates size bytes and returns a pointer to the
    756         // allocated memory. The memory is not initialized. If size is 0, then malloc()
    757         // returns either NULL, or a unique pointer value that can later be successfully
    758         // passed to free().
     749        // The malloc() function allocates size bytes and returns a pointer to the allocated memory. The memory is not
     750        // initialized. If size is 0, then malloc() returns either NULL, or a unique pointer value that can later be
     751        // successfully passed to free().
    759752        void * malloc( size_t size ) {
    760753                #ifdef __STATISTICS__
    761                         __atomic_add_fetch( &malloc_calls, 1, __ATOMIC_SEQ_CST );
    762                         __atomic_add_fetch( &malloc_storage, size, __ATOMIC_SEQ_CST );
    763                 #endif // __STATISTICS__
    764 
    765                 return malloc2( size );
    766                 } // malloc
    767 
    768         // The calloc() function allocates memory for an array of nmemb elements of
    769         // size bytes each and returns a pointer to the allocated memory. The memory
    770         // is set to zero. If nmemb or size is 0, then calloc() returns either NULL,
    771         // or a unique pointer value that can later be successfully passed to free().
    772                 void * calloc( size_t noOfElems, size_t elemSize ) {
     754                __atomic_add_fetch( &malloc_calls, 1, __ATOMIC_SEQ_CST );
     755                __atomic_add_fetch( &malloc_storage, size, __ATOMIC_SEQ_CST );
     756                #endif // __STATISTICS__
     757
     758                return mallocNoStats( size );
     759        } // malloc
     760
     761        // The calloc() function allocates memory for an array of nmemb elements of size bytes each and returns a pointer to
     762        // the allocated memory. The memory is set to zero. If nmemb or size is 0, then calloc() returns either NULL, or a
     763        // unique pointer value that can later be successfully passed to free().
     764        void * calloc( size_t noOfElems, size_t elemSize ) {
    773765                size_t size = noOfElems * elemSize;
    774766                #ifdef __STATISTICS__
    775                         __atomic_add_fetch( &calloc_calls, 1, __ATOMIC_SEQ_CST );
    776                         __atomic_add_fetch( &calloc_storage, size, __ATOMIC_SEQ_CST );
    777                 #endif // __STATISTICS__
    778 
    779                 char * area = (char *)malloc2( size );
    780                 if ( unlikely( area == 0 ) ) return 0;
     767                __atomic_add_fetch( &calloc_calls, 1, __ATOMIC_SEQ_CST );
     768                __atomic_add_fetch( &calloc_storage, size, __ATOMIC_SEQ_CST );
     769                #endif // __STATISTICS__
     770
     771                char * area = (char *)mallocNoStats( size );
     772          if ( unlikely( area == 0 ) ) return 0;
    781773
    782774                HeapManager.Storage.Header * header;
     
    790782                        memset( area, '\0', asize - sizeof(HeapManager.Storage) ); // set to zeros
    791783
    792                 header->kind.real.blockSize |= 2;               // mark as zero filled
     784                header->kind.real.blockSize |= 2;                               // mark as zero filled
    793785                return area;
    794                 } // calloc
     786        } // calloc
    795787
    796788        // #comment TD : Document this function
     
    798790                size_t size = noOfElems * elemSize;
    799791                #ifdef __STATISTICS__
    800                         __atomic_add_fetch( &cmemalign_calls, 1, __ATOMIC_SEQ_CST );
    801                         __atomic_add_fetch( &cmemalign_storage, size, __ATOMIC_SEQ_CST );
    802                 #endif // __STATISTICS__
    803 
    804                 char * area = (char *)memalign2( alignment, size );
    805                 if ( unlikely( area == 0 ) ) return 0;
     792                __atomic_add_fetch( &cmemalign_calls, 1, __ATOMIC_SEQ_CST );
     793                __atomic_add_fetch( &cmemalign_storage, size, __ATOMIC_SEQ_CST );
     794                #endif // __STATISTICS__
     795
     796                char * area = (char *)memalignNoStats( alignment, size );
     797          if ( unlikely( area == 0 ) ) return 0;
    806798                HeapManager.Storage.Header * header;
    807799                HeapManager.FreeHeader * freeElem;
     
    811803                // Mapped storage is zero filled, but in debug mode mapped memory is scrubbed in doMalloc, so it has to be reset to zero.
    812804                if ( ! mapped )
    813                 #endif // __CFA_DEBUG__
     805                        #endif // __CFA_DEBUG__
    814806                        memset( area, '\0', asize - ( (char *)area - (char *)header ) ); // set to zeros
    815807                header->kind.real.blockSize |= 2;                               // mark as zero filled
    816808
    817809                return area;
    818                 } // cmemalign
    819 
    820         // The realloc() function changes the size of the memory block pointed to by
    821         // ptr to size bytes. The contents will be unchanged in the range from the
    822         // start of the region up to the minimum of the old and new sizes. If the new
    823         // size is larger than the old size, the added memory will not be initialized.
    824         // If ptr is NULL, then the call is equivalent to malloc(size), for all values
    825         // of size; if size is equal to zero, and ptr is not NULL, then the call is
    826         // equivalent to free(ptr). Unless ptr is NULL, it must have been returned by
    827         // an earlier call to malloc(), calloc() or realloc(). If the area pointed to
    828         // was moved, a free(ptr) is done.
    829                 void * realloc( void * addr, size_t size ) {
    830                 #ifdef __STATISTICS__
    831                         __atomic_add_fetch( &realloc_calls, 1, __ATOMIC_SEQ_CST );
    832                 #endif // __STATISTICS__
    833 
    834                 if ( unlikely( addr == 0 ) ) return malloc2( size ); // special cases
    835                 if ( unlikely( size == 0 ) ) { free( addr ); return 0; }
     810        } // cmemalign
     811
     812        // The realloc() function changes the size of the memory block pointed to by ptr to size bytes. The contents will be
     813        // unchanged in the range from the start of the region up to the minimum of the old and new sizes. If the new size
     814        // is larger than the old size, the added memory will not be initialized.  If ptr is NULL, then the call is
     815        // equivalent to malloc(size), for all values of size; if size is equal to zero, and ptr is not NULL, then the call
     816        // is equivalent to free(ptr). Unless ptr is NULL, it must have been returned by an earlier call to malloc(),
     817        // calloc() or realloc(). If the area pointed to was moved, a free(ptr) is done.
     818        void * realloc( void * addr, size_t size ) {
     819                #ifdef __STATISTICS__
     820                __atomic_add_fetch( &realloc_calls, 1, __ATOMIC_SEQ_CST );
     821                #endif // __STATISTICS__
     822
     823          if ( unlikely( addr == 0 ) ) return mallocNoStats( size ); // special cases
     824          if ( unlikely( size == 0 ) ) { free( addr ); return 0; }
    836825
    837826                HeapManager.Storage.Header * header;
     
    848837
    849838                #ifdef __STATISTICS__
    850                         __atomic_add_fetch( &realloc_storage, size, __ATOMIC_SEQ_CST );
     839                __atomic_add_fetch( &realloc_storage, size, __ATOMIC_SEQ_CST );
    851840                #endif // __STATISTICS__
    852841
     
    855844                        area = memalign( alignment, size );                     // create new area
    856845                } else {
    857                         area = malloc2( size ); // create new area
     846                        area = mallocNoStats( size );                           // create new area
    858847                } // if
    859                 if ( unlikely( area == 0 ) ) return 0;
     848          if ( unlikely( area == 0 ) ) return 0;
    860849                if ( unlikely( header->kind.real.blockSize & 2 ) ) { // previous request zero fill (calloc/cmemalign) ?
    861850                        assert( (header->kind.real.blockSize & 1) == 0 );
     
    864853                        // Mapped storage is zero filled, but in debug mode mapped memory is scrubbed in doMalloc, so it has to be reset to zero.
    865854                        if ( ! mapped )
    866                         #endif // __CFA_DEBUG__
     855                                #endif // __CFA_DEBUG__
    867856                                memset( (char *)area + usize, '\0', asize - ( (char *)area - (char *)header ) - usize ); // zero-fill back part
    868857                        header->kind.real.blockSize |= 2;                       // mark new request as zero fill
     
    874863
    875864
    876         // The obsolete function memalign() allocates size bytes and returns
    877         // a pointer to the allocated memory. The memory address will be a
    878         // multiple of alignment, which must be a power of two.
    879         void * memalign( size_t alignment, size_t size ) __attribute__ ((deprecated));
    880                 void * memalign( size_t alignment, size_t size ) {
     865        // The obsolete function memalign() allocates size bytes and returns a pointer to the allocated memory. The memory
     866        // address will be a multiple of alignment, which must be a power of two.
     867        void * memalign( size_t alignment, size_t size ) {
    881868                #ifdef __STATISTICS__
    882869                __atomic_add_fetch( &memalign_calls, 1, __ATOMIC_SEQ_CST );
     
    884871                #endif // __STATISTICS__
    885872
    886                 void * area = memalign2( alignment, size );
     873                void * area = memalignNoStats( alignment, size );
    887874
    888875                return area;
    889                 } // memalign
    890 
    891         // The function aligned_alloc() is the same as memalign(), except for
    892         // the added restriction that size should be a multiple of alignment.
     876        } // memalign
     877
     878        // The function aligned_alloc() is the same as memalign(), except for the added restriction that size should be a
     879        // multiple of alignment.
    893880        void * aligned_alloc( size_t alignment, size_t size ) {
    894881                return memalign( alignment, size );
     
    896883
    897884
    898         // The function posix_memalign() allocates size bytes and places the address
    899         // of the allocated memory in *memptr. The address of the allocated memory
    900         // will be a multiple of alignment, which must be a power of two and a multiple
    901         // of sizeof(void *). If size is 0, then posix_memalign() returns either NULL,
    902         // or a unique pointer value that can later be successfully passed to free(3).
     885        // The function posix_memalign() allocates size bytes and places the address of the allocated memory in *memptr. The
     886        // address of the allocated memory will be a multiple of alignment, which must be a power of two and a multiple of
     887        // sizeof(void *). If size is 0, then posix_memalign() returns either NULL, or a unique pointer value that can later
     888        // be successfully passed to free(3).
    903889        int posix_memalign( void ** memptr, size_t alignment, size_t size ) {
    904                 if ( alignment < sizeof(void *) || ! libPow2( alignment ) ) return EINVAL; // check alignment
     890          if ( alignment < sizeof(void *) || ! libPow2( alignment ) ) return EINVAL; // check alignment
    905891                * memptr = memalign( alignment, size );
    906                 if ( unlikely( * memptr == 0 ) ) return ENOMEM;
     892          if ( unlikely( * memptr == 0 ) ) return ENOMEM;
    907893                return 0;
    908894        } // posix_memalign
    909895
    910         // The obsolete function valloc() allocates size bytes and returns a pointer
    911         // to the allocated memory. The memory address will be a multiple of the page size.
    912         // It is equivalent to memalign(sysconf(_SC_PAGESIZE),size).
    913         void * valloc( size_t size ) __attribute__ ((deprecated));
     896        // The obsolete function valloc() allocates size bytes and returns a pointer to the allocated memory. The memory
     897        // address will be a multiple of the page size.  It is equivalent to memalign(sysconf(_SC_PAGESIZE),size).
    914898        void * valloc( size_t size ) {
    915899                return memalign( pageSize, size );
     
    917901
    918902
    919         // The free() function frees the memory space pointed to by ptr, which must
    920         // have been returned by a previous call to malloc(), calloc() or realloc().
    921         // Otherwise, or if free(ptr) has already been called before, undefined
    922         // behavior occurs. If ptr is NULL, no operation is performed.
     903        // The free() function frees the memory space pointed to by ptr, which must have been returned by a previous call to
     904        // malloc(), calloc() or realloc().  Otherwise, or if free(ptr) has already been called before, undefined behavior
     905        // occurs. If ptr is NULL, no operation is performed.
    923906        void free( void * addr ) {
    924907                #ifdef __STATISTICS__
    925                         __atomic_add_fetch( &free_calls, 1, __ATOMIC_SEQ_CST );
     908                __atomic_add_fetch( &free_calls, 1, __ATOMIC_SEQ_CST );
    926909                #endif // __STATISTICS__
    927910
     
    931914                if ( unlikely( addr == 0 ) ) {                                  // special case
    932915                        #ifdef __CFA_DEBUG__
    933                                 if ( traceHeap() ) {
    934                                         #define nullmsg "Free( 0x0 ) size:0\n"
    935                                         // Do not debug print free( 0 ), as it can cause recursive entry from sprintf.
    936                                         __cfaabi_dbg_bits_write( nullmsg, sizeof(nullmsg) - 1 );
    937                                 } // if
     916                        if ( traceHeap() ) {
     917                                #define nullmsg "Free( 0x0 ) size:0\n"
     918                                // Do not debug print free( 0 ), as it can cause recursive entry from sprintf.
     919                                __cfaabi_dbg_bits_write( nullmsg, sizeof(nullmsg) - 1 );
     920                        } // if
    938921                        #endif // __CFA_DEBUG__
    939922                        return;
     
    943926        } // free
    944927
    945         // The mallopt() function adjusts parameters that control the behavior of the
    946         // memory-allocation functions (see malloc(3)). The param argument specifies
    947         // the parameter to be modified, and value specifies the new value for that
     928        // The mallopt() function adjusts parameters that control the behavior of the memory-allocation functions (see
     929        // malloc(3)). The param argument specifies the parameter to be modified, and value specifies the new value for that
    948930        // parameter.
    949                 int mallopt( int option, int value ) {
     931        int mallopt( int option, int value ) {
    950932                choose( option ) {
    951                         case M_TOP_PAD:
    952                                 if ( setHeapExpand( value ) ) fallthru default;
    953                         case M_MMAP_THRESHOLD:
    954                                 if ( setMmapStart( value ) ) fallthru default;
    955                         default:
    956                                 // #comment TD : 1 for unsopported feels wrong
    957                                 return 1;                                                                       // success, or unsupported
     933                  case M_TOP_PAD:
     934                        if ( setHeapExpand( value ) ) fallthru default;
     935                  case M_MMAP_THRESHOLD:
     936                        if ( setMmapStart( value ) ) fallthru default;
     937                  default:
     938                        // #comment TD : 1 for unsopported feels wrong
     939                        return 1;                                                                       // success, or unsupported
    958940                } // switch
    959941                return 0;                                                                               // error
    960942        } // mallopt
    961943
    962         // The malloc_trim() function attempts to release free memory at the top
    963         // of the heap (by calling sbrk(2) with a suitable argument).
     944        // The malloc_trim() function attempts to release free memory at the top of the heap (by calling sbrk(2) with a
     945        // suitable argument).
    964946        int malloc_trim( size_t ) {
    965947                return 0;                                                                               // => impossible to release memory
    966948        } // malloc_trim
    967949
    968         // The malloc_usable_size() function returns the number of usable bytes in the
    969         // block pointed to by ptr, a pointer to a block of memory allocated by
    970         // malloc(3) or a related function.
    971                 size_t malloc_usable_size( void * addr ) {
    972                 if ( unlikely( addr == 0 ) ) return 0;                  // null allocation has 0 size
     950        // The malloc_usable_size() function returns the number of usable bytes in the block pointed to by ptr, a pointer to
     951        // a block of memory allocated by malloc(3) or a related function.
     952        size_t malloc_usable_size( void * addr ) {
     953          if ( unlikely( addr == 0 ) ) return 0;                        // null allocation has 0 size
    973954
    974955                HeapManager.Storage.Header * header;
     
    982963
    983964
    984                 // #comment TD : Document this function
     965    // The malloc_alignment() function returns the alignment of the allocation.
    985966        size_t malloc_alignment( void * addr ) {
    986                 if ( unlikely( addr == 0 ) ) return libAlign(); // minimum alignment
     967          if ( unlikely( addr == 0 ) ) return libAlign();       // minimum alignment
    987968                HeapManager.Storage.Header * header = (HeapManager.Storage.Header *)( (char *)addr - sizeof(HeapManager.Storage) );
    988969                if ( (header->kind.fake.alignment & 1) == 1 ) { // fake header ?
     
    991972                        return libAlign ();                                                     // minimum alignment
    992973                } // if
    993                 } // malloc_alignment
    994 
    995 
    996                 // #comment TD : Document this function
     974        } // malloc_alignment
     975
     976
     977    // The malloc_zero_fill() function returns true if the allocation is zero filled, i.e., initially allocated by calloc().
    997978        bool malloc_zero_fill( void * addr ) {
    998                 if ( unlikely( addr == 0 ) ) return false;              // null allocation is not zero fill
     979          if ( unlikely( addr == 0 ) ) return false;            // null allocation is not zero fill
    999980
    1000981                HeapManager.Storage.Header * header = (HeapManager.Storage.Header *)( (char *)addr - sizeof(HeapManager.Storage) );
     
    1003984                } // if
    1004985                return (header->kind.real.blockSize & 2) != 0;  // zero filled (calloc/cmemalign) ?
    1005                 } // malloc_zero_fill
    1006 
    1007 
    1008         // #comment TD : Document this function
     986        } // malloc_zero_fill
     987
     988
     989    // The malloc_stats() function prints (on default standard error) statistics about memory allocated by malloc(3) and
     990    // related functions.
    1009991        void malloc_stats( void ) {
    1010992                #ifdef __STATISTICS__
    1011                         printStats();
    1012                         if ( checkFree() ) checkFree( heapManager );
    1013                 #endif // __STATISTICS__
    1014                 } // malloc_stats
    1015 
    1016         // #comment TD : Document this function
    1017                 int malloc_stats_fd( int fd ) {
    1018                 #ifdef __STATISTICS__
    1019                         int temp = statfd;
    1020                         statfd = fd;
    1021                         return temp;
     993                printStats();
     994                if ( checkFree() ) checkFree( heapManager );
     995                #endif // __STATISTICS__
     996        } // malloc_stats
     997
     998        // The malloc_stats_fd() function changes the file descripter where malloc_stats() writes the statistics.
     999        int malloc_stats_fd( int fd ) {
     1000                #ifdef __STATISTICS__
     1001                int temp = statfd;
     1002                statfd = fd;
     1003                return temp;
    10221004                #else
    1023                         return -1;
    1024                 #endif // __STATISTICS__
    1025                 } // malloc_stats_fd
    1026 
    1027 
    1028         // #comment TD : Document this function
     1005                return -1;
     1006                #endif // __STATISTICS__
     1007        } // malloc_stats_fd
     1008
     1009        // The malloc_info() function exports an XML string that describes the current state of the memory-allocation
     1010        // implementation in the caller.  The string is printed on the file stream stream.  The exported string includes
     1011        // information about all arenas (see malloc(3)).
    10291012        int malloc_info( int options, FILE * stream ) {
    10301013                return printStatsXML( stream );
     
    10321015
    10331016
    1034         // #comment TD : What are these two functions for?
     1017        // The malloc_get_state() function records the current state of all malloc(3) internal bookkeeping variables (but
     1018        // not the actual contents of the heap or the state of malloc_hook(3) functions pointers).  The state is recorded in
     1019        // a system-dependent opaque data structure dynamically allocated via malloc(3), and a pointer to that data
     1020        // structure is returned as the function result.  (It is the caller's responsibility to free(3) this memory.)
    10351021        void * malloc_get_state( void ) {
    1036                 return 0;
     1022                return 0;                                                                               // unsupported
    10371023        } // malloc_get_state
    10381024
     1025
     1026        // The malloc_set_state() function restores the state of all malloc(3) internal bookkeeping variables to the values
     1027        // recorded in the opaque data structure pointed to by state.
    10391028        int malloc_set_state( void * ptr ) {
    1040                 return 0;
     1029                return 0;                                                                               // unsupported
    10411030        } // malloc_set_state
    10421031} // extern "C"
Note: See TracChangeset for help on using the changeset viewer.