Commit 9ac5d811 authored by Stefan Behnel's avatar Stefan Behnel

Provide a more convenient way to declare internal C properties.

parent 4b90db36
......@@ -1693,19 +1693,13 @@ class PythranExpr(CType):
scope.directives = {}
scope.declare_var("ndim", c_long_type, pos=None, cname="value", is_cdef=True)
shape_type = c_ptr_type(c_long_type)
shape_entry = scope.declare_property(
"shape", doc="Pythran array shape", ctype=shape_type, pos=None)
shape_entry.scope.declare_cfunction(
name="shape",
type=CFuncType(shape_type, [CFuncTypeArg("self", self, pos=None)], nogil=True),
cname="__Pyx_PythranShapeAccessor",
visibility='extern',
pos=None,
scope.declare_cproperty(
"shape", c_ptr_type(c_long_type), "__Pyx_PythranShapeAccessor",
doc="Pythran array shape",
visibility="extern",
nogil=True,
)
return True
def __eq__(self, other):
......
......@@ -2412,6 +2412,27 @@ class CClassScope(ClassScope):
self.property_entries.append(entry)
return entry
def declare_cproperty(self, name, type, cfunc_name, doc=None, pos=None, visibility='extern',
nogil=False, with_gil=False, exception_value=None, exception_check=False):
"""Internal convenience method to declare a C property function in one go.
"""
property_entry = self.declare_property(name, doc=doc, ctype=type, pos=pos)
cfunc_entry = property_entry.scope.declare_cfunction(
name=name,
type=PyrexTypes.CFuncType(
type,
[PyrexTypes.CFuncTypeArg("self", self.parent_type, pos=None)],
nogil=nogil,
with_gil=with_gil,
exception_value=exception_value,
exception_check=exception_check,
),
cname=cfunc_name,
visibility=visibility,
pos=pos,
)
return property_entry, cfunc_entry
def declare_inherited_c_attributes(self, base_scope):
# Declare entries for all the C attributes of an
# inherited type, with cnames modified appropriately
......
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