[issue14153] Expose os.device_encoding() at the C level

2012-02-29 Thread Brett Cannon

Brett Cannon br...@python.org added the comment:

Attached is a patch which is trying to do the refactor, but I'm somehow causing 
a something to be gc'ed when it shouldn't. If anyone spots something obvious 
let me know, else I will try to debug some more on my way home.

--
keywords: +patch
Added file: http://bugs.python.org/file24680/crashing_device_encoding.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14153
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14153] Expose os.device_encoding() at the C level

2012-02-29 Thread Antoine Pitrou

Antoine Pitrou pit...@free.fr added the comment:

I don't seen any refcounting problem here, but your patch is buggy.
Before patch:

 os.device_encoding(0)
'UTF-8'

After patch:

 os.device_encoding(0) is None
True

Interestingly, it seems there is no test for os.device_encoding. Perhaps add 
one to test_os?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14153
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14153] Expose os.device_encoding() at the C level

2012-02-29 Thread STINNER Victor

STINNER Victor victor.stin...@gmail.com added the comment:

 your patch is buggy

It should be a missing #include. Maybe this one:

#ifdef HAVE_LANGINFO_H
#include langinfo.h
#endif

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14153
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14153] Expose os.device_encoding() at the C level

2012-02-29 Thread Brett Cannon

Brett Cannon br...@python.org added the comment:

Victor's point fixed my issue.

As for a test, I will happily write one, but what can I test? A string for fd 0 
and None for fd -1 (or is there some os call I can make to find the largest fd 
so I can test fd+1)?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14153
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14153] Expose os.device_encoding() at the C level

2012-02-29 Thread Antoine Pitrou

Antoine Pitrou pit...@free.fr added the comment:

 As for a test, I will happily write one, but what can I test? A string
 for fd 0 and None for fd -1 (or is there some os call I can make to
 find the largest fd so I can test fd+1)?

For fd 0, it should be a string if the fd is a tty.
(it should also point to a valid codec)
You can also try fd 42 (same, call isatty() on it).

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14153
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14153] Expose os.device_encoding() at the C level

2012-02-29 Thread STINNER Victor

STINNER Victor victor.stin...@gmail.com added the comment:

 For fd 0, it should be a string if the fd is a tty.

os.device_encoding() returns None on a non-Windows OS without langinfo support.

locale.nl_langinfo(locale.CODESET) may be used in such test. (to check
for nl_langinfo() support?)

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14153
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14153] Expose os.device_encoding() at the C level

2012-02-29 Thread Brett Cannon

Brett Cannon br...@python.org added the comment:

OK, so if on windows or isatty + nl_langinfo + CODESET, check fd 0 for a 
returned string that codecs.lookup and find something for. fd 42 (if not a tty) 
should return None.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14153
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14153] Expose os.device_encoding() at the C level

2012-02-29 Thread Roundup Robot

Roundup Robot devn...@psf.upfronthosting.co.za added the comment:

New changeset c80d9a0bd5a0 by Brett Cannon in branch 'default':
Issue #14153 Create _Py_device_encoding() to prevent _io from having to import
http://hg.python.org/cpython/rev/c80d9a0bd5a0

--
nosy: +python-dev

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14153
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14153] Expose os.device_encoding() at the C level

2012-02-29 Thread Brett Cannon

Changes by Brett Cannon br...@python.org:


--
assignee:  - brett.cannon
resolution:  - fixed
stage: needs patch - committed/rejected
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14153
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14153] Expose os.device_encoding() at the C level

2012-02-28 Thread Brett Cannon

New submission from Brett Cannon br...@python.org:

The _io module imports the os module purely for the use of 
os.device_encoding(). That function, though, is defined by posix and thus is 
already available to C code. To avoid this import dependency it would be better 
to simply expose the function somehow so that _io can just directly call the 
function.

Antoine has suggested Python/fileutils.c as a possible place, although I'm 
personally happy simply exposing the function from posix and making it a METH_O 
function so that as little code needs to change for _io to use it.

--
components: Library (Lib)
messages: 154557
nosy: brett.cannon, pitrou
priority: normal
severity: normal
stage: needs patch
status: open
title: Expose os.device_encoding() at the C level
versions: Python 3.3

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14153
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14153] Expose os.device_encoding() at the C level

2012-02-28 Thread Antoine Pitrou

Changes by Antoine Pitrou pit...@free.fr:


--
nosy: +haypo

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14153
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14153] Expose os.device_encoding() at the C level

2012-02-28 Thread STINNER Victor

STINNER Victor victor.stin...@gmail.com added the comment:

If it can help to bootstrap importlib, you can add:

PyObject* _Py_device_encoding(int fd);

And reuse it in posixmodule.c.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14153
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14153] Expose os.device_encoding() at the C level

2012-02-28 Thread Brett Cannon

Brett Cannon br...@python.org added the comment:

Either that or PyObject *_Py_device_encoding(PyObject *fd) would help since 
both _io and posixmodule.c will have a PyObject already for the fd.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14153
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14153] Expose os.device_encoding() at the C level

2012-02-28 Thread Benjamin Peterson

Benjamin Peterson benja...@python.org added the comment:

I think fileutils.c is a good place. Then we can kill the import of os in io, 
which would be nice.

--
nosy: +benjamin.peterson

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14153
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14153] Expose os.device_encoding() at the C level

2012-02-28 Thread Brett Cannon

Brett Cannon br...@python.org added the comment:

OK, then I will make this happen. People care whether it take an int or a 
PyObject? That seems to be the only open question.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14153
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14153] Expose os.device_encoding() at the C level

2012-02-28 Thread Benjamin Peterson

Benjamin Peterson benja...@python.org added the comment:

2012/2/28 Brett Cannon rep...@bugs.python.org:

 Brett Cannon br...@python.org added the comment:

 OK, then I will make this happen. People care whether it take an int or a 
 PyObject? That seems to be the only open question.

Probably int if it goes in fileutils.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14153
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com