[Python-3000-checkins] r57982 - python/branches/py3k/Objects/stringlib/string_format.h

eric.smith python-3000-checkins at python.org
Wed Sep 5 04:02:43 CEST 2007


Author: eric.smith
Date: Wed Sep  5 04:02:43 2007
New Revision: 57982

Modified:
   python/branches/py3k/Objects/stringlib/string_format.h
Log:
Simplified recursion logic.  Modified variable name to match string.Formatter.

Modified: python/branches/py3k/Objects/stringlib/string_format.h
==============================================================================
--- python/branches/py3k/Objects/stringlib/string_format.h	(original)
+++ python/branches/py3k/Objects/stringlib/string_format.h	Wed Sep  5 04:02:43 2007
@@ -29,7 +29,7 @@
 /* forward declaration for recursion */
 static PyObject *
 build_string(SubString *input, PyObject *args, PyObject *kwargs,
-             int *recursion_level);
+             int recursion_depth);
 
 
 
@@ -792,7 +792,7 @@
 output_markup(SubString *field_name, SubString *format_spec,
               int format_spec_needs_expanding, STRINGLIB_CHAR conversion,
               OutputString *output, PyObject *args, PyObject *kwargs,
-              int *recursion_level)
+              int recursion_depth)
 {
     PyObject *tmp = NULL;
     PyObject *fieldobj = NULL;
@@ -818,7 +818,7 @@
 
     /* if needed, recurively compute the format_spec */
     if (format_spec_needs_expanding) {
-        tmp = build_string(format_spec, args, kwargs, recursion_level);
+        tmp = build_string(format_spec, args, kwargs, recursion_depth-1);
         if (tmp == NULL)
             goto done;
 
@@ -852,7 +852,7 @@
 */
 static int
 do_markup(SubString *input, PyObject *args, PyObject *kwargs,
-          OutputString *output, int *recursion_level)
+          OutputString *output, int recursion_depth)
 {
     MarkupIterator iter;
     int format_spec_needs_expanding;
@@ -871,7 +871,7 @@
         if (field_name.ptr != field_name.end)
             if (!output_markup(&field_name, &format_spec,
                                format_spec_needs_expanding, conversion, output,
-                               args, kwargs, recursion_level))
+                               args, kwargs, recursion_depth))
                 return 0;
     }
     return result;
@@ -884,7 +884,7 @@
 */
 static PyObject *
 build_string(SubString *input, PyObject *args, PyObject *kwargs,
-             int *recursion_level)
+             int recursion_depth)
 {
     OutputString output;
     PyObject *result = NULL;
@@ -893,8 +893,7 @@
     output.obj = NULL; /* needed so cleanup code always works */
 
     /* check the recursion level */
-    (*recursion_level)--;
-    if (*recursion_level < 0) {
+    if (recursion_depth <= 0) {
         PyErr_SetString(PyExc_ValueError,
                         "Max string recursion exceeded");
         goto done;
@@ -907,7 +906,7 @@
                            INITIAL_SIZE_INCREMENT))
         goto done;
 
-    if (!do_markup(input, args, kwargs, &output, recursion_level)) {
+    if (!do_markup(input, args, kwargs, &output, recursion_depth)) {
         goto done;
     }
 
@@ -921,7 +920,6 @@
     output.obj = NULL;
 
 done:
-    (*recursion_level)++;
     Py_XDECREF(output.obj);
     return result;
 }
@@ -940,10 +938,10 @@
        "{0:{1}}".format('abc', 's')            # works
        "{0:{1:{2}}}".format('abc', 's', '')    # fails
     */
-    int recursion_level = 2;
+    int recursion_depth = 2;
 
     SubString_init(&input, STRINGLIB_STR(self), STRINGLIB_LEN(self));
-    return build_string(&input, args, kwargs, &recursion_level);
+    return build_string(&input, args, kwargs, recursion_depth);
 }
 
 


More information about the Python-3000-checkins mailing list