From: Matthew Fernandez Date: Sun, 23 Oct 2022 02:44:19 +0000 (-0700) Subject: sfio: remove 'SF_ERROR' X-Git-Tag: 7.0.2~19^2~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ead8c63c3606782ebd9901cb687d1f75098b8b5d;p=graphviz sfio: remove 'SF_ERROR' When doing some unrelated refactoring, Windows compile errors emerge: sfsetbuf.c C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\oaidl.h(322,9): error C2059: syntax error: 'constant' [C:\GitLab-Runner\builds\graphviz\graphviz\build\lib\sfio\sfio.vcxproj] Some investigation leads us to a guess¹ that oaidl.h contains: typedef /* [v1_enum] */ enum tagSF_TYPE { SF_ERROR = VT_ERROR, SF_I1 = VT_I1, SF_I2 = VT_I2, SF_I4 = VT_I4, SF_I8 = VT_I8, SF_BSTR = VT_BSTR, SF_UNKNOWN = VT_UNKNOWN, SF_DISPATCH = VT_DISPATCH, SF_VARIANT = VT_VARIANT, SF_RECORD = VT_RECORD, SF_HAVEIID = ( VT_UNKNOWN | VT_RESERVED ) } SF_TYPE; // Line 319 673b9f1a7dbde9c9cc5d9a2a22ee835a08ab40ab tried to work around this in the past. But there remained a foot gun. If you (possibly transitively) included sfio.h but did not include sfhdr.h, you could end up facing this error. Surprising as it may seem, nothing in the code base checks for `SF_ERROR`. So a cleaner solution that removes the problem in perpetuity is to remove our `SF_ERROR`. Note that `SF_FLAGS` does not need to be adjusted because `SF_ERROR` was not a public flag. Gitlab: fixes #2301 ¹ https://stackoverflow.com/questions/13827599/oaidl-h319-error-c2057-expected-constant-expression --- diff --git a/lib/sfio/sfexcept.c b/lib/sfio/sfexcept.c index ab5e0fbb6..0f4542847 100644 --- a/lib/sfio/sfexcept.c +++ b/lib/sfio/sfexcept.c @@ -33,7 +33,7 @@ int _sfexcept(Sfio_t * f, int type, ssize_t io, Sfdisc_t * disc) lock = f->mode & SF_LOCK; if (local && io <= 0) - f->flags |= io < 0 ? SF_ERROR : SF_EOF; + f->flags |= io < 0 ? 0 : SF_EOF; if (disc && disc->exceptf) { /* let the stream be generally accessible for this duration */ if (local && lock) @@ -89,7 +89,7 @@ int _sfexcept(Sfio_t * f, int type, ssize_t io, Sfdisc_t * disc) /* a normal interrupt, we can continue */ errno = 0; - f->flags &= (unsigned short)~(SF_EOF | SF_ERROR); + f->flags &= (unsigned short)~SF_EOF; SFMTXRETURN(f, SF_ECONT); } diff --git a/lib/sfio/sfhdr.h b/lib/sfio/sfhdr.h index 79a955271..ebc4571a0 100644 --- a/lib/sfio/sfhdr.h +++ b/lib/sfio/sfhdr.h @@ -550,13 +550,6 @@ extern "C" { extern int _sfsetpool(Sfio_t *); extern char *_sfcvt(void *, int, int *, int *, int); -#ifdef _WIN32 -#undef SF_ERROR -#include -#define SF_ERROR 0000400 /* an error happened */ -#else -#endif /* _WIN32 */ - #ifdef __cplusplus } #endif diff --git a/lib/sfio/sfio.h b/lib/sfio/sfio.h index 6eded50c5..9e9063665 100644 --- a/lib/sfio/sfio.h +++ b/lib/sfio/sfio.h @@ -127,7 +127,6 @@ extern "C" { #define SF_LINE 0000040 /* line buffering */ #define SF_SHARE 0000100 /* stream with shared file descriptor */ #define SF_EOF 0000200 /* eof was detected */ -#define SF_ERROR 0000400 /* an error happened */ #define SF_STATIC 0001000 /* a stream that cannot be freed */ #define SF_IOCHECK 0002000 /* call exceptf before doing IO */ #define SF_PUBLIC 0004000 /* SF_SHARE and follow physical seek */ diff --git a/lib/sfio/sfrd.c b/lib/sfio/sfrd.c index 1454ab96b..027f06893 100644 --- a/lib/sfio/sfrd.c +++ b/lib/sfio/sfrd.c @@ -75,7 +75,7 @@ ssize_t sfrd(Sfio_t * f, void * buf, size_t n, if (!(f->flags & SF_STRING) && f->file < 0) SFMTXRETURN(f, 0); - f->flags &= (unsigned short)~(SF_EOF | SF_ERROR); + f->flags &= (unsigned short)~SF_EOF; dc = disc; if (f->flags & SF_STRING) { @@ -95,7 +95,6 @@ ssize_t sfrd(Sfio_t * f, void * buf, size_t n, if ((rv = _sfexcept(f, SF_READ, n, dc)) > 0) n = rv; else if (rv < 0) { - f->flags |= SF_ERROR; SFMTXRETURN(f, (ssize_t) rv); } } diff --git a/lib/sfio/sfseek.c b/lib/sfio/sfseek.c index 7a52bccf7..1ebe2eb36 100644 --- a/lib/sfio/sfseek.c +++ b/lib/sfio/sfseek.c @@ -85,7 +85,7 @@ Sfoff_t sfseek(Sfio_t * f, Sfoff_t p, int type) SFLOCK(f, local); /* clear error and eof bits */ - f->flags &= (unsigned short)~(SF_EOF | SF_ERROR); + f->flags &= (unsigned short)~SF_EOF; while (f->flags & SF_STRING) { SFSTRSIZE(f); diff --git a/lib/sfio/sfwr.c b/lib/sfio/sfwr.c index a8ea57a02..9585e05ce 100644 --- a/lib/sfio/sfwr.c +++ b/lib/sfio/sfwr.c @@ -125,7 +125,7 @@ ssize_t sfwr(Sfio_t * f, const void * buf, size_t n, SFMTXRETURN(f, (ssize_t) 0); /* clear current error states */ - f->flags &= (unsigned short)~(SF_EOF | SF_ERROR); + f->flags &= (unsigned short)~SF_EOF; dc = disc; if (f->flags & SF_STRING) /* total required buffer */ @@ -139,7 +139,6 @@ ssize_t sfwr(Sfio_t * f, const void * buf, size_t n, if ((rv = _sfexcept(f, SF_WRITE, n, dc)) > 0) n = rv; else if (rv < 0) { - f->flags |= SF_ERROR; SFMTXRETURN(f, rv); } }