From beac578c7a38640a274287482827b01e8bcf1d2d Mon Sep 17 00:00:00 2001
From: Uwe Schulzweida <uwe.schulzweida@mpimet.mpg.de>
Date: Tue, 14 Jan 2025 14:12:11 +0100
Subject: [PATCH] stream_def_accesstype: pass stream_t

---
 src/cdi_int.c       | 11 +++++++++++
 src/cdi_int.h       |  3 +--
 src/stream.c        | 39 ++++++++-------------------------------
 src/stream_record.c |  2 +-
 4 files changed, 21 insertions(+), 34 deletions(-)

diff --git a/src/cdi_int.c b/src/cdi_int.c
index 347090c20..2ac868efa 100644
--- a/src/cdi_int.c
+++ b/src/cdi_int.c
@@ -564,6 +564,17 @@ cdiBaseFiletype(int filetype)
   return filetype;
 }
 
+void
+stream_def_accesstype(stream_t *s, int type)
+{
+  if (s->accesstype == CDI_UNDEFID)
+    {
+      s->accesstype = type;
+    }
+  else if (s->accesstype != type)
+    Error("Changing access type from %s not allowed!", s->accesstype == TYPE_REC ? "REC to VAR" : "VAR to REC");
+}
+
 /*
  * Local Variables:
  * c-file-style: "Java"
diff --git a/src/cdi_int.h b/src/cdi_int.h
index 847b95d36..c06e34979 100644
--- a/src/cdi_int.h
+++ b/src/cdi_int.h
@@ -467,8 +467,7 @@ void recordInitEntry(record_t *record);
 
 void cdiCheckZaxis(int zaxisID);
 
-void cdiDefAccesstype(int streamID, int type);
-int cdiInqAccesstype(int streamID);
+void stream_def_accesstype(stream_t *s, int type);
 
 int getByteswap(int byteorder);
 
diff --git a/src/stream.c b/src/stream.c
index 81fee3cae..0498fcac7 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -796,7 +796,7 @@ streamOpenA(const char *filename, const char *filemode, int filetype)
   if (str_is_equal(filemode, "r")) cdiVlistMakeImmutable(streamptr->vlistID);
 
   {
-    void (*streamCloseDelegate)(stream_t *streamptr, int recordBufIsToBeDeleted)
+    void (*streamCloseDelegate)(stream_t * streamptr, int recordBufIsToBeDeleted)
         = (void (*)(stream_t *, int)) namespaceSwitchGet(NSSWITCH_STREAM_CLOSE_BACKEND).func;
 
     streamCloseDelegate(streamptr, 0);
@@ -1339,11 +1339,10 @@ streamDestroyViaDelegate(stream_t *streamptr, void (*streamCloseDelegate)(stream
   Free(streamptr);
 }
 
-
 static void
 streamDestroy(stream_t *streamptr)
 {
-  void (*streamCloseDelegate)(stream_t *streamptr, int recordBufIsToBeDeleted)
+  void (*streamCloseDelegate)(stream_t * streamptr, int recordBufIsToBeDeleted)
       = (void (*)(stream_t *, int)) namespaceSwitchGet(NSSWITCH_STREAM_CLOSE_BACKEND).func;
 
   streamDestroyViaDelegate(streamptr, streamCloseDelegate);
@@ -1440,7 +1439,7 @@ streamSync(int streamID)
 {
   stream_t *streamptr = stream_to_pointer(streamID);
 
-  void (*myStreamSync_)(stream_t *streamptr) = (void (*)(stream_t *)) namespaceSwitchGet(NSSWITCH_STREAM_SYNC).func;
+  void (*myStreamSync_)(stream_t * streamptr) = (void (*)(stream_t *)) namespaceSwitchGet(NSSWITCH_STREAM_SYNC).func;
   myStreamSync_(streamptr);
 }
 
@@ -1474,7 +1473,7 @@ cdiStreamDefTimestep_(stream_t *streamptr, int tsID)
       /* usually points to cdfDefTimestep in serial mode but
        * to cdiPioCdfDefTimestep on servers and to a null-op on
        * clients in client/server mode */
-      void (*myCdfDefTimestep)(stream_t *streamptr, int tsID, size_t)
+      void (*myCdfDefTimestep)(stream_t * streamptr, int tsID, size_t)
           = (void (*)(stream_t *, int, size_t)) namespaceSwitchGet(NSSWITCH_CDF_DEF_TIMESTEP).func;
       myCdfDefTimestep(streamptr, tsID, 1);
     }
@@ -1512,7 +1511,7 @@ streamDefTimestep(int streamID, int tsID)
 
   if (streamptr->lockIO) CDI_IO_LOCK();
 
-  int (*myStreamDefTimestep_)(stream_t *streamptr, int tsID)
+  int (*myStreamDefTimestep_)(stream_t * streamptr, int tsID)
       = (int (*)(stream_t *, int)) namespaceSwitchGet(NSSWITCH_STREAM_DEF_TIMESTEP_).func;
   int status = myStreamDefTimestep_(streamptr, tsID);
 
@@ -1783,26 +1782,6 @@ streamInqFileID(int streamID)
   return s->fileID;
 }
 
-void
-cdiDefAccesstype(int streamID, int type)
-{
-  stream_t *s = (stream_t *) reshGetVal(streamID, &streamOps);
-
-  if (s->accesstype == CDI_UNDEFID)
-    {
-      s->accesstype = type;
-    }
-  else if (s->accesstype != type)
-    Error("Changing access type from %s not allowed!", s->accesstype == TYPE_REC ? "REC to VAR" : "VAR to REC");
-}
-
-int
-cdiInqAccesstype(int streamID)
-{
-  stream_t *s = (stream_t *) reshGetVal(streamID, &streamOps);
-  return s->accesstype;
-}
-
 static int
 streamTxCode(void *s)
 {
@@ -1813,7 +1792,7 @@ streamTxCode(void *s)
 void
 cdiStreamSetupVlist(stream_t *s, int vlistID)
 {
-  void (*myStreamSetupVlist)(stream_t *s, int vlistID)
+  void (*myStreamSetupVlist)(stream_t * s, int vlistID)
       = (void (*)(stream_t *, int)) namespaceSwitchGet(NSSWITCH_STREAM_SETUP_VLIST).func;
   myStreamSetupVlist(s, vlistID);
 }
@@ -1871,7 +1850,7 @@ cdiStreamSetupVlist_(stream_t *streamptr, int vlistID)
             /* calls cdfDefCoordinateVars in serial mode but
              * cdiPioClientStreamNOP (i.e. nothing) on client ranks
              * and cdiPioServerCdfDefVars on server ranks in parallel mode*/
-            void (*myCdfDefVars)(stream_t *streamptr) = (void (*)(stream_t *)) namespaceSwitchGet(NSSWITCH_CDF_STREAM_SETUP).func;
+            void (*myCdfDefVars)(stream_t * streamptr) = (void (*)(stream_t *)) namespaceSwitchGet(NSSWITCH_CDF_STREAM_SETUP).func;
             myCdfDefVars(streamptr);
           }
           break;
@@ -2039,7 +2018,6 @@ streamUnpack(char *unpackBuffer, int unpackBufferSize, int *unpackBufferPos, int
   return retval;
 }
 
-
 /* *
  * This function does not really close the memio,
  * this has to be done outside cdi to access the memory buffer*/
@@ -2069,7 +2047,6 @@ freePtrAfterNCMem(stream_t *streamptr, int recordBufIsToBeDeleted)
     }
 }
 
-
 void
 streamCloseNCMem(int streamID)
 {
@@ -2079,7 +2056,7 @@ streamCloseNCMem(int streamID)
   if (lockIO) CDI_IO_LOCK();
 
   if (CDI_Debug) Message("streamID = %d filename = %s", streamID, streamptr->filename);
-  streamDestroyViaDelegate(streamptr,freePtrAfterNCMem);
+  streamDestroyViaDelegate(streamptr, freePtrAfterNCMem);
   reshRemove(streamID, &streamOps);
   if (CDI_Debug) Message("Removed stream %d from stream list", streamID);
 
diff --git a/src/stream_record.c b/src/stream_record.c
index 114b0df40..1b1e0064f 100644
--- a/src/stream_record.c
+++ b/src/stream_record.c
@@ -104,7 +104,7 @@ streamInqField(int streamID, int *varID, int *levelID)
 
   stream_t *streamptr = stream_to_pointer(streamID);
 
-  cdiDefAccesstype(streamID, TYPE_REC);
+  stream_def_accesstype(streamptr, TYPE_REC);
 
   if (!streamptr->record) cdiInitRecord(streamptr);
 
-- 
GitLab