SquidConfig.cc \
tests/stub_fd.cc \
tests/stub_HelperChildConfig.cc \
- tests/stub_libmem.cc \
tests/STUB.h \
time.cc
$(top_builddir)/src/sbuf/libsbuf.la \
$(top_builddir)/src/debug/libdebug.la \
$(top_builddir)/src/base/libbase.la \
+ $(top_builddir)/src/mem/libminimal.la \
$(COMPAT_LIB) \
$(SSLLIB) \
$(XTRA_LIBS)
tests/stub_fd.cc: $(top_srcdir)/src/tests/stub_fd.cc | tests
cp $(top_srcdir)/src/tests/stub_fd.cc $@
-tests/stub_libmem.cc: $(top_srcdir)/src/tests/stub_libmem.cc | tests
- cp $(top_srcdir)/src/tests/stub_libmem.cc $@
-
tests/STUB.h: $(top_srcdir)/src/tests/STUB.h | tests
cp $(top_srcdir)/src/tests/STUB.h $@
include $(top_srcdir)/src/Common.am
include $(top_srcdir)/src/TestHeaders.am
-noinst_LTLIBRARIES = libmem.la
+noinst_LTLIBRARIES = \
+ libmem.la \
+ libminimal.la
+noinst_HEADERS = \
+ AllocatorProxy.h \
+ Sensitive.h \
+ forward.h
+
+# a full-featured memory management library for sbin/squid use
libmem_la_SOURCES = \
AllocatorProxy.cc \
- AllocatorProxy.h \
Meter.h \
Pool.cc \
Pool.h \
PoolMalloc.cc \
PoolMalloc.h \
PoolingAllocator.h \
- Sensitive.h \
- forward.h \
old_api.cc
+
+# a bare-bones implementation of few libmem.la APIs sufficient for helpers use
+libminimal_la_SOURCES = \
+ minimal.cc
--- /dev/null
+/*
+ * Copyright (C) 1996-2022 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#include "squid.h"
+#include "mem/AllocatorProxy.h"
+#include "mem/forward.h"
+
+/// The number of currently alive objects (poor man's meter.alloc=meter.inuse).
+/// Technically, this is supposed to be a per-allocator statistics, but
+/// AllocatorProxy is not a MemAllocator so we maintain a global counter
+/// instead. We probably do not have to maintain this statistics at all.
+static int Alive = 0;
+
+void *
+Mem::AllocatorProxy::alloc()
+{
+ const auto memory = doZero ? xcalloc(1, size) : xmalloc(size);
+ ++Alive;
+ return memory;
+}
+
+void
+Mem::AllocatorProxy::freeOne(void *memory) {
+ xfree(memory);
+ --Alive;
+}
+
+int
+Mem::AllocatorProxy::inUseCount() const
+{
+ return Alive;
+}
+
+int
+Mem::AllocatorProxy::getStats(MemPoolStats *)
+{
+ return Alive;
+}
+
+void *
+memAllocBuf(const size_t netSize, size_t * const grossSize)
+{
+ *grossSize = netSize;
+ return xcalloc(1, netSize);
+}
+
+void *
+memReallocBuf(void * const oldBuf, const size_t netSize, size_t * const grossSize)
+{
+ *grossSize = netSize;
+ return xrealloc(oldBuf, netSize);
+}
+
+void
+memFree(void *memory, int)
+{
+ xfree(memory);
+}
+
+void *
+memAllocString(const size_t netSize, size_t * const grossSize)
+{
+ return memAllocBuf(netSize, grossSize);
+}
+
+void
+memFreeString(size_t, void *memory)
+{
+ xfree(memory);
+}
+
+void *
+memAllocRigid(const size_t netSize)
+{
+ return xmalloc(netSize);
+}
+
+void
+memFreeBuf(size_t, void * const buf)
+{
+ xfree(buf);
+}
+
+static void
+myFree(void * const buf)
+{
+ xfree(buf);
+}
+
+FREE *
+memFreeBufFunc(size_t)
+{
+ return &myFree;
+}
+
LDADD= \
$(top_builddir)/src/ip/libip.la \
+ $(top_builddir)/src/mem/libminimal.la \
$(top_builddir)/lib/libmiscencoding.la \
$(top_builddir)/lib/libmiscutil.la \
$(COMPAT_LIB) \
tests/stub_cbdata.cc: $(top_srcdir)/src/tests/stub_cbdata.cc | tests
cp $(top_srcdir)/src/tests/stub_cbdata.cc $@
-tests/stub_libmem.cc: $(top_srcdir)/src/tests/stub_libmem.cc | tests
- cp $(top_srcdir)/src/tests/stub_libmem.cc $@
-
tests/STUB.h: $(top_srcdir)/src/tests/STUB.h | tests
cp $(top_srcdir)/src/tests/STUB.h $@
# globals.cc is needed by test_tools.cc.
# Neither of these should be disted from here.
TESTSOURCES= test_tools.cc
-CLEANFILES += test_tools.cc Here.cc CharacterSet.cc MemBuf.cc tests/stub_debug.cc time.cc tests/stub_cbdata.cc tests/stub_libmem.cc tests/STUB.h
+CLEANFILES += test_tools.cc Here.cc CharacterSet.cc MemBuf.cc tests/stub_debug.cc time.cc tests/stub_cbdata.cc tests/STUB.h
## Test Scripts
EXTRA_DIST += helper-ok-dying.pl helper-ok.pl
nodist_cachemgr__CGIEXT__SOURCES = \
tests/stub_cbdata.cc \
tests/stub_debug.cc \
- tests/stub_libmem.cc \
tests/STUB.h
cachemgr__CGIEXT__CXXFLAGS = \
LDADD = \
$(top_builddir)/src/ip/libip.la \
+ $(top_builddir)/src/mem/libminimal.la \
$(top_builddir)/src/base/libbase.la \
$(top_builddir)/lib/libmiscencoding.la \
$(top_builddir)/lib/libmiscutil.la \
time.cc: $(top_srcdir)/src/time.cc
cp $(top_srcdir)/src/time.cc $@
-tests/stub_libmem.cc: $(top_srcdir)/src/tests/stub_libmem.cc | tests
- cp $(top_srcdir)/src/tests/stub_libmem.cc $@
-
tests/STUB.h: $(top_srcdir)/src/tests/STUB.h | tests
cp $(top_srcdir)/src/tests/STUB.h $@
# globals.cc is needed by test_tools.cc.
# Neither of these should be disted from here.
TESTSOURCES= test_tools.cc
-CLEANFILES += test_tools.cc tests/stub_debug.cc time.cc tests/stub_libmem.cc tests/STUB.h
+CLEANFILES += test_tools.cc tests/stub_debug.cc time.cc tests/STUB.h
## ##### squidclient #####
nodist_squidclient_SOURCES = \
tests/stub_debug.cc \
- tests/stub_libmem.cc \
tests/STUB.h