Commit 90603b71 authored by Mark Florisson's avatar Mark Florisson

Compile C test sample code with -fPIC

parents 51714ebf 645bec2f
...@@ -33,3 +33,7 @@ ef9d2c680684d0df7d81f529cda29e9e1741f575 cython-0.10.1 ...@@ -33,3 +33,7 @@ ef9d2c680684d0df7d81f529cda29e9e1741f575 cython-0.10.1
59c67af0674bd93c5fd8958e08c76a9dab9aae37 sage-cythonizes 59c67af0674bd93c5fd8958e08c76a9dab9aae37 sage-cythonizes
0000000000000000000000000000000000000000 sage-cythonizes 0000000000000000000000000000000000000000 sage-cythonizes
478f57be445d18fe294db849d7ad317fe7d7658f 0.14.alpha0 478f57be445d18fe294db849d7ad317fe7d7658f 0.14.alpha0
31b531a6c45b2c34ae5a1af8a2c09f152adea60d 0.14.beta1
7fa84cb6d3d75eb3d015aeeb60bf8b642171fe93 0.14.beta2
7fa84cb6d3d75eb3d015aeeb60bf8b642171fe93 0.14.beta2
8412b39fbc3eb709a543e2f1e95c0c8881ea9ed4 0.14.beta2
...@@ -273,7 +273,7 @@ class DependencyTree(object): ...@@ -273,7 +273,7 @@ class DependencyTree(object):
cimports.update(a) cimports.update(a)
externs.update(b) externs.update(b)
else: 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) return tuple(cimports), tuple(externs)
cimports_and_externs = cached_method(cimports_and_externs) cimports_and_externs = cached_method(cimports_and_externs)
...@@ -304,6 +304,7 @@ class DependencyTree(object): ...@@ -304,6 +304,7 @@ class DependencyTree(object):
if pxd: if pxd:
return pxd return pxd
return self.context.find_pxd_file(module, None) return self.context.find_pxd_file(module, None)
find_pxd = cached_method(find_pxd)
#@cached_method #@cached_method
def cimported_files(self, filename): def cimported_files(self, filename):
...@@ -429,7 +430,9 @@ def create_extension_list(patterns, ctx=None, aliases=None): ...@@ -429,7 +430,9 @@ def create_extension_list(patterns, ctx=None, aliases=None):
return module_list return module_list
# This is the user-exposed entry point. # This is the user-exposed entry point.
def cythonize(module_list, nthreads=0, aliases=None, **options): def cythonize(module_list, nthreads=0, aliases=None, **options):
if 'include_path' not in options:
options['include_path'] = ['.']
c_options = CompilationOptions(**options) c_options = CompilationOptions(**options)
cpp_options = CompilationOptions(**options); cpp_options.cplus = True cpp_options = CompilationOptions(**options); cpp_options.cplus = True
ctx = c_options.create_context() ctx = c_options.create_context()
......
...@@ -123,7 +123,7 @@ static PyObject* __Pyx_PyRun(PyObject* o, PyObject* globals, PyObject* locals) { ...@@ -123,7 +123,7 @@ static PyObject* __Pyx_PyRun(PyObject* o, PyObject* globals, PyObject* locals) {
"code object passed to exec() may not contain free variables"); "code object passed to exec() may not contain free variables");
goto bad; goto bad;
} }
#if PY_VERSION_HEX < 0x030200A4 #if PY_VERSION_HEX < 0x030200B1
result = PyEval_EvalCode((PyCodeObject *)o, globals, locals); result = PyEval_EvalCode((PyCodeObject *)o, globals, locals);
#else #else
result = PyEval_EvalCode(o, globals, locals); result = PyEval_EvalCode(o, globals, locals);
......
...@@ -37,7 +37,7 @@ Options: ...@@ -37,7 +37,7 @@ Options:
--embed Embed the Python interpreter in a main() method. --embed Embed the Python interpreter in a main() method.
-2 Compile based on Python-2 syntax and code semantics. -2 Compile based on Python-2 syntax and code semantics.
-3 Compile based on Python-3 syntax and code semantics. -3 Compile based on Python-3 syntax and code semantics.
--fatal-errors Abort the compilation on the first error --fast-fail Abort the compilation on the first error
-X, --directive <name>=<value>[,<name=value,...] Overrides a compiler directive -X, --directive <name>=<value>[,<name=value,...] Overrides a compiler directive
""" """
...@@ -123,8 +123,8 @@ def parse_command_line(args): ...@@ -123,8 +123,8 @@ def parse_command_line(args):
options.language_level = 2 options.language_level = 2
elif option == '-3': elif option == '-3':
options.language_level = 3 options.language_level = 3
elif option == "--fatal-errors": elif option == "--fast-fail":
Options.fatal_errors = True Options.fast_fail = True
elif option in ("-X", "--directive"): elif option in ("-X", "--directive"):
try: try:
options.compiler_directives = Options.parse_directive_list( options.compiler_directives = Options.parse_directive_list(
......
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: language_level = 3
# #
# Pyrex - Code output module # 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 re
import Naming import Naming
import Options import Options
...@@ -9,13 +15,13 @@ import StringEncoding ...@@ -9,13 +15,13 @@ import StringEncoding
from Cython import Utils from Cython import Utils
from Scanning import SourceDescriptor from Scanning import SourceDescriptor
from Cython.StringIOTree import StringIOTree from Cython.StringIOTree import StringIOTree
try:
set
except NameError:
from sets import Set as set
import DebugFlags import DebugFlags
from Cython.Utils import none_or_sub from Cython.Utils import none_or_sub
try:
basestring
except NameError:
basestring = str
class UtilityCode(object): class UtilityCode(object):
# Stores utility code to add during code generation. # Stores utility code to add during code generation.
...@@ -92,13 +98,13 @@ class FunctionState(object): ...@@ -92,13 +98,13 @@ class FunctionState(object):
# exc_vars (string * 3) exception variables for reraise, or None # exc_vars (string * 3) exception variables for reraise, or None
# Not used for now, perhaps later # 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.names_taken = names_taken
self.owner = owner self.owner = owner
self.error_label = None self.error_label = None
self.label_counter = 0 self.label_counter = 0
self.labels_used = {} self.labels_used = cython.set()
self.return_label = self.new_label() self.return_label = self.new_label()
self.new_error_label() self.new_error_label()
self.continue_label = None self.continue_label = None
...@@ -168,7 +174,7 @@ class FunctionState(object): ...@@ -168,7 +174,7 @@ class FunctionState(object):
return old_labels return old_labels
def use_label(self, lbl): def use_label(self, lbl):
self.labels_used[lbl] = 1 self.labels_used.add(lbl)
def label_used(self, lbl): def label_used(self, lbl):
return lbl in self.labels_used return lbl in self.labels_used
...@@ -260,7 +266,7 @@ class FunctionState(object): ...@@ -260,7 +266,7 @@ class FunctionState(object):
error case. error case.
""" """
return [(cname, type) return [(cname, type)
for (type, manage_ref), freelist in self.temps_free.iteritems() for (type, manage_ref), freelist in self.temps_free.items()
if manage_ref if manage_ref
for cname in freelist] for cname in freelist]
...@@ -287,6 +293,8 @@ class PyObjectConst(object): ...@@ -287,6 +293,8 @@ class PyObjectConst(object):
self.cname = cname self.cname = cname
self.type = type 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_unicode_identifier = re.compile(ur"(?![0-9])\w+$", re.U).match
possible_bytes_identifier = re.compile(r"(?![0-9])\w+$".encode('ASCII')).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 nice_identifier = re.compile(r'\A[a-zA-Z0-9_]+\Z').match
...@@ -436,7 +444,7 @@ class GlobalState(object): ...@@ -436,7 +444,7 @@ class GlobalState(object):
self.filename_table = {} self.filename_table = {}
self.filename_list = [] self.filename_list = []
self.input_file_contents = {} self.input_file_contents = {}
self.utility_codes = set() self.utility_codes = cython.set()
self.declared_cnames = {} self.declared_cnames = {}
self.in_utility_code_generation = False self.in_utility_code_generation = False
self.emit_linenums = emit_linenums self.emit_linenums = emit_linenums
...@@ -683,7 +691,7 @@ class GlobalState(object): ...@@ -683,7 +691,7 @@ class GlobalState(object):
def generate_string_constants(self): def generate_string_constants(self):
c_consts = [ (len(c.cname), c.cname, c) c_consts = [ (len(c.cname), c.cname, c)
for c in self.string_const_index.itervalues() ] for c in self.string_const_index.values() ]
c_consts.sort() c_consts.sort()
py_strings = [] py_strings = []
...@@ -692,7 +700,7 @@ class GlobalState(object): ...@@ -692,7 +700,7 @@ class GlobalState(object):
decls_writer.putln('static char %s[] = "%s";' % ( decls_writer.putln('static char %s[] = "%s";' % (
cname, StringEncoding.split_string_literal(c.escaped_value))) cname, StringEncoding.split_string_literal(c.escaped_value)))
if c.py_strings is not None: if c.py_strings is not None:
for py_string in c.py_strings.itervalues(): for py_string in c.py_strings.values():
py_strings.append((c.cname, len(py_string.cname), py_string)) py_strings.append((c.cname, len(py_string.cname), py_string))
if py_strings: if py_strings:
...@@ -735,7 +743,7 @@ class GlobalState(object): ...@@ -735,7 +743,7 @@ class GlobalState(object):
def generate_int_constants(self): def generate_int_constants(self):
consts = [ (len(c.value), c.value, c.is_long, c) consts = [ (len(c.value), c.value, c.is_long, c)
for c in self.int_const_index.itervalues() ] for c in self.int_const_index.values() ]
consts.sort() consts.sort()
decls_writer = self.parts['decls'] decls_writer = self.parts['decls']
for _, value, longness, c in consts: for _, value, longness, c in consts:
......
...@@ -61,7 +61,6 @@ class CompileWarning(PyrexWarning): ...@@ -61,7 +61,6 @@ class CompileWarning(PyrexWarning):
# self.message = message # self.message = message
Exception.__init__(self, format_position(position) + message) Exception.__init__(self, format_position(position) + message)
class InternalError(Exception): class InternalError(Exception):
# If this is ever raised, there is a bug in the compiler. # If this is ever raised, there is a bug in the compiler.
...@@ -70,6 +69,12 @@ class InternalError(Exception): ...@@ -70,6 +69,12 @@ class InternalError(Exception):
Exception.__init__(self, u"Internal compiler error: %s" Exception.__init__(self, u"Internal compiler error: %s"
% message) % 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): class CompilerCrash(CompileError):
# raised when an unexpected exception occurs in a transform # raised when an unexpected exception occurs in a transform
...@@ -143,8 +148,8 @@ def report_error(err): ...@@ -143,8 +148,8 @@ def report_error(err):
except UnicodeEncodeError: except UnicodeEncodeError:
echo_file.write(line.encode('ASCII', 'replace')) echo_file.write(line.encode('ASCII', 'replace'))
num_errors = num_errors + 1 num_errors = num_errors + 1
if Options.fatal_errors: if Options.fast_fail:
raise InternalError, "abort" raise AbortError, "fatal errors"
def error(position, message): def error(position, message):
#print "Errors.error:", repr(position), repr(message) ### #print "Errors.error:", repr(position), repr(message) ###
......
# cython: language_level=3
# #
# Cython Scanner - Lexical Definitions # Cython Scanner - Lexical Definitions
# #
......
...@@ -21,7 +21,7 @@ import Errors ...@@ -21,7 +21,7 @@ import Errors
import Parsing import Parsing
import Version import Version
from Scanning import PyrexScanner, FileSourceDescriptor 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 Symtab import BuiltinScope, ModuleScope
from Cython import Utils from Cython import Utils
from Cython.Utils import open_new_file, replace_suffix from Cython.Utils import open_new_file, replace_suffix
...@@ -40,7 +40,7 @@ def dumptree(t): ...@@ -40,7 +40,7 @@ def dumptree(t):
def abort_on_errors(node): def abort_on_errors(node):
# Stop the pipeline if there are any errors. # Stop the pipeline if there are any errors.
if Errors.num_errors != 0: if Errors.num_errors != 0:
raise InternalError, "abort" raise AbortError, "pipeline break"
return node return node
class CompilationData(object): class CompilationData(object):
...@@ -231,23 +231,26 @@ class Context(object): ...@@ -231,23 +231,26 @@ class Context(object):
error = None error = None
data = source data = source
try: try:
for phase in pipeline: try:
if phase is not None: for phase in pipeline:
if DebugFlags.debug_verbose_pipeline: if phase is not None:
t = time() if DebugFlags.debug_verbose_pipeline:
print "Entering pipeline phase %r" % phase t = time()
data = phase(data) print "Entering pipeline phase %r" % phase
if DebugFlags.debug_verbose_pipeline: data = phase(data)
print " %.3f seconds" % (time() - t) if DebugFlags.debug_verbose_pipeline:
except CompileError, err: print " %.3f seconds" % (time() - t)
# err is set except CompileError, err:
Errors.report_error(err) # err is set
error = err Errors.report_error(err)
error = err
except InternalError, err: except InternalError, err:
# Only raise if there was not an earlier error # Only raise if there was not an earlier error
if Errors.num_errors == 0: if Errors.num_errors == 0:
raise raise
error = err error = err
except AbortError, err:
error = err
return (error, data) return (error, data)
def find_module(self, module_name, def find_module(self, module_name,
...@@ -714,6 +717,7 @@ def compile_multiple(sources, options): ...@@ -714,6 +717,7 @@ def compile_multiple(sources, options):
a CompilationResultSet. Performs timestamp checking and/or recursion a CompilationResultSet. Performs timestamp checking and/or recursion
if these are specified in the options. if these are specified in the options.
""" """
context = options.create_context()
sources = [os.path.abspath(source) for source in sources] sources = [os.path.abspath(source) for source in sources]
processed = set() processed = set()
results = CompilationResultSet() results = CompilationResultSet()
......
...@@ -578,6 +578,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -578,6 +578,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
#endif #endif
#if PY_MAJOR_VERSION >= 3 #if PY_MAJOR_VERSION >= 3
#define PyIntObject PyLongObject
#define PyInt_Type PyLong_Type #define PyInt_Type PyLong_Type
#define PyInt_Check(op) PyLong_Check(op) #define PyInt_Check(op) PyLong_Check(op)
#define PyInt_CheckExact(op) PyLong_CheckExact(op) #define PyInt_CheckExact(op) PyLong_CheckExact(op)
......
...@@ -2148,9 +2148,10 @@ class DefNode(FuncDefNode): ...@@ -2148,9 +2148,10 @@ class DefNode(FuncDefNode):
entry = env.lookup_here(name) entry = env.lookup_here(name)
if entry and entry.type.is_cfunction and not self.is_wrapper: if entry and entry.type.is_cfunction and not self.is_wrapper:
warning(self.pos, "Overriding cdef method with def method.", 5) 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 self.entry = entry
prefix = env.scope_prefix prefix = env.next_id(env.scope_prefix)
entry.func_cname = \ entry.func_cname = \
Naming.pyfunc_prefix + prefix + name Naming.pyfunc_prefix + prefix + name
entry.pymethdef_cname = \ entry.pymethdef_cname = \
...@@ -2225,7 +2226,7 @@ class DefNode(FuncDefNode): ...@@ -2225,7 +2226,7 @@ class DefNode(FuncDefNode):
def needs_assignment_synthesis(self, env, code=None): def needs_assignment_synthesis(self, env, code=None):
# Should enable for module level as well, that will require more testing... # Should enable for module level as well, that will require more testing...
if self.entry.is_lambda: if self.entry.is_anonymous:
return True return True
if env.is_module_scope: if env.is_module_scope:
if code is None: if code is None:
......
...@@ -20,7 +20,7 @@ annotate = 0 ...@@ -20,7 +20,7 @@ annotate = 0
# This will abort the compilation on the first error occured rather than trying # This will abort the compilation on the first error occured rather than trying
# to keep going and printing further error messages. # to keep going and printing further error messages.
fatal_errors = False fast_fail = False
# This will convert statements of the form "for i in range(...)" # 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 # to "for i from ..." when i is a cdef'd integer type, and the direction
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
cimport cython cimport cython
from Cython.Compiler.Scanning cimport PyrexScanner from Cython.Compiler.Scanning cimport PyrexScanner
ctypedef object (*p_sub_expr_func)(object)
# entry points # entry points
cpdef p_module(PyrexScanner s, pxd, full_module_name) cpdef p_module(PyrexScanner s, pxd, full_module_name)
...@@ -13,8 +15,8 @@ cpdef p_code(PyrexScanner s, level= *) ...@@ -13,8 +15,8 @@ cpdef p_code(PyrexScanner s, level= *)
cdef p_ident(PyrexScanner s, message =*) cdef p_ident(PyrexScanner s, message =*)
cdef p_ident_list(PyrexScanner s) cdef p_ident_list(PyrexScanner s)
cdef p_binop_operator(PyrexScanner s) cdef tuple p_binop_operator(PyrexScanner s)
cdef p_binop_expr(PyrexScanner s, ops, p_sub_expr) cdef p_binop_expr(PyrexScanner s, ops, p_sub_expr_func p_sub_expr)
cpdef p_lambdef(PyrexScanner s, bint allow_conditional=*) cpdef p_lambdef(PyrexScanner s, bint allow_conditional=*)
cdef p_lambdef_nocond(PyrexScanner s) cdef p_lambdef_nocond(PyrexScanner s)
cdef p_test(PyrexScanner s) cdef p_test(PyrexScanner s)
...@@ -29,12 +31,13 @@ cdef p_starred_expr(PyrexScanner s) ...@@ -29,12 +31,13 @@ cdef p_starred_expr(PyrexScanner s)
cdef p_cascaded_cmp(PyrexScanner s) cdef p_cascaded_cmp(PyrexScanner s)
cdef p_cmp_op(PyrexScanner s) cdef p_cmp_op(PyrexScanner s)
cdef p_bit_expr(PyrexScanner s) cdef p_bit_expr(PyrexScanner s)
cpdef p_xor_expr(PyrexScanner s) cdef p_xor_expr(s)
cpdef p_and_expr(PyrexScanner s) cdef p_and_expr(s)
cpdef p_shift_expr(PyrexScanner s) cdef p_shift_expr(s)
cpdef p_arith_expr(PyrexScanner s) cdef p_arith_expr(s)
cpdef p_term(PyrexScanner s) cdef p_term(s)
cpdef p_factor(PyrexScanner s) cdef p_factor(s)
cdef _p_factor(PyrexScanner s)
cdef p_typecast(PyrexScanner s) cdef p_typecast(PyrexScanner s)
cdef p_sizeof(PyrexScanner s) cdef p_sizeof(PyrexScanner s)
cdef p_yield_expression(PyrexScanner s) cdef p_yield_expression(PyrexScanner s)
...@@ -101,7 +104,7 @@ cdef p_if_clause(PyrexScanner s) ...@@ -101,7 +104,7 @@ cdef p_if_clause(PyrexScanner s)
cdef p_else_clause(PyrexScanner s) cdef p_else_clause(PyrexScanner s)
cdef p_while_statement(PyrexScanner s) cdef p_while_statement(PyrexScanner s)
cdef p_for_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_relation(PyrexScanner s)
cdef p_for_from_step(PyrexScanner s) cdef p_for_from_step(PyrexScanner s)
cdef p_target(PyrexScanner s, terminator) cdef p_target(PyrexScanner s, terminator)
......
# cython: auto_cpdef=True, infer_types=True # cython: auto_cpdef=True, infer_types=True, language_level=3
# #
# Pyrex Parser # Pyrex Parser
# #
...@@ -269,6 +269,10 @@ def p_term(s): ...@@ -269,6 +269,10 @@ def p_term(s):
#factor: ('+'|'-'|'~'|'&'|typecast|sizeof) factor | power #factor: ('+'|'-'|'~'|'&'|typecast|sizeof) factor | power
def p_factor(s): def p_factor(s):
# little indirection for C-ification purposes
return _p_factor(s)
def _p_factor(s):
sy = s.sy sy = s.sy
if sy in ('+', '-', '~'): if sy in ('+', '-', '~'):
op = s.sy op = s.sy
...@@ -873,8 +877,7 @@ def p_comp_for(s, body): ...@@ -873,8 +877,7 @@ def p_comp_for(s, body):
pos = s.position() pos = s.position()
s.next() s.next()
kw = p_for_bounds(s, allow_testlist=False) kw = p_for_bounds(s, allow_testlist=False)
kw['else_clause'] = None kw.update(dict(else_clause = None, body = p_comp_iter(s, body)))
kw['body'] = p_comp_iter(s, body)
return Nodes.ForStatNode(pos, **kw) return Nodes.ForStatNode(pos, **kw)
def p_comp_if(s, body): def p_comp_if(s, body):
...@@ -1368,8 +1371,9 @@ def p_for_statement(s): ...@@ -1368,8 +1371,9 @@ def p_for_statement(s):
pos = s.position() pos = s.position()
s.next() s.next()
kw = p_for_bounds(s, allow_testlist=True) kw = p_for_bounds(s, allow_testlist=True)
kw['body'] = p_suite(s) body = p_suite(s)
kw['else_clause'] = p_else_clause(s) else_clause = p_else_clause(s)
kw.update(dict(body = body, else_clause = else_clause))
return Nodes.ForStatNode(pos, **kw) return Nodes.ForStatNode(pos, **kw)
def p_for_bounds(s, allow_testlist=True): def p_for_bounds(s, allow_testlist=True):
...@@ -1377,7 +1381,7 @@ def p_for_bounds(s, allow_testlist=True): ...@@ -1377,7 +1381,7 @@ def p_for_bounds(s, allow_testlist=True):
if s.sy == 'in': if s.sy == 'in':
s.next() s.next()
iterator = p_for_iterator(s, allow_testlist) iterator = p_for_iterator(s, allow_testlist)
return { 'target': target, 'iterator': iterator } return dict( target = target, iterator = iterator )
elif not s.in_python_file: elif not s.in_python_file:
if s.sy == 'from': if s.sy == 'from':
s.next() s.next()
...@@ -1404,12 +1408,13 @@ def p_for_bounds(s, allow_testlist=True): ...@@ -1404,12 +1408,13 @@ def p_for_bounds(s, allow_testlist=True):
if rel1[0] != rel2[0]: if rel1[0] != rel2[0]:
error(rel2_pos, error(rel2_pos,
"Relation directions in for-from do not match") "Relation directions in for-from do not match")
return {'target': target, return dict(target = target,
'bound1': bound1, bound1 = bound1,
'relation1': rel1, relation1 = rel1,
'relation2': rel2, relation2 = rel2,
'bound2': bound2, bound2 = bound2,
'step': step } step = step,
)
else: else:
s.expect('in') s.expect('in')
return {} return {}
...@@ -1701,7 +1706,6 @@ def p_statement(s, ctx, first_statement = 0): ...@@ -1701,7 +1706,6 @@ def p_statement(s, ctx, first_statement = 0):
return p_IF_statement(s, ctx) return p_IF_statement(s, ctx)
elif s.sy == 'DECORATOR': elif s.sy == 'DECORATOR':
if ctx.level not in ('module', 'class', 'c_class', 'function', 'property', 'module_pxd', 'c_class_pxd'): 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.error('decorator not allowed here')
s.level = ctx.level s.level = ctx.level
decorators = p_decorators(s) decorators = p_decorators(s)
......
# cython: infer_types=True, language_level=3
# #
# Cython Scanner # Cython Scanner
# #
...@@ -7,7 +8,7 @@ import os ...@@ -7,7 +8,7 @@ import os
import platform import platform
import cython 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) print_function=object)
from Cython import Plex, Utils from Cython import Plex, Utils
...@@ -359,10 +360,10 @@ class PyrexScanner(Scanner): ...@@ -359,10 +360,10 @@ class PyrexScanner(Scanner):
if sy == IDENT: if sy == IDENT:
if systring in self.keywords: if systring in self.keywords:
if systring == u'print' and print_function in self.context.future_directives: if systring == u'print' and print_function in self.context.future_directives:
self.keywords.remove('print') self.keywords.discard('print')
systring = EncodedString(systring) systring = EncodedString(systring)
elif systring == u'exec' and self.context.language_level >= 3: elif systring == u'exec' and self.context.language_level >= 3:
self.keywords.remove('exec') self.keywords.discard('exec')
systring = EncodedString(systring) systring = EncodedString(systring)
else: else:
sy = systring sy = systring
......
...@@ -75,7 +75,7 @@ class Entry(object): ...@@ -75,7 +75,7 @@ class Entry(object):
# is_cfunction boolean Is a C function # is_cfunction boolean Is a C function
# is_cmethod boolean Is a C method of an extension type # 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_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_type boolean Is a type definition
# is_cclass boolean Is an extension class # is_cclass boolean Is an extension class
# is_cpp_class boolean Is a C++ class # is_cpp_class boolean Is a C++ class
...@@ -138,7 +138,7 @@ class Entry(object): ...@@ -138,7 +138,7 @@ class Entry(object):
is_cfunction = 0 is_cfunction = 0
is_cmethod = 0 is_cmethod = 0
is_unbound_cmethod = 0 is_unbound_cmethod = 0
is_lambda = 0 is_anonymous = 0
is_type = 0 is_type = 0
is_cclass = 0 is_cclass = 0
is_cpp_class = 0 is_cpp_class = 0
...@@ -513,18 +513,36 @@ class Scope(object): ...@@ -513,18 +513,36 @@ class Scope(object):
def declare_builtin(self, name, pos): def declare_builtin(self, name, pos):
return self.outer_scope.declare_builtin(name, pos) return self.outer_scope.declare_builtin(name, pos)
def declare_pyfunction(self, name, pos): def _declare_pyfunction(self, name, pos, visibility='extern', entry=None):
# Add an entry for a Python function.
entry = self.lookup_here(name)
if entry and not entry.type.is_cfunction: 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) 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 entry.signature = pyfunction_signature
self.pyfunc_entries.append(entry) self.pyfunc_entries.append(entry)
return 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): def declare_lambda_function(self, func_cname, pos):
# Add an entry for an anonymous Python function. # Add an entry for an anonymous Python function.
entry = self.declare_var(None, py_object_type, pos, entry = self.declare_var(None, py_object_type, pos,
...@@ -532,7 +550,7 @@ class Scope(object): ...@@ -532,7 +550,7 @@ class Scope(object):
entry.name = EncodedString(func_cname) entry.name = EncodedString(func_cname)
entry.func_cname = func_cname entry.func_cname = func_cname
entry.signature = pyfunction_signature entry.signature = pyfunction_signature
entry.is_lambda = True entry.is_anonymous = True
return entry return entry
def add_lambda_def(self, def_node): def add_lambda_def(self, def_node):
...@@ -1337,17 +1355,8 @@ class ClosureScope(LocalScope): ...@@ -1337,17 +1355,8 @@ class ClosureScope(LocalScope):
# return "%s->%s" % (self.cur_scope_cname, name) # return "%s->%s" % (self.cur_scope_cname, name)
# return "%s->%s" % (self.closure_cname, name) # return "%s->%s" % (self.closure_cname, name)
def declare_pyfunction(self, name, pos): def declare_pyfunction(self, name, pos, allow_redefine=False):
# Add an entry for a Python function. return LocalScope.declare_pyfunction(self, name, pos, allow_redefine, visibility='private')
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
class StructOrUnionScope(Scope): class StructOrUnionScope(Scope):
# Namespace of a C struct or union. # Namespace of a C struct or union.
...@@ -1521,7 +1530,7 @@ class CClassScope(ClassScope): ...@@ -1521,7 +1530,7 @@ class CClassScope(ClassScope):
return entry return entry
def declare_pyfunction(self, name, pos): def declare_pyfunction(self, name, pos, allow_redefine=False):
# Add an entry for a method. # Add an entry for a method.
if name in ('__eq__', '__ne__', '__lt__', '__gt__', '__le__', '__ge__'): if name in ('__eq__', '__ne__', '__lt__', '__gt__', '__le__', '__ge__'):
error(pos, "Special method %s must be implemented via __richcmp__" % name) error(pos, "Special method %s must be implemented via __richcmp__" % name)
...@@ -1765,7 +1774,7 @@ class PropertyScope(Scope): ...@@ -1765,7 +1774,7 @@ class PropertyScope(Scope):
is_property_scope = 1 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. # Add an entry for a method.
signature = get_property_accessor_signature(name) signature = get_property_accessor_signature(name)
if signature: if signature:
......
...@@ -144,7 +144,8 @@ class TestWithTransform(object): # (TransformTest): # Disabled! ...@@ -144,7 +144,8 @@ class TestWithTransform(object): # (TransformTest): # Disabled!
""", t) """, 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 import DebugWriter
from Cython.Debugger.Tests.TestLibCython import DebuggerTestCase from Cython.Debugger.Tests.TestLibCython import DebuggerTestCase
else: else:
......
...@@ -173,6 +173,8 @@ class TreeVisitor(object): ...@@ -173,6 +173,8 @@ class TreeVisitor(object):
result = handler_method(child) result = handler_method(child)
except Errors.CompileError: except Errors.CompileError:
raise raise
except Errors.AbortError:
raise
except Exception, e: except Exception, e:
if DebugFlags.debug_no_exception_intercept: if DebugFlags.debug_no_exception_intercept:
raise raise
......
...@@ -45,7 +45,7 @@ class DebuggerTestCase(unittest.TestCase): ...@@ -45,7 +45,7 @@ class DebuggerTestCase(unittest.TestCase):
shutil.copy(cfuncs_file, self.cfuncs_destfile + '.c') shutil.copy(cfuncs_file, self.cfuncs_destfile + '.c')
compiler = ccompiler.new_compiler() compiler = ccompiler.new_compiler()
compiler.compile(['cfuncs.c'], debug=True) compiler.compile(['cfuncs.c'], debug=True, extra_postargs=['-fPIC'])
opts = dict( opts = dict(
test_directory=self.tempdir, test_directory=self.tempdir,
...@@ -194,4 +194,4 @@ class TestAll(GdbDebuggerTestCase): ...@@ -194,4 +194,4 @@ class TestAll(GdbDebuggerTestCase):
sys.stderr.write(err) sys.stderr.write(err)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
\ No newline at end of file
...@@ -5,4 +5,4 @@ some_c_function(void) ...@@ -5,4 +5,4 @@ some_c_function(void)
a = 1; a = 1;
b = 2; b = 2;
} }
\ No newline at end of file
...@@ -401,4 +401,4 @@ def main(version, trace_code=False): ...@@ -401,4 +401,4 @@ def main(version, trace_code=False):
ignoredirs=[sys.prefix, sys.exec_prefix]) ignoredirs=[sys.prefix, sys.exec_prefix])
tracer.runfunc(runtests) tracer.runfunc(runtests)
else: else:
runtests() runtests()
\ No newline at end of file
...@@ -1286,4 +1286,4 @@ class CyLine(gdb.Function, CythonBase): ...@@ -1286,4 +1286,4 @@ class CyLine(gdb.Function, CythonBase):
return self.get_cython_lineno() return self.get_cython_lineno()
cy = CyCy.register() cy = CyCy.register()
\ No newline at end of file
__version__ = "0.14.alpha0" __version__ = "0.14.beta2"
# Void cython.* directives (for case insensitive operating systems). # Void cython.* directives (for case insensitive operating systems).
from Cython.Shadow import * from Cython.Shadow import *
...@@ -5,6 +5,7 @@ include setup.py ...@@ -5,6 +5,7 @@ include setup.py
include setupegg.py include setupegg.py
include bin/* include bin/*
include cython.py include cython.py
include cygdb.py
recursive-include Cython *.pyx *.pxd recursive-include Cython *.pyx *.pxd
include Doc/* include Doc/*
...@@ -24,5 +25,8 @@ include runtests.py ...@@ -24,5 +25,8 @@ include runtests.py
include Cython/Mac/Makefile include Cython/Mac/Makefile
include Cython/Mac/_Filemodule_patched.c include Cython/Mac/_Filemodule_patched.c
include Cython/Debugger/Tests/cfuncs.c
include Cython/Debugger/Tests/codefile
recursive-include pyximport *.py recursive-include pyximport *.py
include pyximport/PKG-INFO pyximport/README include pyximport/PKG-INFO pyximport/README
...@@ -65,6 +65,7 @@ VER_DEP_MODULES = { ...@@ -65,6 +65,7 @@ VER_DEP_MODULES = {
]), ]),
(2,6) : (operator.lt, lambda x: x in ['run.print_function', (2,6) : (operator.lt, lambda x: x in ['run.print_function',
'run.cython3', 'run.cython3',
'run.pure_py', # decorators, with statement
]), ]),
# The next line should start (3,); but this is a dictionary, so # 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 # we can only have one (3,) key. Since 2.7 is supposed to be the
...@@ -643,6 +644,7 @@ class CythonUnitTestCase(CythonCompileTestCase): ...@@ -643,6 +644,7 @@ class CythonUnitTestCase(CythonCompileTestCase):
except Exception: except Exception:
pass pass
include_debugger = sys.version_info[:2] > (2, 5) include_debugger = sys.version_info[:2] > (2, 5)
def collect_unittests(path, module_prefix, suite, selectors): def collect_unittests(path, module_prefix, suite, selectors):
...@@ -767,7 +769,7 @@ class EndToEndTest(unittest.TestCase): ...@@ -767,7 +769,7 @@ class EndToEndTest(unittest.TestCase):
.replace("PYTHON", sys.executable)) .replace("PYTHON", sys.executable))
try: try:
old_path = os.environ.get('PYTHONPATH') 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'): for command in commands.split('\n'):
if sys.version_info[:2] >= (2,4): if sys.version_info[:2] >= (2,4):
import subprocess import subprocess
......
...@@ -95,9 +95,11 @@ def compile_cython_modules(profile=False, compile_more=False, cython_with_refnan ...@@ -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__)) source_root = os.path.abspath(os.path.dirname(__file__))
compiled_modules = ["Cython.Plex.Scanners", compiled_modules = ["Cython.Plex.Scanners",
"Cython.Plex.Actions", "Cython.Plex.Actions",
"Cython.Compiler.Lexicon",
"Cython.Compiler.Scanning", "Cython.Compiler.Scanning",
"Cython.Compiler.Parsing", "Cython.Compiler.Parsing",
"Cython.Compiler.Visitor", "Cython.Compiler.Visitor",
"Cython.Compiler.Code",
"Cython.Runtime.refnanny"] "Cython.Runtime.refnanny"]
if compile_more: if compile_more:
compiled_modules.extend([ compiled_modules.extend([
...@@ -267,6 +269,7 @@ packages = [ ...@@ -267,6 +269,7 @@ packages = [
if include_debugger: if include_debugger:
packages.append('Cython.Debugger') packages.append('Cython.Debugger')
packages.append('Cython.Debugger.Tests')
setup( setup(
name = 'Cython', name = 'Cython',
......
...@@ -5,4 +5,4 @@ cdef void foo(): ...@@ -5,4 +5,4 @@ cdef void foo():
i = j = c i = j = c
a = b = k a = b = k
(a, b), c = (d, e), f = (x, y), z (a, b), c = (d, e), f = (x, y), z
# a, b = p, q = x, y # a, b = p, q = x, y
\ No newline at end of file
...@@ -3,4 +3,4 @@ cdef extern class Spam.Eggs.Ham: ...@@ -3,4 +3,4 @@ cdef extern class Spam.Eggs.Ham:
cdef Ham ham cdef Ham ham
ham = None ham = None
\ No newline at end of file
...@@ -23,4 +23,4 @@ def f(a, b, c): ...@@ -23,4 +23,4 @@ def f(a, b, c):
i = 1 i = 1
\ No newline at end of file
...@@ -2,4 +2,4 @@ def f(): ...@@ -2,4 +2,4 @@ def f():
from spam import eggs from spam import eggs
from spam.morespam import bacon, eggs, ham from spam.morespam import bacon, eggs, ham
from spam import eggs as ova from spam import eggs as ova
\ No newline at end of file
...@@ -8,4 +8,4 @@ def z(a, b, c): ...@@ -8,4 +8,4 @@ def z(a, b, c):
f(x = 42, **b) f(x = 42, **b)
f(a, *b) f(a, *b)
f(a, x = 42, *b, **c) f(a, x = 42, *b, **c)
\ No newline at end of file
...@@ -3,4 +3,4 @@ def f(): ...@@ -3,4 +3,4 @@ def f():
import spam.eggs import spam.eggs
import spam, eggs, ham import spam, eggs, ham
import spam as tasty import spam as tasty
\ No newline at end of file
...@@ -14,4 +14,4 @@ a[f(2)] += 4 ...@@ -14,4 +14,4 @@ a[f(2)] += 4
print x[1] print x[1]
print a[1] print a[1]
x[<object>f(1)] = 15 x[<object>f(1)] = 15
\ No newline at end of file
...@@ -16,4 +16,4 @@ def f(a, b, c, x): ...@@ -16,4 +16,4 @@ def f(a, b, c, x):
finally: finally:
i = 42 i = 42
\ No newline at end of file
class C:
def f(self):
pass
def f(self):
pass
_ERRORS = u"""
4:1: 'f' already declared
"""
"""
>>> 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)
...@@ -64,4 +64,4 @@ cdef class EqualsEvens: ...@@ -64,4 +64,4 @@ cdef class EqualsEvens:
elif op == Py_NE: elif op == Py_NE:
return other % 2 == 1 return other % 2 == 1
else: else:
return False return False
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment