@@ -35,12 +35,10 @@ void *new_rd_source(PyObject *obj) {
35
35
36
36
*/
37
37
38
- int del_rd_source (void * rds ) {
38
+ void del_rd_source (void * rds ) {
39
39
Py_XDECREF (RDS (rds )-> obj );
40
40
Py_XDECREF (RDS (rds )-> buffer );
41
41
free (rds );
42
-
43
- return 0 ;
44
42
}
45
43
46
44
/*
@@ -49,26 +47,20 @@ int del_rd_source(void *rds) {
49
47
50
48
*/
51
49
52
- void * buffer_rd_bytes (void * source , size_t nbytes , size_t * bytes_read ,
50
+ char * buffer_rd_bytes (void * source , size_t nbytes , size_t * bytes_read ,
53
51
int * status , const char * encoding_errors ) {
54
- PyGILState_STATE state ;
55
- PyObject * result , * func , * args , * tmp ;
56
-
57
- void * retval ;
58
-
59
- size_t length ;
60
52
rd_source * src = RDS (source );
61
- state = PyGILState_Ensure ();
53
+ PyGILState_STATE state = PyGILState_Ensure ();
62
54
63
55
/* delete old object */
64
56
Py_XDECREF (src -> buffer );
65
57
src -> buffer = NULL ;
66
- args = Py_BuildValue ("(i)" , nbytes );
58
+ PyObject * args = Py_BuildValue ("(i)" , nbytes );
67
59
68
- func = PyObject_GetAttrString (src -> obj , "read" );
60
+ PyObject * func = PyObject_GetAttrString (src -> obj , "read" );
69
61
70
62
/* Note: PyObject_CallObject requires the GIL */
71
- result = PyObject_CallObject (func , args );
63
+ PyObject * result = PyObject_CallObject (func , args );
72
64
Py_XDECREF (args );
73
65
Py_XDECREF (func );
74
66
@@ -78,7 +70,7 @@ void *buffer_rd_bytes(void *source, size_t nbytes, size_t *bytes_read,
78
70
* status = CALLING_READ_FAILED ;
79
71
return NULL ;
80
72
} else if (!PyBytes_Check (result )) {
81
- tmp = PyUnicode_AsEncodedString (result , "utf-8" , encoding_errors );
73
+ PyObject * tmp = PyUnicode_AsEncodedString (result , "utf-8" , encoding_errors );
82
74
Py_DECREF (result );
83
75
if (tmp == NULL ) {
84
76
PyGILState_Release (state );
@@ -87,7 +79,7 @@ void *buffer_rd_bytes(void *source, size_t nbytes, size_t *bytes_read,
87
79
result = tmp ;
88
80
}
89
81
90
- length = PySequence_Length (result );
82
+ const size_t length = PySequence_Length (result );
91
83
92
84
if (length == 0 )
93
85
* status = REACHED_EOF ;
@@ -96,7 +88,7 @@ void *buffer_rd_bytes(void *source, size_t nbytes, size_t *bytes_read,
96
88
97
89
/* hang on to the Python object */
98
90
src -> buffer = result ;
99
- retval = ( void * ) PyBytes_AsString (result );
91
+ char * retval = PyBytes_AsString (result );
100
92
101
93
PyGILState_Release (state );
102
94
0 commit comments