Commit ec1b697c authored by Mark Florisson's avatar Mark Florisson

Support CythonUtilityCode dependencies in CythonUtilityCode

parent ab8b5f9d
......@@ -45,6 +45,8 @@ class UtilityCode(object):
#
# hashes/equals by instance
is_cython_utility = False
def __init__(self, proto=None, impl=None, init=None, cleanup=None, requires=None,
proto_block='utility_code_proto'):
# proto_block: Which code block to dump prototype in. See GlobalState.
......
......@@ -111,11 +111,20 @@ undecorated_methods_protos = UtilityCode(proto=u"""
PyObject *self, PyObject *value);
""")
test_cython_utility_dep = CythonUtilityCode(u"""
@cname('__pyx_test_dep')
cdef test_dep(obj):
print 'test_dep', obj
""")
cython_test_extclass_utility_code = CythonUtilityCode(
name="TestClassUtilityCode",
prefix="__pyx_prefix_TestClass_",
requires=[undecorated_methods_protos],
requires=[undecorated_methods_protos, test_cython_utility_dep],
impl=u"""
cdef extern from *:
cdef object __pyx_test_dep(object)
@cname('__pyx_TestClass')
cdef class TestClass(object):
cdef public int value
......@@ -147,6 +156,10 @@ cdef class TestClass(object):
def def_cname_method(self, int value):
print "Hello from def_cname_method", value
@cname('__pyx_test_call_other_cy_util')
cdef test_call(obj):
print 'test_call'
__pyx_test_dep(obj)
@cname('__pyx_TestClass_New')
cdef _testclass_new(int value):
......
......@@ -55,6 +55,8 @@ class CythonUtilityCode(object):
tests/run/cythonscope.pyx for examples.
"""
is_cython_utility = True
def __init__(self, impl, name="CythonUtilityCode", prefix="", requires=None):
# 1) We need to delay the parsing/processing, so that all modules can be
# imported without import loops
......@@ -114,3 +116,7 @@ class CythonUtilityCode(object):
dest_scope.merge_in(self.tree.scope, merge_unused=True)
self.tree.scope = dest_scope
for dep in self.requires:
if dep.is_cython_utility:
dep.declare_in_scope(dest_scope)
......@@ -2,6 +2,7 @@ cimport cython
from cython cimport _testscope as tester
from cython cimport TestClass, _testclass_new as TestClass_New
from cython cimport test_call, test_dep
from cython.view cimport _testscope as viewtester
cdef extern from *:
......@@ -24,6 +25,9 @@ cdef extern from *:
cdef __pyx_TestClass_cpdef_cname(TestClass self, int value, int skip_dispatch)
cdef __pyx_TestClass_def_cname(object self, object value)
cdef __pyx_test_dep(object)
cdef __pyx_test_call_other_cy_util(object)
def test_cdef_cython_utility():
"""
......@@ -127,3 +131,17 @@ def test_extclass_cython_methods():
obj2.cpdef_cname_method(5)
obj2.def_cname_method(6)
def test_cython_utility_dep():
"""
>>> test_cython_utility_dep()
test_dep first
test_call
test_dep second
test_dep third
test_call
test_dep fourth
"""
test_dep('first')
test_call('second')
__pyx_test_dep('third')
__pyx_test_call_other_cy_util('fourth')
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