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
4148f516
Commit
4148f516
authored
Oct 25, 2008
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
replacement implementation for set/frozenset in Py3, mainly by Lisandro
parent
344e435f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
113 additions
and
16 deletions
+113
-16
Cython/Compiler/Builtin.py
Cython/Compiler/Builtin.py
+104
-13
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+5
-1
Cython/Compiler/Symtab.py
Cython/Compiler/Symtab.py
+2
-1
runtests.py
runtests.py
+2
-1
No files found.
Cython/Compiler/Builtin.py
View file @
4148f516
...
...
@@ -109,18 +109,13 @@ builtin_types_table = [
(
"slice"
,
"PySlice_Type"
,
[]),
(
"file"
,
"PyFile_Type"
,
[]),
(
"set"
,
"PySet_Type"
,
[(
"clear"
,
"O"
,
"i"
,
"PySet_Clear"
),
(
"discard"
,
"OO"
,
"i"
,
"PySet_Discard"
),
(
"add"
,
"OO"
,
"i"
,
"PySet_Add"
),
(
"pop"
,
"O"
,
"O"
,
"PySet_Pop"
)]),
(
"frozenset"
,
"PyFrozenSet_Type"
,
[]),
]
if
'set'
in
__builtin__
.
__dict__
:
builtin_types_table
+=
[
(
"set"
,
"PySet_Type"
,
[(
"clear"
,
"O"
,
"i"
,
"PySet_Clear"
),
(
"discard"
,
"OO"
,
"i"
,
"PySet_Discard"
),
(
"add"
,
"OO"
,
"i"
,
"PySet_Add"
),
(
"pop"
,
"O"
,
"O"
,
"PySet_Pop"
)]),
(
"frozenset"
,
"PyFrozenSet_Type"
,
[]),
]
builtin_structs_table
=
[
...
...
@@ -166,9 +161,104 @@ intern_utility_code = ["""
"""
,
"""
"""
]
py23_set_utility_code
=
[
"""
#if PY_VERSION_HEX < 0x02050000
#ifndef PyAnySet_CheckExact
#define PyAnySet_CheckExact(ob)
\
((ob)->ob_type == ((PyTypeObject*)&PySet_Type) ||
\
(ob)->ob_type == ((PyTypeObject*)&PyFrozenSet_Type))
#define PySet_Pop(set) PyObject_CallMethod(set, "pop", NULL)
static INLINE int PySet_Clear(PyObject *set) {
PyObject *ret = PyObject_CallMethod(set, "clear", NULL);
if (!ret) return -1;
Py_DECREF(ret); return 0;
}
static INLINE int PySet_Discard(PyObject *set, PyObject *key) {
PyObject *ret = PyObject_CallMethod(set, "discard", "O", key);
if (!ret) return -1;
Py_DECREF(ret); return 0;
}
static INLINE int PySet_Add(PyObject *set, PyObject *key) {
PyObject *ret = PyObject_CallMethod(set, "add", "O", key);
if (!ret) return -1;
Py_DECREF(ret); return 0;
}
#endif /* PyAnySet_CheckExact (<= Py2.4) */
#if PY_VERSION_HEX < 0x02040000
#ifndef Py_SETOBJECT_H
#define Py_SETOBJECT_H
static PyTypeObject *PySet_Type = NULL;
static PyTypeObject *PyFrozenSet_Type = NULL;
#define PyAnySet_Check(ob)
\
(PyAnySet_CheckExact(ob) ||
\
PyType_IsSubtype((ob)->ob_type, &PySet_Type) ||
\
PyType_IsSubtype((ob)->ob_type, &PyFrozenSet_Type))
#define PyFrozenSet_CheckExact(ob) ((ob)->ob_type == &PyFrozenSet_Type)
#define PySet_New(iterable)
\
PyObject_CallFunctionObjArgs((PyObject *)PySet_Type, iterable, NULL)
#define Pyx_PyFrozenSet_New(iterable)
\
PyObject_CallFunctionObjArgs((PyObject *)PyFrozenSet_Type, iterable, NULL)
#define PySet_Size(anyset) PyObject_Size(anyset)
#define PySet_Contains(anyset, key) PySequence_Contains(anyset, key)
/* ---------------------------------------------------------------- */
static int __Pyx_Py23SetsImport(void) {
PyObject *sets=0, *Set=0, *ImmutableSet=0;
sets = PyImport_ImportModule("sets");
if (!sets) goto bad;
Set = PyObject_GetAttrString(sets, "Set");
if (!Set) goto bad;
ImmutableSet = PyObject_GetAttrString(sets, "ImmutableSet");
if (!ImmutableSet) goto bad;
Py_DECREF(sets);
PySet_Type = (PyTypeObject*) Set;
PyFrozenSet_Type = (PyTypeObject*) ImmutableSet;
/* FIXME: this should be done in dedicated module cleanup code */
/*
Py_DECREF(Set);
Py_DECREF(ImmutableSet);
*/
return 0;
bad:
Py_XDECREF(sets);
Py_XDECREF(Set);
Py_XDECREF(ImmutableSet);
return -1;
}
/* ---------------------------------------------------------------- */
#else
static int py23sets_import(void) { return 0; }
#endif /* !Py_SETOBJECT_H */
#endif /* < Py2.4 */
#endif /* < Py2.5 */
"""
,
"""
"""
]
builtin_utility_code
=
{
'getattr3'
:
getattr3_utility_code
,
'intern'
:
intern_utility_code
,
'getattr3'
:
getattr3_utility_code
,
'intern'
:
intern_utility_code
,
'set'
:
py23_set_utility_code
,
'frozenset'
:
py23_set_utility_code
,
}
builtin_scope
=
BuiltinScope
()
...
...
@@ -185,7 +275,8 @@ def init_builtin_funcs():
def
init_builtin_types
():
for
name
,
cname
,
funcs
in
builtin_types_table
:
the_type
=
builtin_scope
.
declare_builtin_type
(
name
,
cname
)
utility
=
builtin_utility_code
.
get
(
name
)
the_type
=
builtin_scope
.
declare_builtin_type
(
name
,
cname
,
utility
)
for
name
,
args
,
ret
,
cname
in
funcs
:
sig
=
Signature
(
args
,
ret
)
the_type
.
scope
.
declare_cfunction
(
name
,
sig
.
function_type
(),
None
,
cname
)
...
...
Cython/Compiler/ModuleNode.py
View file @
4148f516
...
...
@@ -1567,6 +1567,10 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code
.
putln
(
"/*--- Initialize various global constants etc. ---*/"
)
code
.
putln
(
code
.
error_goto_if_neg
(
"__Pyx_InitGlobals()"
,
self
.
pos
))
code
.
putln
(
"#if PY_VERSION_HEX < 0x02040000"
)
code
.
putln
(
code
.
error_goto_if_neg
(
"__Pyx_Py23SetsImport()"
,
self
.
pos
))
code
.
putln
(
"#endif"
)
code
.
putln
(
"/*--- Module creation code ---*/"
)
self
.
generate_module_creation_code
(
env
,
code
)
...
...
@@ -1574,7 +1578,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code
.
putln
(
"/*--- Builtin init code ---*/"
)
code
.
putln
(
code
.
error_goto_if_neg
(
"__Pyx_InitCachedBuiltins()"
,
self
.
pos
))
code
.
putln
(
"%s = 0;"
%
Naming
.
skip_dispatch_cname
);
code
.
putln
(
"/*--- Global init code ---*/"
)
...
...
Cython/Compiler/Symtab.py
View file @
4148f516
...
...
@@ -706,7 +706,7 @@ class BuiltinScope(Scope):
entry.as_variable = var_entry
return entry
def declare_builtin_type(self, name, cname):
def declare_builtin_type(self, name, cname
, utility_code = None
):
name = EncodedString(name)
type = PyrexTypes.BuiltinObjectType(name, cname)
type.set_scope(CClassScope(name, outer_scope=None, visibility='extern'))
...
...
@@ -720,6 +720,7 @@ class BuiltinScope(Scope):
var_entry.is_variable = 1
var_entry.is_cglobal = 1
var_entry.is_readonly = 1
var_entry.utility_code = utility_code
entry.as_variable = var_entry
return type
...
...
runtests.py
View file @
4148f516
...
...
@@ -19,7 +19,8 @@ EXT_DEP_MODULES = {
}
VER_DEP_MODULES
=
{
(
2
,
4
)
:
lambda
x
:
x
in
[
'run.set'
]
# such as:
# (2,4) : lambda x: x in ['run.set']
}
INCLUDE_DIRS
=
[
d
for
d
in
os
.
getenv
(
'INCLUDE'
,
''
).
split
(
os
.
pathsep
)
if
d
]
...
...
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