2626#include "decoder.h"
2727#include "python_funcs.h"
2828
29+ /******************************************************************************/
30+ /* NumPy 1.x/2.x compatibility macros */
31+ /******************************************************************************/
32+
33+ #ifndef PyDataType_ELSIZE
34+ #define PyDataType_ELSIZE (d ) ((d)->elsize)
35+ #endif
36+
37+ #ifndef PyDataType_TYPE_NUM
38+ #define PyDataType_TYPE_NUM (d ) ((d)->type_num)
39+ #endif
40+
2941/******************************************************************************/
3042
3143#define RECURSE_AND_RETURN_OR_BAIL (action , recurse_msg ) {\
@@ -150,9 +162,6 @@ static _soa_schema_t* _decode_soa_schema(_bjdata_decoder_buffer_t* buffer);
150162
151163/******************************************************************************/
152164
153- /* Returns new decoder buffer or NULL on failure (an exception will be set). Input must either support buffer interface
154- * or be callable. Currently only increases reference count for input parameter.
155- */
156165_bjdata_decoder_buffer_t * _bjdata_decoder_buffer_create (_bjdata_decoder_prefs_t * prefs , PyObject * input ,
157166 PyObject * seek ) {
158167 _bjdata_decoder_buffer_t * buffer ;
@@ -198,26 +207,19 @@ _bjdata_decoder_buffer_t* _bjdata_decoder_buffer_create(_bjdata_decoder_prefs_t*
198207 return NULL ;
199208}
200209
201- // Returns non-zero if buffer cleanup/finalisation failed and no other exception was set already
202210int _bjdata_decoder_buffer_free (_bjdata_decoder_buffer_t * * buffer ) {
203211 int failed = 0 ;
204212
205213 if (NULL != buffer && NULL != * buffer ) {
206214 if ((* buffer )-> view_set ) {
207- // In buffered mode, rewind to position in stream up to which actually read (rather than buffered)
208215 if (NULL != (* buffer )-> seek && (* buffer )-> view .len > (* buffer )-> pos ) {
209216 PyObject * type , * value , * traceback , * seek_result ;
210217
211- // preserve the previous exception, if set
212218 PyErr_Fetch (& type , & value , & traceback );
213219 seek_result = PyObject_CallFunction ((* buffer )-> seek , "nn" ,
214220 ((* buffer )-> pos - (* buffer )-> view .len ), IO_SEEK_CUR );
215221 Py_XDECREF (seek_result );
216222
217- /* Blindly calling PyErr_Restore would clear any exception raised by seek call. If however already had
218- * an error before freeing buffer (this function), propagate that instead. (I.e. this behaves like a
219- * nested try-except block.
220- */
221223 if (NULL != type ) {
222224 PyErr_Restore (type , value , traceback );
223225 } else if (NULL == seek_result ) {
@@ -243,15 +245,6 @@ int _bjdata_decoder_buffer_free(_bjdata_decoder_buffer_t** buffer) {
243245 return failed ;
244246}
245247
246- /* Tries to read len bytes from input, returning read chunk. Len is updated to how many bytes were actually read.
247- * If not NULL, dst_buffer can be an existing buffer to output len bytes into.
248- * Returns NULL if either no input is left (len is set to zero) or an error occurs (len is non-zero). The caller must
249- * NOT modify or free the returned chunk unless they specified out_buffer (in which case that is returned). When this
250- * function is called again, the previously returned output is no longer valid (unless was created by caller).
251- *
252- * This function reads from a fixed buffer (single byte array)
253- */
254-
255248static const char * _decoder_buffer_read_fixed (_bjdata_decoder_buffer_t * buffer , Py_ssize_t * len , char * dst_buffer ) {
256249 Py_ssize_t old_pos ;
257250
@@ -2169,4 +2162,4 @@ int _bjdata_decoder_init(void) {
21692162void _bjdata_decoder_cleanup (void ) {
21702163 Py_CLEAR (DecoderException );
21712164 Py_CLEAR (PyDec_Type );
2172- }
2165+ }
0 commit comments