Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
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
Boxiang Sun
Pyston
Commits
a762c2e7
Commit
a762c2e7
authored
Sep 08, 2014
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check the number of arguments during string formatting
parent
a1152469
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
4 deletions
+24
-4
src/runtime/str.cpp
src/runtime/str.cpp
+12
-4
test/tests/string_interpolation.py
test/tests/string_interpolation.py
+12
-0
No files found.
src/runtime/str.cpp
View file @
a762c2e7
...
...
@@ -139,7 +139,8 @@ extern "C" Box* strMod(BoxedString* lhs, Box* rhs) {
RELEASE_ASSERT
(
nspace
==
0
,
""
);
if
(
!
val_to_use
)
{
RELEASE_ASSERT
(
elt_num
<
num_elts
,
"insufficient number of arguments for format string"
);
if
(
elt_num
>=
num_elts
)
raiseExcHelper
(
TypeError
,
"not enough arguments for format string"
);
val_to_use
=
(
*
elts
)[
elt_num
];
elt_num
++
;
}
...
...
@@ -149,7 +150,8 @@ extern "C" Box* strMod(BoxedString* lhs, Box* rhs) {
break
;
}
else
if
(
c
==
'c'
)
{
if
(
!
val_to_use
)
{
RELEASE_ASSERT
(
elt_num
<
num_elts
,
"insufficient number of arguments for format string"
);
if
(
elt_num
>=
num_elts
)
raiseExcHelper
(
TypeError
,
"not enough arguments for format string"
);
val_to_use
=
(
*
elts
)[
elt_num
];
elt_num
++
;
}
...
...
@@ -168,7 +170,8 @@ extern "C" Box* strMod(BoxedString* lhs, Box* rhs) {
break
;
}
else
if
(
c
==
'd'
||
c
==
'i'
)
{
if
(
!
val_to_use
)
{
RELEASE_ASSERT
(
elt_num
<
num_elts
,
"insufficient number of arguments for format string"
);
if
(
elt_num
>=
num_elts
)
raiseExcHelper
(
TypeError
,
"not enough arguments for format string"
);
val_to_use
=
(
*
elts
)[
elt_num
];
elt_num
++
;
}
...
...
@@ -191,7 +194,8 @@ extern "C" Box* strMod(BoxedString* lhs, Box* rhs) {
break
;
}
else
if
(
c
==
'f'
)
{
if
(
!
val_to_use
)
{
RELEASE_ASSERT
(
elt_num
<
num_elts
,
"insufficient number of arguments for format string"
);
if
(
elt_num
>=
num_elts
)
raiseExcHelper
(
TypeError
,
"not enough arguments for format string"
);
val_to_use
=
(
*
elts
)[
elt_num
];
elt_num
++
;
}
...
...
@@ -227,6 +231,10 @@ extern "C" Box* strMod(BoxedString* lhs, Box* rhs) {
}
assert
(
fmt
==
fmt_end
&&
"incomplete format"
);
if
(
dict
==
NULL
&&
elt_num
<
num_elts
)
{
raiseExcHelper
(
TypeError
,
"not all arguments converted during string formatting"
);
}
return
boxString
(
os
.
str
());
}
...
...
test/tests/string_interpolation.py
View file @
a762c2e7
...
...
@@ -22,3 +22,15 @@ try:
print
repr
(
"%c"
%
256
)
except
OverflowError
,
e
:
print
e
try
:
""
%
(
1
,
2
)
assert
0
except
TypeError
,
e
:
print
e
try
:
"%d"
%
()
assert
0
except
TypeError
,
e
:
print
e
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