[issue23098] mknod devices can be >32 bits

2015-01-18 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Committed to 2.7 with small change: stat() and makedev() should return int 
instead of long if possible.

--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23098] mknod devices can be >32 bits

2015-01-18 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 7ee09e2fec13 by Serhiy Storchaka in branch '2.7':
Issue #23098: 64-bit dev_t is now supported in the os module.
https://hg.python.org/cpython/rev/7ee09e2fec13

New changeset 18703ffea2b3 by Serhiy Storchaka in branch '3.4':
Issue #23098: 64-bit dev_t is now supported in the os module.
https://hg.python.org/cpython/rev/18703ffea2b3

New changeset fe0fddd6fd21 by Serhiy Storchaka in branch 'default':
Issue #23098: 64-bit dev_t is now supported in the os module.
https://hg.python.org/cpython/rev/fe0fddd6fd21

--
nosy: +python-dev

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23098] mknod devices can be >32 bits

2014-12-22 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

And here are patches for 2.7 and 3.4 (unfortunately none of patches is applied 
clear to other version).

--
Added file: http://bugs.python.org/file37532/posix_dev_t_converter-2.7.patch
Added file: http://bugs.python.org/file37533/posix_dev_t_converter-3.4.patch

___
Python tracker 

___diff -r c6491d91d59a Modules/posixmodule.c
--- a/Modules/posixmodule.c Sat Dec 20 17:42:24 2014 +0200
+++ b/Modules/posixmodule.c Tue Dec 23 09:48:10 2014 +0200
@@ -474,6 +474,29 @@ OverflowUp:
 #endif /* MS_WINDOWS */
 
 
+#if defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)
+static int
+_Py_Dev_Converter(PyObject *obj, void *p)
+{
+#ifdef HAVE_LONG_LONG
+*((dev_t *)p) = PyLong_AsUnsignedLongLong(obj);
+#else
+*((dev_t *)p) = PyLong_AsUnsignedLong(obj);
+#endif
+if (PyErr_Occurred())
+return 0;
+return 1;
+}
+
+#ifdef HAVE_LONG_LONG
+#  define _PyLong_FromDev PyLong_FromLongLong
+#else
+#  define _PyLong_FromDev PyLong_FromLong
+#endif
+
+#endif
+
+
 #if defined _MSC_VER && _MSC_VER >= 1400
 /* Microsoft CRT in VS2005 and higher will verify that a filehandle is
  * valid and raise an assertion if it isn't.
@@ -1426,11 +1449,10 @@ static PyObject*
 #else
 PyStructSequence_SET_ITEM(v, 1, PyInt_FromLong((long)st->st_ino));
 #endif
-#if defined(HAVE_LONG_LONG) && !defined(MS_WINDOWS)
-PyStructSequence_SET_ITEM(v, 2,
-  PyLong_FromLongLong((PY_LONG_LONG)st->st_dev));
+#ifdef MS_WINDOWS
+PyStructSequence_SET_ITEM(v, 2, PyLong_FromUnsignedLong(st->st_dev));
 #else
-PyStructSequence_SET_ITEM(v, 2, PyInt_FromLong((long)st->st_dev));
+PyStructSequence_SET_ITEM(v, 2, _PyLong_FromDev(st->st_dev));
 #endif
 PyStructSequence_SET_ITEM(v, 3, PyInt_FromLong((long)st->st_nlink));
 #if defined(MS_WINDOWS)
@@ -7009,9 +7031,11 @@ posix_mknod(PyObject *self, PyObject *ar
 {
 char *filename;
 int mode = 0600;
-int device = 0;
+dev_t device = 0;
 int res;
-if (!PyArg_ParseTuple(args, "s|ii:mknod", &filename, &mode, &device))
+if (!PyArg_ParseTuple(args, "s|iO&:mknod",
+&filename, &mode,
+_Py_Dev_Converter, &device))
 return NULL;
 Py_BEGIN_ALLOW_THREADS
 res = mknod(filename, mode, device);
@@ -7031,8 +7055,8 @@ Extracts a device major number from a ra
 static PyObject *
 posix_major(PyObject *self, PyObject *args)
 {
-int device;
-if (!PyArg_ParseTuple(args, "i:major", &device))
+dev_t device;
+if (!PyArg_ParseTuple(args, "O&:major", _Py_Dev_Converter, &device))
 return NULL;
 return PyInt_FromLong((long)major(device));
 }
@@ -7044,8 +7068,8 @@ Extracts a device minor number from a ra
 static PyObject *
 posix_minor(PyObject *self, PyObject *args)
 {
-int device;
-if (!PyArg_ParseTuple(args, "i:minor", &device))
+dev_t device;
+if (!PyArg_ParseTuple(args, "O&:minor", _Py_Dev_Converter, &device))
 return NULL;
 return PyInt_FromLong((long)minor(device));
 }
@@ -7060,7 +7084,7 @@ posix_makedev(PyObject *self, PyObject *
 int major, minor;
 if (!PyArg_ParseTuple(args, "ii:makedev", &major, &minor))
 return NULL;
-return PyInt_FromLong((long)makedev(major, minor));
+return _PyLong_FromDev(makedev(major, minor));
 }
 #endif /* device macros */
 
@@ -8522,7 +8546,6 @@ setup_confname_table(struct constdef *ta
 {
 PyObject *d = NULL;
 size_t i;
-
 qsort(table, tablesize, sizeof(struct constdef), cmp_constdefs);
 d = PyDict_New();
 if (d == NULL)
diff -r c4643b32cd9a Modules/posixmodule.c
--- a/Modules/posixmodule.c Mon Dec 22 22:09:50 2014 +0100
+++ b/Modules/posixmodule.c Tue Dec 23 09:37:08 2014 +0200
@@ -623,6 +623,29 @@ fail:
 #endif /* MS_WINDOWS */
 
 
+#if defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)
+static int
+_Py_Dev_Converter(PyObject *obj, void *p)
+{
+#ifdef HAVE_LONG_LONG
+*((dev_t *)p) = PyLong_AsUnsignedLongLong(obj);
+#else
+*((dev_t *)p) = PyLong_AsUnsignedLong(obj);
+#endif
+if (PyErr_Occurred())
+return 0;
+return 1;
+}
+
+#ifdef HAVE_LONG_LONG
+#  define _PyLong_FromDev PyLong_FromLongLong
+#else
+#  define _PyLong_FromDev PyLong_FromLong
+#endif
+
+#endif
+
+
 #ifdef AT_FDCWD
 /*
  * Why the (int) cast?  Solaris 10 defines AT_FDCWD as 0xffd19553 (-3041965);
@@ -2218,11 +2241,8 @@ static PyObject*
 #endif
 #ifdef MS_WINDOWS
 PyStructSequence_SET_ITEM(v, 2, PyLong_FromUnsignedLong(st->st_dev));
-#elif defined(HAVE_LONG_LONG)
-PyStructSequence_SET_ITEM(v, 2,
-  PyLong_FromLongLong((PY_LONG_LONG)st->st_dev));
-#else
-PyStructSequence_SET_ITEM(v, 2, PyLong_FromLong((long)st->st_dev));
+#else
+PyStructSequence_SET_ITEM(v, 2, _PyLong_FromDev(st->st_dev));
 #endif
 PyStructSequence_SET_ITEM(v, 3, PyLong_FromLong((long)st->st_nlink));
 #if defined(MS_WINDOWS)
@@ -8633,16 +865

[issue23098] mknod devices can be >32 bits

2014-12-22 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

As pointed by Antoine there are other affected functions. Updated patch fixes 
converting of arguments or results in makedev(), major() and minor().

--
Added file: http://bugs.python.org/file37527/posix_dev_t_converter-3.5_2.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23098] mknod devices can be >32 bits

2014-12-22 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Here is a patch against 3.5. Unsigned bitwise int converter is used for dev_t 
because dev_t can be unsigned (and it is on Linux). This is not ideal solution, 
there is no overflow check, but at least it should work for correct code.

--
keywords: +patch
Added file: http://bugs.python.org/file37526/posix_dev_t_converter-3.5.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23098] mknod devices can be >32 bits

2014-12-22 Thread Jesús Cea Avión

Jesús Cea Avión added the comment:

Serhiy, could you consider to create a patch for 2.7 and 3.4?. I am not 
familiar with the details of Argument Clinic.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23098] mknod devices can be >32 bits

2014-12-22 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

This is not so easy as look at first glance. PY_LONG_LONG should be used 
instead of long long. And as far as this type is optional, its use should be 
conditional if HAVE_LONG_LONG is defined.

May be needed complex converter like _Py_Uid_Converter because dev_t on Linux 
is 64-bit unsigned int and can not fit in the range of 64-bit signed int.

The code for 3.x should be even more complex due to using Argument Clinic.

--
components: +Extension Modules
nosy: +serhiy.storchaka
type:  -> behavior

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23098] mknod devices can be >32 bits

2014-12-21 Thread Jesús Cea Avión

New submission from Jesús Cea Avión:

Dan MacDonald told me that "os.mknod()" should accept devices >32 bits.

I wrote this code in linux 64 bits:

"""
#include 
#include 
#include 
#include 
#include 

int main(void) {
printf("%d", sizeof(dev_t));
return 0;
}
"""

The result of running this is "8". We need a long long.

I did this change in Python 2.7 branch:

"""
diff -r f00412d32b41 Modules/posixmodule.c
--- a/Modules/posixmodule.c Sat Dec 20 13:41:14 2014 -0600
+++ b/Modules/posixmodule.c Sun Dec 21 23:30:00 2014 +0100
@@ -7009,9 +7009,9 @@
 {
 char *filename;
 int mode = 0600;
-int device = 0;
+long long device = 0;
 int res;
-if (!PyArg_ParseTuple(args, "s|ii:mknod", &filename, &mode, &device))
+if (!PyArg_ParseTuple(args, "s|iL:mknod", &filename, &mode, &device))
 return NULL;
 Py_BEGIN_ALLOW_THREADS
 res = mknod(filename, mode, device);
"""

Looks like this patch is trivial. Please, comment.

--
assignee: jcea
keywords: easy
messages: 233004
nosy: jcea
priority: normal
severity: normal
stage: patch review
status: open
title: mknod devices can be >32 bits
versions: Python 2.7, Python 3.4, Python 3.5

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com