@@ -1218,14 +1218,24 @@ _multibytecodec_MultibyteIncrementalDecoder_getstate_impl(MultibyteIncrementalDe
1218
1218
/*[clinic end generated code: output=255009c4713b7f82 input=4006aa49bddbaa75]*/
1219
1219
{
1220
1220
PyObject * buffer ;
1221
+ PyObject * statelong ;
1221
1222
1222
1223
buffer = PyBytes_FromStringAndSize ((const char * )self -> pending ,
1223
1224
self -> pendingsize );
1224
1225
if (buffer == NULL ) {
1225
1226
return NULL ;
1226
1227
}
1227
1228
1228
- return make_tuple (buffer , (Py_ssize_t )* self -> state .c );
1229
+ statelong = (PyObject * )_PyLong_FromByteArray (self -> state .c ,
1230
+ sizeof (self -> state .c ),
1231
+ 1 /* little-endian */ ,
1232
+ 0 /* unsigned */ );
1233
+ if (statelong == NULL ) {
1234
+ Py_DECREF (buffer );
1235
+ return NULL ;
1236
+ }
1237
+
1238
+ return Py_BuildValue ("NN" , buffer , statelong );
1229
1239
}
1230
1240
1231
1241
/*[clinic input]
@@ -1240,16 +1250,23 @@ _multibytecodec_MultibyteIncrementalDecoder_setstate_impl(MultibyteIncrementalDe
1240
1250
/*[clinic end generated code: output=106b2fbca3e2dcc2 input=e5d794e8baba1a47]*/
1241
1251
{
1242
1252
PyObject * buffer ;
1253
+ PyLongObject * statelong ;
1243
1254
Py_ssize_t buffersize ;
1244
1255
char * bufferstr ;
1245
- unsigned long long flag ;
1256
+ unsigned char statebytes [ 8 ] ;
1246
1257
1247
- if (!PyArg_ParseTuple (state , "SK ;setstate(): illegal state argument" ,
1248
- & buffer , & flag ))
1258
+ if (!PyArg_ParseTuple (state , "SO! ;setstate(): illegal state argument" ,
1259
+ & buffer , & PyLong_Type , & statelong ))
1249
1260
{
1250
1261
return NULL ;
1251
1262
}
1252
1263
1264
+ if (_PyLong_AsByteArray (statelong , statebytes , sizeof (statebytes ),
1265
+ 1 /* little-endian */ ,
1266
+ 0 /* unsigned */ ) < 0 ) {
1267
+ return NULL ;
1268
+ }
1269
+
1253
1270
buffersize = PyBytes_Size (buffer );
1254
1271
if (buffersize == -1 ) {
1255
1272
return NULL ;
@@ -1266,7 +1283,7 @@ _multibytecodec_MultibyteIncrementalDecoder_setstate_impl(MultibyteIncrementalDe
1266
1283
}
1267
1284
self -> pendingsize = buffersize ;
1268
1285
memcpy (self -> pending , bufferstr , self -> pendingsize );
1269
- memcpy (self -> state .c , ( unsigned char * ) & flag , sizeof (flag ));
1286
+ memcpy (self -> state .c , statebytes , sizeof (statebytes ));
1270
1287
1271
1288
Py_RETURN_NONE ;
1272
1289
}
0 commit comments