[Python-checkins] r74040 - in python/trunk: Lib/test/test_warnings.py Python/_warnings.c

Alexandre Vassalotti alexandre at peadrop.com
Sat Jul 18 02:58:45 CEST 2009


On Fri, Jul 17, 2009 at 2:20 AM,
hirokazu.yamamoto<python-checkins at python.org> wrote:
> Author: hirokazu.yamamoto
> Date: Fri Jul 17 08:20:46 2009
> New Revision: 74040
>> Log:
> Issue #6415: Fixed warnings.warn sagfault on bad formatted string.
>> Modified:
>   python/trunk/Lib/test/test_warnings.py
>   python/trunk/Python/_warnings.c
>> Modified: python/trunk/Lib/test/test_warnings.py
> ==============================================================================
> --- python/trunk/Lib/test/test_warnings.py      (original)
> +++ python/trunk/Lib/test/test_warnings.py      Fri Jul 17 08:20:46 2009
> @@ -327,6 +327,19 @@
>                             self.module.warn_explicit,
>                             None, Warning, None, 1, registry=42)
>> +    def test_bad_str(self):
> +        # issue 6415
> +        # Warnings instance with a bad format string for __str__ should not
> +        # trigger a bus error.
> +        class BadStrWarning(Warning):
> +            """Warning with a bad format string for __str__."""
> +            def __str__(self):
> +                return ("A bad formatted string %(err)" %
> +                        {"err" : "there is no %(err)s"})
> +
> +        with self.assertRaises(ValueError):
> +            self.module.warn(BadStrWarning())
> +
>
assertRaises() takes two arguments on 2.6. Also, you cannot use
assertRaises() as a context manager on 2.6.
>  class CWarnTests(BaseTest, WarnTests):
>     module = c_warnings
>> Modified: python/trunk/Python/_warnings.c
> ==============================================================================
> --- python/trunk/Python/_warnings.c     (original)
> +++ python/trunk/Python/_warnings.c     Fri Jul 17 08:20:46 2009
> @@ -317,6 +317,8 @@
>     }
>     if (rc == 1) {
>         text = PyObject_Str(message);
> +        if (text == NULL)
> +            goto cleanup;
>         category = (PyObject*)message->ob_type;
>     }
>     else {
> _______________________________________________
> Python-checkins mailing list
> Python-checkins at python.org
> http://mail.python.org/mailman/listinfo/python-checkins
>
-- 
-- Alexandre


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /