Tcl Source Code

Artifact [e080b51aea]
Login

Artifact e080b51aeafe3ebdd46b15b71ce51426d4d5b141:

Attachment "longseektell.patch" to ticket [219197ffff] added by dkf 2001-09-14 20:19:42.
Index: ChangeLog
===================================================================
RCS file: /cvsroot/tcl/tcl/ChangeLog,v
retrieving revision 1.613
diff -u -r1.613 ChangeLog
--- ChangeLog	2001/09/14 09:10:47	1.613
+++ ChangeLog	2001/09/14 12:13:55
@@ -1,3 +1,15 @@
+2001-09-14  Donal K. Fellows  <[email protected]>
+
+	* generic/tclIO.c (Tcl_Seek, Tcl_Tell): Rewritten to use long
+	instead of int for file offsets.
+	* generic/tclIO.c (Tcl_SeekBackwardCompat, Tcl_TellBackwardCompat):
+	New backward compatability interfaces to preserve exact backward
+	compatability on systems where sizeof(int)!=sizeof(long) where
+	stubs are being used; NOT DOCUMENTED, AS NOT TO BE USED IN USER
+	CODE and the documented interface with the changed type is
+	preferred for all new code.
+	* doc/OpenFileChnl.3: Matching documentation update.
+
 2001-09-13  Andreas Kupries  <[email protected]>
 
 	* win/Makefile.in:
Index: doc/OpenFileChnl.3
===================================================================
RCS file: /cvsroot/tcl/tcl/doc/OpenFileChnl.3,v
retrieving revision 1.12
diff -u -r1.12 OpenFileChnl.3
--- doc/OpenFileChnl.3	2001/09/11 18:29:56	1.12
+++ doc/OpenFileChnl.3	2001/09/14 12:13:56
@@ -100,10 +100,10 @@
 int
 \fBTcl_InputBuffered\fR(\fIchannel\fR)
 .sp
-int
+long
 \fBTcl_Seek\fR(\fIchannel, offset, seekMode\fR)
 .sp
-int
+long
 \fBTcl_Tell\fR(\fIchannel\fR)
 .sp
 int
@@ -191,7 +191,7 @@
 The number of bytes to consume from \fIcharBuf\fR or \fIbyteBuf\fR and
 output to the channel.
 .VE
-.AP int offset in
+.AP long offset in
 How far to move the access point in the channel at which the next input or
 output operation will be applied, measured in bytes from the position
 given by \fIseekMode\fR.  May be either positive or negative.
Index: generic/tcl.decls
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tcl.decls,v
retrieving revision 1.58
diff -u -r1.58 tcl.decls
--- generic/tcl.decls	2001/09/13 11:56:19	1.58
+++ generic/tcl.decls	2001/09/14 12:13:56
@@ -772,8 +772,9 @@
 declare 219 generic {
     int Tcl_ScanCountedElement(CONST char *str, int length, int *flagPtr)
 }
+# REMOVE Tcl_SeekBackwardCompat AT MAJOR VERSION CHANGE
 declare 220 generic {
-    int Tcl_Seek(Tcl_Channel chan, int offset, int mode)
+    int Tcl_SeekBackwardCompat(Tcl_Channel chan, int offset, int mode)
 }
 declare 221 generic {
     int Tcl_ServiceAll(void)
@@ -859,8 +860,9 @@
 declare 245 generic {
     int Tcl_StringMatch(CONST char *str, CONST char *pattern)
 }
+# REMOVE Tcl_TellBackwardCompat AT MAJOR VERSION CHANGE
 declare 246 generic {
-    int Tcl_Tell(Tcl_Channel chan)
+    int Tcl_TellBackwardCompat(Tcl_Channel chan)
 }
 declare 247 generic {
     int Tcl_TraceVar(Tcl_Interp *interp, char *varName, int flags, \
@@ -1685,7 +1687,14 @@
 declare 481 generic {
     int Tcl_EvalTokensStandard(Tcl_Interp *interp, Tcl_Token *tokenPtr, int count)
 }
- 
+# These are type-improved versions of the functions in slots 220 and 246
+declare 482 generic {
+    long Tcl_Seek(Tcl_Channel chan, long offset, int mode)
+}
+declare 483 generic {
+    long Tcl_Tell(Tcl_Channel chan)
+}
+
 ##############################################################################
 
 # Define the platform specific public Tcl interface.  These functions are
Index: generic/tclDecls.h
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclDecls.h,v
retrieving revision 1.58
diff -u -r1.58 tclDecls.h
--- generic/tclDecls.h	2001/09/13 11:56:19	1.58
+++ generic/tclDecls.h	2001/09/14 12:13:57
@@ -711,8 +711,8 @@
 EXTERN int		Tcl_ScanCountedElement _ANSI_ARGS_((CONST char * str, 
 				int length, int * flagPtr));
 /* 220 */
-EXTERN int		Tcl_Seek _ANSI_ARGS_((Tcl_Channel chan, int offset, 
-				int mode));
+EXTERN int		Tcl_SeekBackwardCompat _ANSI_ARGS_((Tcl_Channel chan, 
+				int offset, int mode));
 /* 221 */
 EXTERN int		Tcl_ServiceAll _ANSI_ARGS_((void));
 /* 222 */
@@ -787,7 +787,7 @@
 EXTERN int		Tcl_StringMatch _ANSI_ARGS_((CONST char * str, 
 				CONST char * pattern));
 /* 246 */
-EXTERN int		Tcl_Tell _ANSI_ARGS_((Tcl_Channel chan));
+EXTERN int		Tcl_TellBackwardCompat _ANSI_ARGS_((Tcl_Channel chan));
 /* 247 */
 EXTERN int		Tcl_TraceVar _ANSI_ARGS_((Tcl_Interp * interp, 
 				char * varName, int flags, 
@@ -1504,6 +1504,11 @@
 EXTERN int		Tcl_EvalTokensStandard _ANSI_ARGS_((
 				Tcl_Interp * interp, Tcl_Token * tokenPtr, 
 				int count));
+/* 482 */
+EXTERN long		Tcl_Seek _ANSI_ARGS_((Tcl_Channel chan, long offset, 
+				int mode));
+/* 483 */
+EXTERN long		Tcl_Tell _ANSI_ARGS_((Tcl_Channel chan));
 
 typedef struct TclStubHooks {
     struct TclPlatStubs *tclPlatStubs;
@@ -1783,7 +1788,7 @@
     void (*tcl_ResetResult) _ANSI_ARGS_((Tcl_Interp * interp)); /* 217 */
     int (*tcl_ScanElement) _ANSI_ARGS_((CONST char * str, int * flagPtr)); /* 218 */
     int (*tcl_ScanCountedElement) _ANSI_ARGS_((CONST char * str, int length, int * flagPtr)); /* 219 */
-    int (*tcl_Seek) _ANSI_ARGS_((Tcl_Channel chan, int offset, int mode)); /* 220 */
+    int (*tcl_SeekBackwardCompat) _ANSI_ARGS_((Tcl_Channel chan, int offset, int mode)); /* 220 */
     int (*tcl_ServiceAll) _ANSI_ARGS_((void)); /* 221 */
     int (*tcl_ServiceEvent) _ANSI_ARGS_((int flags)); /* 222 */
     void (*tcl_SetAssocData) _ANSI_ARGS_((Tcl_Interp * interp, CONST char * name, Tcl_InterpDeleteProc * proc, ClientData clientData)); /* 223 */
@@ -1809,7 +1814,7 @@
     void (*tcl_SplitPath) _ANSI_ARGS_((CONST char * path, int * argcPtr, char *** argvPtr)); /* 243 */
     void (*tcl_StaticPackage) _ANSI_ARGS_((Tcl_Interp * interp, char * pkgName, Tcl_PackageInitProc * initProc, Tcl_PackageInitProc * safeInitProc)); /* 244 */
     int (*tcl_StringMatch) _ANSI_ARGS_((CONST char * str, CONST char * pattern)); /* 245 */
-    int (*tcl_Tell) _ANSI_ARGS_((Tcl_Channel chan)); /* 246 */
+    int (*tcl_TellBackwardCompat) _ANSI_ARGS_((Tcl_Channel chan)); /* 246 */
     int (*tcl_TraceVar) _ANSI_ARGS_((Tcl_Interp * interp, char * varName, int flags, Tcl_VarTraceProc * proc, ClientData clientData)); /* 247 */
     int (*tcl_TraceVar2) _ANSI_ARGS_((Tcl_Interp * interp, char * part1, char * part2, int flags, Tcl_VarTraceProc * proc, ClientData clientData)); /* 248 */
     char * (*tcl_TranslateFileName) _ANSI_ARGS_((Tcl_Interp * interp, char * name, Tcl_DString * bufferPtr)); /* 249 */
@@ -2045,6 +2050,8 @@
     int (*tcl_OutputBuffered) _ANSI_ARGS_((Tcl_Channel chan)); /* 479 */
     void (*tcl_FSMountsChanged) _ANSI_ARGS_((Tcl_Filesystem * fsPtr)); /* 480 */
     int (*tcl_EvalTokensStandard) _ANSI_ARGS_((Tcl_Interp * interp, Tcl_Token * tokenPtr, int count)); /* 481 */
+    long (*tcl_Seek) _ANSI_ARGS_((Tcl_Channel chan, long offset, int mode)); /* 482 */
+    long (*tcl_Tell) _ANSI_ARGS_((Tcl_Channel chan)); /* 483 */
 } TclStubs;
 
 #ifdef __cplusplus
@@ -2968,9 +2975,9 @@
 #define Tcl_ScanCountedElement \
 	(tclStubsPtr->tcl_ScanCountedElement) /* 219 */
 #endif
-#ifndef Tcl_Seek
-#define Tcl_Seek \
-	(tclStubsPtr->tcl_Seek) /* 220 */
+#ifndef Tcl_SeekBackwardCompat
+#define Tcl_SeekBackwardCompat \
+	(tclStubsPtr->tcl_SeekBackwardCompat) /* 220 */
 #endif
 #ifndef Tcl_ServiceAll
 #define Tcl_ServiceAll \
@@ -3072,9 +3079,9 @@
 #define Tcl_StringMatch \
 	(tclStubsPtr->tcl_StringMatch) /* 245 */
 #endif
-#ifndef Tcl_Tell
-#define Tcl_Tell \
-	(tclStubsPtr->tcl_Tell) /* 246 */
+#ifndef Tcl_TellBackwardCompat
+#define Tcl_TellBackwardCompat \
+	(tclStubsPtr->tcl_TellBackwardCompat) /* 246 */
 #endif
 #ifndef Tcl_TraceVar
 #define Tcl_TraceVar \
@@ -4012,6 +4019,14 @@
 #ifndef Tcl_EvalTokensStandard
 #define Tcl_EvalTokensStandard \
 	(tclStubsPtr->tcl_EvalTokensStandard) /* 481 */
+#endif
+#ifndef Tcl_Seek
+#define Tcl_Seek \
+	(tclStubsPtr->tcl_Seek) /* 482 */
+#endif
+#ifndef Tcl_Tell
+#define Tcl_Tell \
+	(tclStubsPtr->tcl_Tell) /* 483 */
 #endif
 
 #endif /* defined(USE_TCL_STUBS) && !defined(USE_TCL_STUB_PROCS) */
Index: generic/tclIO.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclIO.c,v
retrieving revision 1.35
diff -u -r1.35 tclIO.c
--- generic/tclIO.c	2001/09/06 09:35:39	1.35
+++ generic/tclIO.c	2001/09/14 12:13:58
@@ -5243,23 +5243,23 @@
  *----------------------------------------------------------------------
  */
 
-int
+long
 Tcl_Seek(chan, offset, mode)
     Tcl_Channel chan;		/* The channel on which to seek. */
-    int offset;			/* Offset to seek to. */
+    long offset;		/* Offset to seek to. */
     int mode;			/* Relative to which location to seek? */
 {
     Channel *chanPtr = (Channel *) chan;	/* The real IO channel. */
     ChannelState *statePtr = chanPtr->state;	/* state info for channel */
     int inputBuffered, outputBuffered;
     int result;			/* Of device driver operations. */
-    int curPos;			/* Position on the device. */
+    long curPos;		/* Position on the device. */
     int wasAsync;		/* Was the channel nonblocking before the
                                  * seek operation? If so, must restore to
                                  * nonblocking mode after the seek. */
 
     if (CheckChannelErrors(statePtr, TCL_WRITABLE | TCL_READABLE) != 0) {
-	return -1;
+	return -1L;
     }
 
     /*
@@ -5269,7 +5269,7 @@
      * registered in an interpreter.
      */
 
-    if (CheckForDeadChannel(NULL, statePtr)) return -1;
+    if (CheckForDeadChannel(NULL, statePtr)) return -1L;
 
     /*
      * This operation should occur at the top of a channel stack.
@@ -5284,7 +5284,7 @@
 
     if (chanPtr->typePtr->seekProc == (Tcl_DriverSeekProc *) NULL) {
         Tcl_SetErrno(EINVAL);
-        return -1;
+        return -1L;
     }
 
     /*
@@ -5297,7 +5297,7 @@
 
     if ((inputBuffered != 0) && (outputBuffered != 0)) {
         Tcl_SetErrno(EFAULT);
-        return -1;
+        return -1L;
     }
 
     /*
@@ -5336,7 +5336,7 @@
         wasAsync = 1;
         result = StackSetBlockMode(chanPtr, TCL_MODE_BLOCKING);
 	if (result != 0) {
-	    return -1;
+	    return -1L;
 	}
         statePtr->flags &= (~(CHANNEL_NONBLOCKING));
         if (statePtr->flags & BG_FLUSH_SCHEDULED) {
@@ -5353,7 +5353,7 @@
      */
     
     if (FlushChannel(NULL, chanPtr, 0) != 0) {
-        curPos = -1;
+        curPos = -1L;
     } else {
 
         /*
@@ -5362,8 +5362,8 @@
          */
 
         curPos = (chanPtr->typePtr->seekProc) (chanPtr->instanceData,
-                (long) offset, mode, &result);
-        if (curPos == -1) {
+					       offset, mode, &result);
+        if (curPos == -1L) {
             Tcl_SetErrno(result);
         }
     }
@@ -5379,7 +5379,7 @@
         statePtr->flags |= CHANNEL_NONBLOCKING;
         result = StackSetBlockMode(chanPtr, TCL_MODE_NONBLOCKING);
 	if (result != 0) {
-	    return -1;
+	    return -1L;
 	}
     }
 
@@ -5405,7 +5405,7 @@
  *----------------------------------------------------------------------
  */
 
-int
+long
 Tcl_Tell(chan)
     Tcl_Channel chan;			/* The channel to return pos for. */
 {
@@ -5413,10 +5413,10 @@
     ChannelState *statePtr = chanPtr->state;	/* state info for channel */
     int inputBuffered, outputBuffered;
     int result;				/* Of calling device driver. */
-    int curPos;				/* Position on device. */
+    long curPos;			/* Position on device. */
 
     if (CheckChannelErrors(statePtr, TCL_WRITABLE | TCL_READABLE) != 0) {
-	return -1;
+	return -1L;
     }
 
     /*
@@ -5427,7 +5427,7 @@
      */
 
     if (CheckForDeadChannel(NULL, statePtr)) {
-	return -1;
+	return -1L;
     }
 
     /*
@@ -5443,7 +5443,7 @@
 
     if (chanPtr->typePtr->seekProc == (Tcl_DriverSeekProc *) NULL) {
         Tcl_SetErrno(EINVAL);
-        return -1;
+        return -1L;
     }
 
     /*
@@ -5456,7 +5456,7 @@
 
     if ((inputBuffered != 0) && (outputBuffered != 0)) {
         Tcl_SetErrno(EFAULT);
-        return -1;
+        return -1L;
     }
 
     /*
@@ -5465,15 +5465,71 @@
      */
 
     curPos = (chanPtr->typePtr->seekProc) (chanPtr->instanceData,
-            (long) 0, SEEK_CUR, &result);
+					   0L, SEEK_CUR, &result);
     if (curPos == -1) {
         Tcl_SetErrno(result);
-        return -1;
+        return -1L;
     }
     if (inputBuffered != 0) {
         return (curPos - inputBuffered);
     }
     return (curPos + outputBuffered);
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * Tcl_SeekBackwardCompat --
+ *
+ *	Implements seeking on Tcl Channels. This function only exists
+ *	for backward compatability on systems where the sizes of int
+ *	and long are different, and should not be called by new code.
+ *
+ * Results:
+ *	The new access point or -1 on error. If error, use Tcl_GetErrno()
+ *	to retrieve the POSIX error code for the error that occurred.
+ *
+ * Side effects:
+ *	May flush output on the channel. May discard queued input.
+ *
+ *----------------------------------------------------------------------
+ */
+
+int
+Tcl_SeekBackwardCompat(chan, offset, mode)
+    Tcl_Channel chan;		/* The channel on which to seek. */
+    int offset;			/* Offset to seek to. */
+    int mode;			/* Relative to which location to seek? */
+{
+    return (int)Tcl_Seek(chan, (long)offset, mode);
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * Tcl_TellBackwardCompat --
+ *
+ *	Returns the position of the next character to be read/written on
+ *	this channel. This function only exists for backward compatability
+ *	on systems where the sizes of int and long are different, and
+ *	should not be called by new code.
+ *
+ * Results:
+ *	A nonnegative integer on success, -1 on failure. If failed,
+ *	use Tcl_GetErrno() to retrieve the POSIX error code for the
+ *	error that occurred.
+ *
+ * Side effects:
+ *	None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+int
+Tcl_TellBackwardCompat(chan)
+    Tcl_Channel chan;			/* The channel to return pos for. */
+{
+    return (int)Tcl_Tell(chan);
 }
 
 /*
Index: generic/tclStubInit.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclStubInit.c,v
retrieving revision 1.61
diff -u -r1.61 tclStubInit.c
--- generic/tclStubInit.c	2001/09/13 11:56:20	1.61
+++ generic/tclStubInit.c	2001/09/14 12:13:58
@@ -617,7 +617,7 @@
     Tcl_ResetResult, /* 217 */
     Tcl_ScanElement, /* 218 */
     Tcl_ScanCountedElement, /* 219 */
-    Tcl_Seek, /* 220 */
+    Tcl_SeekBackwardCompat, /* 220 */
     Tcl_ServiceAll, /* 221 */
     Tcl_ServiceEvent, /* 222 */
     Tcl_SetAssocData, /* 223 */
@@ -643,7 +643,7 @@
     Tcl_SplitPath, /* 243 */
     Tcl_StaticPackage, /* 244 */
     Tcl_StringMatch, /* 245 */
-    Tcl_Tell, /* 246 */
+    Tcl_TellBackwardCompat, /* 246 */
     Tcl_TraceVar, /* 247 */
     Tcl_TraceVar2, /* 248 */
     Tcl_TranslateFileName, /* 249 */
@@ -879,6 +879,8 @@
     Tcl_OutputBuffered, /* 479 */
     Tcl_FSMountsChanged, /* 480 */
     Tcl_EvalTokensStandard, /* 481 */
+    Tcl_Seek, /* 482 */
+    Tcl_Tell, /* 483 */
 };
 
 /* !END!: Do not edit above this line. */