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
ab8b75a5
Commit
ab8b75a5
authored
Oct 04, 2016
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #28350: String constants with null character no longer interned.
parent
317d350f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
8 deletions
+27
-8
Lib/test/test_code.py
Lib/test/test_code.py
+17
-3
Misc/NEWS
Misc/NEWS
+2
-0
Objects/codeobject.c
Objects/codeobject.c
+8
-5
No files found.
Lib/test/test_code.py
View file @
ab8b75a5
...
@@ -112,19 +112,27 @@ class CodeTest(unittest.TestCase):
...
@@ -112,19 +112,27 @@ class CodeTest(unittest.TestCase):
self
.
assertEqual
(
co
.
co_name
,
"funcname"
)
self
.
assertEqual
(
co
.
co_name
,
"funcname"
)
self
.
assertEqual
(
co
.
co_firstlineno
,
15
)
self
.
assertEqual
(
co
.
co_firstlineno
,
15
)
def
isinterned
(
s
):
return
s
is
intern
((
'_'
+
s
+
'_'
)[
1
:
-
1
])
class
CodeConstsTest
(
unittest
.
TestCase
):
class
CodeConstsTest
(
unittest
.
TestCase
):
def
find_const
(
self
,
consts
,
value
):
def
find_const
(
self
,
consts
,
value
):
for
v
in
consts
:
for
v
in
consts
:
if
v
==
value
:
if
v
==
value
:
return
v
return
v
self
.
assertIn
(
value
,
consts
)
# rises an exception
self
.
assertIn
(
value
,
consts
)
# r
a
ises an exception
self
.
fail
(
'Should
be never
reached'
)
self
.
fail
(
'Should
never be
reached'
)
def
assertIsInterned
(
self
,
s
):
def
assertIsInterned
(
self
,
s
):
if
s
is
not
intern
(
s
):
if
not
isinterned
(
s
):
self
.
fail
(
'String %r is not interned'
%
(
s
,))
self
.
fail
(
'String %r is not interned'
%
(
s
,))
def
assertIsNotInterned
(
self
,
s
):
if
isinterned
(
s
):
self
.
fail
(
'String %r is interned'
%
(
s
,))
@
cpython_only
@
cpython_only
def
test_interned_string
(
self
):
def
test_interned_string
(
self
):
co
=
compile
(
'res = "str_value"'
,
'?'
,
'exec'
)
co
=
compile
(
'res = "str_value"'
,
'?'
,
'exec'
)
...
@@ -143,6 +151,12 @@ class CodeConstsTest(unittest.TestCase):
...
@@ -143,6 +151,12 @@ class CodeConstsTest(unittest.TestCase):
return
a
return
a
self
.
assertIsInterned
(
f
())
self
.
assertIsInterned
(
f
())
@
cpython_only
def
test_interned_string_with_null
(
self
):
co
=
compile
(
r'res = "str\0value!"'
,
'?'
,
'exec'
)
v
=
self
.
find_const
(
co
.
co_consts
,
'str
\
0
value!'
)
self
.
assertIsNotInterned
(
v
)
class
CodeWeakRefTest
(
unittest
.
TestCase
):
class
CodeWeakRefTest
(
unittest
.
TestCase
):
...
...
Misc/NEWS
View file @
ab8b75a5
...
@@ -10,6 +10,8 @@ What's New in Python 2.7.13?
...
@@ -10,6 +10,8 @@ What's New in Python 2.7.13?
Core and Builtins
Core and Builtins
-----------------
-----------------
- Issue #28350: String constants with null character no longer interned.
- Issue #27942: String constants now interned recursively in tuples and frozensets.
- Issue #27942: String constants now interned recursively in tuples and frozensets.
- Issue #15578: Correctly incref the parent module while importing.
- Issue #15578: Correctly incref the parent module while importing.
...
...
Objects/codeobject.c
View file @
ab8b75a5
...
@@ -8,17 +8,20 @@
...
@@ -8,17 +8,20 @@
/* all_name_chars(s): true iff all chars in s are valid NAME_CHARS */
/* all_name_chars(s): true iff all chars in s are valid NAME_CHARS */
static
int
static
int
all_name_chars
(
unsigned
char
*
s
)
all_name_chars
(
PyObject
*
o
)
{
{
static
char
ok_name_char
[
256
];
static
char
ok_name_char
[
256
];
static
unsigned
char
*
name_chars
=
(
unsigned
char
*
)
NAME_CHARS
;
static
const
unsigned
char
*
name_chars
=
(
unsigned
char
*
)
NAME_CHARS
;
const
unsigned
char
*
s
,
*
e
;
if
(
ok_name_char
[
*
name_chars
]
==
0
)
{
if
(
ok_name_char
[
*
name_chars
]
==
0
)
{
unsigned
char
*
p
;
const
unsigned
char
*
p
;
for
(
p
=
name_chars
;
*
p
;
p
++
)
for
(
p
=
name_chars
;
*
p
;
p
++
)
ok_name_char
[
*
p
]
=
1
;
ok_name_char
[
*
p
]
=
1
;
}
}
while
(
*
s
)
{
s
=
(
unsigned
char
*
)
PyString_AS_STRING
(
o
);
e
=
s
+
PyString_GET_SIZE
(
o
);
while
(
s
!=
e
)
{
if
(
ok_name_char
[
*
s
++
]
==
0
)
if
(
ok_name_char
[
*
s
++
]
==
0
)
return
0
;
return
0
;
}
}
...
@@ -49,7 +52,7 @@ intern_string_constants(PyObject *tuple)
...
@@ -49,7 +52,7 @@ intern_string_constants(PyObject *tuple)
for
(
i
=
PyTuple_GET_SIZE
(
tuple
);
--
i
>=
0
;
)
{
for
(
i
=
PyTuple_GET_SIZE
(
tuple
);
--
i
>=
0
;
)
{
PyObject
*
v
=
PyTuple_GET_ITEM
(
tuple
,
i
);
PyObject
*
v
=
PyTuple_GET_ITEM
(
tuple
,
i
);
if
(
PyString_CheckExact
(
v
))
{
if
(
PyString_CheckExact
(
v
))
{
if
(
all_name_chars
(
(
unsigned
char
*
)
PyString_AS_STRING
(
v
)
))
{
if
(
all_name_chars
(
v
))
{
PyObject
*
w
=
v
;
PyObject
*
w
=
v
;
PyString_InternInPlace
(
&
v
);
PyString_InternInPlace
(
&
v
);
if
(
w
!=
v
)
{
if
(
w
!=
v
)
{
...
...
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