From 194f7cff8380bd44b72319b69737c6e455de2317 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Thu, 13 Mar 2025 18:22:33 -0400 Subject: [PATCH] legacy stdc++: Delete all unused protected streambuf APIs that use IO_FILE directly. Unfortunately there are some marked "public" that also use it, so we can't just move the remainder to an internal file and then drop libio.h from public consumption. Delete all the unused portions of the public libio.h while at it. --- headers/cpp/libio.h | 90 ++++------------------------- headers/cpp/streambuf.h | 30 ---------- src/libs/stdc++/legacy/streambuf.cc | 11 ---- 3 files changed, 12 insertions(+), 119 deletions(-) diff --git a/headers/cpp/libio.h b/headers/cpp/libio.h index 6ddaadebbe..efc012f176 100644 --- a/headers/cpp/libio.h +++ b/headers/cpp/libio.h @@ -35,53 +35,25 @@ #endif #define _IO_pos_t off_t /* obsolete */ -#define _IO_fpos_t off_t #define _IO_fpos64_t off_t #define _IO_size_t size_t #define _IO_ssize_t ssize_t #define _IO_off_t off_t #define _IO_off64_t off_t #define _IO_pid_t pid_t -#define _IO_uid_t uid_t -#define _IO_HAVE_SYS_WAIT _G_HAVE_SYS_WAIT -#define _IO_HAVE_ST_BLKSIZE _G_HAVE_ST_BLKSIZE #define _IO_BUFSIZ BUFSIZ #define _IO_va_list va_list +#define _G_IO_IO_FILE_VERSION 0x20001 + #define _IOS_INPUT 1 #define _IOS_OUTPUT 2 -#define _IOS_ATEND 4 #define _IOS_APPEND 8 -#define _IOS_TRUNC 16 -#define _IOS_NOCREATE 32 -#define _IOS_NOREPLACE 64 #define _IOS_BIN 128 -/* Magic numbers and bits for the _flags field. - The magic numbers use the high-order bits of _flags; - the remaining bits are available for variable flags. - Note: The magic numbers must all be negative if stdio - emulation is desired. */ - -#define _IO_MAGIC 0xFBAD0000 /* Magic number */ -#define _OLD_STDIO_MAGIC 0xFABC0000 /* Emulate old stdio. */ -#define _IO_MAGIC_MASK 0xFFFF0000 -#define _IO_USER_BUF 1 /* User owns buffer; don't delete it on close. */ #define _IO_UNBUFFERED 2 -#define _IO_NO_READS 4 /* Reading not allowed */ -#define _IO_NO_WRITES 8 /* Writing not allowd */ -#define _IO_EOF_SEEN 0x10 -#define _IO_ERR_SEEN 0x20 -#define _IO_DELETE_DONT_CLOSE 0x40 /* Don't call close(_fileno) on cleanup. */ -#define _IO_LINKED 0x80 /* Set if linked (using _chain) to streambuf::_list_all.*/ #define _IO_IN_BACKUP 0x100 #define _IO_LINE_BUF 0x200 -#define _IO_TIED_PUT_GET 0x400 /* Set if put and get pointer logicly tied. */ -#define _IO_CURRENTLY_PUTTING 0x800 -#define _IO_IS_APPENDING 0x1000 -#define _IO_IS_FILEBUF 0x2000 -#define _IO_BAD_SEEN 0x4000 -#define _G_IO_IO_FILE_VERSION 0x20001 /* These are "formatting flags" matching the iostream fmtflags enum values. */ #define _IO_SKIPWS 01 @@ -100,13 +72,9 @@ #define _IO_UNITBUF 020000 #define _IO_STDIO 040000 #define _IO_DONT_CLOSE 0100000 -#define _IO_BOOLALPHA 0200000 struct _IO_marker; -struct _IO_codecvt; -struct _IO_wide_data; -typedef void _IO_lock_t; struct _IO_marker { @@ -134,33 +102,25 @@ typedef struct _IO_FILE { char *_IO_backup_base; /* Pointer to first valid character of backup area */ char *_IO_save_end; /* Pointer to end of non-current get area. */ - struct _IO_marker *_markers; + void *_private0; - struct _IO_FILE *_chain; + void *_private1; int _fileno; -/* int _blksize; */ - int _flags2; - off_t _old_offset; /* This used to be _offset but it's too small. */ - /* -> not true on BeOS, but who cares */ + int _private2; + off_t _unused0; /* 1+column number of pbase(); 0 is unknown. */ unsigned short _cur_column; - signed char _vtable_offset; + signed char _private3; char _shortbuf[1]; - _IO_lock_t *_lock; + void *_private4; - off_t _offset; -/* #if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T */ - /* Wide character stream stuff. */ - struct _IO_codecvt *_codecvt; - struct _IO_wide_data *_wide_data; -/* #else - * void *__pad1; - * void *__pad2; - * #endif */ - int _mode; + off_t _private5; + void *_private6; + void *_private7; + int _private8; /* Make sure we don't get into trouble again. */ char _unused2[15 * sizeof (int) - 2 * sizeof (void *)]; } _IO_FILE; @@ -170,16 +130,10 @@ typedef struct _IO_FILE { extern "C" { #endif -extern int _IO_feof(_IO_FILE *stream); -#define _IO_feof_unlocked(__fp) (((__fp)->_flags & _IO_EOF_SEEN) != 0) -extern int _IO_ferror(_IO_FILE *stream); -#define _IO_ferror_unlocked(__fp) (((__fp)->_flags & _IO_ERR_SEEN) != 0) extern int _IO_putc(int c, _IO_FILE *stream); extern int _IO_getc(_IO_FILE *stream); extern int __underflow(_IO_FILE *stream); -extern int __uflow(_IO_FILE *stream); -extern int __overflow(_IO_FILE *stream, int c); extern int _IO_peekc_locked(_IO_FILE *stream); #define _IO_peekc(_fp) _IO_peekc_locked (_fp) @@ -198,26 +152,6 @@ extern _IO_fpos64_t _IO_seekpos(_IO_FILE *, _IO_fpos64_t, int); extern void _IO_free_backup_area(_IO_FILE *); -#if __GNUC__ >= 3 -# define _IO_BE(expr, res) __builtin_expect (expr, res) -#else -# define _IO_BE(expr, res) (expr) -#endif - -#define _IO_getc_unlocked(_fp) \ - (_IO_BE ((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end, 0) \ - ? __uflow (_fp) : *(unsigned char *) (_fp)->_IO_read_ptr++) -#define _IO_peekc_unlocked(_fp) \ - (_IO_BE ((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end, 0) \ - && __underflow (_fp) == EOF ? EOF \ - : *(unsigned char *) (_fp)->_IO_read_ptr) -#define _IO_putc_unlocked(_ch, _fp) \ - (_IO_BE ((_fp)->_IO_write_ptr >= (_fp)->_IO_write_end, 0) \ - ? __overflow (_fp, (unsigned char) (_ch)) \ - : (unsigned char) (*(_fp)->_IO_write_ptr++ = (_ch))) - - - #ifdef __cplusplus } #endif diff --git a/headers/cpp/streambuf.h b/headers/cpp/streambuf.h index 81f1c37269..0ef64cae05 100644 --- a/headers/cpp/streambuf.h +++ b/headers/cpp/streambuf.h @@ -288,7 +288,6 @@ struct streambuf : public _IO_FILE { // protected?? const void *&_vtable() { return *(const void**)((_IO_FILE*)this + 1); } protected: static streambuf* _list_all; /* List of open streambufs. */ - _IO_FILE*& xchain() { return _chain; } void _un_link(); void _link_in(); char* gptr() const @@ -302,13 +301,8 @@ struct streambuf : public _IO_FILE { // protected?? { return _IO_file_flags & _IO_IN_BACKUP ? _IO_save_base : _IO_read_base;} char* base() const { return _IO_buf_base; } char* ebuf() const { return _IO_buf_end; } - int blen() const { return _IO_buf_end - _IO_buf_base; } - void xput_char(char c) { *_IO_write_ptr++ = c; } int xflags() { return _IO_file_flags; } int xflags(int f) {int fl = _IO_file_flags; _IO_file_flags = f; return fl;} - void xsetflags(int f) { _IO_file_flags |= f; } - void xsetflags(int f, int mask) - { _IO_file_flags = (_IO_file_flags & ~mask) | (f & mask); } void gbump(int n) { _IO_file_flags & _IO_IN_BACKUP ? (_IO_save_base+=n):(_IO_read_ptr+=n);} void pbump(int n) { _IO_write_ptr += n; } @@ -318,26 +312,6 @@ struct streambuf : public _IO_FILE { // protected?? void setg(char* eb, char* g, char *eg) { if (_IO_file_flags & _IO_IN_BACKUP) _IO_free_backup_area(this); _IO_read_base = eb; _IO_read_ptr = g; _IO_read_end = eg; } - char *shortbuf() { return _shortbuf; } - - int in_backup() { return _flags & _IO_IN_BACKUP; } - // The start of the main get area: FIXME: wrong for write-mode filebuf? - char *Gbase() { return in_backup() ? _IO_save_base : _IO_read_base; } - // The end of the main get area: - char *eGptr() { return in_backup() ? _IO_save_end : _IO_read_end; } - // The start of the backup area: - char *Bbase() { return in_backup() ? _IO_read_base : _IO_save_base; } - char *Bptr() { return _IO_backup_base; } - // The end of the backup area: - char *eBptr() { return in_backup() ? _IO_read_end : _IO_save_end; } - char *Nbase() { return _IO_save_base; } - char *eNptr() { return _IO_save_end; } - int have_backup() { return _IO_save_base != NULL; } - int have_markers() { return _markers != NULL; } - void free_backup_area(); - void unsave_markers(); // Make all streammarkers !saving(). - int put_mode() { return _flags & _IO_CURRENTLY_PUTTING; } - int switch_to_get_mode(); streambuf(int flags=0); public: @@ -446,10 +420,6 @@ class filebuf : public streambuf { virtual int sync(); protected: // See documentation in filebuf.C. // virtual int pbackfail(int c); - int is_reading() { return eback() != egptr(); } - char* cur_ptr() { return is_reading() ? gptr() : pptr(); } - /* System's idea of pointer */ - char* file_ptr() { return eGptr(); } // Low-level operations (Usually invoke system calls.) virtual streamsize sys_read(char* buf, streamsize size); virtual streampos sys_seek(streamoff, _seek_dir); diff --git a/src/libs/stdc++/legacy/streambuf.cc b/src/libs/stdc++/legacy/streambuf.cc index 677f6965fc..d1120e3e2d 100644 --- a/src/libs/stdc++/legacy/streambuf.cc +++ b/src/libs/stdc++/legacy/streambuf.cc @@ -40,12 +40,6 @@ void streambuf::_un_link() { _IO_un_link(reinterpret_cast<_IO_FILE_plus*>(this)) void streambuf::_link_in() { _IO_link_in(reinterpret_cast<_IO_FILE_plus*>(this)); } -int streambuf::switch_to_get_mode() -{ return _IO_switch_to_get_mode(this); } - -void streambuf::free_backup_area() -{ _IO_free_backup_area(this); } - #if 0 int streambuf::switch_to_put_mode() { return _IO_:switch_to_put_mode(this); } @@ -339,11 +333,6 @@ int streambuf::seekmark(streammarker& mark, int delta /* = 0 */) return _IO_seekmark(this, &mark, delta); } -void streambuf::unsave_markers() -{ - _IO_unsave_markers(this); -} - int ios::readable() { return !(rdbuf()->_flags & _IO_NO_READS); } int ios::writable() { return !(rdbuf()->_flags & _IO_NO_WRITES); } int ios::is_open() { return rdbuf()