Module: sip-router
Branch: kamailio_3.0
Commit: ff80e418e01e1c6a92b0a5a5c74defe2a52a2e42
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=ff80e41…
Author: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Date: Fri Mar 12 12:16:16 2010 +0100
mem: fix real_used stats for realloc
A realloc that shrank an allocation accounted twice for the
fragment overhead. Basically each shrinking realloc would
introduce an error in the real_used mem stats, between 8 bytes
(f_malloc, no debugging, 32 bits) and up to 96 bytes (q_malloc
with debugging, 64 bits).
This bug concerns only the accounting part. It does not cause any
memory leak or any real runtime problem. It was introduced
in commit fb9d6e50 (2005).
(cherry picked from commit 75c1e9a735c693a6985a7a1786116b5fe4044fd9)
---
mem/f_malloc.c | 4 +++-
mem/q_malloc.c | 7 +++++--
2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/mem/f_malloc.c b/mem/f_malloc.c
index 2c05fe6..49c4b7a 100644
--- a/mem/f_malloc.c
+++ b/mem/f_malloc.c
@@ -491,7 +491,9 @@ void* fm_realloc(struct fm_block* qm, void* p, unsigned long size)
fm_split_frag(qm, f, size);
#endif
#if defined(DBG_F_MALLOC) || defined(MALLOC_STATS)
- qm->real_used-=(orig_size-f->size-FRAG_OVERHEAD);
+ /* fm_split frag already adds FRAG_OVERHEAD for the newly created
+ free frag, so here we only need orig_size-f->size for real used */
+ qm->real_used-=(orig_size-f->size);
qm->used-=(orig_size-f->size);
#endif
}else if (f->size<size){
diff --git a/mem/q_malloc.c b/mem/q_malloc.c
index 09cb5c7..04c6dc9 100644
--- a/mem/q_malloc.c
+++ b/mem/q_malloc.c
@@ -562,8 +562,11 @@ void* qm_realloc(struct qm_block* qm, void* p, unsigned long size)
#else
if(split_frag(qm, f, size)!=0){
#endif
- /* update used sizes: freed the spitted frag */
- qm->real_used-=(orig_size-f->size-FRAG_OVERHEAD);
+ /* update used sizes: freed the splited frag */
+ /* split frag already adds FRAG_OVERHEAD for the newly created
+ free frag, so here we only need orig_size-f->size for real used
+ */
+ qm->real_used-=(orig_size-f->size);
qm->used-=(orig_size-f->size);
}
Module: sip-router
Branch: kamailio_3.0
Commit: 07681e1b6e89a902d8f9bdeba9674de6a3d353f5
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=07681e1…
Author: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Date: Wed Mar 10 09:25:13 2010 +0100
make: on-the-fly dependency generation
- support on-the-fly dependency file generation with gcc >=3.0
(the dependency files are generated while compiling the object
file, eliminating another gcc+sed invocation)
- support for using makedepend -f- for generating dependencies
E.g.: make cfg MKDEP="makedepend -f-". In general gcc should be
preferred if available (use this if you don't have gcc and your
compiler doesn't generate good deps).
(cherry picked from commit 5a9014ee4977c6afbc4b0cf65a9fad6237c2e2a6)
(cherry picked from commit 929598a19dfb09efcfcbb1aee57a83f45b12592f)
---
Makefile.defs | 12 ++++++++++--
Makefile.rules | 22 +++++++++++++++++++---
2 files changed, 29 insertions(+), 5 deletions(-)
diff --git a/Makefile.defs b/Makefile.defs
index 527743c..a6575a4 100644
--- a/Makefile.defs
+++ b/Makefile.defs
@@ -74,6 +74,9 @@
# from the host (andrei)
# 2009-10-01 use -fsigned-char for gcc on ppc, ppc64, arm and arm6
# (on those archs char is unsigned by default) (andrei)
+# 2010-03-10 added CC_MKDEP_OPTS, which contains to the list of options
+# needed to generate dependencies on-the-fly while compiling
+# or is empty if the compiler doesn't support it (andrei)
quiet?=$(if $(filter 1 yes on,$(Q)),silent,verbose)
@@ -350,7 +353,7 @@ ifneq (,$(findstring gcc, $(CC_LONGVER)))
# -e 's/^[^0-9].*\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/')
# sed with POSIX.1 regex doesn't support |, + or ?
# (darwin, solaris ...) => this complicated expression
- MKDEP=$(CC) -MM
+ MKDEP=$(CC) -MM -MG
#transform gcc version into 2.9x or 3.0
CC_SHORTVER:=$(shell echo "$(CC_VER)" | cut -d" " -f 2| \
sed -e 's/[^0-9]*-\(.*\)/\1/'| \
@@ -359,7 +362,11 @@ ifneq (,$(findstring gcc, $(CC_LONGVER)))
's/3\.[4-9]/3.4/' -e 's/4\.[0-1]\..*/4.x/' -e \
's/4\.[0-1]/4.x/' -e 's/4\.[2-9]\..*/4.2+/' -e \
's/4\.[2-9]$$/4.2+/')
-endif
+ifeq (,$(strip $(filter-out 3.0 3.4 4.x 4.2+,$(CC_SHORTVER))))
+ # dependencies can be generated on-the-fly while compiling *.c
+ CC_MKDEP_OPTS=-MMD -MP
+endif # 3.0 <= $(CC_SHORTVER) <= 4.x
+endif # gcc
ifneq (, $(findstring Sun, $(CC_LONGVER)))
CC_NAME=suncc
@@ -1946,6 +1953,7 @@ export exported_vars
saved_fixed_vars:= MAIN_NAME CFG_NAME SCR_NAME FLAVOUR INSTALL_FLAVOUR \
SRC_NAME RELEASE OS ARCH \
C_DEFS DEFS_RM PROFILE CC LD MKDEP MKTAGS LDFLAGS C_INCLUDES \
+ CC_MKDEP_OPTS \
MOD_LDFLAGS LIB_LDFLAGS UTILS_LDFLAGS LIB_SONAME LD_RPATH \
LIB_SUFFIX LIB_PREFIX \
LIBS \
diff --git a/Makefile.rules b/Makefile.rules
index 5ee7d76..93da8ec 100644
--- a/Makefile.rules
+++ b/Makefile.rules
@@ -25,6 +25,11 @@
# used only for "temporary" defines/includes inside modules or
# libs, C_DEFS and C_INCLUDES are used for the common stuff)
# (andrei)
+# 2010-03-09 generate dependencies when compiling .o instead of on
+# include .d and fix build errors when a .h is moved
+# support for using MKDEP="makedepend-f-" (andrei)
+# 2010-03-10 support for on the-fly dependency generation (while compiling,
+# see CC_MKDEP_OPTS) (andrei)
# check if the saved cfg corresponds with the current one
@@ -59,6 +64,19 @@ cmd_CC=$(CC) $(CFLAGS) $(C_INCLUDES) $(INCLUDES) $(C_DEFS) $(DEFS) -c $< -o $@
cmd_LD=$(LD) $(LDFLAGS) $(objs) $(extra_objs) $(ALL_LIBS) $(SER_RPATH) \
-o $(NAME)
+ifeq (,$(CC_MKDEP_OPTS))
+# if CCC_MKDEP_OPTS is empty => CC cannot generate dependencies on the fly
+cmd_MKDEP=$(MKDEP) $(filter -D% -I%,$(CFLAGS)) $(C_INCLUDES) $(INCLUDES) \
+ $(C_DEFS) $(DEFS) $< \
+ | sed -e 's/\#.*//' -e '/:[ ]*$$/d' -e '/^[ ]*$$/d' \
+ -e 's|.*:|$@: $$(wildcard |' -e 's/\([^\\]\)$$/\1)/'> $*.d
+else
+# deps can be generated on the fly by cmd_CC
+cmd_CC+=$(CC_MKDEP_OPTS)
+# no MKDEP command any more
+cmd_MKDEP=
+endif # CC_MKDEP_OPTS
+
# what will be displayed if quiet==silent
silent_cmd_CC=CC ($(CC)) [$(strip $(crt_type) $(NAME))] $@
silent_cmd_LD=LD ($(LD)) [$(strip $(crt_type) $(NAME))] $@
@@ -84,9 +102,7 @@ exec_cmd= $(if $($(quiet)_cmd_$(1)),\
#implicit rules
%.o:%.c $(ALLDEP)
$(call exec_cmd,CC)
- @$(MKDEP) $(CFLAGS) $(C_INCLUDES) $(INCLUDES) $(C_DEFS) $(DEFS) $< \
- | sed -e 's/#.*//' -e '/:[ ]*$$/d' -e '/^[ ]*$$/d' \
- -e 's#.*:#$@: $$(wildcard #g' -e 's/\([^\\]\)$$/\1)/'> $*.d
+ @$(call cmd_MKDEP)
# use RPATH and SER_LIBS if needed (make install and the module depends
# on some ser libs)