Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
67edf731
Kaydet (Commit)
67edf731
authored
Eyl 30, 2016
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #27942: String constants now interned recursively in tuples and frozensets.
üst
8d7fa40c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
79 additions
and
10 deletions
+79
-10
test_code.py
Lib/test/test_code.py
+32
-1
NEWS
Misc/NEWS
+2
-0
codeobject.c
Objects/codeobject.c
+45
-9
No files found.
Lib/test/test_code.py
Dosyayı görüntüle @
67edf731
...
...
@@ -112,6 +112,37 @@ class CodeTest(unittest.TestCase):
self
.
assertEqual
(
co
.
co_name
,
"funcname"
)
self
.
assertEqual
(
co
.
co_firstlineno
,
15
)
class
CodeConstsTest
(
unittest
.
TestCase
):
def
find_const
(
self
,
consts
,
value
):
for
v
in
consts
:
if
v
==
value
:
return
v
self
.
assertIn
(
value
,
consts
)
# rises an exception
self
.
fail
(
'Should be never reached'
)
def
assertIsInterned
(
self
,
s
):
if
s
is
not
intern
(
s
):
self
.
fail
(
'String
%
r is not interned'
%
(
s
,))
@cpython_only
def
test_interned_string
(
self
):
co
=
compile
(
'res = "str_value"'
,
'?'
,
'exec'
)
v
=
self
.
find_const
(
co
.
co_consts
,
'str_value'
)
self
.
assertIsInterned
(
v
)
@cpython_only
def
test_interned_string_in_tuple
(
self
):
co
=
compile
(
'res = ("str_value",)'
,
'?'
,
'exec'
)
v
=
self
.
find_const
(
co
.
co_consts
,
(
'str_value'
,))
self
.
assertIsInterned
(
v
[
0
])
@cpython_only
def
test_interned_string_default
(
self
):
def
f
(
a
=
'str_value'
):
return
a
self
.
assertIsInterned
(
f
())
class
CodeWeakRefTest
(
unittest
.
TestCase
):
...
...
@@ -141,7 +172,7 @@ class CodeWeakRefTest(unittest.TestCase):
def
test_main
(
verbose
=
None
):
from
test
import
test_code
run_doctest
(
test_code
,
verbose
)
run_unittest
(
CodeTest
,
CodeWeakRefTest
)
run_unittest
(
CodeTest
,
Code
ConstsTest
,
Code
WeakRefTest
)
if
__name__
==
"__main__"
:
...
...
Misc/NEWS
Dosyayı görüntüle @
67edf731
...
...
@@ -10,6 +10,8 @@ What's New in Python 2.7.13?
Core and Builtins
-----------------
- Issue #27942: String constants now interned recursively in tuples and frozensets.
- Issue #15578: Correctly incref the parent module while importing.
- Issue #26307: The profile-opt build now applys PGO to the built-in modules.
...
...
Objects/codeobject.c
Dosyayı görüntüle @
67edf731
...
...
@@ -39,6 +39,50 @@ intern_strings(PyObject *tuple)
}
}
/* Intern selected string constants */
static
int
intern_string_constants
(
PyObject
*
tuple
)
{
int
modified
=
0
;
Py_ssize_t
i
;
for
(
i
=
PyTuple_GET_SIZE
(
tuple
);
--
i
>=
0
;
)
{
PyObject
*
v
=
PyTuple_GET_ITEM
(
tuple
,
i
);
if
(
PyString_CheckExact
(
v
))
{
if
(
all_name_chars
((
unsigned
char
*
)
PyString_AS_STRING
(
v
)))
{
PyObject
*
w
=
v
;
PyString_InternInPlace
(
&
v
);
if
(
w
!=
v
)
{
PyTuple_SET_ITEM
(
tuple
,
i
,
v
);
modified
=
1
;
}
}
}
else
if
(
PyTuple_CheckExact
(
v
))
{
intern_string_constants
(
v
);
}
else
if
(
PyFrozenSet_CheckExact
(
v
))
{
PyObject
*
tmp
=
PySequence_Tuple
(
v
);
if
(
tmp
==
NULL
)
{
PyErr_Clear
();
continue
;
}
if
(
intern_string_constants
(
tmp
))
{
v
=
PyFrozenSet_New
(
tmp
);
if
(
v
==
NULL
)
{
PyErr_Clear
();
}
else
{
PyTuple_SET_ITEM
(
tuple
,
i
,
v
);
modified
=
1
;
}
}
Py_DECREF
(
tmp
);
}
}
return
modified
;
}
PyCodeObject
*
PyCode_New
(
int
argcount
,
int
nlocals
,
int
stacksize
,
int
flags
,
...
...
@@ -68,15 +112,7 @@ PyCode_New(int argcount, int nlocals, int stacksize, int flags,
intern_strings
(
varnames
);
intern_strings
(
freevars
);
intern_strings
(
cellvars
);
/* Intern selected string constants */
for
(
i
=
PyTuple_Size
(
consts
);
--
i
>=
0
;
)
{
PyObject
*
v
=
PyTuple_GetItem
(
consts
,
i
);
if
(
!
PyString_Check
(
v
))
continue
;
if
(
!
all_name_chars
((
unsigned
char
*
)
PyString_AS_STRING
(
v
)))
continue
;
PyString_InternInPlace
(
&
PyTuple_GET_ITEM
(
consts
,
i
));
}
intern_string_constants
(
consts
);
co
=
PyObject_NEW
(
PyCodeObject
,
&
PyCode_Type
);
if
(
co
!=
NULL
)
{
co
->
co_argcount
=
argcount
;
...
...
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