summaryrefslogtreecommitdiff
path: root/print/hplip/files/patch-pcard_pcardext_pcardext.c
blob: 2b6ea5eb61d3da5a7ae3295a8df524ce6e409e1a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
--- pcard/pcardext/pcardext.c.orig	2022-10-27 13:08:44 UTC
+++ pcard/pcardext/pcardext.c
@@ -59,7 +59,7 @@ int ReadSector(int sector, int nsector, void *buf, int
         if( result )
         {
             Py_ssize_t len = 0;
-            PyString_AsStringAndSize( result, &result_str, &len );
+            PyBytes_AsStringAndSize( result, &result_str, &len );
             
             if( len < nsector*FAT_HARDSECT )
             {
@@ -83,7 +83,7 @@ int WriteSector(int sector, int nsector, void *buf, in
     {
         result = PyObject_CallFunction( writesectorFunc, "iis#", sector, nsector, buf, size );
         
-        return PyInt_AS_LONG( result );
+        return PyLong_AS_LONG( result );
     }
 
     return 1;
@@ -208,7 +208,7 @@ PyObject * pcardext_read( PyObject * self, PyObject * 
     
     if( FatReadFileExt( name, offset, len, buffer ) == len )
     {
-        return PyString_FromStringAndSize( (char *)buffer, len );
+        return PyBytes_FromStringAndSize( (char *)buffer, len );
     }
     else
     {
@@ -234,16 +234,16 @@ static PyMethodDef pcardext_methods[] = 
 };  
 
 
-static char pcardext_documentation[] = "Python extension for HP photocard services";
+PyDoc_STRVAR(pcardext_documentation, "Python extension for HP photocard services");
 
-void initpcardext( void )
+static struct PyModuleDef pcardext_module = {
+    PyModuleDef_HEAD_INIT, "pcardext", pcardext_documentation, -1,
+    pcardext_methods,
+};
+
+PyMODINIT_FUNC PyInit_pcardext( void )
 {
-    PyObject * mod = Py_InitModule4( "pcardext", pcardext_methods, 
-                                     pcardext_documentation, (PyObject*)NULL, 
-                                     PYTHON_API_VERSION );
-                     
-    if (mod == NULL)
-      return;
+    return PyModule_Create(&pcardext_module);
 }