Commit b04f0424 authored by Dag Sverre Seljebotn's avatar Dag Sverre Seljebotn

Merge + no need to cimport __cython__ any longer (sorry about non-isolated commit...)

--HG--
rename : Includes/python_buffer.pxd => Cython/Includes/python_buffer.pxd
parents abf0d29c ae9630e5
...@@ -237,12 +237,6 @@ class IntroduceBufferAuxiliaryVars(CythonTransform): ...@@ -237,12 +237,6 @@ class IntroduceBufferAuxiliaryVars(CythonTransform):
def __call__(self, node): def __call__(self, node):
assert isinstance(node, ModuleNode) assert isinstance(node, ModuleNode)
try:
cymod = self.context.modules[u'__cython__']
except KeyError:
# No buffer fun for this module
return node
self.bufstruct_type = cymod.entries[u'Py_buffer'].type
self.tscheckers = {} self.tscheckers = {}
self.tsfuncs = set() self.tsfuncs = set()
self.ts_funcs = [] self.ts_funcs = []
...@@ -281,7 +275,7 @@ class IntroduceBufferAuxiliaryVars(CythonTransform): ...@@ -281,7 +275,7 @@ class IntroduceBufferAuxiliaryVars(CythonTransform):
# Declare auxiliary vars # Declare auxiliary vars
cname = scope.mangle(Naming.bufstruct_prefix, name) cname = scope.mangle(Naming.bufstruct_prefix, name)
bufinfo = scope.declare_var(name="$%s" % cname, cname=cname, bufinfo = scope.declare_var(name="$%s" % cname, cname=cname,
type=self.bufstruct_type, pos=node.pos) type=PyrexTypes.c_py_buffer_type, pos=node.pos)
bufinfo.used = True bufinfo.used = True
......
from Visitor import CythonTransform
from sets import Set as set
class AnchorTemps(CythonTransform):
def init_scope(self, scope):
scope.free_temp_entries = []
def handle_node(self, node):
if node.temps:
for temp in node.temps:
temp.cname = self.scope.allocate_temp(temp.type)
self.temps_beneath_try.add(temp.cname)
self.visitchildren(node)
for temp in node.temps:
self.scope.release_temp(temp.cname)
else:
self.visitchildren(node)
def visit_Node(self, node):
self.handle_node(node)
return node
def visit_ModuleNode(self, node):
self.scope = node.scope
self.temps_beneath_try = set()
self.init_scope(self.scope)
self.handle_node(node)
return node
def visit_FuncDefNode(self, node):
pscope = self.scope
pscope_temps = self.temps_beneath_try
self.scope = node.local_scope
self.init_scope(node.local_scope)
self.handle_node(node)
self.scope = pscope
self.temps_beneath_try = pscope_temps
return node
def visit_TryExceptNode(self, node):
old_tbt = self.temps_beneath_try
self.temps_beneath_try = set()
self.handle_node(node)
entries = [ scope.cname_to_entry[cname] for
cname in self.temps_beneath_try]
node.cleanup_list.extend(entries)
return node
...@@ -588,25 +588,6 @@ class NoneNode(PyConstNode): ...@@ -588,25 +588,6 @@ class NoneNode(PyConstNode):
def compile_time_value(self, denv): def compile_time_value(self, denv):
return None return None
class BoolNode(PyConstNode):
# The constant value True or False
def compile_time_value(self, denv):
return self.value
def calculate_result_code(self):
if self.value:
return "Py_True"
else:
return "Py_False"
def coerce_to(self, dst_type, env):
value = self.value
if dst_type.is_numeric:
return IntNode(self.pos, value=int(self.value)).coerce_to(dst_type, env)
else:
return PyConstNode.coerce_to(self, dst_type, env)
class EllipsisNode(PyConstNode): class EllipsisNode(PyConstNode):
# '...' in a subscript list. # '...' in a subscript list.
...@@ -639,6 +620,16 @@ class ConstNode(AtomicExprNode): ...@@ -639,6 +620,16 @@ class ConstNode(AtomicExprNode):
pass pass
class BoolNode(ConstNode):
type = PyrexTypes.c_bint_type
# The constant value True or False
def compile_time_value(self, denv):
return self.value
def calculate_result_code(self):
return int(self.value)
class NullNode(ConstNode): class NullNode(ConstNode):
type = PyrexTypes.c_null_ptr_type type = PyrexTypes.c_null_ptr_type
value = "NULL" value = "NULL"
...@@ -1217,20 +1208,24 @@ class NextNode(AtomicExprNode): ...@@ -1217,20 +1208,24 @@ class NextNode(AtomicExprNode):
self.is_temp = 1 self.is_temp = 1
def generate_result_code(self, code): def generate_result_code(self, code):
for py_type in ["List", "Tuple"]:
code.putln( code.putln(
"if (likely(%s != -1)) {" % self.iterator.counter.result_code) "if (likely(Py%s_CheckExact(%s))) {" % (py_type, self.iterator.py_result()))
code.putln( code.putln(
"if (%s >= PySequence_Fast_GET_SIZE(%s)) break;" % ( "if (%s >= Py%s_GET_SIZE(%s)) break;" % (
self.iterator.counter.result_code, self.iterator.counter.result_code,
py_type,
self.iterator.py_result())) self.iterator.py_result()))
code.putln( code.putln(
"%s = PySequence_Fast_GET_ITEM(%s, %s); Py_INCREF(%s); %s++;" % ( "%s = Py%s_GET_ITEM(%s, %s); Py_INCREF(%s); %s++;" % (
self.result_code, self.result_code,
py_type,
self.iterator.py_result(), self.iterator.py_result(),
self.iterator.counter.result_code, self.iterator.counter.result_code,
self.result_code, self.result_code,
self.iterator.counter.result_code)) self.iterator.counter.result_code))
code.putln("} else {") code.put("} else ")
code.putln("{")
code.putln( code.putln(
"%s = PyIter_Next(%s);" % ( "%s = PyIter_Next(%s);" % (
self.result_code, self.result_code,
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
cdef extern from "sys/types.h": cdef extern from "sys/types.h":
ctypedef unsigned int size_t ctypedef unsigned int size_t
ctypedef int ssize_t
cdef extern from "stdio.h": cdef extern from "stdio.h":
ctypedef struct FILE: ctypedef struct FILE:
...@@ -26,7 +25,6 @@ cdef extern from "Python.h": ...@@ -26,7 +25,6 @@ cdef extern from "Python.h":
# XXX: This is platform dependent. # XXX: This is platform dependent.
ctypedef unsigned short Py_UNICODE ctypedef unsigned short Py_UNICODE
ctypedef ssize_t Py_ssize_t
ctypedef struct PyTypeObject: ctypedef struct PyTypeObject:
pass pass
......
...@@ -11,11 +11,14 @@ if sys.platform == "win32": ...@@ -11,11 +11,14 @@ if sys.platform == "win32":
setup_args = {} setup_args = {}
if sys.version_info < (2,4): if sys.version_info < (2,4):
compiler_dir = os.path.join(get_python_lib(prefix=''), 'Cython/Compiler') cython_dir = os.path.join(get_python_lib(prefix=''), 'Cython')
compiler_dir = os.path.join(cython_dir, 'Compiler')
setup_args['data_files'] = [ setup_args['data_files'] = [
{compiler_dir : ['Cython/Compiler/Lexicon.pickle']}] {compiler_dir : ['Cython/Compiler/Lexicon.pickle'],
cython_dir : ['Cython/Includes/*.pxd']}]
else: else:
setup_args['package_data'] = {'Cython.Compiler' : ['Lexicon.pickle']} setup_args['package_data'] = {'Cython.Compiler' : ['Lexicon.pickle'],
'Cython' : ['Includes/*.pxd']}
if os.name == "posix": if os.name == "posix":
scripts = ["bin/cython"] scripts = ["bin/cython"]
...@@ -23,7 +26,7 @@ else: ...@@ -23,7 +26,7 @@ else:
scripts = ["cython.py"] scripts = ["cython.py"]
try: try:
sys.argv.remove("--no-compile") sys.argv.remove("--no-cython-compile")
except ValueError: except ValueError:
try: try:
from Cython.Compiler.Main import compile from Cython.Compiler.Main import compile
......
cimport __cython__
# Tests the buffer access syntax functionality by constructing # Tests the buffer access syntax functionality by constructing
# mock buffer objects. # mock buffer objects.
# #
......
...@@ -23,9 +23,9 @@ __doc__ = u""" ...@@ -23,9 +23,9 @@ __doc__ = u"""
""" """
def test_in(s): def test_in(s):
if s in ('ABC', 'BCD'): if s in (u'ABC', u'BCD'):
return 1 return 1
elif s.upper() in ('ABC', 'BCD'): elif s.upper() in (u'ABC', u'BCD'):
return 2 return 2
elif len(s) in (1,2): elif len(s) in (1,2):
return 3 return 3
...@@ -35,9 +35,9 @@ def test_in(s): ...@@ -35,9 +35,9 @@ def test_in(s):
return 5 return 5
def test_not_in(s): def test_not_in(s):
if s not in ('ABC', 'BCD', 'CDE', 'CDEF'): if s not in (u'ABC', u'BCD', u'CDE', u'CDEF'):
return 1 return 1
elif s.upper() not in ('ABC', 'BCD', 'CDEF'): elif s.upper() not in (u'ABC', u'BCD', u'CDEF'):
return 2 return 2
elif len(s) not in [3]: elif len(s) not in [3]:
return 3 return 3
......
...@@ -49,20 +49,20 @@ class ContextManager: ...@@ -49,20 +49,20 @@ class ContextManager:
return self.value return self.value
def no_as(): def no_as():
with ContextManager("value"): with ContextManager(u"value"):
print "hello" print u"hello"
def basic(): def basic():
with ContextManager("value") as x: with ContextManager(u"value") as x:
print x print x
def with_exception(exit_ret): def with_exception(exit_ret):
try: try:
with ContextManager("value", exit_ret=exit_ret) as value: with ContextManager(u"value", exit_ret=exit_ret) as value:
print value print value
raise MyException() raise MyException()
except: except:
print "outer except" print u"outer except"
def multitarget(): def multitarget():
with ContextManager((1, 2, (3, (4, 5)))) as (a, b, (c, (d, e))): with ContextManager((1, 2, (3, (4, 5)))) as (a, b, (c, (d, e))):
......
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