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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
f7b4f6fe
Commit
f7b4f6fe
authored
Feb 28, 2008
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow single-character ascii strings to be treated as c character literals.
parent
f5aeb375
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
2 deletions
+29
-2
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+29
-2
No files found.
Cython/Compiler/ExprNodes.py
View file @
f7b4f6fe
...
...
@@ -682,6 +682,12 @@ class StringNode(ConstNode):
self
.
entry
=
env
.
add_string_const
(
self
.
value
)
def
coerce_to
(
self
,
dst_type
,
env
):
if
dst_type
.
is_int
:
if
not
self
.
type
.
is_pyobject
and
len
(
self
.
value
)
==
1
:
return
CharNode
(
self
.
pos
,
value
=
self
.
value
)
else
:
error
(
self
.
pos
,
"Only coerce single-character ascii strings can be used as ints."
)
return
self
# Arrange for a Python version of the string to be pre-allocated
# when coercing to a Python type.
if
dst_type
.
is_pyobject
and
not
self
.
type
.
is_pyobject
:
...
...
@@ -3355,6 +3361,8 @@ class PrimaryCmpNode(ExprNode, CmpNode):
self
.
is_pycmp
=
self
.
is_python_comparison
()
if
self
.
is_pycmp
:
self
.
coerce_operands_to_pyobjects
(
env
)
if
self
.
has_int_operands
():
self
.
coerce_chars_to_ints
(
env
)
if
self
.
cascade
:
#self.operand2 = self.operand2.coerce_to_temp(env) #CTT
self
.
operand2
=
self
.
operand2
.
coerce_to_simple
(
env
)
...
...
@@ -3387,6 +3395,18 @@ class PrimaryCmpNode(ExprNode, CmpNode):
if
self
.
cascade
:
self
.
cascade
.
coerce_operands_to_pyobjects
(
env
)
def
has_int_operands
(
self
):
return
(
self
.
operand1
.
type
.
is_int
or
self
.
operand2
.
type
.
is_int
)
\
or
(
self
.
cascade
and
self
.
cascade
.
has_int_operands
())
def
coerce_chars_to_ints
(
self
,
env
):
if
self
.
operand1
.
type
.
is_string
:
self
.
operand1
=
self
.
operand1
.
coerce_to
(
PyrexTypes
.
c_uchar_type
,
env
)
if
self
.
operand2
.
type
.
is_string
:
self
.
operand2
=
self
.
operand2
.
coerce_to
(
PyrexTypes
.
c_uchar_type
,
env
)
if
self
.
cascade
:
self
.
cascade
.
coerce_chars_to_ints
(
env
)
def
allocate_subexpr_temps
(
self
,
env
):
self
.
operand1
.
allocate_temps
(
env
)
self
.
operand2
.
allocate_temps
(
env
)
...
...
@@ -3467,6 +3487,13 @@ class CascadedCmpNode(Node, CmpNode):
if
self
.
cascade
:
self
.
cascade
.
coerce_operands_to_pyobjects
(
env
)
def
has_int_operands
(
self
):
return
self
.
operand2
.
type
.
is_int
def
coerce_chars_to_ints
(
self
,
env
):
if
self
.
operand2
.
type
.
is_string
:
self
.
operand2
=
self
.
operand2
.
coerce_to
(
PyrexTypes
.
c_uchar_type
,
env
)
def
coerce_cascaded_operands_to_temp
(
self
,
env
):
if
self
.
cascade
:
#self.operand2 = self.operand2.coerce_to_temp(env) #CTT
...
...
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