Kaydet (Commit) 8a4eb298 authored tarafından Neal Norwitz's avatar Neal Norwitz

Fix refleaks in test_unicode and test_string related to the new format code.

Stop polluting namespace.
üst 2bad9702
...@@ -1437,10 +1437,8 @@ PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strchr( ...@@ -1437,10 +1437,8 @@ PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strchr(
const Py_UNICODE *s, Py_UNICODE c const Py_UNICODE *s, Py_UNICODE c
); );
PyObject * PyObject *_PyUnicode_FormatterIterator(PyObject *str);
_unicodeformatter_iterator(PyObject *str); PyObject *_PyUnicode_FormatterFieldNameSplit(PyObject *field_name);
PyObject *
_unicodeformatter_field_name_split(PyObject *field_name);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -416,6 +416,7 @@ get_field_object(SubString *input, PyObject *args, PyObject *kwargs) ...@@ -416,6 +416,7 @@ get_field_object(SubString *input, PyObject *args, PyObject *kwargs)
Py_DECREF(key); Py_DECREF(key);
goto error; goto error;
} }
Py_DECREF(key);
Py_INCREF(obj); Py_INCREF(obj);
} else { } else {
/* look up in args */ /* look up in args */
......
...@@ -9206,11 +9206,11 @@ formatteriter_next(formatteriterobject *it) ...@@ -9206,11 +9206,11 @@ formatteriter_next(formatteriterobject *it)
PyObject *field_name_str = NULL; PyObject *field_name_str = NULL;
PyObject *format_spec_str = NULL; PyObject *format_spec_str = NULL;
PyObject *conversion_str = NULL; PyObject *conversion_str = NULL;
PyObject *result = NULL; PyObject *tuple = NULL;
is_markup_bool = PyBool_FromLong(is_markup); is_markup_bool = PyBool_FromLong(is_markup);
if (!is_markup_bool) if (!is_markup_bool)
goto error; return NULL;
if (is_markup) { if (is_markup) {
/* field_name, format_spec, and conversion are /* field_name, format_spec, and conversion are
...@@ -9251,22 +9251,16 @@ formatteriter_next(formatteriterobject *it) ...@@ -9251,22 +9251,16 @@ formatteriter_next(formatteriterobject *it)
Py_INCREF(format_spec_str); Py_INCREF(format_spec_str);
Py_INCREF(conversion_str); Py_INCREF(conversion_str);
} }
/* return a tuple of values */ tuple = PyTuple_Pack(5, is_markup_bool, literal_str,
result = PyTuple_Pack(5, is_markup_bool, literal_str, field_name_str, format_spec_str,
field_name_str, format_spec_str, conversion_str);
conversion_str);
if (result == NULL)
goto error;
return result;
error: error:
Py_XDECREF(is_markup_bool); Py_XDECREF(is_markup_bool);
Py_XDECREF(literal_str); Py_XDECREF(literal_str);
Py_XDECREF(field_name_str); Py_XDECREF(field_name_str);
Py_XDECREF(format_spec_str); Py_XDECREF(format_spec_str);
Py_XDECREF(conversion_str); Py_XDECREF(conversion_str);
Py_XDECREF(result); return tuple;
return NULL;
} }
} }
...@@ -9308,10 +9302,11 @@ PyTypeObject PyFormatterIter_Type = { ...@@ -9308,10 +9302,11 @@ PyTypeObject PyFormatterIter_Type = {
}; };
PyObject * PyObject *
_unicodeformatter_iterator(PyObject *str) _PyUnicode_FormatterIterator(PyObject *str)
{ {
formatteriterobject *it; formatteriterobject *it;
assert(PyUnicode_Check(str));
it = PyObject_New(formatteriterobject, &PyFormatterIter_Type); it = PyObject_New(formatteriterobject, &PyFormatterIter_Type);
if (it == NULL) if (it == NULL)
return NULL; return NULL;
...@@ -9440,21 +9435,24 @@ static PyTypeObject PyFieldNameIter_Type = { ...@@ -9440,21 +9435,24 @@ static PyTypeObject PyFieldNameIter_Type = {
0}; 0};
PyObject * PyObject *
_unicodeformatter_field_name_split(PyObject *field_name) _PyUnicode_FormatterFieldNameSplit(PyObject *field_name)
{ {
SubString first; SubString first;
Py_ssize_t first_idx; Py_ssize_t first_idx;
fieldnameiterobject *it; fieldnameiterobject *it;
PyObject *first_obj = NULL; PyObject *first_obj = NULL;
PyObject *it_obj = NULL; PyObject *result = NULL;
PyObject *result;
assert(PyUnicode_Check(field_name));
it = PyObject_New(fieldnameiterobject, &PyFieldNameIter_Type); it = PyObject_New(fieldnameiterobject, &PyFieldNameIter_Type);
if (it == NULL) if (it == NULL)
goto error; return NULL;
it->str = NULL;
it_obj = (PyObject *)it; /* take ownership, give the object to the iterator. this is
just to keep the field_name alive */
Py_INCREF(field_name);
it->str = field_name;
if (!field_name_split(STRINGLIB_STR(field_name), if (!field_name_split(STRINGLIB_STR(field_name),
STRINGLIB_LEN(field_name), STRINGLIB_LEN(field_name),
...@@ -9470,21 +9468,13 @@ _unicodeformatter_field_name_split(PyObject *field_name) ...@@ -9470,21 +9468,13 @@ _unicodeformatter_field_name_split(PyObject *field_name)
if (first_obj == NULL) if (first_obj == NULL)
goto error; goto error;
/* take ownership, give the object to the iterator. this is
just to keep the field_name alive */
Py_INCREF(field_name);
it->str = field_name;
/* return a tuple of values */ /* return a tuple of values */
result = PyTuple_Pack(2, first_obj, it_obj); result = PyTuple_Pack(2, first_obj, it);
if (result == NULL)
goto error;
return result;
error: error:
Py_XDECREF(it_obj); Py_XDECREF(it);
Py_XDECREF(first_obj); Py_XDECREF(first_obj);
return NULL; return result;
} }
/********************* Unicode Iterator **************************/ /********************* Unicode Iterator **************************/
......
...@@ -663,7 +663,7 @@ sys_current_frames(PyObject *self, PyObject *noargs) ...@@ -663,7 +663,7 @@ sys_current_frames(PyObject *self, PyObject *noargs)
/* sys_formatter_iterator is used to implement /* sys_formatter_iterator is used to implement
string.Formatter.vformat. it parses a string and returns tuples string.Formatter.vformat. it parses a string and returns tuples
describing the parsed elements. see unicodeobject.c's describing the parsed elements. see unicodeobject.c's
_unicodeformatter_iterator for details */ _PyUnicode_FormatterIterator for details */
static PyObject * static PyObject *
sys_formatter_iterator(PyObject *self, PyObject *args) sys_formatter_iterator(PyObject *self, PyObject *args)
{ {
...@@ -680,14 +680,14 @@ sys_formatter_iterator(PyObject *self, PyObject *args) ...@@ -680,14 +680,14 @@ sys_formatter_iterator(PyObject *self, PyObject *args)
return NULL; return NULL;
} }
return _unicodeformatter_iterator(str); return _PyUnicode_FormatterIterator(str);
} }
/* sys_formatter_field_name_split is used to implement /* sys_formatter_field_name_split is used to implement
string.Formatter.vformat. it takes an PEP 3101 "field name", and string.Formatter.vformat. it takes an PEP 3101 "field name", and
returns a tuple of (first, rest): "first", the part before the returns a tuple of (first, rest): "first", the part before the
first '.' or '['; and "rest", an iterator for the rest of the field first '.' or '['; and "rest", an iterator for the rest of the field
name. see unicodeobjects' _unicode_formatter_field_name_split for name. see unicodeobjects' _PyUnicode_FormatterFieldNameSplit for
details */ details */
static PyObject * static PyObject *
sys_formatter_field_name_split(PyObject *self, PyObject *args) sys_formatter_field_name_split(PyObject *self, PyObject *args)
...@@ -704,7 +704,7 @@ sys_formatter_field_name_split(PyObject *self, PyObject *args) ...@@ -704,7 +704,7 @@ sys_formatter_field_name_split(PyObject *self, PyObject *args)
return NULL; return NULL;
} }
return _unicodeformatter_field_name_split(field_name); return _PyUnicode_FormatterFieldNameSplit(field_name);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment