hplip/pcardext-python3-fixes.patch
Martin Wilck 4becc237ee Accepting request 589977 from home:mwilck:hplip
- photocard.py: fixed broken import statement (bsc#1071255) 
  * added photocard-fix-import-error-for-pcardext.patch
  * spec file: fixed dependency for dbus-1-python (Leap42.2)

- Use python3 on tumbleweed and SLE15/Leap15 (bsc#1071255)
  * add pcardext-python3-fixes.patch
  * add hplip-misc-missing-includes-and-definitions.patch
  * hp_ipp.h-add-missing-prototypes.patch
  * spec file: replace "/usr/bin/env python" and "/usr/bin/python" with
    desired interpreter
  * spec file: add py2/py3 selection macros
  * spec file: dropped python-openssl build dependency (not needed anymore)

OBS-URL: https://build.opensuse.org/request/show/589977
OBS-URL: https://build.opensuse.org/package/show/Printing/hplip?expand=0&rev=151
2018-03-22 09:45:27 +00:00

82 lines
2.1 KiB
Diff

From 74ed15a16e7564d0665afc68defbd6d03bdff21d Mon Sep 17 00:00:00 2001
From: Martin Wilck <mwilck@suse.com>
Date: Wed, 21 Mar 2018 23:55:12 +0100
Subject: [PATCH] pcardext: python3 fixes
---
pcard/pcardext/pcardext.c | 36 ++++++++++++++++++++++++++++++++++--
1 file changed, 34 insertions(+), 2 deletions(-)
diff --git a/pcard/pcardext/pcardext.c b/pcard/pcardext/pcardext.c
index c1a8273e4359..cdf260d62223 100644
--- a/pcard/pcardext/pcardext.c
+++ b/pcard/pcardext/pcardext.c
@@ -36,6 +36,12 @@ typedef int Py_ssize_t;
#define PY_SSIZE_T_MIN INT_MIN
#endif
+#if PY_MAJOR_VERSION >= 3
+#define PyString_AsStringAndSize PyBytes_AsStringAndSize
+#define PyString_FromStringAndSize PyBytes_FromStringAndSize
+#define PyInt_AS_LONG PyLong_AS_LONG
+#endif
+
int verbose=0;
PyObject * readsectorFunc = NULL;
@@ -78,8 +84,11 @@ int WriteSector(int sector, int nsector, void *buf, int size )
if( writesectorFunc )
{
+#if PY_MAJOR_VERSION >= 3
result = PyObject_CallFunction( writesectorFunc, "iis#", sector, nsector, buf, size );
-
+#else
+ result = PyObject_CallFunction( writesectorFunc, "iiy#", sector, nsector, buf, size );
+#endif
return PyInt_AS_LONG( result );
}
@@ -230,9 +239,31 @@ static PyMethodDef pcardext_methods[] =
{ NULL, NULL }
};
-
static char pcardext_documentation[] = "Python extension for HP photocard services";
+#if PY_MAJOR_VERSION >= 3
+static struct PyModuleDef moduledef = {
+ .m_base = PyModuleDef_HEAD_INIT,
+ .m_name = "pcardext",
+ .m_doc = pcardext_documentation,
+ .m_size = -1,
+ .m_methods = pcardext_methods,
+ .m_slots = NULL,
+ .m_traverse = NULL,
+ .m_clear = NULL,
+ .m_free = NULL,
+};
+
+PyMODINIT_FUNC
+PyInit_pcardext( void )
+{
+ PyObject *module = PyModule_Create2(&moduledef, PYTHON_API_VERSION);
+
+ return module;
+}
+
+#else
+
void initpcardext( void )
{
PyObject * mod = Py_InitModule4( "pcardext", pcardext_methods,
@@ -243,4 +274,5 @@ void initpcardext( void )
return;
}
+#endif
--
2.16.1