Commit 08f5ef39 authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Move non-fail alloc wrappers to dmemory.[hc].

parent 178e605c
......@@ -9,6 +9,7 @@
#include <yaxt.h>
#include "cdi.h"
#include "cdipio.h"
#include "dmemory.h"
#include "pio_util.h"
#include "resource_handle.h"
#include "resource_unpack.h"
......
......@@ -9,6 +9,7 @@
#include <stdarg.h>
#include <errno.h>
#include "error.h"
#if ! defined (HAVE_CONFIG_H)
#if ! defined (HAVE_MALLOC_H)
......@@ -530,6 +531,35 @@ void Free(const char *caller, const char *file, int line, void *ptr)
free(ptr);
}
void *cdiXmalloc(size_t size, const char *filename, const char *functionname,
int line)
{
void * value = calloc (1, size );
if ( value == NULL )
cdiAbort(filename, functionname, line, "malloc failed: %s",
strerror(errno));
return value;
}
void *cdiXcalloc(size_t nmemb, size_t size, const char *filename,
const char *functionname, int line)
{
void * value = calloc ( nmemb, size );
if ( value == NULL )
cdiAbort(filename, functionname, line, "calloc failed: %s",
strerror(errno) );
return value;
}
void *cdiXrealloc(void *p, size_t size, const char *functionname,
const char *filename, int line)
{
void *value = realloc(p, size);
if ( value == NULL )
cdiAbort(filename, functionname, line, "realloc failed: %s",
strerror(errno));
return value;
}
size_t memTotal(void)
{
......
......@@ -42,6 +42,17 @@ extern void Free (const char *caller, const char *file, int line, void *ptr
#endif /* DEBUG_MEMORY */
void *cdiXmalloc(size_t, const char *, const char *, int);
#define xmalloc(size) cdiXmalloc((size), __FILE__, __func__, __LINE__ )
void *cdiXcalloc(size_t, size_t, const char *, const char *, int);
#define xcalloc(nmemb,size) cdiXcalloc((nmemb), (size), \
__FILE__, __func__, __LINE__)
void *cdiXrealloc(void *, size_t, const char *, const char *, int);
#define xrealloc(p,size) cdiXrealloc((p), (size), \
__FILE__, __func__, __LINE__)
#endif /* _DMEMORY_H */
/*
* Local Variables:
......
......@@ -2,6 +2,7 @@
#include <stdlib.h>
#include <stdio.h>
#include "cdi.h"
#include "dmemory.h"
#include "namespace.h"
#include "resource_handle.h"
#include "pio_util.h"
......
......@@ -7,6 +7,7 @@
#include "pio_comm.h"
#include "cdi.h"
#include "dmemory.h"
#include "pio_util.h"
#ifdef USE_MPI
......
......@@ -14,6 +14,7 @@
#include "cdi.h"
#include "cdipio.h"
#include "dmemory.h"
#include "pio_util.h"
#include "vlist_var.h"
......
......@@ -9,6 +9,7 @@
#include <stdarg.h>
#include "cdi.h"
#include "dmemory.h"
#ifdef USE_MPI
#include "pio_impl.h"
......
......@@ -11,6 +11,7 @@
#include <mpi.h>
#include "cdi.h"
#include "dmemory.h"
#include "pio.h"
#include "pio_comm.h"
#include "pio_impl.h"
......
......@@ -26,6 +26,7 @@
#include "pio_comm.h"
#include "pio_impl.h"
#include "pio_util.h"
#include "dmemory.h"
extern char * command2charP[6];
......
......@@ -21,7 +21,7 @@
#include "pio_comm.h"
#include "pio_impl.h"
#include "pio_util.h"
#include "dmemory.h"
extern char * command2charP[6];
......
......@@ -15,6 +15,8 @@
#include "pio_impl.h"
#include "pio_util.h"
#include "dmemory.h"
extern char * command2charP[6];
extern char *token;
......
......@@ -11,6 +11,7 @@
#include "pio_comm.h"
#include "pio_impl.h"
#include "pio_util.h"
#include "dmemory.h"
extern char *command2charP[];
extern double accumWait;
......
......@@ -22,6 +22,7 @@
#include "cdi.h"
#include "cdipio.h"
#include "dmemory.h"
#include "namespace.h"
#include "taxis.h"
#include "pio.h"
......
......@@ -10,6 +10,7 @@
#include "pio_util.h"
#include "cdi.h"
#include "dmemory.h"
#ifdef USE_MPI
static
......@@ -55,36 +56,6 @@ void cdiPioWarning(const char *caller, const char *fmt, va_list ap)
/*****************************************************************************/
void * pcdiXmalloc ( size_t size, const char *filename, const char *functionname,
int line )
{
void * value = calloc (1, size );
if ( value == NULL )
cdiAbort(filename, functionname, line, "malloc failed: %s",
strerror(errno));
return value;
}
void * pcdiXcalloc ( size_t nmemb, size_t size, const char *filename,
const char *functionname, int line )
{
void * value = calloc ( nmemb, size );
if ( value == NULL )
cdiAbort(filename, functionname, line, "calloc failed: %s",
strerror(errno) );
return value;
}
void * pcdiXrealloc ( void *p, size_t size, const char *functionname,
const char *filename, int line )
{
void * value = realloc ( p, size );
if ( value == NULL )
cdiAbort(filename, functionname, line, "realloc failed: %s",
strerror(errno));
return value;
}
/***************************************************************/
#ifdef USE_MPI
......
......@@ -87,17 +87,6 @@ getMPICommWorldRank()
}
#endif
void * pcdiXmalloc ( size_t, const char *, const char *, int );
#define xmalloc(size) pcdiXmalloc ( size, __FILE__, __func__, __LINE__ )
void * pcdiXcalloc ( size_t, size_t, const char *, const char *, int );
#define xcalloc(nmemb,size) pcdiXcalloc(nmemb, size, \
__FILE__, __func__, __LINE__)
void * pcdiXrealloc ( void *, size_t, const char *, const char *, int );
#define xrealloc(p,size) pcdiXrealloc(p, size, \
__FILE__, __func__, __LINE__)
void pcdiXMPI(int iret, const char *, int);
#define xmpi(ret) do { \
int tmpIRet = (ret); \
......
......@@ -9,6 +9,7 @@
#include <stdlib.h>
#include <stdio.h>
#include "dmemory.h"
#include "resource_handle.h"
#include "pio_util.h"
#include "namespace.h"
......
......@@ -4,6 +4,7 @@
#include "cdi.h"
#include "pio_util.h"
#include "dmemory.h"
#include "institution.h"
#include "model.h"
#include "cdi_int.h"
......
......@@ -20,6 +20,7 @@ typedef int MPI_Comm;
#include "cdi.h"
#include "pio_util.h"
#include "dmemory.h"
#include "pio_write.h"
#ifdef USE_MPI
#include "cdipio.h"
......
......@@ -20,6 +20,7 @@ typedef int MPI_Comm;
#include "cksum.h"
#include "pio_util.h"
#include "dmemory.h"
#include "pio_write.h"
enum {
......
......@@ -2,7 +2,7 @@
#include "cksum.h"
#include "stream_cksum.h"
#include "pio_util.h"
#include "dmemory.h"
struct cksum_table *
cksum_stream(const char *fname, size_t *table_len)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment