1 From: Till Kamppeter <till.kamppeter@gmail.com>
2 Date: Fri, 22 Jul 2016 09:33:04 +0200
3 Subject: Workaround patch for missing Python3 transition of the old
4 (pre-USB-storage) photo memory card support (pcardext) as this part builds
5 in Python3 environments but with pointer-related warnings which are fatal
6 errors for Ubuntu's build servers. The patch silences the warnings but the
7 memory card support is dropped in Python3 environments. This patch is
8 supplied by the HPLIP upstream developers and will be replaced by a more
9 proper solution in the next upstream release of HPLIP (see LP: #1275353)
12 pcard/pcardext/pcardext.c | 59 +++++++++++++++++++++++++++++++++++++----------
13 pcard/photocard.py | 2 +-
15 3 files changed, 53 insertions(+), 13 deletions(-)
17 diff --git a/pcard/pcardext/pcardext.c b/pcard/pcardext/pcardext.c
18 index c1a8273..37d979b 100644
19 --- a/pcard/pcardext/pcardext.c
20 +++ b/pcard/pcardext/pcardext.c
21 @@ -20,7 +20,7 @@ pcardext - Python extension for HP photocard services
28 \*****************************************************************************/
30 @@ -38,9 +38,37 @@ typedef int Py_ssize_t;
34 +#if PY_MAJOR_VERSION >= 3
35 + #define MOD_ERROR_VAL NULL
36 + #define MOD_SUCCESS_VAL(val) val
37 + #define MOD_INIT(name) PyMODINIT_FUNC PyInit_##name(void)
38 + #define PyInt_AS_LONG PyLong_AS_LONG
39 + #define MOD_DEF(ob, name, doc, methods) \
40 + static struct PyModuleDef moduledef = { \
41 + PyModuleDef_HEAD_INIT, name, doc, -1, methods, }; \
42 + ob = PyModule_Create(&moduledef);
45 + #define PY_String_Bytes PyBytes_FromStringAndSize
46 + #define PY_AsString_Bytes PyBytes_AsStringAndSize
49 + #define MOD_ERROR_VAL
50 + #define MOD_SUCCESS_VAL(val)
51 + #define MOD_INIT(name) void init##name(void)
52 + #define MOD_DEF(ob, name, doc, methods) \
53 + ob = Py_InitModule3(name, methods, doc);
55 + #define PY_String_Bytes PyString_FromStringAndSize
56 + #define PY_AsString_Bytes PyString_AsStringAndSize
60 PyObject * readsectorFunc = NULL;
61 PyObject * writesectorFunc = NULL;
65 int ReadSector(int sector, int nsector, void *buf, int size)
68 @@ -56,9 +84,13 @@ int ReadSector(int sector, int nsector, void *buf, int size)
72 - PyString_AsStringAndSize( result, &result_str, &len );
74 + //PyString_AsStringAndSize( result, &result_str, &len );
75 + //PyBytes_AsStringAndSize( result, &result_str, &len );
76 + PY_AsString_Bytes( result, &result_str, &len );
78 - if( len < nsector*FAT_HARDSECT )
80 + if( len < nsector*FAT_HARDSECT )
84 @@ -205,7 +237,9 @@ PyObject * pcardext_read( PyObject * self, PyObject * args )
86 if( FatReadFileExt( name, offset, len, buffer ) == len )
88 - return PyString_FromStringAndSize( (char *)buffer, len );
89 + // return PyString_FromStringAndSize( (char *)buffer, len );
90 + return PY_String_Bytes( (char *)buffer, len );
91 + // return PyBytes_FromStringAndSize( (char *)buffer, len );
95 @@ -233,14 +267,15 @@ static PyMethodDef pcardext_methods[] =
97 static char pcardext_documentation[] = "Python extension for HP photocard services";
99 -void initpcardext( void )
101 - PyObject * mod = Py_InitModule4( "pcardext", pcardext_methods,
102 - pcardext_documentation, (PyObject*)NULL,
103 - PYTHON_API_VERSION );
107 +MOD_INIT(pcardext) {
110 + MOD_DEF(mod, "pcardext", pcardext_documentation, pcardext_methods);
112 + return MOD_ERROR_VAL;
114 + return MOD_SUCCESS_VAL(mod);
119 diff --git a/unload.py b/unload.py
120 index 3fdd5a3..ce8b069 100755
123 @@ -44,6 +44,11 @@ except ImportError:
127 +from base.sixext import PY3
129 + log.error("This functionality is not spported in python3 environment.")
132 from base import device, utils, tui, module
133 from prnt import cups