Commit 231b6b64 authored by Vitja Makarov's avatar Vitja Makarov

Merge remote branch 'upstream/master'

parents 4039edb9 42091eac
...@@ -2501,6 +2501,8 @@ class SliceIndexNode(ExprNode): ...@@ -2501,6 +2501,8 @@ class SliceIndexNode(ExprNode):
elif base_type in (bytes_type, str_type, unicode_type, elif base_type in (bytes_type, str_type, unicode_type,
list_type, tuple_type): list_type, tuple_type):
return base_type return base_type
elif base_type.is_ptr or base_type.is_array:
return PyrexTypes.c_array_type(base_type.base_type, None)
return py_object_type return py_object_type
def calculate_constant_result(self): def calculate_constant_result(self):
...@@ -6049,7 +6051,7 @@ class DivNode(NumBinopNode): ...@@ -6049,7 +6051,7 @@ class DivNode(NumBinopNode):
operand2 = self.operand2.compile_time_value(denv) operand2 = self.operand2.compile_time_value(denv)
try: try:
func = self.find_compile_time_binary_operator( func = self.find_compile_time_binary_operator(
self, operand1, operand2) operand1, operand2)
return func(operand1, operand2) return func(operand1, operand2)
except Exception, e: except Exception, e:
self.compile_time_value_error(e) self.compile_time_value_error(e)
......
...@@ -4525,7 +4525,12 @@ class ForInStatNode(LoopNode, StatNode): ...@@ -4525,7 +4525,12 @@ class ForInStatNode(LoopNode, StatNode):
self.target.analyse_target_types(env) self.target.analyse_target_types(env)
self.iterator.analyse_expressions(env) self.iterator.analyse_expressions(env)
self.item = ExprNodes.NextNode(self.iterator, env) self.item = ExprNodes.NextNode(self.iterator, env)
self.item = self.item.coerce_to(self.target.type, env) if (self.iterator.type.is_ptr or self.iterator.type.is_array) and \
self.target.type.assignable_from(self.iterator.type):
# C array slice optimization.
pass
else:
self.item = self.item.coerce_to(self.target.type, env)
self.body.analyse_expressions(env) self.body.analyse_expressions(env)
if self.else_clause: if self.else_clause:
self.else_clause.analyse_expressions(env) self.else_clause.analyse_expressions(env)
......
...@@ -375,6 +375,9 @@ class IterationTransform(Visitor.VisitorTransform): ...@@ -375,6 +375,9 @@ class IterationTransform(Visitor.VisitorTransform):
base=counter_temp, base=counter_temp,
type=Builtin.bytes_type, type=Builtin.bytes_type,
is_temp=1) is_temp=1)
elif node.target.type.is_ptr and not node.target.type.assignable_from(ptr_type.base_type):
# Allow iteration with pointer target to avoid copy.
target_value = counter_temp
else: else:
target_value = ExprNodes.IndexNode( target_value = ExprNodes.IndexNode(
node.target.pos, node.target.pos,
......
...@@ -483,7 +483,7 @@ def map_starred_assignment(lhs_targets, starred_assignments, lhs_args, rhs_args) ...@@ -483,7 +483,7 @@ def map_starred_assignment(lhs_targets, starred_assignments, lhs_args, rhs_args)
# right side of the starred target # right side of the starred target
for i, (targets, expr) in enumerate(zip(lhs_targets[-lhs_remaining:], for i, (targets, expr) in enumerate(zip(lhs_targets[-lhs_remaining:],
lhs_args[-lhs_remaining:])): lhs_args[starred + 1:])):
targets.append(expr) targets.append(expr)
# the starred target itself, must be assigned a (potentially empty) list # the starred target itself, must be assigned a (potentially empty) list
......
# #
# Pyrex wrapper for the cheesefinder API # Cython wrapper for the cheesefinder API
# #
cdef extern from "cheesefinder.h": cdef extern from "cheesefinder.h":
......
# Makefile for Microsoft compiler statically linking PYVERSION = 2.2 PYHOME = \Python$(PYVERSION:.=) PYINCLUDE = -I$(PYHOME)\include PYLIB = /LIBPATH:$(PYHOME)\libs python22.lib CFLAGS = $(PYINCLUDE) /Ox /W3 /GX -nologo .SUFFIXES: .exe .dll .obj .c .cpp .pyx .pyx.c: $(PYHOME)\Python.exe ../../pyrexc.py $< all: main.exe clean: -del /Q/F *.obj embedded.h embedded.c main.exe main.exe: main.obj embedded.obj link /nologo $** $(PYLIB) /OUT:main.exe embedded.h: embedded.c main.obj: embedded.h # Makefile for Microsoft compiler statically linking PYVERSION = 2.2 PYHOME = \Python$(PYVERSION:.=) PYINCLUDE = -I$(PYHOME)\include PYLIB = /LIBPATH:$(PYHOME)\libs python22.lib CFLAGS = $(PYINCLUDE) /Ox /W3 /GX -nologo .SUFFIXES: .exe .dll .obj .c .cpp .pyx .pyx.c: $(PYHOME)\Python.exe ../../cython.py $< all: main.exe clean: -del /Q/F *.obj embedded.h embedded.c main.exe main.exe: main.obj embedded.obj link /nologo $** $(PYLIB) /OUT:main.exe embedded.h: embedded.c main.obj: embedded.h
\ No newline at end of file \ No newline at end of file
......
This example demonstrates how Pyrex-generated code can be called directly from a main program written in C. In this example, the module's initialisation function (called "initembedded", since the module is called "embedded") is called explicitly. This is necessary because the module is not being imported using the normal Python import mechanism. The Windows makefiles were contributed by Duncan Booth <Duncan.Booth@SuttonCourtenay.org.uk>. This example demonstrates how Cython-generated code
\ No newline at end of file can be called directly from a main program written in C.
The Windows makefiles were contributed by
Duncan Booth <Duncan.Booth@SuttonCourtenay.org.uk>.
...@@ -217,3 +217,19 @@ def iter_doublearray_for_loop_c(): ...@@ -217,3 +217,19 @@ def iter_doublearray_for_loop_c():
""" """
cdef double d cdef double d
print [ d for d in cdoubles ] print [ d for d in cdoubles ]
cdef struct MyStruct:
int i
def struct_ptr_iter():
"""
>>> struct_ptr_iter()
([0, 1, 2, 3, 4], [0, 1, 2, 3, 4])
"""
cdef MyStruct my_structs[5]
for i in range(5):
my_structs[i].i = i
cdef MyStruct value
cdef MyStruct *ptr
return [ value.i for value in my_structs[:5] ], [ ptr.i for ptr in my_structs[:5] ]
...@@ -401,7 +401,7 @@ cdef class VerySpecial: ...@@ -401,7 +401,7 @@ cdef class VerySpecial:
def __imod__(self, other): def __imod__(self, other):
print "VS __imod__ %d %%= %d" % (self.value, other.value) print "VS __imod__ %d %%= %d" % (self.value, other.value)
def __ipow__(self, other, mod): def __ipow__(self, other):
# We must declare mod as an argument, but we must not touch it # We must declare mod as an argument, but we must not touch it
# or we'll get a segfault. See #562 # or we'll get a segfault. See #562
print "VS __ipow__ %d %d" % (self.value, other.value) print "VS __ipow__ %d %d" % (self.value, other.value)
......
def assign():
"""
>>> assign()
(1, [2, 3, 4, 5])
"""
a, *b = 1, 2, 3, 4, 5
return a, b
def assign3():
"""
>>> assign3()
(1, [2, 3, 4, 5], 6)
"""
a, *b, c = 1, 2, 3, 4, 5, 6
return a, b, c
def assign4():
"""
>>> assign4()
(1, [2, 3, 4], 5, 6)
"""
a, *b, c, d = 1, 2, 3, 4, 5, 6
return a, b, c, d
...@@ -333,6 +333,20 @@ def loop_over_int_array(): ...@@ -333,6 +333,20 @@ def loop_over_int_array():
pass pass
return typeof(i) return typeof(i)
cdef struct MyStruct:
int a
def loop_over_struct_ptr():
"""
>>> print( loop_over_struct_ptr() )
MyStruct
"""
cdef MyStruct a_list[10]
cdef MyStruct *a_ptr = a_list
for i in a_list[:10]:
pass
return typeof(i)
cdef unicode retu(): cdef unicode retu():
return u"12345" return u"12345"
......
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