blob: 194deb8b81f7ec0c3e9486b6757f18c6ec5b31ed [file] [log] [blame]
Andrew Geissler87f5cff2022-09-30 13:13:31 -05001From: Till Kamppeter <till.kamppeter@gmail.com>
2Date: Fri, 22 Jul 2016 09:33:04 +0200
3Subject: 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)
10
11---
Patrick Williams520786c2023-06-25 16:20:36 -050012Upstream-Status: Pending
13
Andrew Geissler87f5cff2022-09-30 13:13:31 -050014 pcard/pcardext/pcardext.c | 59 +++++++++++++++++++++++++++++++++++++----------
15 pcard/photocard.py | 2 +-
16 unload.py | 5 ++++
17 3 files changed, 53 insertions(+), 13 deletions(-)
18
19--- a/pcard/pcardext/pcardext.c
20+++ b/pcard/pcardext/pcardext.c
21@@ -20,7 +20,7 @@ pcardext - Python extension for HP photo
22 Requires:
23 Python 2.2+
24
25-Author: Don Welch
26+Author: Don Welch
27
28 \*****************************************************************************/
29
30@@ -41,9 +41,37 @@ typedef int Py_ssize_t;
31
32 int verbose=0;
33
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);
43+
44+
45+ #define PY_String_Bytes PyBytes_FromStringAndSize
46+ #define PY_AsString_Bytes PyBytes_AsStringAndSize
47+
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);
54+
55+ #define PY_String_Bytes PyString_FromStringAndSize
56+ #define PY_AsString_Bytes PyString_AsStringAndSize
57+
58+#endif
59+
60 PyObject * readsectorFunc = NULL;
61 PyObject * writesectorFunc = NULL;
62
63+
64+
65 int ReadSector(int sector, int nsector, void *buf, int size)
66 {
67 PyObject * result;
68@@ -59,9 +87,13 @@ int ReadSector(int sector, int nsector,
69 if( result )
70 {
71 Py_ssize_t len = 0;
72- PyString_AsStringAndSize( result, &result_str, &len );
73+
74+ //PyString_AsStringAndSize( result, &result_str, &len );
75+ //PyBytes_AsStringAndSize( result, &result_str, &len );
76+ PY_AsString_Bytes( result, &result_str, &len );
77
78- if( len < nsector*FAT_HARDSECT )
79+
80+ if( len < nsector*FAT_HARDSECT )
81 {
82 goto abort;
83 }
84@@ -208,7 +240,9 @@ PyObject * pcardext_read( PyObject * sel
85
86 if( FatReadFileExt( name, offset, len, buffer ) == len )
87 {
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 );
92 }
93 else
94 {
95@@ -236,14 +270,15 @@ static PyMethodDef pcardext_methods[] =
96
97 static char pcardext_documentation[] = "Python extension for HP photocard services";
98
99-void initpcardext( void )
100-{
101- PyObject * mod = Py_InitModule4( "pcardext", pcardext_methods,
102- pcardext_documentation, (PyObject*)NULL,
103- PYTHON_API_VERSION );
104-
105- if (mod == NULL)
106- return;
107+MOD_INIT(pcardext) {
108+
109+ PyObject* mod ;
110+ MOD_DEF(mod, "pcardext", pcardext_documentation, pcardext_methods);
111+ if (mod == NULL)
112+ return MOD_ERROR_VAL;
113+
114+ return MOD_SUCCESS_VAL(mod);
115+
116 }
117
118
119--- a/unload.py
120+++ b/unload.py
121@@ -44,6 +44,11 @@ except ImportError:
122
123 # Local
124 from base.g import *
125+from base.sixext import PY3
126+if PY3:
127+ log.error("This functionality is not spported in python3 environment.")
128+ sys.exit(1)
129+
130 from base import device, utils, tui, module
131 from prnt import cups
132