@@ -34,8 +34,9 @@ static const char guard[GUARDSZ] _Py_NONSTRING = "\x00\xfa\x69\xc4\x67\xa3\x6c\x
3434
3535/*[clinic input]
3636module fcntl
37+ class fcntl.fstore "fstoreObject *" "&fstore_type"
3738[clinic start generated code]*/
38- /*[clinic end generated code: output=da39a3ee5e6b4b0d input=124b58387c158179 ]*/
39+ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=1fbf02539f611b1d ]*/
3940
4041#include "clinic/fcntlmodule.c.h"
4142
@@ -548,45 +549,46 @@ fstore_getbuffer(fstoreObject *self, Py_buffer *view, int flags)
548549 sizeof (struct fstore ), 1 , flags );
549550}
550551
552+ /*[clinic input]
553+ @classmethod
554+ fcntl.fstore.from_buffer
555+
556+ data: Py_buffer
557+ /
558+
559+ Create an fstore instance from bytes data.
560+
561+ This is useful for creating an fstore instance from the result of
562+ fcntl.fcntl when using the F_PREALLOCATE command.
563+
564+ Raises ValueError if the data is not exactly the size of struct fstore.
565+ [clinic start generated code]*/
566+
551567static PyObject *
552- fstore_frombytes (PyTypeObject * type , PyObject * args , PyObject * kwds )
568+ fcntl_fstore_from_buffer_impl (PyTypeObject * type , Py_buffer * data )
569+ /*[clinic end generated code: output=e401a2f775342265 input=3148957e92e9570f]*/
553570{
554- static char * kwlist [] = {"data" , NULL };
555- PyObject * data_obj ;
556- Py_buffer view ;
557571 fstoreObject * self ;
558572
559- if (!PyArg_ParseTupleAndKeywords (args , kwds , "O" , kwlist , & data_obj )) {
560- return NULL ;
561- }
562-
563- if (PyObject_GetBuffer (data_obj , & view , PyBUF_SIMPLE ) < 0 ) {
564- return NULL ;
565- }
566-
567- if (view .len != sizeof (struct fstore )) {
568- PyBuffer_Release (& view );
573+ if (data -> len != sizeof (struct fstore )) {
569574 PyErr_Format (PyExc_ValueError ,
570575 "data must be exactly %zu bytes, got %zd bytes" ,
571- sizeof (struct fstore ), view . len );
576+ sizeof (struct fstore ), data -> len );
572577 return NULL ;
573578 }
574579
575580 self = (fstoreObject * )PyType_GenericNew (type , NULL , NULL );
576581 if (self == NULL ) {
577- PyBuffer_Release (& view );
578582 return NULL ;
579583 }
580584
581- memcpy (& self -> fstore , view .buf , sizeof (struct fstore ));
582- PyBuffer_Release (& view );
585+ memcpy (& self -> fstore , data -> buf , sizeof (struct fstore ));
583586
584587 return (PyObject * )self ;
585588}
586589
587590static PyMethodDef fstore_methods [] = {
588- {"frombytes" , (PyCFunction )fstore_frombytes , METH_VARARGS | METH_KEYWORDS | METH_CLASS ,
589- "Create an fstore instance from bytes data." },
591+ FCNTL_FSTORE_FROM_BUFFER_METHODDEF
590592 {NULL , NULL }
591593};
592594
0 commit comments