@@ -711,7 +711,7 @@ PyDoc_STRVAR(deserialize__doc__,
711
711
{"deserialize", (PyCFunction)(void(*)(void))deserialize, METH_FASTCALL|METH_KEYWORDS, deserialize__doc__},
712
712
713
713
static PyObject *
714
- deserialize_impl (pysqlite_Connection * self , PyObject * data ,
714
+ deserialize_impl (pysqlite_Connection * self , Py_buffer * data ,
715
715
const char * schema );
716
716
717
717
static PyObject *
@@ -722,14 +722,30 @@ deserialize(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs,
722
722
static _PyArg_Parser _parser = {NULL , _keywords , "deserialize" , 0 };
723
723
PyObject * argsbuf [2 ];
724
724
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE (kwnames ) : 0 ) - 1 ;
725
- PyObject * data ;
725
+ Py_buffer data = { NULL , NULL } ;
726
726
const char * schema = "main" ;
727
727
728
728
args = _PyArg_UnpackKeywords (args , nargs , NULL , kwnames , & _parser , 1 , 1 , 0 , argsbuf );
729
729
if (!args ) {
730
730
goto exit ;
731
731
}
732
- data = args [0 ];
732
+ if (PyUnicode_Check (args [0 ])) {
733
+ Py_ssize_t len ;
734
+ const char * ptr = PyUnicode_AsUTF8AndSize (args [0 ], & len );
735
+ if (ptr == NULL ) {
736
+ goto exit ;
737
+ }
738
+ PyBuffer_FillInfo (& data , args [0 ], (void * )ptr , len , 1 , 0 );
739
+ }
740
+ else { /* any bytes-like object */
741
+ if (PyObject_GetBuffer (args [0 ], & data , PyBUF_SIMPLE ) != 0 ) {
742
+ goto exit ;
743
+ }
744
+ if (!PyBuffer_IsContiguous (& data , 'C' )) {
745
+ _PyArg_BadArgument ("deserialize" , "argument 1" , "contiguous buffer" , args [0 ]);
746
+ goto exit ;
747
+ }
748
+ }
733
749
if (!noptargs ) {
734
750
goto skip_optional_kwonly ;
735
751
}
@@ -747,9 +763,14 @@ deserialize(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs,
747
763
goto exit ;
748
764
}
749
765
skip_optional_kwonly :
750
- return_value = deserialize_impl (self , data , schema );
766
+ return_value = deserialize_impl (self , & data , schema );
751
767
752
768
exit :
769
+ /* Cleanup for data */
770
+ if (data .obj ) {
771
+ PyBuffer_Release (& data );
772
+ }
773
+
753
774
return return_value ;
754
775
}
755
776
@@ -825,4 +846,4 @@ pysqlite_connection_exit(pysqlite_Connection *self, PyObject *const *args, Py_ss
825
846
#ifndef DESERIALIZE_METHODDEF
826
847
#define DESERIALIZE_METHODDEF
827
848
#endif /* !defined(DESERIALIZE_METHODDEF) */
828
- /*[clinic end generated code: output=19c5e77935335c4d input=a9049054013a1b77]*/
849
+ /*[clinic end generated code: output=b84e5a71dd4a0e61 input=a9049054013a1b77]*/
0 commit comments