Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
45c07873
Commit
45c07873
authored
Sep 05, 2007
by
Eric Smith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplified recursion logic. Modified variable name to match string.Formatter.
parent
11529195
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
12 deletions
+10
-12
Objects/stringlib/string_format.h
Objects/stringlib/string_format.h
+10
-12
No files found.
Objects/stringlib/string_format.h
View file @
45c07873
...
...
@@ -29,7 +29,7 @@ typedef struct {
/* forward declaration for recursion */
static
PyObject
*
build_string
(
SubString
*
input
,
PyObject
*
args
,
PyObject
*
kwargs
,
int
*
recursion_level
);
int
recursion_depth
);
...
...
@@ -792,7 +792,7 @@ static int
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 @@ output_markup(SubString *field_name, SubString *format_spec,
/* 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 @@ done:
*/
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 @@ do_markup(SubString *input, PyObject *args, PyObject *kwargs,
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 @@ do_markup(SubString *input, PyObject *args, PyObject *kwargs,
*/
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 @@ build_string(SubString *input, PyObject *args, PyObject *kwargs,
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 @@ build_string(SubString *input, PyObject *args, PyObject *kwargs,
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 @@ build_string(SubString *input, PyObject *args, PyObject *kwargs,
output
.
obj
=
NULL
;
done:
(
*
recursion_level
)
++
;
Py_XDECREF
(
output
.
obj
);
return
result
;
}
...
...
@@ -940,10 +938,10 @@ do_string_format(PyObject *self, PyObject *args, PyObject *kwargs)
"{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
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment