Commit 1c692a1e authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Fix void * conversions of function pointers.

parent 72887407
......@@ -59,7 +59,7 @@ void cdf_create(const char *path, int cmode, int *ncidp)
if ( cdiNcChunksizehint != CDI_UNDEFID ) chunksizehint = cdiNcChunksizehint;
cdi_nc__create_funcp my_nc__create =
namespaceSwitchGet(NSSWITCH_NC__CREATE);
(cdi_nc__create_funcp)namespaceSwitchGet(NSSWITCH_NC__CREATE).func;
status = my_nc__create(path, cmode, initialsz, &chunksizehint, ncidp);
if ( CDF_Debug || status != NC_NOERR )
......@@ -241,7 +241,7 @@ void cdf_def_var(int ncid, const char *name, nc_type xtype, int ndims,
const int dimids[], int *varidp)
{
cdi_cdf_def_var_funcp my_cdf_def_var
= namespaceSwitchGet(NSSWITCH_CDF_DEF_VAR);
= (cdi_cdf_def_var_funcp)namespaceSwitchGet(NSSWITCH_CDF_DEF_VAR).func;
my_cdf_def_var(ncid, name, xtype, ndims, dimids, varidp);
}
......
......@@ -686,7 +686,8 @@ cdiStreamSetupVlist(stream_t *streamptr, int vlistID, int vlistIDorig)
{
#ifdef HAVE_LIBNETCDF
void (*myCdfDefVars)(stream_t *streamptr)
= namespaceSwitchGet(NSSWITCH_CDF_STREAM_SETUP);
= (void (*)(stream_t *))
namespaceSwitchGet(NSSWITCH_CDF_STREAM_SETUP).func;
myCdfDefVars(streamptr);
#endif
}
......
......@@ -61,7 +61,8 @@ void cdiAbortC(const char * caller, const char * filename,
{
va_list ap;
va_start(ap, errorString);
cdiAbortCFunc cdiAbortC_p = namespaceSwitchGet(NSSWITCH_ABORT);
cdiAbortCFunc cdiAbortC_p
= (cdiAbortCFunc)namespaceSwitchGet(NSSWITCH_ABORT).func;
cdiAbortC_p(caller, filename, functionname, line, errorString, ap);
va_end(ap);
}
......
......@@ -1102,7 +1102,8 @@ void fileSetBufferSize(int fileID, long buffersize)
int fileOpen(const char *filename, const char *mode)
{
int (*myFileOpen)(const char *filename, const char *mode)
= namespaceSwitchGet(NSSWITCH_FILE_OPEN);
= (int (*)(const char *, const char *))
namespaceSwitchGet(NSSWITCH_FILE_OPEN).func;
return myFileOpen(filename, mode);
}
......@@ -1200,7 +1201,7 @@ int fileOpen_serial(const char *filename, const char *mode)
int fileClose(int fileID)
{
int (*myFileClose)(int fileID)
= namespaceSwitchGet(NSSWITCH_FILE_CLOSE);
= (int (*)(int))namespaceSwitchGet(NSSWITCH_FILE_CLOSE).func;
return myFileClose(fileID);
}
......
......@@ -16,34 +16,38 @@ static int nNamespaces = 1;
static int activeNamespace = 0;
#ifdef HAVE_LIBNETCDF
#define CDI_NETCDF_SWITCHES nc__create,cdf_def_var_serial,cdfDefTimestep,\
cdfDefVars
#define CDI_NETCDF_SWITCHES \
{ .func = (void (*)()) nc__create }, \
{ .func = (void (*)()) cdf_def_var_serial }, \
{ .func = (void (*)()) cdfDefTimestep }, \
{ .func = (void (*)()) cdfDefVars }
#else
#define CDI_NETCDF_SWITCHES
#endif
#define defaultSwitches { \
cdiAbortC_serial, \
serializeGetSizeInCore, \
serializePackInCore, \
serializeUnpackInCore, \
fileOpen_serial, \
fileWrite, \
fileClose_serial, \
cdiStreamOpenDefaultDelegate, \
cdiStreamDefVlist_, \
cdiStreamWriteVar_, \
cdiStreamwriteVarChunk_, \
NULL, \
cdiStreamCloseDefaultDelegate, \
cdiStreamSync_, \
CDI_NETCDF_SWITCHES \
}
#define defaultSwitches { \
{ .func = (void (*)()) cdiAbortC_serial }, \
{ .func = (void (*)()) serializeGetSizeInCore }, \
{ .func = (void (*)()) serializePackInCore }, \
{ .func = (void (*)()) serializeUnpackInCore }, \
{ .func = (void (*)()) fileOpen_serial }, \
{ .func = (void (*)()) fileWrite }, \
{ .func = (void (*)()) fileClose_serial }, \
{ .func = (void (*)()) cdiStreamOpenDefaultDelegate }, \
{ .func = (void (*)()) cdiStreamDefVlist_ }, \
{ .func = (void (*)()) cdiStreamWriteVar_ }, \
{ .func = (void (*)()) cdiStreamwriteVarChunk_ }, \
{ .data = NULL }, \
{ .func = (void (*)()) cdiStreamCloseDefaultDelegate }, \
{ .func = (void (*)()) cdiStreamSync_ }, \
CDI_NETCDF_SWITCHES \
}
struct namespace
{
statusCode resStage;
void *switches[NUM_NAMESPACE_SWITCH];
union namespaceSwitchValue switches[NUM_NAMESPACE_SWITCH];
} initialNamespace = {
.resStage = STAGE_DEFINITION,
.switches = defaultSwitches
......@@ -167,7 +171,7 @@ namespaceNew()
++nNamespaces;
namespaces[newNamespaceID].resStage = STAGE_DEFINITION;
memcpy(namespaces[newNamespaceID].switches,
(void *[NUM_NAMESPACE_SWITCH])defaultSwitches,
(union namespaceSwitchValue[NUM_NAMESPACE_SWITCH])defaultSwitches,
sizeof (namespaces[newNamespaceID].switches));
reshListCreate(newNamespaceID);
NAMESPACE_UNLOCK();
......@@ -263,14 +267,14 @@ statusCode namespaceInqResStatus ( void )
return namespaces[nsp].resStage;
}
void namespaceSwitchSet(enum namespaceSwitch sw, void *value)
void namespaceSwitchSet(enum namespaceSwitch sw, union namespaceSwitchValue value)
{
xassert(sw > NSSWITCH_NO_SUCH_SWITCH && sw < NUM_NAMESPACE_SWITCH);
int nsp = namespaceGetActive();
namespaces[nsp].switches[sw] = value;
}
void *namespaceSwitchGet(enum namespaceSwitch sw)
union namespaceSwitchValue namespaceSwitchGet(enum namespaceSwitch sw)
{
xassert(sw > NSSWITCH_NO_SUCH_SWITCH && sw < NUM_NAMESPACE_SWITCH);
int nsp = namespaceGetActive();
......
......@@ -44,6 +44,14 @@ enum namespaceSwitch
NUM_NAMESPACE_SWITCH,
};
union namespaceSwitchValue
{
void *data;
void (*func)();
};
#define NSSW_FUNC(p) ((union namespaceSwitchValue){ .func = (void (*)())(p) })
#define NSSW_DATA(p) ((union namespaceSwitchValue){ .data = (void *)(p) })
int namespaceNew();
void namespaceDelete(int namespaceID);
......@@ -57,8 +65,9 @@ int namespaceAdaptKey ( int, int );
int namespaceAdaptKey2 ( int );
void namespaceDefResStatus ( statusCode );
statusCode namespaceInqResStatus ( void );
void namespaceSwitchSet(enum namespaceSwitch sw, void *value);
void *namespaceSwitchGet(enum namespaceSwitch sw);
void namespaceSwitchSet(enum namespaceSwitch sw,
union namespaceSwitchValue value);
union namespaceSwitchValue namespaceSwitchGet(enum namespaceSwitch sw);
#endif
......
......@@ -58,8 +58,8 @@ cdiPioCdfDefVar(int ncid, const char *name, nc_type xtype, int ndims,
void
cdiPioEnableNetCDFParAccess()
{
namespaceSwitchSet(NSSWITCH_NC__CREATE, cdiPio_nc__create);
namespaceSwitchSet(NSSWITCH_CDF_DEF_VAR, cdiPioCdfDefVar);
namespaceSwitchSet(NSSWITCH_NC__CREATE, NSSW_FUNC(cdiPio_nc__create));
namespaceSwitchSet(NSSWITCH_CDF_DEF_VAR, NSSW_FUNC(cdiPioCdfDefVar));
}
......
......@@ -14,6 +14,7 @@
#include "pio_interface.h"
#include "pio_rpc.h"
#include "pio_util.h"
#include "pio_serialize.h"
static int
cdiPioClientStreamOpen(const char *filename, const char *filemode,
......@@ -154,18 +155,25 @@ cdiPioClientSetup(int *pioNamespace_, int *pioNamespace)
int callerCDINamespace = namespaceGetActive();
pioNamespaceSetActive(*pioNamespace_);
serializeSetMPI();
namespaceSwitchSet(NSSWITCH_STREAM_OPEN_BACKEND, cdiPioClientStreamOpen);
namespaceSwitchSet(NSSWITCH_STREAM_DEF_VLIST_, cdiPioClientStreamDefVlist_);
namespaceSwitchSet(NSSWITCH_STREAM_WRITE_VAR_, cdiPioClientStreamWriteVar_);
namespaceSwitchSet(NSSWITCH_STREAM_OPEN_BACKEND,
NSSW_FUNC(cdiPioClientStreamOpen));
namespaceSwitchSet(NSSWITCH_STREAM_DEF_VLIST_,
NSSW_FUNC(cdiPioClientStreamDefVlist_));
namespaceSwitchSet(NSSWITCH_STREAM_WRITE_VAR_,
NSSW_FUNC(cdiPioClientStreamWriteVar_));
namespaceSwitchSet(NSSWITCH_STREAM_WRITE_VAR_CHUNK_,
cdiPioClientStreamWriteVarChunk_);
NSSW_FUNC(cdiPioClientStreamWriteVarChunk_));
namespaceSwitchSet(NSSWITCH_STREAM_WRITE_VAR_PART_,
cdiPioClientStreamWriteVarPart);
namespaceSwitchSet(NSSWITCH_STREAM_CLOSE_BACKEND, cdiPioClientStreamClose);
namespaceSwitchSet(NSSWITCH_STREAM_SYNC, cdiPioClientStreamNOP);
NSSW_FUNC(cdiPioClientStreamWriteVarPart));
namespaceSwitchSet(NSSWITCH_STREAM_CLOSE_BACKEND,
NSSW_FUNC(cdiPioClientStreamClose));
namespaceSwitchSet(NSSWITCH_STREAM_SYNC,
NSSW_FUNC(cdiPioClientStreamNOP));
#ifdef HAVE_LIBNETCDF
namespaceSwitchSet(NSSWITCH_CDF_DEF_TIMESTEP, cdiPioCdfDefTimestepNOP);
namespaceSwitchSet(NSSWITCH_CDF_STREAM_SETUP, cdiPioClientStreamNOP);
namespaceSwitchSet(NSSWITCH_CDF_DEF_TIMESTEP,
NSSW_FUNC(cdiPioCdfDefTimestepNOP));
namespaceSwitchSet(NSSWITCH_CDF_STREAM_SETUP,
NSSW_FUNC(cdiPioClientStreamNOP));
#endif
pioNamespaceSetActive(callerCDINamespace);
}
......
......@@ -747,9 +747,9 @@ pioInit(MPI_Comm commGlob, int nProcsIO, int IOMode,
if ( commInqIsProcIO ())
{
serializeSetMPI();
namespaceSwitchSet(NSSWITCH_ABORT, cdiAbortC_MPI);
namespaceSwitchSet(NSSWITCH_FILE_OPEN, pioFileOpen);
namespaceSwitchSet(NSSWITCH_FILE_CLOSE, pioFileClose);
namespaceSwitchSet(NSSWITCH_ABORT, NSSW_FUNC(cdiAbortC_MPI));
namespaceSwitchSet(NSSWITCH_FILE_OPEN, NSSW_FUNC(pioFileOpen));
namespaceSwitchSet(NSSWITCH_FILE_CLOSE, NSSW_FUNC(pioFileClose));
IOServer ();
namespaceDelete(0);
commDestroy ();
......@@ -913,7 +913,8 @@ streamWriteVarPart(int streamID, int varID, const void *data,
void (*myStreamWriteVarPart)(int streamID, int varID, const void *data,
int nmiss, Xt_idxlist partDesc)
= namespaceSwitchGet(NSSWITCH_STREAM_WRITE_VAR_PART_);
= (void (*)(int, int, const void *, int, Xt_idxlist))
namespaceSwitchGet(NSSWITCH_STREAM_WRITE_VAR_PART_).func;
if (!myStreamWriteVarPart)
xabort("local part writing is unsupported!");
......
......@@ -94,9 +94,12 @@ void serializeSetMPI()
if (!dtDictMatchComplete)
setupDtDict();
#endif
namespaceSwitchSet(NSSWITCH_SERIALIZE_GET_SIZE, serializeGetSizeMPI);
namespaceSwitchSet(NSSWITCH_SERIALIZE_PACK, serializePackMPI);
namespaceSwitchSet(NSSWITCH_SERIALIZE_UNPACK, serializeUnpackMPI);
namespaceSwitchSet(NSSWITCH_SERIALIZE_GET_SIZE,
NSSW_FUNC(serializeGetSizeMPI));
namespaceSwitchSet(NSSWITCH_SERIALIZE_PACK,
NSSW_FUNC(serializePackMPI));
namespaceSwitchSet(NSSWITCH_SERIALIZE_UNPACK,
NSSW_FUNC(serializeUnpackMPI));
}
......
......@@ -934,13 +934,18 @@ void IOServer ()
#elif defined (HAVE_LIBNETCDF)
cdiSerialOpenFileCount = xcalloc(sizeof (cdiSerialOpenFileCount[0]),
commInqSizeColl());
namespaceSwitchSet(NSSWITCH_STREAM_OPEN_BACKEND, cdiPioStreamCDFOpenWrap);
namespaceSwitchSet(NSSWITCH_STREAM_CLOSE_BACKEND, cdiPioStreamCDFCloseWrap);
namespaceSwitchSet(NSSWITCH_CDF_DEF_TIMESTEP, cdiPioCdfDefTimestep);
namespaceSwitchSet(NSSWITCH_CDF_STREAM_SETUP, cdiPioServerCdfDefVars);
namespaceSwitchSet(NSSWITCH_STREAM_OPEN_BACKEND,
NSSW_FUNC(cdiPioStreamCDFOpenWrap));
namespaceSwitchSet(NSSWITCH_STREAM_CLOSE_BACKEND,
NSSW_FUNC(cdiPioStreamCDFCloseWrap));
namespaceSwitchSet(NSSWITCH_CDF_DEF_TIMESTEP,
NSSW_FUNC(cdiPioCdfDefTimestep));
namespaceSwitchSet(NSSWITCH_CDF_STREAM_SETUP,
NSSW_FUNC(cdiPioServerCdfDefVars));
#endif
namespaceSwitchSet(NSSWITCH_FILE_WRITE, cdiPioFileWrite);
namespaceSwitchSet(NSSWITCH_FILE_WRITE,
NSSW_FUNC(cdiPioFileWrite));
for ( ;; )
{
xmpi ( MPI_Probe ( MPI_ANY_SOURCE, MPI_ANY_TAG, commCalc, &status ));
......
......@@ -10,7 +10,8 @@ int
serializeGetSize(int count, int datatype, void *context)
{
int (*serialize_get_size_p)(int count, int datatype, void *context)
= namespaceSwitchGet(NSSWITCH_SERIALIZE_GET_SIZE);
= (int (*)(int, int, void *))
namespaceSwitchGet(NSSWITCH_SERIALIZE_GET_SIZE).func;
return serialize_get_size_p(count, datatype, context);
}
......@@ -19,7 +20,8 @@ void serializePack(void *data, int count, int datatype,
{
void (*serialize_pack_p)(void *data, int count, int datatype,
void *buf, int buf_size, int *position, void *context)
= namespaceSwitchGet(NSSWITCH_SERIALIZE_PACK);
= (void (*)(void *, int, int, void *, int, int *, void *))
namespaceSwitchGet(NSSWITCH_SERIALIZE_PACK).func;
serialize_pack_p(data, count, datatype, buf, buf_size, position, context);
}
......@@ -28,7 +30,8 @@ void serializeUnpack(void *buf, int buf_size, int *position,
{
void (*serialize_unpack_p)(void *buf, int buf_size, int *position,
void *data, int count, int datatype, void *context)
= namespaceSwitchGet(NSSWITCH_SERIALIZE_UNPACK);
= (void (*)(void *, int, int *, void *, int, int, void *))
namespaceSwitchGet(NSSWITCH_SERIALIZE_UNPACK).func;
serialize_unpack_p(buf, buf_size, position, data, count, datatype, context);
}
......
......@@ -751,7 +751,8 @@ int streamOpen(const char *filename, const char *filemode, int filetype)
{
int (*streamOpenDelegate)(const char *filename, const char *filemode,
int filetype, stream_t *streamptr)
= namespaceSwitchGet(NSSWITCH_STREAM_OPEN_BACKEND);
= (int (*)(const char *, const char *, int, stream_t *))
namespaceSwitchGet(NSSWITCH_STREAM_OPEN_BACKEND).func;
fileID = streamOpenDelegate(filename, filemode, filetype, streamptr);
}
......@@ -808,7 +809,8 @@ static int streamOpenA(const char *filename, const char *filemode, int filetype)
{
int (*streamOpenDelegate)(const char *filename, const char *filemode,
int filetype, stream_t *streamptr)
= namespaceSwitchGet(NSSWITCH_STREAM_OPEN_BACKEND);
= (int (*)(const char *, const char *, int, stream_t *))
namespaceSwitchGet(NSSWITCH_STREAM_OPEN_BACKEND).func;
fileID = streamOpenDelegate(filename, "r", filetype, streamptr);
}
......@@ -839,7 +841,8 @@ static int streamOpenA(const char *filename, const char *filemode, int filetype)
{
void (*streamCloseDelegate)(stream_t *streamptr, int recordBufIsToBeDeleted)
= namespaceSwitchGet(NSSWITCH_STREAM_CLOSE_BACKEND);
= (void (*)(stream_t *, int))
namespaceSwitchGet(NSSWITCH_STREAM_CLOSE_BACKEND).func;
streamCloseDelegate(streamptr, 0);
}
......@@ -1161,7 +1164,8 @@ void streamClose(int streamID)
vlistID = streamptr->vlistID;
void (*streamCloseDelegate)(stream_t *streamptr, int recordBufIsToBeDeleted)
= namespaceSwitchGet(NSSWITCH_STREAM_CLOSE_BACKEND);
= (void (*)(stream_t *, int))
namespaceSwitchGet(NSSWITCH_STREAM_CLOSE_BACKEND).func;
streamCloseDelegate(streamptr, 1);
......@@ -1279,7 +1283,7 @@ void streamSync(int streamID)
stream_check_ptr(__func__, streamptr);
void (*myStreamSync_)(stream_t *streamptr)
= namespaceSwitchGet(NSSWITCH_STREAM_SYNC);
= (void (*)(stream_t *))namespaceSwitchGet(NSSWITCH_STREAM_SYNC).func;
myStreamSync_(streamptr);
}
......@@ -1361,7 +1365,8 @@ int streamDefTimestep(int streamID, int tsID)
&& vlistHasTime(vlistID))
{
void (*myCdfDefTimestep)(stream_t *streamptr, int tsID)
= namespaceSwitchGet(NSSWITCH_CDF_DEF_TIMESTEP);
= (void (*)(stream_t *, int))
namespaceSwitchGet(NSSWITCH_CDF_DEF_TIMESTEP).func;
myCdfDefTimestep(streamptr, tsID);
}
#endif
......@@ -1587,7 +1592,8 @@ void streamWriteVar(int streamID, int varID, const double *data, int nmiss)
{
void (*myCdiStreamWriteVar_)(int streamID, int varID, int memtype,
const void *data, int nmiss)
= namespaceSwitchGet(NSSWITCH_STREAM_WRITE_VAR_);
= (void (*)(int, int, int, const void *, int))
namespaceSwitchGet(NSSWITCH_STREAM_WRITE_VAR_).func;
myCdiStreamWriteVar_(streamID, varID, MEMTYPE_DOUBLE, data, nmiss);
}
......@@ -1685,7 +1691,8 @@ void streamWriteVarF(int streamID, int varID, const float *data, int nmiss)
{
void (*myCdiStreamWriteVar_)(int streamID, int varID, int memtype,
const void *data, int nmiss)
= namespaceSwitchGet(NSSWITCH_STREAM_WRITE_VAR_);
= (void (*)(int, int, int, const void *, int))
namespaceSwitchGet(NSSWITCH_STREAM_WRITE_VAR_).func;
myCdiStreamWriteVar_(streamID, varID, MEMTYPE_FLOAT, data, nmiss);
}
......@@ -1898,7 +1905,8 @@ streamWriteVarChunk(int streamID, int varID,
void (*myCdiStreamWriteVarChunk_)(int streamID, int varID, int memtype,
const int rect[][2], const void *data,
int nmiss)
= namespaceSwitchGet(NSSWITCH_STREAM_WRITE_VAR_CHUNK_);
= (void (*)(int, int, int, const int [][2], const void *, int))
namespaceSwitchGet(NSSWITCH_STREAM_WRITE_VAR_CHUNK_).func;
myCdiStreamWriteVarChunk_(streamID, varID, MEMTYPE_DOUBLE, rect, data, nmiss);
}
......@@ -2149,7 +2157,7 @@ The function @func{streamDefVlist} defines the variable list of a stream.
void streamDefVlist(int streamID, int vlistID)
{
void (*myStreamDefVlist)(int streamID, int vlistID)
= namespaceSwitchGet(NSSWITCH_STREAM_DEF_VLIST_);
= (void (*)(int, int))namespaceSwitchGet(NSSWITCH_STREAM_DEF_VLIST_).func;
myStreamDefVlist(streamID, vlistID);
}
......
......@@ -557,7 +557,8 @@ int grb_write_var_slice(stream_t *streamptr, int varID, int levelID, int memtype
{
size_t (*myFileWrite)(int fileID, const void *restrict buffer,
size_t len, int tsID)
= namespaceSwitchGet(NSSWITCH_FILE_WRITE);
= (size_t (*)(int, const void *restrict, size_t, int))
namespaceSwitchGet(NSSWITCH_FILE_WRITE).func;
nwrite = myFileWrite(fileID, gribbuffer, nbytes, tsID);
}
......
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