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):
def __call__(self, node):
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.tsfuncs = set()
self.ts_funcs = []
......@@ -281,7 +275,7 @@ class IntroduceBufferAuxiliaryVars(CythonTransform):
# Declare auxiliary vars
cname = scope.mangle(Naming.bufstruct_prefix, name)
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
......
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):
def compile_time_value(self, denv):
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):
# '...' in a subscript list.
......@@ -639,6 +620,16 @@ class ConstNode(AtomicExprNode):
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):
type = PyrexTypes.c_null_ptr_type
value = "NULL"
......@@ -1217,20 +1208,24 @@ class NextNode(AtomicExprNode):
self.is_temp = 1
def generate_result_code(self, code):
code.putln(
"if (likely(%s != -1)) {" % self.iterator.counter.result_code)
code.putln(
"if (%s >= PySequence_Fast_GET_SIZE(%s)) break;" % (
self.iterator.counter.result_code,
self.iterator.py_result()))
code.putln(
"%s = PySequence_Fast_GET_ITEM(%s, %s); Py_INCREF(%s); %s++;" % (
self.result_code,
self.iterator.py_result(),
self.iterator.counter.result_code,
self.result_code,
self.iterator.counter.result_code))
code.putln("} else {")
for py_type in ["List", "Tuple"]:
code.putln(
"if (likely(Py%s_CheckExact(%s))) {" % (py_type, self.iterator.py_result()))
code.putln(
"if (%s >= Py%s_GET_SIZE(%s)) break;" % (
self.iterator.counter.result_code,
py_type,
self.iterator.py_result()))
code.putln(
"%s = Py%s_GET_ITEM(%s, %s); Py_INCREF(%s); %s++;" % (
self.result_code,
py_type,
self.iterator.py_result(),
self.iterator.counter.result_code,
self.result_code,
self.iterator.counter.result_code))
code.put("} else ")
code.putln("{")
code.putln(
"%s = PyIter_Next(%s);" % (
self.result_code,
......
......@@ -16,7 +16,6 @@
cdef extern from "sys/types.h":
ctypedef unsigned int size_t
ctypedef int ssize_t
cdef extern from "stdio.h":
ctypedef struct FILE:
......@@ -26,7 +25,6 @@ cdef extern from "Python.h":
# XXX: This is platform dependent.
ctypedef unsigned short Py_UNICODE
ctypedef ssize_t Py_ssize_t
ctypedef struct PyTypeObject:
pass
......
......@@ -11,11 +11,14 @@ if sys.platform == "win32":
setup_args = {}
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'] = [
{compiler_dir : ['Cython/Compiler/Lexicon.pickle']}]
{compiler_dir : ['Cython/Compiler/Lexicon.pickle'],
cython_dir : ['Cython/Includes/*.pxd']}]
else:
setup_args['package_data'] = {'Cython.Compiler' : ['Lexicon.pickle']}
setup_args['package_data'] = {'Cython.Compiler' : ['Lexicon.pickle'],
'Cython' : ['Includes/*.pxd']}
if os.name == "posix":
scripts = ["bin/cython"]
......@@ -23,7 +26,7 @@ else:
scripts = ["cython.py"]
try:
sys.argv.remove("--no-compile")
sys.argv.remove("--no-cython-compile")
except ValueError:
try:
from Cython.Compiler.Main import compile
......
cimport __cython__
# Tests the buffer access syntax functionality by constructing
# mock buffer objects.
#
......
......@@ -23,9 +23,9 @@ __doc__ = u"""
"""
def test_in(s):
if s in ('ABC', 'BCD'):
if s in (u'ABC', u'BCD'):
return 1
elif s.upper() in ('ABC', 'BCD'):
elif s.upper() in (u'ABC', u'BCD'):
return 2
elif len(s) in (1,2):
return 3
......@@ -35,9 +35,9 @@ def test_in(s):
return 5
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
elif s.upper() not in ('ABC', 'BCD', 'CDEF'):
elif s.upper() not in (u'ABC', u'BCD', u'CDEF'):
return 2
elif len(s) not in [3]:
return 3
......
......@@ -49,20 +49,20 @@ class ContextManager:
return self.value
def no_as():
with ContextManager("value"):
print "hello"
with ContextManager(u"value"):
print u"hello"
def basic():
with ContextManager("value") as x:
with ContextManager(u"value") as x:
print x
def with_exception(exit_ret):
try:
with ContextManager("value", exit_ret=exit_ret) as value:
with ContextManager(u"value", exit_ret=exit_ret) as value:
print value
raise MyException()
except:
print "outer except"
print u"outer except"
def multitarget():
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