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
90603b71
Commit
90603b71
authored
Dec 09, 2010
by
Mark Florisson
Browse files
Options
Browse Files
Download
Plain Diff
Compile C test sample code with -fPIC
parents
51714ebf
645bec2f
Changes
36
Show whitespace changes
Inline
Side-by-side
Showing
36 changed files
with
299 additions
and
110 deletions
+299
-110
.hgtags
.hgtags
+4
-0
Cython/Build/Dependencies.py
Cython/Build/Dependencies.py
+5
-2
Cython/Compiler/Builtin.py
Cython/Compiler/Builtin.py
+1
-1
Cython/Compiler/CmdLine.py
Cython/Compiler/CmdLine.py
+3
-3
Cython/Compiler/Code.pxd
Cython/Compiler/Code.pxd
+79
-0
Cython/Compiler/Code.py
Cython/Compiler/Code.py
+20
-12
Cython/Compiler/Errors.py
Cython/Compiler/Errors.py
+8
-3
Cython/Compiler/Lexicon.py
Cython/Compiler/Lexicon.py
+1
-0
Cython/Compiler/Main.py
Cython/Compiler/Main.py
+18
-14
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+1
-0
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+4
-3
Cython/Compiler/Options.py
Cython/Compiler/Options.py
+1
-1
Cython/Compiler/Parsing.pxd
Cython/Compiler/Parsing.pxd
+12
-9
Cython/Compiler/Parsing.py
Cython/Compiler/Parsing.py
+17
-13
Cython/Compiler/Scanning.py
Cython/Compiler/Scanning.py
+4
-3
Cython/Compiler/Symtab.py
Cython/Compiler/Symtab.py
+31
-22
Cython/Compiler/Tests/TestParseTreeTransforms.py
Cython/Compiler/Tests/TestParseTreeTransforms.py
+2
-1
Cython/Compiler/Visitor.py
Cython/Compiler/Visitor.py
+2
-0
Cython/Debugger/Tests/TestLibCython.py
Cython/Debugger/Tests/TestLibCython.py
+2
-2
Cython/Debugger/Tests/cfuncs.c
Cython/Debugger/Tests/cfuncs.c
+1
-1
Cython/Debugger/Tests/test_libcython_in_gdb.py
Cython/Debugger/Tests/test_libcython_in_gdb.py
+1
-1
Cython/Debugger/libcython.py
Cython/Debugger/libcython.py
+1
-1
Cython/__init__.py
Cython/__init__.py
+1
-1
MANIFEST.in
MANIFEST.in
+4
-0
runtests.py
runtests.py
+3
-1
setup.py
setup.py
+3
-0
tests/broken/cascadedass.pyx
tests/broken/cascadedass.pyx
+1
-1
tests/compile/extimported.pyx
tests/compile/extimported.pyx
+1
-1
tests/compile/for.pyx
tests/compile/for.pyx
+1
-1
tests/compile/fromimport.pyx
tests/compile/fromimport.pyx
+1
-1
tests/compile/gencall.pyx
tests/compile/gencall.pyx
+1
-1
tests/compile/import.pyx
tests/compile/import.pyx
+1
-1
tests/compile/indices.pyx
tests/compile/indices.pyx
+1
-1
tests/compile/tryfinally.pyx
tests/compile/tryfinally.pyx
+1
-1
tests/errors/e_redeclmeth.pyx
tests/errors/e_redeclmeth.pyx
+0
-8
tests/run/pyfunction_redefine_T489.pyx
tests/run/pyfunction_redefine_T489.pyx
+62
-0
No files found.
.hgtags
View file @
90603b71
...
...
@@ -33,3 +33,7 @@ ef9d2c680684d0df7d81f529cda29e9e1741f575 cython-0.10.1
59c67af0674bd93c5fd8958e08c76a9dab9aae37 sage-cythonizes
0000000000000000000000000000000000000000 sage-cythonizes
478f57be445d18fe294db849d7ad317fe7d7658f 0.14.alpha0
31b531a6c45b2c34ae5a1af8a2c09f152adea60d 0.14.beta1
7fa84cb6d3d75eb3d015aeeb60bf8b642171fe93 0.14.beta2
7fa84cb6d3d75eb3d015aeeb60bf8b642171fe93 0.14.beta2
8412b39fbc3eb709a543e2f1e95c0c8881ea9ed4 0.14.beta2
Cython/Build/Dependencies.py
View file @
90603b71
...
...
@@ -273,7 +273,7 @@ class DependencyTree(object):
cimports
.
update
(
a
)
externs
.
update
(
b
)
else
:
print
"Unable to locate '%s' referenced from '%s'"
%
(
filename
,
include
)
print
(
"Unable to locate '%s' referenced from '%s'"
%
(
filename
,
include
)
)
return
tuple
(
cimports
),
tuple
(
externs
)
cimports_and_externs
=
cached_method
(
cimports_and_externs
)
...
...
@@ -304,6 +304,7 @@ class DependencyTree(object):
if
pxd
:
return
pxd
return
self
.
context
.
find_pxd_file
(
module
,
None
)
find_pxd
=
cached_method
(
find_pxd
)
#@cached_method
def
cimported_files
(
self
,
filename
):
...
...
@@ -430,6 +431,8 @@ def create_extension_list(patterns, ctx=None, aliases=None):
# This is the user-exposed entry point.
def
cythonize
(
module_list
,
nthreads
=
0
,
aliases
=
None
,
**
options
):
if
'include_path'
not
in
options
:
options
[
'include_path'
]
=
[
'.'
]
c_options
=
CompilationOptions
(
**
options
)
cpp_options
=
CompilationOptions
(
**
options
);
cpp_options
.
cplus
=
True
ctx
=
c_options
.
create_context
()
...
...
Cython/Compiler/Builtin.py
View file @
90603b71
...
...
@@ -123,7 +123,7 @@ static PyObject* __Pyx_PyRun(PyObject* o, PyObject* globals, PyObject* locals) {
"code object passed to exec() may not contain free variables");
goto bad;
}
#if PY_VERSION_HEX < 0x030200
A4
#if PY_VERSION_HEX < 0x030200
B1
result = PyEval_EvalCode((PyCodeObject *)o, globals, locals);
#else
result = PyEval_EvalCode(o, globals, locals);
...
...
Cython/Compiler/CmdLine.py
View file @
90603b71
...
...
@@ -37,7 +37,7 @@ Options:
--embed Embed the Python interpreter in a main() method.
-2 Compile based on Python-2 syntax and code semantics.
-3 Compile based on Python-3 syntax and code semantics.
--fa
tal-errors
Abort the compilation on the first error
--fa
st-fail
Abort the compilation on the first error
-X, --directive <name>=<value>[,<name=value,...] Overrides a compiler directive
"""
...
...
@@ -123,8 +123,8 @@ def parse_command_line(args):
options
.
language_level
=
2
elif
option
==
'-3'
:
options
.
language_level
=
3
elif
option
==
"--fa
tal-errors
"
:
Options
.
fa
tal_errors
=
True
elif
option
==
"--fa
st-fail
"
:
Options
.
fa
st_fail
=
True
elif
option
in
(
"-X"
,
"--directive"
):
try
:
options
.
compiler_directives
=
Options
.
parse_directive_list
(
...
...
Cython/Compiler/Code.pxd
0 → 100644
View file @
90603b71
cimport
cython
cdef
class
UtilityCode
:
cdef
public
object
proto
cdef
public
object
impl
cdef
public
object
init
cdef
public
object
cleanup
cdef
public
object
requires
cdef
public
dict
_cache
cdef
public
list
specialize_list
cdef
public
object
proto_block
cpdef
put_code
(
self
,
output
)
cdef
class
FunctionState
:
cdef
public
set
names_taken
cdef
public
object
owner
cdef
public
object
error_label
cdef
public
size_t
label_counter
cdef
public
set
labels_used
cdef
public
object
return_label
cdef
public
object
continue_label
cdef
public
object
break_label
cdef
public
object
return_from_error_cleanup_label
# not used in __init__ ?
cdef
public
bint
in_try_finally
cdef
public
object
exc_vars
cdef
public
list
temps_allocated
cdef
public
dict
temps_free
cdef
public
dict
temps_used_type
cdef
public
size_t
temp_counter
@
cython
.
locals
(
n
=
size_t
)
cpdef
new_label
(
self
,
name
=*
)
cpdef
tuple
get_loop_labels
(
self
)
cpdef
set_loop_labels
(
self
,
labels
)
cpdef
tuple
get_all_labels
(
self
)
cpdef
set_all_labels
(
self
,
labels
)
cpdef
list
temps_in_use
(
self
)
cdef
class
IntConst
:
cdef
public
object
cname
cdef
public
object
value
cdef
public
bint
is_long
cdef
class
PyObjectConst
:
cdef
public
object
cname
cdef
public
object
type
cdef
class
StringConst
:
cdef
public
object
cname
cdef
public
object
text
cdef
public
object
escaped_value
cdef
public
dict
py_strings
@
cython
.
locals
(
intern
=
bint
,
is_str
=
bint
,
is_unicode
=
bint
)
cpdef
get_py_string_const
(
self
,
encoding
,
identifier
=*
,
is_str
=*
)
## cdef class PyStringConst:
## cdef public object cname
## cdef public object encoding
## cdef public bint is_str
## cdef public bint is_unicode
## cdef public bint intern
#class GlobalState(object):
#def funccontext_property(name):
#class CCodeWriter(object):
cdef
class
PyrexCodeWriter
:
cdef
public
object
f
cdef
public
Py_ssize_t
level
Cython/Compiler/Code.py
View file @
90603b71
# cython: language_level = 3
#
# Pyrex - Code output module
#
import
cython
cython
.
declare
(
re
=
object
,
Naming
=
object
,
Options
=
object
,
StringEncoding
=
object
,
Utils
=
object
,
SourceDescriptor
=
object
,
StringIOTree
=
object
,
DebugFlags
=
object
,
none_or_sub
=
object
)
import
re
import
Naming
import
Options
...
...
@@ -9,13 +15,13 @@ import StringEncoding
from
Cython
import
Utils
from
Scanning
import
SourceDescriptor
from
Cython.StringIOTree
import
StringIOTree
try
:
set
except
NameError
:
from
sets
import
Set
as
set
import
DebugFlags
from
Cython.Utils
import
none_or_sub
try
:
basestring
except
NameError
:
basestring
=
str
class
UtilityCode
(
object
):
# Stores utility code to add during code generation.
...
...
@@ -92,13 +98,13 @@ class FunctionState(object):
# exc_vars (string * 3) exception variables for reraise, or None
# Not used for now, perhaps later
def
__init__
(
self
,
owner
,
names_taken
=
set
()):
def
__init__
(
self
,
owner
,
names_taken
=
cython
.
set
()):
self
.
names_taken
=
names_taken
self
.
owner
=
owner
self
.
error_label
=
None
self
.
label_counter
=
0
self
.
labels_used
=
{}
self
.
labels_used
=
cython
.
set
()
self
.
return_label
=
self
.
new_label
()
self
.
new_error_label
()
self
.
continue_label
=
None
...
...
@@ -168,7 +174,7 @@ class FunctionState(object):
return
old_labels
def
use_label
(
self
,
lbl
):
self
.
labels_used
[
lbl
]
=
1
self
.
labels_used
.
add
(
lbl
)
def
label_used
(
self
,
lbl
):
return
lbl
in
self
.
labels_used
...
...
@@ -260,7 +266,7 @@ class FunctionState(object):
error case.
"""
return
[(
cname
,
type
)
for
(
type
,
manage_ref
),
freelist
in
self
.
temps_free
.
ite
rite
ms
()
for
(
type
,
manage_ref
),
freelist
in
self
.
temps_free
.
items
()
if
manage_ref
for
cname
in
freelist
]
...
...
@@ -287,6 +293,8 @@ class PyObjectConst(object):
self
.
cname
=
cname
self
.
type
=
type
cython
.
declare
(
possible_unicode_identifier
=
object
,
possible_bytes_identifier
=
object
,
nice_identifier
=
object
,
find_alphanums
=
object
)
possible_unicode_identifier
=
re
.
compile
(
ur"(?![0-9])\
w+$
", re.U).match
possible_bytes_identifier = re.compile(r"
(
?!
[
0
-
9
])
\
w
+
$
".encode('ASCII')).match
nice_identifier = re.compile(r'
\
A[
a
-zA-Z0-9_]+
\
Z
'
).match
...
...
@@ -436,7 +444,7 @@ class GlobalState(object):
self.filename_table = {}
self.filename_list = []
self.input_file_contents = {}
self.utility_codes = set()
self.utility_codes =
cython.
set()
self.declared_cnames = {}
self.in_utility_code_generation = False
self.emit_linenums = emit_linenums
...
...
@@ -683,7 +691,7 @@ class GlobalState(object):
def generate_string_constants(self):
c_consts = [ (len(c.cname), c.cname, c)
for c in self.string_const_index.
iter
values() ]
for c in self.string_const_index.values() ]
c_consts.sort()
py_strings = []
...
...
@@ -692,7 +700,7 @@ class GlobalState(object):
decls_writer.putln('static char %s[] = "
%
s
";' % (
cname, StringEncoding.split_string_literal(c.escaped_value)))
if c.py_strings is not None:
for py_string in c.py_strings.
iter
values():
for py_string in c.py_strings.values():
py_strings.append((c.cname, len(py_string.cname), py_string))
if py_strings:
...
...
@@ -735,7 +743,7 @@ class GlobalState(object):
def generate_int_constants(self):
consts = [ (len(c.value), c.value, c.is_long, c)
for c in self.int_const_index.
iter
values() ]
for c in self.int_const_index.values() ]
consts.sort()
decls_writer = self.parts['decls']
for _, value, longness, c in consts:
...
...
Cython/Compiler/Errors.py
View file @
90603b71
...
...
@@ -61,7 +61,6 @@ class CompileWarning(PyrexWarning):
# self.message = message
Exception
.
__init__
(
self
,
format_position
(
position
)
+
message
)
class
InternalError
(
Exception
):
# If this is ever raised, there is a bug in the compiler.
...
...
@@ -70,6 +69,12 @@ class InternalError(Exception):
Exception
.
__init__
(
self
,
u"Internal compiler error: %s"
%
message
)
class
AbortError
(
Exception
):
# Throw this to stop the compilation immediately.
def
__init__
(
self
,
message
):
self
.
message_only
=
message
Exception
.
__init__
(
self
,
u"Abort error: %s"
%
message
)
class
CompilerCrash
(
CompileError
):
# raised when an unexpected exception occurs in a transform
...
...
@@ -143,8 +148,8 @@ def report_error(err):
except
UnicodeEncodeError
:
echo_file
.
write
(
line
.
encode
(
'ASCII'
,
'replace'
))
num_errors
=
num_errors
+
1
if
Options
.
fa
tal_errors
:
raise
InternalError
,
"abort
"
if
Options
.
fa
st_fail
:
raise
AbortError
,
"fatal errors
"
def
error
(
position
,
message
):
#print "Errors.error:", repr(position), repr(message) ###
...
...
Cython/Compiler/Lexicon.py
View file @
90603b71
# cython: language_level=3
#
# Cython Scanner - Lexical Definitions
#
...
...
Cython/Compiler/Main.py
View file @
90603b71
...
...
@@ -21,7 +21,7 @@ import Errors
import
Parsing
import
Version
from
Scanning
import
PyrexScanner
,
FileSourceDescriptor
from
Errors
import
PyrexError
,
CompileError
,
InternalError
,
error
,
warning
from
Errors
import
PyrexError
,
CompileError
,
InternalError
,
AbortError
,
error
,
warning
from
Symtab
import
BuiltinScope
,
ModuleScope
from
Cython
import
Utils
from
Cython.Utils
import
open_new_file
,
replace_suffix
...
...
@@ -40,7 +40,7 @@ def dumptree(t):
def
abort_on_errors
(
node
):
# Stop the pipeline if there are any errors.
if
Errors
.
num_errors
!=
0
:
raise
InternalError
,
"abort
"
raise
AbortError
,
"pipeline break
"
return
node
class
CompilationData
(
object
):
...
...
@@ -230,6 +230,7 @@ class Context(object):
def
run_pipeline
(
self
,
pipeline
,
source
):
error
=
None
data
=
source
try
:
try
:
for
phase
in
pipeline
:
if
phase
is
not
None
:
...
...
@@ -248,6 +249,8 @@ class Context(object):
if
Errors
.
num_errors
==
0
:
raise
error
=
err
except
AbortError
,
err
:
error
=
err
return
(
error
,
data
)
def
find_module
(
self
,
module_name
,
...
...
@@ -714,6 +717,7 @@ def compile_multiple(sources, options):
a CompilationResultSet. Performs timestamp checking and/or recursion
if these are specified in the options.
"""
context
=
options
.
create_context
()
sources
=
[
os
.
path
.
abspath
(
source
)
for
source
in
sources
]
processed
=
set
()
results
=
CompilationResultSet
()
...
...
Cython/Compiler/ModuleNode.py
View file @
90603b71
...
...
@@ -578,6 +578,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
#endif
#if PY_MAJOR_VERSION >= 3
#define PyIntObject PyLongObject
#define PyInt_Type PyLong_Type
#define PyInt_Check(op) PyLong_Check(op)
#define PyInt_CheckExact(op) PyLong_CheckExact(op)
...
...
Cython/Compiler/Nodes.py
View file @
90603b71
...
...
@@ -2148,9 +2148,10 @@ class DefNode(FuncDefNode):
entry
=
env
.
lookup_here
(
name
)
if
entry
and
entry
.
type
.
is_cfunction
and
not
self
.
is_wrapper
:
warning
(
self
.
pos
,
"Overriding cdef method with def method."
,
5
)
entry
=
env
.
declare_pyfunction
(
name
,
self
.
pos
)
entry
=
env
.
declare_pyfunction
(
name
,
self
.
pos
,
allow_redefine
=
not
self
.
is_wrapper
)
self
.
entry
=
entry
prefix
=
env
.
scope_prefix
prefix
=
env
.
next_id
(
env
.
scope_prefix
)
entry
.
func_cname
=
\
Naming
.
pyfunc_prefix
+
prefix
+
name
entry
.
pymethdef_cname
=
\
...
...
@@ -2225,7 +2226,7 @@ class DefNode(FuncDefNode):
def
needs_assignment_synthesis
(
self
,
env
,
code
=
None
):
# Should enable for module level as well, that will require more testing...
if
self
.
entry
.
is_
lambda
:
if
self
.
entry
.
is_
anonymous
:
return
True
if
env
.
is_module_scope
:
if
code
is
None
:
...
...
Cython/Compiler/Options.py
View file @
90603b71
...
...
@@ -20,7 +20,7 @@ annotate = 0
# This will abort the compilation on the first error occured rather than trying
# to keep going and printing further error messages.
fa
tal_errors
=
False
fa
st_fail
=
False
# This will convert statements of the form "for i in range(...)"
# to "for i from ..." when i is a cdef'd integer type, and the direction
...
...
Cython/Compiler/Parsing.pxd
View file @
90603b71
...
...
@@ -3,6 +3,8 @@
cimport
cython
from
Cython.Compiler.Scanning
cimport
PyrexScanner
ctypedef
object
(
*
p_sub_expr_func
)(
object
)
# entry points
cpdef
p_module
(
PyrexScanner
s
,
pxd
,
full_module_name
)
...
...
@@ -13,8 +15,8 @@ cpdef p_code(PyrexScanner s, level= *)
cdef
p_ident
(
PyrexScanner
s
,
message
=*
)
cdef
p_ident_list
(
PyrexScanner
s
)
cdef
p_binop_operator
(
PyrexScanner
s
)
cdef
p_binop_expr
(
PyrexScanner
s
,
ops
,
p_sub_expr
)
cdef
tuple
p_binop_operator
(
PyrexScanner
s
)
cdef
p_binop_expr
(
PyrexScanner
s
,
ops
,
p_sub_expr
_func
p_sub_expr
)
cpdef
p_lambdef
(
PyrexScanner
s
,
bint
allow_conditional
=*
)
cdef
p_lambdef_nocond
(
PyrexScanner
s
)
cdef
p_test
(
PyrexScanner
s
)
...
...
@@ -29,12 +31,13 @@ cdef p_starred_expr(PyrexScanner s)
cdef
p_cascaded_cmp
(
PyrexScanner
s
)
cdef
p_cmp_op
(
PyrexScanner
s
)
cdef
p_bit_expr
(
PyrexScanner
s
)
cpdef
p_xor_expr
(
PyrexScanner
s
)
cpdef
p_and_expr
(
PyrexScanner
s
)
cpdef
p_shift_expr
(
PyrexScanner
s
)
cpdef
p_arith_expr
(
PyrexScanner
s
)
cpdef
p_term
(
PyrexScanner
s
)
cpdef
p_factor
(
PyrexScanner
s
)
cdef
p_xor_expr
(
s
)
cdef
p_and_expr
(
s
)
cdef
p_shift_expr
(
s
)
cdef
p_arith_expr
(
s
)
cdef
p_term
(
s
)
cdef
p_factor
(
s
)
cdef
_p_factor
(
PyrexScanner
s
)
cdef
p_typecast
(
PyrexScanner
s
)
cdef
p_sizeof
(
PyrexScanner
s
)
cdef
p_yield_expression
(
PyrexScanner
s
)
...
...
@@ -101,7 +104,7 @@ cdef p_if_clause(PyrexScanner s)
cdef
p_else_clause
(
PyrexScanner
s
)
cdef
p_while_statement
(
PyrexScanner
s
)
cdef
p_for_statement
(
PyrexScanner
s
)
cpdef
p_for_bounds
(
PyrexScanner
s
,
bint
allow_testlist
=
*
)
cpdef
dict
p_for_bounds
(
PyrexScanner
s
,
bint
allow_testlist
=
*
)
cdef
p_for_from_relation
(
PyrexScanner
s
)
cdef
p_for_from_step
(
PyrexScanner
s
)
cdef
p_target
(
PyrexScanner
s
,
terminator
)
...
...
Cython/Compiler/Parsing.py
View file @
90603b71
# cython: auto_cpdef=True, infer_types=True
# cython: auto_cpdef=True, infer_types=True
, language_level=3
#
# Pyrex Parser
#
...
...
@@ -269,6 +269,10 @@ def p_term(s):
#factor: ('+'|'-'|'~'|'&'|typecast|sizeof) factor | power
def
p_factor
(
s
):
# little indirection for C-ification purposes
return
_p_factor
(
s
)
def
_p_factor
(
s
):
sy
=
s
.
sy
if
sy
in
(
'+'
,
'-'
,
'~'
):
op
=
s
.
sy
...
...
@@ -873,8 +877,7 @@ def p_comp_for(s, body):
pos
=
s
.
position
()
s
.
next
()
kw
=
p_for_bounds
(
s
,
allow_testlist
=
False
)
kw
[
'else_clause'
]
=
None
kw
[
'body'
]
=
p_comp_iter
(
s
,
body
)
kw
.
update
(
dict
(
else_clause
=
None
,
body
=
p_comp_iter
(
s
,
body
)))
return
Nodes
.
ForStatNode
(
pos
,
**
kw
)
def
p_comp_if
(
s
,
body
):
...
...
@@ -1368,8 +1371,9 @@ def p_for_statement(s):
pos
=
s
.
position
()
s
.
next
()
kw
=
p_for_bounds
(
s
,
allow_testlist
=
True
)
kw
[
'body'
]
=
p_suite
(
s
)
kw
[
'else_clause'
]
=
p_else_clause
(
s
)
body
=
p_suite
(
s
)
else_clause
=
p_else_clause
(
s
)
kw
.
update
(
dict
(
body
=
body
,
else_clause
=
else_clause
))
return
Nodes
.
ForStatNode
(
pos
,
**
kw
)
def
p_for_bounds
(
s
,
allow_testlist
=
True
):
...
...
@@ -1377,7 +1381,7 @@ def p_for_bounds(s, allow_testlist=True):
if
s
.
sy
==
'in'
:
s
.
next
()
iterator
=
p_for_iterator
(
s
,
allow_testlist
)
return
{
'target'
:
target
,
'iterator'
:
iterator
}
return
dict
(
target
=
target
,
iterator
=
iterator
)
elif
not
s
.
in_python_file
:
if
s
.
sy
==
'from'
:
s
.
next
()
...
...
@@ -1404,12 +1408,13 @@ def p_for_bounds(s, allow_testlist=True):
if
rel1
[
0
]
!=
rel2
[
0
]:
error
(
rel2_pos
,
"Relation directions in for-from do not match"
)
return
{
'target'
:
target
,
'bound1'
:
bound1
,
'relation1'
:
rel1
,
'relation2'
:
rel2
,
'bound2'
:
bound2
,
'step'
:
step
}
return
dict
(
target
=
target
,
bound1
=
bound1
,
relation1
=
rel1
,
relation2
=
rel2
,
bound2
=
bound2
,
step
=
step
,
)
else
:
s
.
expect
(
'in'
)
return
{}
...
...
@@ -1701,7 +1706,6 @@ def p_statement(s, ctx, first_statement = 0):
return
p_IF_statement
(
s
,
ctx
)
elif
s
.
sy
==
'DECORATOR'
:
if
ctx
.
level
not
in
(
'module'
,
'class'
,
'c_class'
,
'function'
,
'property'
,
'module_pxd'
,
'c_class_pxd'
):
print
ctx
.
level
s
.
error
(
'decorator not allowed here'
)
s
.
level
=
ctx
.
level
decorators
=
p_decorators
(
s
)
...
...
Cython/Compiler/Scanning.py
View file @
90603b71
# cython: infer_types=True, language_level=3
#
# Cython Scanner
#
...
...
@@ -7,7 +8,7 @@ import os
import
platform
import
cython
cython
.
declare
(
EncodedString
=
object
,
string_prefixes
=
object
,
raw_prefixes
=
object
,
IDENT
=
object
,
cython
.
declare
(
EncodedString
=
object
,
string_prefixes
=
object
,
raw_prefixes
=
object
,
IDENT
=
unicode
,
print_function
=
object
)
from
Cython
import
Plex
,
Utils
...
...
@@ -359,10 +360,10 @@ class PyrexScanner(Scanner):
if
sy
==
IDENT
:
if
systring
in
self
.
keywords
:
if
systring
==
u'print'
and
print_function
in
self
.
context
.
future_directives
:
self
.
keywords
.
remove
(
'print'
)
self
.
keywords
.
discard
(
'print'
)
systring
=
EncodedString
(
systring
)
elif
systring
==
u'exec'
and
self
.
context
.
language_level
>=
3
:
self
.
keywords
.
remove
(
'exec'
)
self
.
keywords
.
discard
(
'exec'
)
systring
=
EncodedString
(
systring
)
else
:
sy
=
systring
...
...
Cython/Compiler/Symtab.py
View file @
90603b71
...
...
@@ -75,7 +75,7 @@ class Entry(object):
# is_cfunction boolean Is a C function
# is_cmethod boolean Is a C method of an extension type
# is_unbound_cmethod boolean Is an unbound C method of an extension type
# is_
lambda boolean Is a lambda function
# is_
anonymous boolean Is a anonymous pyfunction entry
# is_type boolean Is a type definition
# is_cclass boolean Is an extension class
# is_cpp_class boolean Is a C++ class
...
...
@@ -138,7 +138,7 @@ class Entry(object):
is_cfunction = 0
is_cmethod = 0
is_unbound_cmethod = 0
is_
lambda
= 0
is_
anonymous
= 0
is_type = 0
is_cclass = 0
is_cpp_class = 0
...
...
@@ -514,17 +514,35 @@ class Scope(object):
def declare_builtin(self, name, pos):
return self.outer_scope.declare_builtin(name, pos)
def declare_pyfunction(self, name, pos):
# Add an entry for a Python function.
entry = self.lookup_here(name)
def _declare_pyfunction(self, name, pos, visibility='extern', entry=None):
if entry and not entry.type.is_cfunction:
# This is legal Python, but for now will produce invalid C.
error(pos, "'%s'
already
declared
" % name)
entry = self.declare_var(name, py_object_type, pos, visibility='extern')
error(entry.pos, "
Previous
declaration
is
here
")
entry = self.declare_var(name, py_object_type, pos, visibility=visibility)
entry.signature = pyfunction_signature
self.pyfunc_entries.append(entry)
return entry
def declare_pyfunction(self, name, pos, allow_redefine=False, visibility='extern'):
# Add an entry for a Python function.
entry = self.lookup_here(name)
if not allow_redefine:
return self._declare_pyfunction(name, pos, visibility=visibility, entry=entry)
if entry:
if entry.type.is_unspecified:
entry.type = py_object_type
elif entry.type is not py_object_type:
return self._declare_pyfunction(name, pos, visibility=visibility, entry=entry)
else: # declare entry stub
self.declare_var(name, py_object_type, pos, visibility=visibility)
entry = self.declare_var(None, py_object_type, pos,
cname=name, visibility='private')
entry.name = EncodedString(name)
entry.qualified_name = self.qualify_name(name)
entry.signature = pyfunction_signature
entry.is_anonymous = True
return entry
def declare_lambda_function(self, func_cname, pos):
# Add an entry for an anonymous Python function.
entry = self.declare_var(None, py_object_type, pos,
...
...
@@ -532,7 +550,7 @@ class Scope(object):
entry.name = EncodedString(func_cname)
entry.func_cname = func_cname
entry.signature = pyfunction_signature
entry.is_
lambda
= True
entry.is_
anonymous
= True
return entry
def add_lambda_def(self, def_node):
...
...
@@ -1337,17 +1355,8 @@ class ClosureScope(LocalScope):
# return "%s->%s" % (self.cur_scope_cname, name)
# return "%s->%s" % (self.closure_cname, name)
def declare_pyfunction(self, name, pos):
# Add an entry for a Python function.
entry = self.lookup_here(name)
if entry and not entry.type.is_cfunction:
# This is legal Python, but for now may produce invalid C.
error(pos, "'
%
s
' already declared" % name)
entry = self.declare_var(name, py_object_type, pos)
entry.signature = pyfunction_signature
self.pyfunc_entries.append(entry)
return entry
def declare_pyfunction(self, name, pos, allow_redefine=False):
return LocalScope.declare_pyfunction(self, name, pos, allow_redefine, visibility='
private
')
class StructOrUnionScope(Scope):
# Namespace of a C struct or union.
...
...
@@ -1521,7 +1530,7 @@ class CClassScope(ClassScope):
return
entry
def
declare_pyfunction
(
self
,
name
,
pos
):
def
declare_pyfunction
(
self
,
name
,
pos
,
allow_redefine
=
False
):
# Add an entry for a method.
if
name
in
(
'__eq__'
,
'__ne__'
,
'__lt__'
,
'__gt__'
,
'__le__'
,
'__ge__'
):
error
(
pos
,
"Special method %s must be implemented via __richcmp__"
%
name
)
...
...
@@ -1765,7 +1774,7 @@ class PropertyScope(Scope):
is_property_scope
=
1
def
declare_pyfunction
(
self
,
name
,
pos
):
def
declare_pyfunction
(
self
,
name
,
pos
,
allow_redefine
=
False
):
# Add an entry for a method.
signature
=
get_property_accessor_signature
(
name
)
if
signature
:
...
...
Cython/Compiler/Tests/TestParseTreeTransforms.py
View file @
90603b71
...
...
@@ -144,7 +144,8 @@ class TestWithTransform(object): # (TransformTest): # Disabled!
"""
,
t
)
if
sys
.
version_info
[:
2
]
>
(
2
,
4
):
# TODO: Re-enable once they're more robust.
if
sys
.
version_info
[:
2
]
>=
(
2
,
5
)
and
False
:
from
Cython.Debugger
import
DebugWriter
from
Cython.Debugger.Tests.TestLibCython
import
DebuggerTestCase
else
:
...
...
Cython/Compiler/Visitor.py
View file @
90603b71
...
...
@@ -173,6 +173,8 @@ class TreeVisitor(object):
result
=
handler_method
(
child
)
except
Errors
.
CompileError
:
raise
except
Errors
.
AbortError
:
raise
except
Exception
,
e
:
if
DebugFlags
.
debug_no_exception_intercept
:
raise
...
...
Cython/Debugger/Tests/TestLibCython.py
View file @
90603b71
...
...
@@ -45,7 +45,7 @@ class DebuggerTestCase(unittest.TestCase):
shutil
.
copy
(
cfuncs_file
,
self
.
cfuncs_destfile
+
'.c'
)
compiler
=
ccompiler
.
new_compiler
()
compiler
.
compile
([
'cfuncs.c'
],
debug
=
True
)
compiler
.
compile
([
'cfuncs.c'
],
debug
=
True
,
extra_postargs
=
[
'-fPIC'
]
)
opts
=
dict
(
test_directory
=
self
.
tempdir
,
...
...
Cython/Debugger/Tests/cfuncs.c
View file @
90603b71
Cython/Debugger/Tests/test_libcython_in_gdb.py
View file @
90603b71
Cython/Debugger/libcython.py
View file @
90603b71
Cython/__init__.py
View file @
90603b71
__version__
=
"0.14.
alpha0
"
__version__
=
"0.14.
beta2
"
# Void cython.* directives (for case insensitive operating systems).
from
Cython.Shadow
import
*
MANIFEST.in
View file @
90603b71
...
...
@@ -5,6 +5,7 @@ include setup.py
include setupegg.py
include bin/*
include cython.py
include cygdb.py
recursive-include Cython *.pyx *.pxd
include Doc/*
...
...
@@ -24,5 +25,8 @@ include runtests.py
include Cython/Mac/Makefile
include Cython/Mac/_Filemodule_patched.c
include Cython/Debugger/Tests/cfuncs.c
include Cython/Debugger/Tests/codefile
recursive-include pyximport *.py
include pyximport/PKG-INFO pyximport/README
runtests.py
View file @
90603b71
...
...
@@ -65,6 +65,7 @@ VER_DEP_MODULES = {
]),
(2,6) : (operator.lt, lambda x: x in ['
run
.
print_function
',
'
run
.
cython3
',
'
run
.
pure_py
', # decorators, with statement
]),
# The next line should start (3,); but this is a dictionary, so
# we can only have one (3,) key. Since 2.7 is supposed to be the
...
...
@@ -643,6 +644,7 @@ class CythonUnitTestCase(CythonCompileTestCase):
except
Exception
:
pass
include_debugger
=
sys
.
version_info
[:
2
]
>
(
2
,
5
)
def
collect_unittests
(
path
,
module_prefix
,
suite
,
selectors
):
...
...
@@ -767,7 +769,7 @@ class EndToEndTest(unittest.TestCase):
.
replace
(
"PYTHON"
,
sys
.
executable
))
try
:
old_path
=
os
.
environ
.
get
(
'PYTHONPATH'
)
os
.
environ
[
'PYTHONPATH'
]
=
os
.
path
.
join
(
self
.
cython_syspath
,
(
old_path
or
''
))
os
.
environ
[
'PYTHONPATH'
]
=
self
.
cython_syspath
+
os
.
pathsep
+
os
.
path
.
join
(
self
.
cython_syspath
,
(
old_path
or
''
))
for
command
in
commands
.
split
(
'
\
n
'
):
if
sys
.
version_info
[:
2
]
>=
(
2
,
4
):
import
subprocess
...
...
setup.py
View file @
90603b71
...
...
@@ -95,9 +95,11 @@ def compile_cython_modules(profile=False, compile_more=False, cython_with_refnan
source_root
=
os
.
path
.
abspath
(
os
.
path
.
dirname
(
__file__
))
compiled_modules
=
[
"Cython.Plex.Scanners"
,
"Cython.Plex.Actions"
,
"Cython.Compiler.Lexicon"
,
"Cython.Compiler.Scanning"
,
"Cython.Compiler.Parsing"
,
"Cython.Compiler.Visitor"
,
"Cython.Compiler.Code"
,
"Cython.Runtime.refnanny"
]
if
compile_more
:
compiled_modules
.
extend
([
...
...
@@ -267,6 +269,7 @@ packages = [
if
include_debugger
:
packages
.
append
(
'Cython.Debugger'
)
packages
.
append
(
'Cython.Debugger.Tests'
)
setup
(
name
=
'Cython'
,
...
...
tests/broken/cascadedass.pyx
View file @
90603b71
tests/compile/extimported.pyx
View file @
90603b71
tests/compile/for.pyx
View file @
90603b71
tests/compile/fromimport.pyx
View file @
90603b71
tests/compile/gencall.pyx
View file @
90603b71
tests/compile/import.pyx
View file @
90603b71
tests/compile/indices.pyx
View file @
90603b71
tests/compile/tryfinally.pyx
View file @
90603b71
tests/errors/e_redeclmeth.pyx
deleted
100644 → 0
View file @
51714ebf
class
C
:
def
f
(
self
):
pass
def
f
(
self
):
pass
_ERRORS
=
u"""
4:1: 'f' already declared
"""
tests/run/pyfunction_redefine_T489.pyx
0 → 100644
View file @
90603b71
"""
>>> xxx
[0, 1, 2, 3]
"""
xxx
=
[]
foo
=
0
xxx
.
append
(
foo
)
def
foo
():
return
1
xxx
.
append
(
foo
())
def
foo
():
return
2
xxx
.
append
(
foo
())
foo
=
3
xxx
.
append
(
foo
)
def
closure_scope
(
a
):
"""
>>> closure_scope(0)
[0, 1, 'X', -4, 3]
"""
ret
=
[]
foo
=
a
+
0
ret
.
append
(
foo
)
def
foo
():
return
a
+
1
ret
.
append
(
foo
())
def
foo
():
return
'X'
ret
.
append
(
foo
())
def
foo
(
b
):
return
a
-
b
ret
.
append
(
foo
(
4
))
foo
=
a
+
3
ret
.
append
(
foo
)
return
ret
class
ClassScope
(
object
):
"""
>>> obj = ClassScope()
[0, 1, 2, 3]
"""
x
=
[]
def
__init__
(
self
):
r
=
[]
for
x
in
self
.
x
:
if
isinstance
(
x
,
int
):
r
.
append
(
x
)
else
:
r
.
append
(
x
(
self
))
print
r
foo
=
0
x
.
append
(
foo
)
def
foo
(
self
):
return
1
x
.
append
(
foo
)
def
foo
(
self
):
return
2
x
.
append
(
foo
)
foo
=
3
x
.
append
(
foo
)
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