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
d7d47656
Commit
d7d47656
authored
May 07, 2015
by
Rudi Chen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement intern() builtin function.
parent
27e24f67
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
0 deletions
+28
-0
src/runtime/builtin_modules/builtins.cpp
src/runtime/builtin_modules/builtins.cpp
+13
-0
test/tests/intern.py
test/tests/intern.py
+15
-0
No files found.
src/runtime/builtin_modules/builtins.cpp
View file @
d7d47656
...
...
@@ -958,6 +958,16 @@ Box* input(Box* prompt) {
throwCAPIException
();
}
Box
*
intern
(
Box
*
str
)
{
if
(
!
PyString_Check
(
str
))
{
raiseExcHelper
(
TypeError
,
"must be string, not %s"
,
getTypeName
(
str
));
}
if
(
!
PyString_CheckExact
(
str
))
{
raiseExcHelper
(
TypeError
,
"can't intern subclass of string"
);
}
return
PyString_InternFromString
(
PyString_AsString
(
str
));
}
Box
*
builtinRound
(
Box
*
_number
,
Box
*
_ndigits
)
{
if
(
!
isSubclass
(
_number
->
cls
,
float_cls
))
raiseExcHelper
(
TypeError
,
"a float is required"
);
...
...
@@ -1104,6 +1114,9 @@ void setupBuiltins() {
builtins_module
->
giveAttr
(
"__import__"
,
new
BoxedBuiltinFunctionOrMethod
(
import_func
,
"__import__"
,
{
None
,
None
,
None
,
new
BoxedInt
(
-
1
)
}));
Box
*
intern_obj
=
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
intern
,
UNKNOWN
,
1
),
"intern"
);
builtins_module
->
giveAttr
(
"intern"
,
intern_obj
);
enumerate_cls
=
BoxedHeapClass
::
create
(
type_cls
,
object_cls
,
&
BoxedEnumerate
::
gcHandler
,
0
,
0
,
sizeof
(
BoxedEnumerate
),
false
,
"enumerate"
);
enumerate_cls
->
giveAttr
(
...
...
test/tests/intern.py
0 → 100644
View file @
d7d47656
try
:
print
intern
(
123
)
except
TypeError
:
print
"caught expected TypeError"
print
intern
(
"abcd"
)
class
StringSubclass
(
str
):
pass
# CPython does not allow interning on subclasses of str
try
:
print
intern
(
StringSubclass
())
except
TypeError
:
print
"caught expected TypeError from subclassing"
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