Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
6524acb7
Commit
6524acb7
authored
Sep 13, 2015
by
Jelle Zijlstra
Committed by
Jelle Zijlstra
Mar 20, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fstrings: fix more bugs
Not sure about the refcounting
parent
25417282
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
21 deletions
+23
-21
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+16
-10
Cython/Compiler/Parsing.py
Cython/Compiler/Parsing.py
+7
-11
No files found.
Cython/Compiler/ExprNodes.py
View file @
6524acb7
...
...
@@ -2937,8 +2937,8 @@ class FormattedValueNode(ExprNode):
def
generate_result_code
(
self
,
code
):
value_result
=
self
.
value
.
py_result
()
conversion_result
=
Naming
.
quick_temp_cname
format_spec_result
=
self
.
format_spec
.
py_result
()
# TODO conversion chars
if
self
.
conversion_char
==
's'
:
fn
=
'PyObject_Str'
elif
self
.
conversion_char
==
'r'
:
...
...
@@ -2948,25 +2948,31 @@ class FormattedValueNode(ExprNode):
else
:
fn
=
None
code
.
putln
(
'{'
)
if
fn
is
not
None
:
code
.
putln
(
'%s = %s(%s); %s'
%
(
value
_result
,
code
.
putln
(
'
PyObject *
%s = %s(%s); %s'
%
(
conversion
_result
,
fn
,
value_result
,
code
.
error_goto_if_null
(
value
_result
,
self
.
pos
)
code
.
error_goto_if_null
(
conversion
_result
,
self
.
pos
)
))
code
.
put_gotref
(
value_result
)
decref_line
=
'__Pyx_DECREF(%s);'
%
value_result
else
:
decref_line
=
''
code
.
putln
(
'PyObject *%s = %s;'
%
(
conversion_result
,
value_result
))
#code.put_incref(conversion_result, py_object_type)
# TODO this should need more refcounting, figure out whether this is correct
#code.put_gotref(conversion_result)
#code.put_decref(value_result, self.value.ctype())
decref_line
=
''
# '__Pyx_DECREF(%s);' % conversion_result
code
.
putln
(
"%s = PyObject_Format(%s, %s); %s %s"
%
(
self
.
result
(),
value
_result
,
conversion
_result
,
format_spec_result
,
decref_line
,
code
.
error_goto_if_null
(
self
.
result
(),
self
.
pos
)))
code
.
put_gotref
(
self
.
py_result
())
code
.
putln
(
'}'
)
#-------------------------------------------------------------------
...
...
Cython/Compiler/Parsing.py
View file @
6524acb7
...
...
@@ -998,15 +998,14 @@ def p_f_string(s, unicode_value, pos):
current_literal_start
=
0
while
i
<
size
:
c
=
unicode_value
[
i
]
if
c
==
'}'
:
if
i
+
1
>=
size
or
unicode_value
[
i
+
1
]
!=
'}'
:
s
.
error
(
"single '}' encountered in format string"
)
else
:
i
+=
2
elif
c
==
'{'
:
# double { escapes it
if
i
+
1
<
size
and
unicode_value
[
i
+
1
]
==
'{'
:
if
c
in
(
'{'
,
'}'
):
if
i
+
1
<
size
and
unicode_value
[
i
+
1
]
==
c
:
encoded_str
=
EncodedString
(
unicode_value
[
current_literal_start
:
i
+
1
])
values
.
append
(
ExprNodes
.
UnicodeNode
(
pos
,
value
=
encoded_str
))
i
+=
2
current_literal_start
=
i
elif
c
==
'}'
:
s
.
error
(
"single '}' encountered in format string"
)
else
:
encoded_str
=
EncodedString
(
unicode_value
[
current_literal_start
:
i
])
values
.
append
(
ExprNodes
.
UnicodeNode
(
pos
,
value
=
encoded_str
))
...
...
@@ -1018,7 +1017,6 @@ def p_f_string(s, unicode_value, pos):
encoded_str
=
EncodedString
(
unicode_value
[
current_literal_start
:])
values
.
append
(
ExprNodes
.
UnicodeNode
(
pos
,
value
=
encoded_str
))
print
(
"F-STRING VALUES"
,
values
)
return
values
...
...
@@ -1109,8 +1107,6 @@ def p_f_string_expr(s, unicode_value, pos, starting_index):
if
terminal_char
!=
'}'
:
s
.
error
(
"missing '}' in format string expression'"
)
print
(
'expr=%r, conversion_char=%r, format_spec=%r'
%
(
expr_str
,
conversion_char
,
format_spec_str
))
# parse the expression
name
=
'format string expression'
code_source
=
StringSourceDescriptor
(
name
,
expr_str
)
...
...
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