Skip to content

Commit d82cf67

Browse files
committed
Convert fstore constuctor to use AC
1 parent 5bbff3a commit d82cf67

2 files changed

Lines changed: 145 additions & 33 deletions

File tree

Modules/clinic/fcntlmodule.c.h

Lines changed: 108 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/fcntlmodule.c

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,18 @@
3232
// NUL followed by random bytes.
3333
static const char guard[GUARDSZ] _Py_NONSTRING = "\x00\xfa\x69\xc4\x67\xa3\x6c\x58";
3434

35+
#ifdef F_PREALLOCATE
36+
typedef struct {
37+
PyObject_HEAD
38+
struct fstore fstore;
39+
} FStoreObject;
40+
#endif /* F_PREALLOCATE */
41+
3542
/*[clinic input]
3643
module fcntl
37-
class fcntl.fstore "fstoreObject *" "&fstore_type"
44+
class fcntl.fstore "FStoreObject *" "&PyType_Type"
3845
[clinic start generated code]*/
39-
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=1fbf02539f611b1d]*/
46+
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=54136216ba908cf8]*/
4047

4148
#include "clinic/fcntlmodule.c.h"
4249

@@ -512,38 +519,36 @@ fcntl_lockf_impl(PyObject *module, int fd, int code, PyObject *lenobj,
512519

513520
#ifdef F_PREALLOCATE
514521

515-
typedef struct {
516-
PyObject_HEAD
517-
struct fstore fstore;
518-
} fstoreObject;
522+
/*[clinic input]
523+
fcntl.fstore.__init__
524+
525+
flags: int = 0
526+
posmode: int = 0
527+
offset: long = 0
528+
length: long = 0
529+
530+
Initialize an fstore structure.
531+
532+
This structure is used with the F_PREALLOCATE command to preallocate
533+
file space on macOS systems.
534+
[clinic start generated code]*/
519535

520536
static int
521-
fstore_init(fstoreObject *self, PyObject *args, PyObject *kwds)
537+
fcntl_fstore___init___impl(FStoreObject *self, int flags, int posmode,
538+
long offset, long length)
539+
/*[clinic end generated code: output=4fcf4413aa57e2dd input=f4caa1fbbe7a0e32]*/
522540
{
523-
static char *kwlist[] = {
524-
"flags", "posmode", "offset", "length", NULL
525-
};
526-
int flags = 0;
527-
int posmode = 0;
528-
off_t offset = 0;
529-
off_t length = 0;
530-
531-
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|iiLL", kwlist,
532-
&flags, &posmode, &offset, &length)) {
533-
return -1;
534-
}
535-
536541
memset(&self->fstore, 0, sizeof(struct fstore));
537542
self->fstore.fst_flags = flags;
538543
self->fstore.fst_posmode = posmode;
539-
self->fstore.fst_offset = offset;
540-
self->fstore.fst_length = length;
544+
self->fstore.fst_offset = (off_t)offset;
545+
self->fstore.fst_length = (off_t)length;
541546

542547
return 0;
543548
}
544549

545550
static Py_ssize_t
546-
fstore_getbuffer(fstoreObject *self, Py_buffer *view, int flags)
551+
fstore_getbuffer(FStoreObject *self, Py_buffer *view, int flags)
547552
{
548553
return PyBuffer_FillInfo(view, (PyObject *)self, (void *)&self->fstore,
549554
sizeof(struct fstore), 1, flags);
@@ -568,7 +573,7 @@ static PyObject *
568573
fcntl_fstore_from_buffer_impl(PyTypeObject *type, Py_buffer *data)
569574
/*[clinic end generated code: output=e401a2f775342265 input=3148957e92e9570f]*/
570575
{
571-
fstoreObject *self;
576+
FStoreObject *self;
572577

573578
if (data->len != sizeof(struct fstore)) {
574579
PyErr_Format(PyExc_ValueError,
@@ -577,7 +582,7 @@ fcntl_fstore_from_buffer_impl(PyTypeObject *type, Py_buffer *data)
577582
return NULL;
578583
}
579584

580-
self = (fstoreObject *)PyType_GenericNew(type, NULL, NULL);
585+
self = (FStoreObject *)PyType_GenericNew(type, NULL, NULL);
581586
if (self == NULL) {
582587
return NULL;
583588
}
@@ -593,21 +598,21 @@ static PyMethodDef fstore_methods[] = {
593598
};
594599

595600
static PyMemberDef fstore_members[] = {
596-
{"flags", Py_T_INT, offsetof(fstoreObject, fstore.fst_flags), 0,
601+
{"flags", Py_T_INT, offsetof(FStoreObject, fstore.fst_flags), 0,
597602
"Allocation flags"},
598-
{"posmode", Py_T_INT, offsetof(fstoreObject, fstore.fst_posmode), 0,
603+
{"posmode", Py_T_INT, offsetof(FStoreObject, fstore.fst_posmode), 0,
599604
"Position mode"},
600-
{"offset", Py_T_LONGLONG, offsetof(fstoreObject, fstore.fst_offset), 0,
605+
{"offset", Py_T_LONGLONG, offsetof(FStoreObject, fstore.fst_offset), 0,
601606
"File offset"},
602-
{"length", Py_T_LONGLONG, offsetof(fstoreObject, fstore.fst_length), 0,
607+
{"length", Py_T_LONGLONG, offsetof(FStoreObject, fstore.fst_length), 0,
603608
"Length to allocate"},
604-
{"bytesalloc", Py_T_LONGLONG, offsetof(fstoreObject, fstore.fst_bytesalloc), Py_READONLY,
609+
{"bytesalloc", Py_T_LONGLONG, offsetof(FStoreObject, fstore.fst_bytesalloc), Py_READONLY,
605610
"Number of bytes actually allocated"},
606611
{NULL},
607612
};
608613

609614
static PyType_Slot fstore_slots[] = {
610-
{Py_tp_init, (initproc)fstore_init},
615+
{Py_tp_init, (initproc)fcntl_fstore___init__},
611616
{Py_tp_members, fstore_members},
612617
{Py_tp_methods, fstore_methods},
613618
{Py_tp_doc, "fstore structure for F_PREALLOCATE"},
@@ -617,7 +622,7 @@ static PyType_Slot fstore_slots[] = {
617622

618623
static PyType_Spec fstore_spec = {
619624
.name = "fcntl.fstore",
620-
.basicsize = sizeof(fstoreObject),
625+
.basicsize = sizeof(FStoreObject),
621626
.flags = Py_TPFLAGS_DEFAULT,
622627
.slots = fstore_slots,
623628
};

0 commit comments

Comments
 (0)