Re: [Python-Dev] cpython: threading.RLock._acquire_restore() now raises a TypeError instead of a

2014-01-03 Thread Serhiy Storchaka

02.01.14 13:54, victor.stinner написав(ла):

http://hg.python.org/cpython/rev/9a61be172c23
changeset:   88249:9a61be172c23
user:Victor Stinner 
date:Thu Jan 02 12:47:24 2014 +0100
summary:
   threading.RLock._acquire_restore() now raises a TypeError instead of a
SystemError when it is not called with 2 arguments



-if (!PyArg_ParseTuple(arg, "kl:_acquire_restore", &count, &owner))
+if (!PyArg_ParseTuple(args, "(kl):_acquire_restore", &count, &owner))
  return NULL;


Please don't use "(...)" in PyArg_ParseTuple, it is dangerous (see 
issue6083 [1]).


[1] http://bugs.python.org/issue6083


___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] cpython: threading.RLock._acquire_restore() now raises a TypeError instead of a

2014-01-03 Thread Victor Stinner
Hi,

2014/1/3 Serhiy Storchaka :
>> -if (!PyArg_ParseTuple(arg, "kl:_acquire_restore", &count, &owner))
>> +if (!PyArg_ParseTuple(args, "(kl):_acquire_restore", &count, &owner))
>>   return NULL;
>
> Please don't use "(...)" in PyArg_ParseTuple, it is dangerous (see issue6083
> [1]).
>
> [1] http://bugs.python.org/issue6083

Oh, I didn't know this issue. Keeping a reference to the tuple is
annoying, it adds a lot of cleanup code.

Would it be possible to handle this issue in Argument Clinic, split
the function in two parts: a function to parse arguments and keep
references, and the implementation function?

I already saw that when a format requires to keep a reference. See for
example os_path() and os_path_impl() in Modules/posixmodule.c.

Victor
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] cpython: threading.RLock._acquire_restore() now raises a TypeError instead of a

2014-01-03 Thread Victor Stinner
2014/1/3 Victor Stinner :
> 2014/1/3 Serhiy Storchaka :
>>> -if (!PyArg_ParseTuple(arg, "kl:_acquire_restore", &count, &owner))
>>> +if (!PyArg_ParseTuple(args, "(kl):_acquire_restore", &count, &owner))
>>>   return NULL;
>>
>> Please don't use "(...)" in PyArg_ParseTuple, it is dangerous (see issue6083
>> [1]).
>>
>> [1] http://bugs.python.org/issue6083
>
> ...
>
> Would it be possible to handle this issue in Argument Clinic, split
> the function in two parts: a function to parse arguments and keep
> references, and the implementation function?

Oh, I found a similiar issue but different issue:

>>> import resource
>>> resource.prlimit(0, resource.RLIMIT_CORE, "\u0100\u0101")
Erreur de segmentation (core dumped)

This new function uses the following code to parse arguments:

if (!PyArg_ParseTuple(args, _Py_PARSE_PID "i|(OO):prlimit",
  &pid, &resource, &curobj, &maxobj))
return NULL;

"\u0100\u0101" is seen as a sequence. Getting an item of this sequence
creates a new substring of 1 character, but the substring has only 1
reference, and the only reference is immediatly removed, so the
borrowed reference (curobj and maxobj) become immediatly dangling
pointers...

Victor
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] [Python-checkins] cpython: add unicode_char() in unicodeobject.c to factorize code

2014-01-03 Thread Zachary Ware
On Fri, Jan 3, 2014 at 6:01 AM, victor.stinner
 wrote:
> http://hg.python.org/cpython/rev/d453c95def31
> changeset:   88271:d453c95def31
> user:Victor Stinner 
> date:Fri Jan 03 12:53:47 2014 +0100
> summary:
>   add unicode_char() in unicodeobject.c to factorize code
>
> files:
>   Objects/unicodeobject.c |  86 ++--
>   1 files changed, 31 insertions(+), 55 deletions(-)
>
>
> diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
> --- a/Objects/unicodeobject.c
> +++ b/Objects/unicodeobject.c

> @@ -2887,17 +2883,7 @@
>  return NULL;
>  }
>
> -if ((Py_UCS4)ordinal < 256)
> -return get_latin1_char((unsigned char)ordinal);
> -
> -v = PyUnicode_New(1, ordinal);
> -if (v == NULL)
> -return NULL;
> -kind = PyUnicode_KIND(v);
> -data = PyUnicode_DATA(v);
> -PyUnicode_WRITE(kind, data, 0, ordinal);
> -assert(_PyUnicode_CheckConsistency(v, 1));
> -return v;
> +return unicode_char((Py_UCS4)ordinal);
>  }
>
>  PyObject *
> @@ -11354,17 +11340,7 @@
>  kind = PyUnicode_KIND(self);
>  data = PyUnicode_DATA(self);
>  ch = PyUnicode_READ(kind, data, index);
> -if (ch < 256)
> -return get_latin1_char(ch);
> -
> -res = PyUnicode_New(1, ch);
> -if (res == NULL)
> -return NULL;
> -kind = PyUnicode_KIND(res);
> -data = PyUnicode_DATA(res);
> -PyUnicode_WRITE(kind, data, 0, ch);
> -assert(_PyUnicode_CheckConsistency(res, 1));
> -return res;
> +return unicode_char(ch);
>  }
>
>  /* Believe it or not, this produces the same value for ASCII strings

The above-quoted parts of this changeset caused several compiler
warnings due to unused variables.  On 32-bit Windows:

..\Objects\unicodeobject.c(2881): warning C4101: 'kind' : unreferenced
local variable [P:\ath\to\cpython\PCbuild\pythoncore.vcxproj]
..\Objects\unicodeobject.c(2879): warning C4101: 'v' : unreferenced
local variable [P:\ath\to\cpython\PCbuild\pythoncore.vcxproj]
..\Objects\unicodeobject.c(2880): warning C4101: 'data' : unreferenced
local variable [P:\ath\to\cpython\PCbuild\pythoncore.vcxproj]
..\Objects\unicodeobject.c(11333): warning C4101: 'res' : unreferenced
local variable [P:\ath\to\cpython\PCbuild\pythoncore.vcxproj]

I believe this should fix it, but I'll leave it up to you to confirm
that, Victor :)

diff -r 8a3718f31188 Objects/unicodeobject.c
--- a/Objects/unicodeobject.c   Fri Jan 03 15:53:20 2014 +0100
+++ b/Objects/unicodeobject.c   Fri Jan 03 10:20:12 2014 -0600
@@ -2876,10 +2876,6 @@
 PyObject *
 PyUnicode_FromOrdinal(int ordinal)
 {
-PyObject *v;
-void *data;
-int kind;
-
 if (ordinal < 0 || ordinal > MAX_UNICODE) {
 PyErr_SetString(PyExc_ValueError,
 "chr() arg not in range(0x11)");
@@ -11330,7 +11326,6 @@
 void *data;
 enum PyUnicode_Kind kind;
 Py_UCS4 ch;
-PyObject *res;

 if (!PyUnicode_Check(self) || PyUnicode_READY(self) == -1) {
 PyErr_BadArgument();



-- 
Zach
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] [Python-checkins] cpython: add unicode_char() in unicodeobject.c to factorize code

2014-01-03 Thread Victor Stinner
2014/1/3 Zachary Ware :
> The above-quoted parts of this changeset caused several compiler
> warnings due to unused variables.  On 32-bit Windows:
> (...)
> I believe this should fix it, but I'll leave it up to you to confirm
> that, Victor :)

Oh, I didn't notice these warnings. I fixed them, thanks.

Victor
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


[Python-Dev] Summary of Python tracker Issues

2014-01-03 Thread Python tracker

ACTIVITY SUMMARY (2013-12-27 - 2014-01-03)
Python tracker at http://bugs.python.org/

To view or respond to any of the issues listed below, click on the issue.
Do NOT respond to this message.

Issues counts and deltas:
  open4348 (+16)
  closed 27538 (+18)
  total  31886 (+34)

Open issues with patches: 1977 


Issues opened (27)
==

#18310: itertools.tee() can't accept keyword arguments
http://bugs.python.org/issue18310  reopened by py.user

#20081: sys.getwindowsversion does not show some fields
http://bugs.python.org/issue20081  opened by giampaolo.rodola

#20082: Misbehavior of BufferedRandom.write with raw file in append mo
http://bugs.python.org/issue20082  opened by erik.bray

#20083: smtplib: support for IDN (international domain names)
http://bugs.python.org/issue20083  opened by macfreek

#20085: Python2.7, wxPython and IDLE 2.7
http://bugs.python.org/issue20085  opened by stubz

#20086: test_locale fails on PPC64 PowerLinux
http://bugs.python.org/issue20086  opened by serhiy.storchaka

#20087: Mismatch between glibc and X11 locale.alias
http://bugs.python.org/issue20087  opened by serhiy.storchaka

#20088: locale.getlocale() fails if locale name doesn't include encodi
http://bugs.python.org/issue20088  opened by serhiy.storchaka

#20089: email.message_from_string no longer working in Python 3.4
http://bugs.python.org/issue20089  opened by apollo13

#20090: slight ambiguity in README.txt instructions for building docs
http://bugs.python.org/issue20090  opened by MLModel

#20091: An index entry for __main__ in "30.5 runpy" is missing
http://bugs.python.org/issue20091  opened by MLModel

#20092: type() constructor should bind __int__ to __index__ when __ind
http://bugs.python.org/issue20092  opened by ethan.furman

#20093: Wrong OSError message from os.rename() when dst is a non-empty
http://bugs.python.org/issue20093  opened by jderose

#20094: intermitent failures with test_dbm
http://bugs.python.org/issue20094  opened by ethan.furman

#20096: Mention modernize and future in Python 2/3 porting HOWTO
http://bugs.python.org/issue20096  opened by brett.cannon

#20098: email policy needs a mangle_from setting
http://bugs.python.org/issue20098  opened by r.david.murray

#20100: epoll docs are not clear with regards to CLOEXEC.
http://bugs.python.org/issue20100  opened by r.david.murray

#20101: Determine correct behavior for time functions on Windows
http://bugs.python.org/issue20101  opened by zach.ware

#20102: shutil._make_zipfile possible resource leak
http://bugs.python.org/issue20102  opened by [email protected]

#20103: Documentation of itertools.accumulate is confused
http://bugs.python.org/issue20103  opened by MLModel

#20104: expose posix_spawn(p)
http://bugs.python.org/issue20104  opened by benjamin.peterson

#20105: Codec exception chaining is losing traceback details
http://bugs.python.org/issue20105  opened by ncoghlan

#20106: warn_dir is always true for install_data, even if an install_d
http://bugs.python.org/issue20106  opened by tabrezm

#20109: TestProgram is mentioned in the unittest docs but is not docum
http://bugs.python.org/issue20109  opened by r.david.murray

#20112: The documentation for http.server error_message_format is inad
http://bugs.python.org/issue20112  opened by r.david.murray

#20113: os.readv() and os.writev() don't raise an OSError on readv()/w
http://bugs.python.org/issue20113  opened by haypo

#20114: Sporadic failure of test_semaphore_tracker() of test_multiproc
http://bugs.python.org/issue20114  opened by haypo



Most recent 15 issues with no replies (15)
==

#20114: Sporadic failure of test_semaphore_tracker() of test_multiproc
http://bugs.python.org/issue20114

#20112: The documentation for http.server error_message_format is inad
http://bugs.python.org/issue20112

#20109: TestProgram is mentioned in the unittest docs but is not docum
http://bugs.python.org/issue20109

#20106: warn_dir is always true for install_data, even if an install_d
http://bugs.python.org/issue20106

#20105: Codec exception chaining is losing traceback details
http://bugs.python.org/issue20105

#20103: Documentation of itertools.accumulate is confused
http://bugs.python.org/issue20103

#20102: shutil._make_zipfile possible resource leak
http://bugs.python.org/issue20102

#20096: Mention modernize and future in Python 2/3 porting HOWTO
http://bugs.python.org/issue20096

#20091: An index entry for __main__ in "30.5 runpy" is missing
http://bugs.python.org/issue20091

#20090: slight ambiguity in README.txt instructions for building docs
http://bugs.python.org/issue20090

#20088: locale.getlocale() fails if locale name doesn't include encodi
http://bugs.python.org/issue20088

#20087: Mismatch between glibc and X11 locale.alias
http://bugs.python.org/issue20087

#20082: Misbehavior of BufferedRandom.write with raw file in append mo
http://bugs.python.org/issue20082

#20078: zipfile - ZipExtFile.read goes into 100% CPU infini