sharkcz / rpms / calibre

Forked from rpms/calibre 4 years ago
Clone
Blob Blame History Raw
From 05a852817487dc8432fbb88a6b56472963204867 Mon Sep 17 00:00:00 2001
From: Kovid Goyal <kovid@kovidgoyal.net>
Date: Wed, 31 Jul 2019 16:28:04 +0530
Subject: [PATCH 32/71] Simplify podofo str->unicode conversion

---
 src/calibre/utils/podofo/doc.cpp   | 9 +--------
 src/calibre/utils/podofo/utils.cpp | 3 +--
 2 files changed, 2 insertions(+), 10 deletions(-)

diff --git a/src/calibre/utils/podofo/doc.cpp b/src/calibre/utils/podofo/doc.cpp
index 164bc17cb7..8eb48d97f9 100644
--- a/src/calibre/utils/podofo/doc.cpp
+++ b/src/calibre/utils/podofo/doc.cpp
@@ -394,7 +394,6 @@ PDFDoc_version_getter(PDFDoc *self, void *closure) {
 static PyObject *
 PDFDoc_getter(PDFDoc *self, int field)
 {
-    PyObject *ans;
     PdfString s;
     PdfInfo *info = self->doc->GetInfo();
     if (info == NULL) {
@@ -419,13 +418,7 @@ PDFDoc_getter(PDFDoc *self, int field)
             return NULL;
     }
 
-    ans = podofo_convert_pdfstring(s);
-    if (ans == NULL) {PyErr_NoMemory(); return NULL;}
-    PyObject *uans = PyUnicode_FromEncodedObject(ans, "utf-8", "replace");
-    Py_DECREF(ans);
-    if (uans == NULL) {return NULL;}
-    Py_INCREF(uans);
-    return uans;
+    return podofo_convert_pdfstring(s);
 }
 
 static int
diff --git a/src/calibre/utils/podofo/utils.cpp b/src/calibre/utils/podofo/utils.cpp
index da1272014e..6ecf1ec7fd 100644
--- a/src/calibre/utils/podofo/utils.cpp
+++ b/src/calibre/utils/podofo/utils.cpp
@@ -25,8 +25,7 @@ pdf::podofo_set_exception(const PdfError &err) {
 
 PyObject *
 pdf::podofo_convert_pdfstring(const PdfString &s) {
-    std::string raw = s.GetStringUtf8();
-	return PyBytes_FromStringAndSize(raw.c_str(), raw.length());
+    return PyUnicode_FromString(s.GetStringUtf8().c_str());
 }
 
 PdfString *