/* Copyright 1996 Acorn Computers Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifndef m_H
#define m_H

/*m.h - redirection for memory allocation functions*/

/*From CLib*/
#include <stdlib.h>

/*From Support*/
#ifndef realloc_H
   #include "realloc.h"
#endif

#ifndef trace_H
   #include "trace.h"
#endif

/*To use this module, you must call m_ALLOC, m_FREE, m_REALLOC in place
   of malloc, free, realloc at ALL PLACES in the programme. Then it is
   possible to change your allocation discipline by changing the values of
   these macros.*/

#if TRACE
   extern void *m_alloc (char *file, int line, int);

   extern void m_free (char *file, int line, void *ptr, int size);

   extern void *m_realloc (char *file, int line, void *ptr, int old_size,
         int size);

   extern void m_summary (char *file, int line);

   extern void *m_validate_address (char *file, int line, void *ptr);

   #define m_ALLOC(size) \
         m_alloc (__FILE__, __LINE__, size)

   #define m_FREE(ptr, size) \
         m_free (__FILE__, __LINE__, ptr, size)

   #define m_REALLOC(ptr, old_size, size) \
         m_realloc (__FILE__, __LINE__, ptr, old_size, size)

   #define m_SUMMARY() \
         m_summary (__FILE__, __LINE__)

   #define m_VALIDATE_ADDRESS(ptr) \
         m_validate_address (__FILE__, __LINE__, ptr)
#else
   #define m_ALLOC(size)                  malloc (size)
   #define m_FREE(ptr, size)              free (ptr)
   #define m_REALLOC(ptr, old_size, size) REALLOC (ptr, size)
   #define m_SUMMARY()                    SKIP
   #define m_VALIDATE_ADDRESS(ptr)        ((void *) (ptr))
#endif

#endif