From: Matthew Fernandez Date: Thu, 19 Jan 2023 16:17:29 +0000 (-0800) Subject: sfio: remove macro implementations of character functions X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1e31f4bd7dd733da6670cbf27b8eeec662747788;p=graphviz sfio: remove macro implementations of character functions These were implemented as an optimization to allow inlining. This is no longer necessary on contemporary compilers with link-time optimization. Removing them will unblock fixing some strict aliasing problems with the `Sfio_t` type. Gitlab: #2338 --- diff --git a/cmd/gvpr/Makefile.am b/cmd/gvpr/Makefile.am index 7f5055633..f366edaaa 100644 --- a/cmd/gvpr/Makefile.am +++ b/cmd/gvpr/Makefile.am @@ -37,6 +37,7 @@ gvpr_static_LDADD = \ $(top_builddir)/lib/gvpr/libgvpr_C.la \ $(top_builddir)/lib/expr/libexpr_C.la \ $(top_builddir)/lib/sfio/libsfio_C.la \ + $(top_builddir)/lib/sfio/Sfio_f/libsfiof_C.la \ $(top_builddir)/lib/vmalloc/libvmalloc_C.la \ $(top_builddir)/lib/ingraphs/libingraphs_C.la \ $(top_builddir)/lib/ast/libast_C.la \ diff --git a/lib/expr/Makefile.am b/lib/expr/Makefile.am index 073d7a925..1eec24f3b 100644 --- a/lib/expr/Makefile.am +++ b/lib/expr/Makefile.am @@ -22,6 +22,7 @@ libexpr_C_la_LIBADD = \ $(top_builddir)/lib/ast/libast_C.la \ $(top_builddir)/lib/vmalloc/libvmalloc_C.la \ $(top_builddir)/lib/sfio/libsfio_C.la \ + $(top_builddir)/lib/sfio/Sfio_f/libsfiof_C.la \ $(top_builddir)/lib/cdt/libcdt.la $(libexpr_C_la_OBJECTS) $(libexpr_la_OBJECTS): \ diff --git a/lib/sfio/Sfio_f/_sffileno.c b/lib/sfio/Sfio_f/_sffileno.c index 7e9276a6e..ca0c25281 100644 --- a/lib/sfio/Sfio_f/_sffileno.c +++ b/lib/sfio/Sfio_f/_sffileno.c @@ -10,9 +10,4 @@ #include -#undef sffileno - -int sffileno(Sfio_t * f) -{ - return __sf_fileno(f); -} +int sffileno(Sfio_t *f) { return f ? f->file : -1; } diff --git a/lib/sfio/Sfio_f/_sfgetc.c b/lib/sfio/Sfio_f/_sfgetc.c index 5ecb8b563..0b158cccb 100644 --- a/lib/sfio/Sfio_f/_sfgetc.c +++ b/lib/sfio/Sfio_f/_sfgetc.c @@ -10,9 +10,7 @@ #include -#undef sfgetc - int sfgetc(Sfio_t * f) { - return __sf_getc(f); + return f->next >= f->endr ? _sffilbuf(f, 0) : (int)(*f->next++); } diff --git a/lib/sfio/Sfio_f/_sfputc.c b/lib/sfio/Sfio_f/_sfputc.c index 5bf53b749..c1d9c212c 100644 --- a/lib/sfio/Sfio_f/_sfputc.c +++ b/lib/sfio/Sfio_f/_sfputc.c @@ -10,9 +10,8 @@ #include -#undef sfputc - int sfputc(Sfio_t * f, int c) { - return __sf_putc(f, c); + return f->next >= f->endw ? _sfflsbuf(f, (int)((unsigned char)(c))) + : (int)(*f->next++ = (unsigned char)(c)); } diff --git a/lib/sfio/Sfio_f/_sfslen.c b/lib/sfio/Sfio_f/_sfslen.c index 8f93cfa5e..09a0b5d5b 100644 --- a/lib/sfio/Sfio_f/_sfslen.c +++ b/lib/sfio/Sfio_f/_sfslen.c @@ -10,9 +10,4 @@ #include -#undef sfslen - -ssize_t sfslen(void) -{ - return __sf_slen(); -} +ssize_t sfslen(void) { return _Sfi; } diff --git a/lib/sfio/sfio.h b/lib/sfio/sfio.h index 9e9063665..7a4331842 100644 --- a/lib/sfio/sfio.h +++ b/lib/sfio/sfio.h @@ -221,23 +221,6 @@ extern "C" { #undef extern -#if defined(__cplusplus) -#define _SF_(f) (f) -#else -#define _SF_(f) ((Sfio_t*)(f)) -#endif -#define __sf_putc(f,c) (_SF_(f)->next >= _SF_(f)->endw ? \ - _sfflsbuf(_SF_(f),(int)((unsigned char)(c))) : \ - (int)(*_SF_(f)->next++ = (unsigned char)(c)) ) -#define __sf_getc(f) (_SF_(f)->next >= _SF_(f)->endr ? _sffilbuf(_SF_(f),0) : \ - (int)(*_SF_(f)->next++) ) -#define __sf_fileno(f) ((f) ? _SF_(f)->file : -1) -#define __sf_slen() (_Sfi) - -#define sfputc(f,c) ( __sf_putc((f),(c)) ) -#define sfgetc(f) ( __sf_getc(f) ) -#define sffileno(f) ( __sf_fileno(f) ) -#define sfslen() ( __sf_slen() ) #ifdef __cplusplus } #endif