diff options
author | Stefan Behnel <stefan_ml@behnel.de> | 2020-05-05 12:37:41 +0200 |
---|---|---|
committer | Stefan Behnel <stefan_ml@behnel.de> | 2020-05-05 12:37:41 +0200 |
commit | 9ac5d81184d35cab4543d86e1e24d12378ca99e2 (patch) | |
tree | d46ed94cfda079b306583e625722b474d203c531 | |
parent | 4b90db366e1cf7b360573a92931a70ff3fb6fa0d (diff) | |
download | cython-9ac5d81184d35cab4543d86e1e24d12378ca99e2.tar.gz |
Provide a more convenient way to declare internal C properties.
-rw-r--r-- | Cython/Compiler/PyrexTypes.py | 16 | ||||
-rw-r--r-- | Cython/Compiler/Symtab.py | 21 |
2 files changed, 26 insertions, 11 deletions
diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index f3618ffd2..e898f4057 100644 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -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): diff --git a/Cython/Compiler/Symtab.py b/Cython/Compiler/Symtab.py index 17b99be11..aeb7a38c1 100644 --- a/Cython/Compiler/Symtab.py +++ b/Cython/Compiler/Symtab.py @@ -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 |