|
5 | 5 | # distutils: language = c++
|
6 | 6 | # distutils: depends = libgolang.h os/signal.h _golang_str.pyx
|
7 | 7 | #
|
8 |
| -# Copyright (C) 2018-2023 Nexedi SA and Contributors. |
| 8 | +# Copyright (C) 2018-2024 Nexedi SA and Contributors. |
9 | 9 | # Kirill Smelkov <[email protected]>
|
10 | 10 | #
|
11 | 11 | # This program is free software: you can Use, Study, Modify and Redistribute
|
@@ -173,11 +173,18 @@ cdef void __goviac(void *arg) nogil:
|
173 | 173 |
|
174 | 174 | # ---- channels ----
|
175 | 175 |
|
| 176 | +# _frompyx indicates that a constructor is called from pyx code |
| 177 | +cdef object _frompyx = object() |
| 178 | + |
176 | 179 | @final
|
177 | 180 | cdef class pychan:
|
178 | 181 | def __cinit__(pychan pych, size=0, dtype=object):
|
179 |
| - pych.dtype = parse_dtype(dtype) |
180 |
| - pych._ch = _makechan_pyexc(dtypeRegistry[<int>pych.dtype].size, size) |
| 182 | + if dtype is _frompyx: |
| 183 | + pych.dtype = DTYPE_STRUCTZ # anything |
| 184 | + pych._ch = NULL |
| 185 | + else: |
| 186 | + pych.dtype = parse_dtype(dtype) |
| 187 | + pych._ch = _makechan_pyexc(dtypeRegistry[<int>pych.dtype].size, size) |
181 | 188 |
|
182 | 189 | # pychan.nil(X) creates new nil pychan with specified dtype.
|
183 | 190 | # TODO try to avoid exposing .nil on pychan instances, and expose only pychan.nil
|
@@ -370,7 +377,7 @@ cdef void pychan_asserttype(pychan pych, DType dtype) nogil:
|
370 | 377 | panic("pychan: channel type mismatch")
|
371 | 378 |
|
372 | 379 | cdef pychan pychan_from_raw(_chan *_ch, DType dtype):
|
373 |
| - cdef pychan pych = pychan.__new__(pychan) |
| 380 | + cdef pychan pych = pychan.__new__(pychan, dtype=_frompyx) |
374 | 381 | pych.dtype = dtype
|
375 | 382 | pych._ch = _ch; _chanxincref(_ch)
|
376 | 383 | return pych
|
@@ -626,9 +633,7 @@ cdef object c_to_py(DType dtype, const chanElemBuf *cfrom):
|
626 | 633 |
|
627 | 634 | # mkpynil creates pychan instance that represents nil[dtype].
|
628 | 635 | cdef PyObject *mkpynil(DType dtype):
|
629 |
| - cdef pychan pynil = pychan.__new__(pychan) |
630 |
| - pynil.dtype = dtype |
631 |
| - pynil._ch = NULL # should be already NULL |
| 636 | + cdef pychan pynil = pychan_from_raw(NULL, dtype) |
632 | 637 | Py_INCREF(pynil)
|
633 | 638 | return <PyObject *>pynil
|
634 | 639 |
|
@@ -818,9 +823,6 @@ from libcpp.typeinfo cimport type_info
|
818 | 823 | from cython.operator cimport typeid
|
819 | 824 | from libc.string cimport strcmp
|
820 | 825 |
|
821 |
| -# _frompyx indicates that a constructor is called from pyx code |
822 |
| -cdef object _frompyx = object() |
823 |
| - |
824 | 826 | cdef class pyerror(Exception):
|
825 | 827 | # pyerror <- error
|
826 | 828 | @staticmethod
|
|
0 commit comments