Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b2653b3

Browse files
Issue #23098: 64-bit dev_t is now supported in the os module.
1 parent ccb416f commit b2653b3

2 files changed

Lines changed: 34 additions & 12 deletions

File tree

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ Core and Builtins
4444
Library
4545
-------
4646

47+
- Issue #23098: 64-bit dev_t is now supported in the os module.
48+
4749
- Issue #23250: In the http.cookies module, capitalize "HttpOnly" and "Secure"
4850
as they are written in the standard.
4951

Modules/posixmodule.c

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,29 @@ _Py_Gid_Converter(PyObject *obj, void *p)
623623
#endif /* MS_WINDOWS */
624624

625625

626+
#if defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)
627+
static int
628+
_Py_Dev_Converter(PyObject *obj, void *p)
629+
{
630+
#ifdef HAVE_LONG_LONG
631+
*((dev_t *)p) = PyLong_AsUnsignedLongLong(obj);
632+
#else
633+
*((dev_t *)p) = PyLong_AsUnsignedLong(obj);
634+
#endif
635+
if (PyErr_Occurred())
636+
return 0;
637+
return 1;
638+
}
639+
640+
#ifdef HAVE_LONG_LONG
641+
# define _PyLong_FromDev PyLong_FromLongLong
642+
#else
643+
# define _PyLong_FromDev PyLong_FromLong
644+
#endif
645+
646+
#endif
647+
648+
626649
#ifdef AT_FDCWD
627650
/*
628651
* Why the (int) cast? Solaris 10 defines AT_FDCWD as 0xffd19553 (-3041965);
@@ -2218,11 +2241,8 @@ _pystat_fromstructstat(STRUCT_STAT *st)
22182241
#endif
22192242
#ifdef MS_WINDOWS
22202243
PyStructSequence_SET_ITEM(v, 2, PyLong_FromUnsignedLong(st->st_dev));
2221-
#elif defined(HAVE_LONG_LONG)
2222-
PyStructSequence_SET_ITEM(v, 2,
2223-
PyLong_FromLongLong((PY_LONG_LONG)st->st_dev));
22242244
#else
2225-
PyStructSequence_SET_ITEM(v, 2, PyLong_FromLong((long)st->st_dev));
2245+
PyStructSequence_SET_ITEM(v, 2, _PyLong_FromDev(st->st_dev));
22262246
#endif
22272247
PyStructSequence_SET_ITEM(v, 3, PyLong_FromLong((long)st->st_nlink));
22282248
#if defined(MS_WINDOWS)
@@ -8633,16 +8653,16 @@ posix_mknod(PyObject *self, PyObject *args, PyObject *kwargs)
86338653
{
86348654
path_t path;
86358655
int mode = 0666;
8636-
int device = 0;
8656+
dev_t device = 0;
86378657
int dir_fd = DEFAULT_DIR_FD;
86388658
int result;
86398659
PyObject *return_value = NULL;
86408660
static char *keywords[] = {"path", "mode", "device", "dir_fd", NULL};
86418661

86428662
memset(&path, 0, sizeof(path));
8643-
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|ii$O&:mknod", keywords,
8663+
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|iO&$O&:mknod", keywords,
86448664
path_converter, &path,
8645-
&mode, &device,
8665+
&mode, _Py_Dev_Converter, &device,
86468666
#ifdef HAVE_MKNODAT
86478667
dir_fd_converter, &dir_fd
86488668
#else
@@ -8682,8 +8702,8 @@ Extracts a device major number from a raw device number.");
86828702
static PyObject *
86838703
posix_major(PyObject *self, PyObject *args)
86848704
{
8685-
int device;
8686-
if (!PyArg_ParseTuple(args, "i:major", &device))
8705+
dev_t device;
8706+
if (!PyArg_ParseTuple(args, "O&:major", _Py_Dev_Converter, &device))
86878707
return NULL;
86888708
return PyLong_FromLong((long)major(device));
86898709
}
@@ -8695,8 +8715,8 @@ Extracts a device minor number from a raw device number.");
86958715
static PyObject *
86968716
posix_minor(PyObject *self, PyObject *args)
86978717
{
8698-
int device;
8699-
if (!PyArg_ParseTuple(args, "i:minor", &device))
8718+
dev_t device;
8719+
if (!PyArg_ParseTuple(args, "O&:minor", _Py_Dev_Converter, &device))
87008720
return NULL;
87018721
return PyLong_FromLong((long)minor(device));
87028722
}
@@ -8711,7 +8731,7 @@ posix_makedev(PyObject *self, PyObject *args)
87118731
int major, minor;
87128732
if (!PyArg_ParseTuple(args, "ii:makedev", &major, &minor))
87138733
return NULL;
8714-
return PyLong_FromLong((long)makedev(major, minor));
8734+
return _PyLong_FromDev(makedev(major, minor));
87158735
}
87168736
#endif /* device macros */
87178737

0 commit comments

Comments
 (0)