diff options
Diffstat (limited to 'include/Exceptions.h')
| -rw-r--r-- | include/Exceptions.h | 38 | 
1 files changed, 29 insertions, 9 deletions
| diff --git a/include/Exceptions.h b/include/Exceptions.h index 6e8e1db..16737e0 100644 --- a/include/Exceptions.h +++ b/include/Exceptions.h @@ -25,7 +25,17 @@  // Impossible de surcharger free(void *). Les compilateurs  // refuseront de passer un char * par exemple. +#ifdef OVER_FREE  #define free(p) xfree((void*)p) +#else +#include <stdlib.h> +#endif + +class MemoryException; + +char * xstrdup(const char *) throw (MemoryException); +void * xmalloc(ssize_t) throw (MemoryException); +void xfree(void *&);  // On prédéfinit la classe String, pour éviter  // les deadlocks de compilation... @@ -33,13 +43,27 @@ class String;  class Base {    public: -    char * strdup(const char *) const; -    void * malloc(ssize_t) const; -    void * operator new(size_t); -    void * operator new(size_t, void *); +    char * strdup(const char * s) const { +	return xstrdup(s); +    } +    void * malloc(ssize_t s) const { +	return malloc(s); +    } +    void * operator new(size_t s) { +	return xmalloc(s); +    } +    void * operator new(size_t s, void * p) { +	return memset(p, 0, s); +    } +    void free(void * p) const { +	xfree(p); +    } +    void free(char * p) const { +	xfree((void *) p); +    }  }; -class GeneralException : public Base{ +class GeneralException : public Base {    public:        GeneralException(String);        GeneralException(const GeneralException &); @@ -76,10 +100,6 @@ class IOInternal : public GeneralException {        IOInternal(String, op_t);  }; -char * xstrdup(const char *) throw (MemoryException); -void * xmalloc(ssize_t) throw (MemoryException); -void xfree(void *&); -  #else  #error This only works with a C++ compiler  #endif | 
