summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorda-woods <dw-git@d-woods.co.uk>2022-12-12 08:34:41 +0000
committerda-woods <dw-git@d-woods.co.uk>2022-12-12 08:34:41 +0000
commitcfad75e551c708a9675ff57671f10862dce3eb1d (patch)
treef384afd74e5a1decb9a55746308b54e578b59e59
parent88ba54a6f8bd103b49f83a87a4329013cc7aa0e3 (diff)
parentcbcda04523900612ef543ac7f99d70f5bfd0ca88 (diff)
downloadcython-patma-preview.tar.gz
Merge branch 'master' into patma-previewpatma-preview
-rw-r--r--Cython/Compiler/ModuleNode.py2
-rw-r--r--Cython/Utility/Complex.c3
-rw-r--r--docs/src/userguide/language_basics.rst28
3 files changed, 30 insertions, 3 deletions
diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py
index 0a7308562..635dcd543 100644
--- a/Cython/Compiler/ModuleNode.py
+++ b/Cython/Compiler/ModuleNode.py
@@ -2787,7 +2787,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
env.module_cname,
Naming.pymoduledef_cname))
module_state.putln("#else")
- module_state.putln('static %s %s_static = {};' % (
+ module_state.putln('static %s %s_static = {0};' % (
Naming.modulestate_cname,
Naming.modulestateglobal_cname
))
diff --git a/Cython/Utility/Complex.c b/Cython/Utility/Complex.c
index 6bd846033..642184486 100644
--- a/Cython/Utility/Complex.c
+++ b/Cython/Utility/Complex.c
@@ -349,12 +349,11 @@ static double __Pyx_SoftComplexToDouble(__pyx_t_double_complex value) {
static PyObject *__pyx_Py_FromSoftComplex(__pyx_t_double_complex value); /* proto */
//////// SoftComplexToPy ////////////////
-//@requires: ToPy
//@requires: RealImag
static PyObject *__pyx_Py_FromSoftComplex(__pyx_t_double_complex value) {
if (__Pyx_CIMAG(value)) {
- return __pyx_PyComplex_FromComplex(value);
+ return PyComplex_FromDoubles(__Pyx_CREAL(value), __Pyx_CIMAG(value));
} else {
return PyFloat_FromDouble(__Pyx_CREAL(value));
}
diff --git a/docs/src/userguide/language_basics.rst b/docs/src/userguide/language_basics.rst
index ff7007760..191cb32b2 100644
--- a/docs/src/userguide/language_basics.rst
+++ b/docs/src/userguide/language_basics.rst
@@ -317,6 +317,34 @@ and is typically what one wants).
If you want to use these numeric Python types simply omit the
type declaration and let them be objects.
+
+Type qualifiers
+---------------
+
+Cython supports ``const`` and ``volatile`` `C type qualifiers <https://en.wikipedia.org/wiki/Type_qualifier>`_::
+
+ cdef volatile int i = 5
+
+ cdef const int sum(const int a, const int b):
+ return a + b
+
+ cdef void print_const_pointer(const int *value):
+ print(value[0])
+
+ cdef void print_pointer_to_const_value(int * const value):
+ print(value[0])
+
+ cdef void print_const_pointer_to_const_value(const int * const value):
+ print(value[0])
+
+.. Note::
+
+ Both type qualifiers are not supported by pure python mode. Moreover, the ``const`` modifier is unusable
+ in a lot of contexts since Cython needs to generate definitions and their assignments separately. Therefore
+ we suggest using it mainly for function argument and pointer types where ``const`` is necessary to
+ work with an existing C/C++ interface.
+
+
Extension Types
---------------