[poppler] glib/poppler-attachment.cc glib/poppler-attachment.h glib/poppler-document.cc glib/poppler-document.h glib/poppler-media.cc glib/poppler-media.h test/gtk-test.cc

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Dec 15 16:54:40 UTC 2021


 glib/poppler-attachment.cc |    4 ++++
 glib/poppler-attachment.h  |    2 ++
 glib/poppler-document.cc   |   19 ++++++++++++++-----
 glib/poppler-document.h    |    6 ++++++
 glib/poppler-media.cc      |    4 ++++
 glib/poppler-media.h       |    2 ++
 test/gtk-test.cc           |    7 ++++++-
 7 files changed, 38 insertions(+), 6 deletions(-)

New commits:
commit eae2b1f08c87979385c9c0d0ad4b4f7a3f6e0802
Author: Christian Persch <chpe at src.gnome.org>
Date:   Wed Dec 8 13:13:29 2021 +0100

    glib: Remove FD-taking functions on windows
    
    They don't compile, and are not useful on windows anyway. Remove the
    functions completely, not just stub out their implementation, since
    otherwise the API contract of consuming the FD would be violated.
    
    https://gitlab.freedesktop.org/poppler/poppler/-/issues/1180

diff --git a/glib/poppler-attachment.cc b/glib/poppler-attachment.cc
index 2af11044..f97cb5b8 100644
--- a/glib/poppler-attachment.cc
+++ b/glib/poppler-attachment.cc
@@ -275,6 +275,8 @@ gboolean poppler_attachment_save(PopplerAttachment *attachment, const char *file
     return result;
 }
 
+#ifndef G_OS_WIN32
+
 /**
  * poppler_attachment_save_to_fd:
  * @attachment: A #PopplerAttachment.
@@ -319,6 +321,8 @@ gboolean poppler_attachment_save_to_fd(PopplerAttachment *attachment, int fd, GE
     return result;
 }
 
+#endif /* !G_OS_WIN32 */
+
 #define BUF_SIZE 1024
 
 /**
diff --git a/glib/poppler-attachment.h b/glib/poppler-attachment.h
index b04b3f7b..664a566e 100644
--- a/glib/poppler-attachment.h
+++ b/glib/poppler-attachment.h
@@ -111,8 +111,10 @@ POPPLER_PUBLIC
 gsize poppler_attachment_get_size(PopplerAttachment *attachment);
 POPPLER_PUBLIC
 gboolean poppler_attachment_save(PopplerAttachment *attachment, const char *filename, GError **error);
+#ifndef G_OS_WIN32
 POPPLER_PUBLIC
 gboolean poppler_attachment_save_to_fd(PopplerAttachment *attachment, int fd, GError **error);
+#endif
 POPPLER_PUBLIC
 gboolean poppler_attachment_save_to_callback(PopplerAttachment *attachment, PopplerAttachmentSaveFunc save_func, gpointer user_data, GError **error);
 
diff --git a/glib/poppler-document.cc b/glib/poppler-document.cc
index 36c52be9..6a226919 100644
--- a/glib/poppler-document.cc
+++ b/glib/poppler-document.cc
@@ -415,6 +415,8 @@ PopplerDocument *poppler_document_new_from_gfile(GFile *file, const char *passwo
     return document;
 }
 
+#ifndef G_OS_WIN32
+
 /**
  * poppler_document_new_from_fd:
  * @fd: a valid file descriptor
@@ -435,7 +437,6 @@ PopplerDocument *poppler_document_new_from_gfile(GFile *file, const char *passwo
  */
 PopplerDocument *poppler_document_new_from_fd(int fd, const char *password, GError **error)
 {
-#ifndef G_OS_WIN32
     struct stat statbuf;
     int flags;
     BaseStream *stream;
@@ -490,12 +491,10 @@ PopplerDocument *poppler_document_new_from_fd(int fd, const char *password, GErr
     delete password_g;
 
     return _poppler_document_new_from_pdfdoc(std::move(initer), newDoc, error);
-#else
-    g_set_error_literal(error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Not supported on win32");
-    return nullptr;
-#endif /* G_OS_WIN32 */
 }
 
+#endif /* !G_OS_WIN32 */
+
 static gboolean handle_save_error(int err_code, GError **error)
 {
     switch (err_code) {
@@ -584,6 +583,8 @@ gboolean poppler_document_save_a_copy(PopplerDocument *document, const char *uri
     return retval;
 }
 
+#ifndef G_OS_WIN32
+
 /**
  * poppler_document_save_to_fd:
  * @document: a #PopplerDocument
@@ -632,6 +633,8 @@ gboolean poppler_document_save_to_fd(PopplerDocument *document, int fd, gboolean
     return handle_save_error(rv, error);
 }
 
+#endif /* !G_OS_WIN32 */
+
 static void poppler_document_finalize(GObject *object)
 {
     PopplerDocument *document = POPPLER_DOCUMENT(object);
@@ -3458,8 +3461,10 @@ static void poppler_ps_file_finalize(GObject *object)
     delete ps_file->out;
     g_object_unref(ps_file->document);
     g_free(ps_file->filename);
+#ifndef G_OS_WIN32
     if (ps_file->fd != -1)
         close(ps_file->fd);
+#endif /* !G_OS_WIN32 */
 
     G_OBJECT_CLASS(poppler_ps_file_parent_class)->finalize(object);
 }
@@ -3492,6 +3497,8 @@ PopplerPSFile *poppler_ps_file_new(PopplerDocument *document, const char *filena
     return ps_file;
 }
 
+#ifndef G_OS_WIN32
+
 /**
  * poppler_ps_file_new_fd:
  * @document: a #PopplerDocument
@@ -3524,6 +3531,8 @@ PopplerPSFile *poppler_ps_file_new_fd(PopplerDocument *document, int fd, int fir
     return ps_file;
 }
 
+#endif /* !G_OS_WIN32 */
+
 /**
  * poppler_ps_file_set_paper_size:
  * @ps_file: a PopplerPSFile which was not yet printed to.
diff --git a/glib/poppler-document.h b/glib/poppler-document.h
index c6a3ef0f..595c2de7 100644
--- a/glib/poppler-document.h
+++ b/glib/poppler-document.h
@@ -302,14 +302,18 @@ POPPLER_PUBLIC
 PopplerDocument *poppler_document_new_from_stream(GInputStream *stream, goffset length, const char *password, GCancellable *cancellable, GError **error);
 POPPLER_PUBLIC
 PopplerDocument *poppler_document_new_from_gfile(GFile *file, const char *password, GCancellable *cancellable, GError **error);
+#ifndef G_OS_WIN32
 POPPLER_PUBLIC
 PopplerDocument *poppler_document_new_from_fd(int fd, const char *password, GError **error);
+#endif
 POPPLER_PUBLIC
 gboolean poppler_document_save(PopplerDocument *document, const char *uri, GError **error);
 POPPLER_PUBLIC
 gboolean poppler_document_save_a_copy(PopplerDocument *document, const char *uri, GError **error);
+#ifndef G_OS_WIN32
 POPPLER_PUBLIC
 gboolean poppler_document_save_to_fd(PopplerDocument *document, int fd, gboolean include_changes, GError **error);
+#endif
 POPPLER_PUBLIC
 gboolean poppler_document_get_id(PopplerDocument *document, gchar **permanent_id, gchar **update_id);
 POPPLER_PUBLIC
@@ -504,8 +508,10 @@ POPPLER_PUBLIC
 GType poppler_ps_file_get_type(void) G_GNUC_CONST;
 POPPLER_PUBLIC
 PopplerPSFile *poppler_ps_file_new(PopplerDocument *document, const char *filename, int first_page, int n_pages);
+#ifndef G_OS_WIN32
 POPPLER_PUBLIC
 PopplerPSFile *poppler_ps_file_new_fd(PopplerDocument *document, int fd, int first_page, int n_pages);
+#endif
 POPPLER_PUBLIC
 void poppler_ps_file_set_paper_size(PopplerPSFile *ps_file, double width, double height);
 POPPLER_PUBLIC
diff --git a/glib/poppler-media.cc b/glib/poppler-media.cc
index 9cc44594..db1334ab 100644
--- a/glib/poppler-media.cc
+++ b/glib/poppler-media.cc
@@ -277,6 +277,8 @@ gboolean poppler_media_save(PopplerMedia *poppler_media, const char *filename, G
     return result;
 }
 
+#ifndef G_OS_WIN32
+
 /**
  * poppler_media_save_to_fd:
  * @poppler_media: a #PopplerMedia
@@ -321,6 +323,8 @@ gboolean poppler_media_save_to_fd(PopplerMedia *poppler_media, int fd, GError **
     return result;
 }
 
+#endif /* !G_OS_WIN32 */
+
 #define BUF_SIZE 1024
 
 /**
diff --git a/glib/poppler-media.h b/glib/poppler-media.h
index 3d54c785..72094b38 100644
--- a/glib/poppler-media.h
+++ b/glib/poppler-media.h
@@ -68,8 +68,10 @@ POPPLER_PUBLIC
 gfloat poppler_media_get_repeat_count(PopplerMedia *poppler_media);
 POPPLER_PUBLIC
 gboolean poppler_media_save(PopplerMedia *poppler_media, const char *filename, GError **error);
+#ifndef G_OS_WIN32
 POPPLER_PUBLIC
 gboolean poppler_media_save_to_fd(PopplerMedia *poppler_media, int fd, GError **error);
+#endif
 POPPLER_PUBLIC
 gboolean poppler_media_save_to_callback(PopplerMedia *poppler_media, PopplerMediaSaveFunc save_func, gpointer user_data, GError **error);
 
diff --git a/test/gtk-test.cc b/test/gtk-test.cc
index 4c09a8d6..1a847f1b 100644
--- a/test/gtk-test.cc
+++ b/test/gtk-test.cc
@@ -26,7 +26,9 @@ static const char **file_arguments = nullptr;
 static const GOptionEntry options[] = { { "cairo", 'c', 0, G_OPTION_ARG_NONE, &cairo_output, "Cairo Output Device", nullptr },
                                         { "splash", 's', 0, G_OPTION_ARG_NONE, &splash_output, "Splash Output Device", nullptr },
                                         { "page", 'p', 0, G_OPTION_ARG_INT, &requested_page, "Page number", "PAGE" },
+#ifndef G_OS_WIN32
                                         { "fd", 'f', 0, G_OPTION_ARG_NONE, &args_are_fds, "File descriptors", nullptr },
+#endif
                                         { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &file_arguments, nullptr, "PDF-FILES…" },
                                         {} };
 
@@ -344,6 +346,7 @@ int main(int argc, char *argv[])
         const char *arg;
 
         arg = file_arguments[i];
+#ifndef G_OS_WIN32
         if (args_are_fds) {
             char *end;
             gint64 v;
@@ -356,7 +359,9 @@ int main(int argc, char *argv[])
             } else {
                 doc = poppler_document_new_from_fd(int(v), nullptr, &error);
             }
-        } else {
+        } else
+#endif /* !G_OS_WIN32 */
+        {
             file = g_file_new_for_commandline_arg(arg);
             doc = poppler_document_new_from_gfile(file, nullptr, nullptr, &error);
             if (!doc) {


More information about the poppler mailing list