Andrew Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame^] | 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) |
| 10 | |
| 11 | --- |
| 12 | pcard/pcardext/pcardext.c | 59 +++++++++++++++++++++++++++++++++++++---------- |
| 13 | pcard/photocard.py | 2 +- |
| 14 | unload.py | 5 ++++ |
| 15 | 3 files changed, 53 insertions(+), 13 deletions(-) |
| 16 | |
| 17 | --- a/pcard/pcardext/pcardext.c |
| 18 | +++ b/pcard/pcardext/pcardext.c |
| 19 | @@ -20,7 +20,7 @@ pcardext - Python extension for HP photo |
| 20 | Requires: |
| 21 | Python 2.2+ |
| 22 | |
| 23 | -Author: Don Welch |
| 24 | +Author: Don Welch |
| 25 | |
| 26 | \*****************************************************************************/ |
| 27 | |
| 28 | @@ -41,9 +41,37 @@ typedef int Py_ssize_t; |
| 29 | |
| 30 | int verbose=0; |
| 31 | |
| 32 | +#if PY_MAJOR_VERSION >= 3 |
| 33 | + #define MOD_ERROR_VAL NULL |
| 34 | + #define MOD_SUCCESS_VAL(val) val |
| 35 | + #define MOD_INIT(name) PyMODINIT_FUNC PyInit_##name(void) |
| 36 | + #define PyInt_AS_LONG PyLong_AS_LONG |
| 37 | + #define MOD_DEF(ob, name, doc, methods) \ |
| 38 | + static struct PyModuleDef moduledef = { \ |
| 39 | + PyModuleDef_HEAD_INIT, name, doc, -1, methods, }; \ |
| 40 | + ob = PyModule_Create(&moduledef); |
| 41 | + |
| 42 | + |
| 43 | + #define PY_String_Bytes PyBytes_FromStringAndSize |
| 44 | + #define PY_AsString_Bytes PyBytes_AsStringAndSize |
| 45 | + |
| 46 | +#else |
| 47 | + #define MOD_ERROR_VAL |
| 48 | + #define MOD_SUCCESS_VAL(val) |
| 49 | + #define MOD_INIT(name) void init##name(void) |
| 50 | + #define MOD_DEF(ob, name, doc, methods) \ |
| 51 | + ob = Py_InitModule3(name, methods, doc); |
| 52 | + |
| 53 | + #define PY_String_Bytes PyString_FromStringAndSize |
| 54 | + #define PY_AsString_Bytes PyString_AsStringAndSize |
| 55 | + |
| 56 | +#endif |
| 57 | + |
| 58 | PyObject * readsectorFunc = NULL; |
| 59 | PyObject * writesectorFunc = NULL; |
| 60 | |
| 61 | + |
| 62 | + |
| 63 | int ReadSector(int sector, int nsector, void *buf, int size) |
| 64 | { |
| 65 | PyObject * result; |
| 66 | @@ -59,9 +87,13 @@ int ReadSector(int sector, int nsector, |
| 67 | if( result ) |
| 68 | { |
| 69 | Py_ssize_t len = 0; |
| 70 | - PyString_AsStringAndSize( result, &result_str, &len ); |
| 71 | + |
| 72 | + //PyString_AsStringAndSize( result, &result_str, &len ); |
| 73 | + //PyBytes_AsStringAndSize( result, &result_str, &len ); |
| 74 | + PY_AsString_Bytes( result, &result_str, &len ); |
| 75 | |
| 76 | - if( len < nsector*FAT_HARDSECT ) |
| 77 | + |
| 78 | + if( len < nsector*FAT_HARDSECT ) |
| 79 | { |
| 80 | goto abort; |
| 81 | } |
| 82 | @@ -208,7 +240,9 @@ PyObject * pcardext_read( PyObject * sel |
| 83 | |
| 84 | if( FatReadFileExt( name, offset, len, buffer ) == len ) |
| 85 | { |
| 86 | - return PyString_FromStringAndSize( (char *)buffer, len ); |
| 87 | + // return PyString_FromStringAndSize( (char *)buffer, len ); |
| 88 | + return PY_String_Bytes( (char *)buffer, len ); |
| 89 | + // return PyBytes_FromStringAndSize( (char *)buffer, len ); |
| 90 | } |
| 91 | else |
| 92 | { |
| 93 | @@ -236,14 +270,15 @@ static PyMethodDef pcardext_methods[] = |
| 94 | |
| 95 | static char pcardext_documentation[] = "Python extension for HP photocard services"; |
| 96 | |
| 97 | -void initpcardext( void ) |
| 98 | -{ |
| 99 | - PyObject * mod = Py_InitModule4( "pcardext", pcardext_methods, |
| 100 | - pcardext_documentation, (PyObject*)NULL, |
| 101 | - PYTHON_API_VERSION ); |
| 102 | - |
| 103 | - if (mod == NULL) |
| 104 | - return; |
| 105 | +MOD_INIT(pcardext) { |
| 106 | + |
| 107 | + PyObject* mod ; |
| 108 | + MOD_DEF(mod, "pcardext", pcardext_documentation, pcardext_methods); |
| 109 | + if (mod == NULL) |
| 110 | + return MOD_ERROR_VAL; |
| 111 | + |
| 112 | + return MOD_SUCCESS_VAL(mod); |
| 113 | + |
| 114 | } |
| 115 | |
| 116 | |
| 117 | --- a/unload.py |
| 118 | +++ b/unload.py |
| 119 | @@ -44,6 +44,11 @@ except ImportError: |
| 120 | |
| 121 | # Local |
| 122 | from base.g import * |
| 123 | +from base.sixext import PY3 |
| 124 | +if PY3: |
| 125 | + log.error("This functionality is not spported in python3 environment.") |
| 126 | + sys.exit(1) |
| 127 | + |
| 128 | from base import device, utils, tui, module |
| 129 | from prnt import cups |
| 130 | |