@@ -438,18 +438,18 @@ write_int(PyObject *self, PyObject *args, PyObject *kwds) {
438438 return Py_None ;
439439}
440440
441- static CPyTagged
441+ static uint8_t
442442read_tag_internal (PyObject * data ) {
443443 if (_check_buffer (data ) == 2 )
444- return CPY_INT_TAG ;
444+ return CPY_LL_UINT_ERROR ;
445445
446446 if (_check_read ((BufferObject * )data , 1 ) == 2 )
447- return CPY_INT_TAG ;
447+ return CPY_LL_UINT_ERROR ;
448448 char * buf = ((BufferObject * )data )-> buf ;
449449
450450 uint8_t ret = * (uint8_t * )(buf + ((BufferObject * )data )-> pos );
451451 ((BufferObject * )data )-> pos += 1 ;
452- return (( CPyTagged ) ret ) << 1 ;
452+ return ret ;
453453}
454454
455455static PyObject *
@@ -458,27 +458,22 @@ read_tag(PyObject *self, PyObject *args, PyObject *kwds) {
458458 PyObject * data = NULL ;
459459 if (!PyArg_ParseTupleAndKeywords (args , kwds , "O" , kwlist , & data ))
460460 return NULL ;
461- CPyTagged retval = read_tag_internal (data );
462- if (retval == CPY_INT_TAG ) {
461+ uint8_t retval = read_tag_internal (data );
462+ if (retval == CPY_LL_UINT_ERROR && PyErr_Occurred () ) {
463463 return NULL ;
464464 }
465- return CPyTagged_StealAsObject (retval );
465+ return PyLong_FromLong (retval );
466466}
467467
468468static char
469- write_tag_internal (PyObject * data , CPyTagged value ) {
469+ write_tag_internal (PyObject * data , uint8_t value ) {
470470 if (_check_buffer (data ) == 2 )
471471 return 2 ;
472472
473- if (value > MAX_SHORT_INT_TAGGED ) {
474- PyErr_SetString (PyExc_OverflowError , "value must fit in single byte" );
475- return 2 ;
476- }
477-
478473 if (_check_size ((BufferObject * )data , 1 ) == 2 )
479474 return 2 ;
480475 uint8_t * buf = (uint8_t * )((BufferObject * )data )-> buf ;
481- * (buf + ((BufferObject * )data )-> pos ) = ( uint8_t )( value >> 1 ) ;
476+ * (buf + ((BufferObject * )data )-> pos ) = value ;
482477 ((BufferObject * )data )-> pos += 1 ;
483478 ((BufferObject * )data )-> end += 1 ;
484479 return 1 ;
@@ -491,12 +486,12 @@ write_tag(PyObject *self, PyObject *args, PyObject *kwds) {
491486 PyObject * value = NULL ;
492487 if (!PyArg_ParseTupleAndKeywords (args , kwds , "OO" , kwlist , & data , & value ))
493488 return NULL ;
494- if (!PyLong_Check (value )) {
495- PyErr_SetString (PyExc_TypeError , "value must be an int" );
489+ uint8_t unboxed = CPyLong_AsUInt8 (value );
490+ if (unboxed == CPY_LL_UINT_ERROR && PyErr_Occurred ()) {
491+ CPy_TypeError ("u8" , value );
496492 return NULL ;
497493 }
498- CPyTagged tagged_value = CPyTagged_BorrowFromObject (value );
499- if (write_tag_internal (data , tagged_value ) == 2 ) {
494+ if (write_tag_internal (data , unboxed ) == 2 ) {
500495 return NULL ;
501496 }
502497 Py_INCREF (Py_None );
0 commit comments