summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--TODO4
-rw-r--r--include/qpdf/InputSource.hh10
-rw-r--r--libqpdf/FileInputSource.cc2
-rw-r--r--libqpdf/QPDF.cc6
-rw-r--r--libqpdf/QPDFTokenizer.cc2
-rw-r--r--libtests/closed_file_input_source.cc18
-rw-r--r--manual/qpdf-manual.xml22
8 files changed, 24 insertions, 49 deletions
diff --git a/ChangeLog b/ChangeLog
index a173ff00..edc4ecce 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -81,15 +81,6 @@
disables passing -rpath to the linker when building shared
libraries with libtool. Fixes #422.
-2020-10-18 Jay Berkenbilt <ejb@ql.org>
-
- * Note that InputSource::unreadCh is deprecated and will be
- removed in qpdf 11. Use seek(-1, SEEK_CUR) instead. This is what
- it has always effectively done with some input sources and some
- operating systems which don't allow unreading other than the most
- recently read character. InputSource::unreadCh is no longer used
- internally within libqpdf.
-
2020-10-16 Jay Berkenbilt <ejb@ql.org>
* Accept pull request that improves how the Windows native crypto
diff --git a/TODO b/TODO
index 80dbb9a9..29bb38ab 100644
--- a/TODO
+++ b/TODO
@@ -157,10 +157,6 @@ ABI Changes
This is a list of changes to make next time there is an ABI change.
Comments appear in the code prefixed by "ABI"
-* Consider removing InputSource::unreadCh. Maybe we can declare it
- final and delete so it will be forced to be removed from derived
- classes.
-
C++-11
======
diff --git a/include/qpdf/InputSource.hh b/include/qpdf/InputSource.hh
index 22e3abcd..02254bb3 100644
--- a/include/qpdf/InputSource.hh
+++ b/include/qpdf/InputSource.hh
@@ -85,14 +85,12 @@ class QPDF_DLL_CLASS InputSource
virtual size_t read(char* buffer, size_t length) = 0;
// Note: you can only unread the character you just read. The
- // specific character is ignored by some implementations. unreadCh
- // will be removed from the API in qpdf 11.
+ // specific character is ignored by some implementations, and the
+ // implementation doesn't check this. Use of unreadCh is
+ // semantically equivalent to seek(-1, SEEK_CUR) but is much more
+ // efficient.
virtual void unreadCh(char ch) = 0;
- // ABI: delete unreadCh, and direct people to seek backward by 1
- // character instead.
- // virtual void unreadCh(char ch) final = delete;
-
protected:
qpdf_offset_t last_offset;
diff --git a/libqpdf/FileInputSource.cc b/libqpdf/FileInputSource.cc
index 5ec6a170..cd8feda4 100644
--- a/libqpdf/FileInputSource.cc
+++ b/libqpdf/FileInputSource.cc
@@ -80,7 +80,7 @@ FileInputSource::findAndSkipNextEOL()
}
else if (! ((ch == '\r') || (ch == '\n')))
{
- this->seek(-1, SEEK_CUR);
+ this->unreadCh(ch);
done = true;
}
}
diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc
index d256e444..d4d7d519 100644
--- a/libqpdf/QPDF.cc
+++ b/libqpdf/QPDF.cc
@@ -632,7 +632,7 @@ QPDF::read_xref(qpdf_offset_t xref_offset)
}
else
{
- this->m->file->seek(-1, SEEK_CUR);
+ this->m->file->unreadCh(ch);
done = true;
}
}
@@ -1604,7 +1604,7 @@ QPDF::readObject(PointerHolder<InputSource> input,
// start reading stream data in spite
// of not having seen a newline.
QTC::TC("qpdf", "QPDF stream with CR only");
- input->seek(-1, SEEK_CUR);
+ input->unreadCh(ch);
warn(QPDFExc(
qpdf_e_damaged_pdf,
input->getName(),
@@ -1629,7 +1629,7 @@ QPDF::readObject(PointerHolder<InputSource> input,
else
{
QTC::TC("qpdf", "QPDF stream without newline");
- input->seek(-1, SEEK_CUR);
+ input->unreadCh(ch);
warn(QPDFExc(qpdf_e_damaged_pdf, input->getName(),
this->m->last_object_description,
input->tell(),
diff --git a/libqpdf/QPDFTokenizer.cc b/libqpdf/QPDFTokenizer.cc
index 4f2e2153..4217575c 100644
--- a/libqpdf/QPDFTokenizer.cc
+++ b/libqpdf/QPDFTokenizer.cc
@@ -855,7 +855,7 @@ QPDFTokenizer::readToken(PointerHolder<InputSource> input,
if (unread_char)
{
- input->seek(-1, SEEK_CUR);
+ input->unreadCh(char_to_unread);
}
if (token.getType() != tt_eof)
diff --git a/libtests/closed_file_input_source.cc b/libtests/closed_file_input_source.cc
index 2d58cf80..f3e4f2ac 100644
--- a/libtests/closed_file_input_source.cc
+++ b/libtests/closed_file_input_source.cc
@@ -27,10 +27,22 @@ void do_tests(InputSource* is)
check("tell after findAndSkipNextEOL", 522 == is->tell());
char b[1];
b[0] = '\0';
- is->seek(-1, SEEK_CUR);
- check("read previous character", 1 == is->read(b, 1));
+#ifdef _WIN32
+ // Empirical evidence, and the passage of the rest of the qpdf
+ // test suite, suggest that this is working on Windows in the way
+ // that it needs to work. If this ifdef is made to be true on
+ // Windows, it passes with ClosedFileInputSource but not with
+ // FileInputSource, which doesn't make any sense since
+ // ClosedFileInputSource is calling FileInputSource to do its
+ // work.
+ is->seek(521, SEEK_SET);
+ is->read(b, 1);
+#else
+ is->unreadCh('\n');
+ check("read unread character", 1 == is->read(b, 1));
check("got character", '\n' == b[0]);
- check("last offset after read previous", 521 == is->getLastOffset());
+#endif
+ check("last offset after read unread", 521 == is->getLastOffset());
is->seek(0, SEEK_END);
check("tell at end", 556 == is->tell());
is->seek(-25, SEEK_END);
diff --git a/manual/qpdf-manual.xml b/manual/qpdf-manual.xml
index 17b778b9..e3afc704 100644
--- a/manual/qpdf-manual.xml
+++ b/manual/qpdf-manual.xml
@@ -4967,28 +4967,6 @@ print "\n";
</listitem>
</itemizedlist>
</listitem>
- <listitem>
- <para>
- Notice of upcoming API change
- </para>
- <itemizedlist>
- <listitem>
- <para>
- The method <function>InputSource::unreadCh(unsigned
- char)</function> is deprecated and will be removed in qpdf
- 11. It has never worked properly to pass a character to
- <function>unreadCh</function> other than the most recently
- read character. If you happen to be deriving a class from
- <type>InputSource</type>, just implement
- <function>unreadCh</function> to seek backward by one
- character if the current position is greater than 0. If you
- are calling this in your own code, replacing with
- <literal>seek(-1, SEEK_CUR)</literal> should work in all
- cases.
- </para>
- </listitem>
- </itemizedlist>
- </listitem>
</itemizedlist>
</listitem>
</varlistentry>