archrelease: copy trunk to extra-x86_64
[arch-packages.git] / hplip / trunk / python3.diff
blob636d165c11e2959f39d1cd0b062ec0e09ce8e570
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)
11 ---
12 pcard/pcardext/pcardext.c | 59 +++++++++++++++++++++++++++++++++++++----------
13 pcard/photocard.py | 2 +-
14 unload.py | 5 ++++
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
22 Requires:
23 Python 2.2+
25 -Author: Don Welch
26 +Author: Don Welch
28 \*****************************************************************************/
30 @@ -38,9 +38,37 @@ typedef int Py_ssize_t;
32 int verbose=0;
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
48 +#else
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
58 +#endif
60 PyObject * readsectorFunc = NULL;
61 PyObject * writesectorFunc = NULL;
65 int ReadSector(int sector, int nsector, void *buf, int size)
67 PyObject * result;
68 @@ -56,9 +84,13 @@ int ReadSector(int sector, int nsector, void *buf, int size)
69 if( result )
71 Py_ssize_t len = 0;
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 )
82 goto abort;
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 );
93 else
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 );
105 - if (mod == NULL)
106 - return;
107 +MOD_INIT(pcardext) {
109 + PyObject* mod ;
110 + MOD_DEF(mod, "pcardext", pcardext_documentation, pcardext_methods);
111 + if (mod == NULL)
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
121 --- a/unload.py
122 +++ b/unload.py
123 @@ -44,6 +44,11 @@ except ImportError:
125 # Local
126 from base.g import *
127 +from base.sixext import PY3
128 +if PY3:
129 + log.error("This functionality is not spported in python3 environment.")
130 + sys.exit(1)
132 from base import device, utils, tui, module
133 from prnt import cups