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
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)
/* 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);
}
extern int _sfsetpool(Sfio_t *);
extern char *_sfcvt(void *, int, int *, int *, int);
-#ifdef _WIN32
-#undef SF_ERROR
-#include <io.h>
-#define SF_ERROR 0000400 /* an error happened */
-#else
-#endif /* _WIN32 */
-
#ifdef __cplusplus
}
#endif
#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 */
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) {
if ((rv = _sfexcept(f, SF_READ, n, dc)) > 0)
n = rv;
else if (rv < 0) {
- f->flags |= SF_ERROR;
SFMTXRETURN(f, (ssize_t) rv);
}
}
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);
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 */
if ((rv = _sfexcept(f, SF_WRITE, n, dc)) > 0)
n = rv;
else if (rv < 0) {
- f->flags |= SF_ERROR;
SFMTXRETURN(f, rv);
}
}