X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Flib%2Fsmartall.h;h=4973f4fa255819c4a6fd5ca6ed3896bc6b08d975;hb=8944db1b635424752b455e55dfc73cf4f26860d5;hp=a319ec526046f3815fbe466405ec7054ce187b41;hpb=4c9d5e05d85b2567788335730f326f9081df87cd;p=bacula%2Fbacula diff --git a/bacula/src/lib/smartall.h b/bacula/src/lib/smartall.h index a319ec5260..4973f4fa25 100644 --- a/bacula/src/lib/smartall.h +++ b/bacula/src/lib/smartall.h @@ -1,37 +1,47 @@ /* + Bacula® - The Network Backup Solution - Definitions for the smart memory allocator - - Version $Id$ - -*/ - -/* - Copyright (C) 2000-2004 Kern Sibbald and John Walker + Copyright (C) 2000-2010 Free Software Foundation Europe e.V. - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License, or (at your option) any later version. + The main author of Bacula is Kern Sibbald, with contributions from + many others, a complete list can be found in the file AUTHORS. + This program is Free Software; you can redistribute it and/or + modify it under the terms of version three of the GNU Affero General Public + License as published by the Free Software Foundation and included + in the file LICENSE. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public - License along with this program; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA. + You should have received a copy of the GNU Affero General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. - */ + Bacula® is a registered trademark of Kern Sibbald. + The licensor of Bacula is the Free Software Foundation Europe + (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, + Switzerland, email:ftf@fsfeurope.org. +*/ +/* -extern uint64_t sm_max_bytes; -extern uint64_t sm_bytes; -extern uint32_t sm_max_buffers; -extern uint32_t sm_buffers; + Definitions for the smart memory allocator -#ifdef SMARTALLOC +*/ + +#ifndef SMARTALLOC_H +#define SMARTALLOC_H + +extern uint64_t DLL_IMP_EXP sm_max_bytes; +extern uint64_t DLL_IMP_EXP sm_bytes; +extern uint32_t DLL_IMP_EXP sm_max_buffers; +extern uint32_t DLL_IMP_EXP sm_buffers; + +#ifdef SMARTALLOC +#undef SMARTALLOC +#define SMARTALLOC SMARTALLOC extern void *sm_malloc(const char *fname, int lineno, unsigned int nbytes), @@ -43,13 +53,15 @@ extern void *sm_malloc(const char *fname, int lineno, unsigned int nbytes), *actuallyrealloc(void *ptr, unsigned int size); extern void sm_free(const char *fname, int lineno, void *fp); extern void actuallyfree(void *cp), - sm_dump(bool bufdump), sm_static(int mode); + sm_dump(bool bufdump, bool in_use=false), sm_static(int mode); extern void sm_new_owner(const char *fname, int lineno, char *buf); #ifdef SMCHECK +#define Dsm_check(lvl) if ((lvl)<=debug_level) sm_check(__FILE__, __LINE__, true) extern void sm_check(const char *fname, int lineno, bool bufdump); extern int sm_check_rtn(const char *fname, int lineno, bool bufdump); #else +#define Dsm_check(lvl) #define sm_check(f, l, fl) #define sm_check_rtn(f, l, fl) 1 #endif @@ -76,53 +88,67 @@ extern int sm_check_rtn(const char *fname, int lineno, bool bufdump); #define sm_dump(x) #define sm_static(x) #define sm_new_owner(a, b, c) -#define sm_malloc(f, l, n) malloc(n) - +#define sm_malloc(f, l, n) malloc(n) +#define sm_free(f, l, n) free(n) #define sm_check(f, l, fl) #define sm_check_rtn(f, l, fl) 1 extern void *b_malloc(); -#define malloc(x) b_malloc(__FILE__, __LINE__, (x)) +#define malloc(x) b_malloc(__FILE__, __LINE__, (x)) #endif #ifdef SMARTALLOC -#define New(type) new(__FILE__, __LINE__ type +#define New(type) new(__FILE__, __LINE__) type -#undef SMARTALLOC -#define SMARTALLOC SMARTALLOC +/* We do memset(0) because it's not possible to memset a class when + * using subclass with virtual functions + */ class SMARTALLOC { -private: public: void *operator new(size_t s, const char *fname, int line) { - void *p = sm_malloc(fname, line, s > sizeof(int) ? s : sizeof(int)); - return p; + size_t size = s > sizeof(int) ? (unsigned int)s : sizeof(int); + void *p = sm_malloc(fname, line, size); + memset(p, 0, size); + return p; } void *operator new[](size_t s, const char *fname, int line) { - void *p = sm_malloc(fname, line, s > sizeof(int) ? s : sizeof(int)); + size_t size = s > sizeof(int) ? (unsigned int)s : sizeof(int); + void *p = sm_malloc(fname, line, size); + memset(p, 0, size); return p; } + void operator delete(void *ptr) { free(ptr); } -void operator delete[](void *ptr, size_t i) +void operator delete[](void *ptr, size_t /*i*/) +{ + free(ptr); +} + +void operator delete(void *ptr, const char * /*fname*/, int /*line*/) +{ + free(ptr); +} +void operator delete[](void *ptr, size_t /*i*/, + const char * /*fname*/, int /*line*/) { free(ptr); } private: -void *operator new(size_t s) throw() { return 0; } -void *operator new[](size_t s) throw() { return 0; } +void *operator new(size_t s) throw() { (void)s; return 0; } +void *operator new[](size_t s) throw() { (void)s; return 0; } }; - #else @@ -131,21 +157,23 @@ void *operator new[](size_t s) throw() { return 0; } class SMARTALLOC { public: - void *operator new(size_t s) - { - return malloc(s); + void *operator new(size_t s) { + void *p = malloc(s); + memset(p, 0, s); + return p; } - void *operator new[](size_t s) - { - return malloc(s); + void *operator new[](size_t s) { + void *p = malloc(s); + memset(p, 0, s); + return p; } - void operator delete(void *ptr) - { + void operator delete(void *ptr) { free(ptr); } - void operator delete[](void *ptr, size_t i) - { + void operator delete[](void *ptr, size_t i) { free(ptr); } }; -#endif +#endif /* SMARTALLOC */ + +#endif /* !SMARTALLOC_H */