ctypedef extern class without importing

閲覧: 81 回
最初の未読メッセージにスキップ

Jeroen Demeyer

未読、
2017/06/16 9:56:362017/06/16
To: cython-users
One thing which annoys me about the syntax

cdef extern from "complexobject.h":
ctypedef class __builtin__.complex [object PyComplexObject]:
cdef Py_complex cval

is that it requires the type (__builtin__.complex in this case) to be
importable. Unfortunately, some types in Python are exposed through the
C/API but are not available as Python object in some standard module (I
am in particular interested in PyWrapperDescr_Type). The above syntax
also doesn't work for __builtin__.long because "long" in Cython means
something else.

Would it be possible to allow specifying the PyTypeObject name instead
of an importable name? So something like

cdef extern from "complexobject.h":
ctypedef class CUSTOM_NAME [object PyComplexObject, type
PyComplex_Type]:
cdef Py_complex cval

Where CUSTOM_NAME is simply an identifier used to refer to the type.

Robert Bradshaw

未読、
2017/06/16 18:46:002017/06/16
To: cython...@googlegroups.com
Even if a PyTypeObject name is exposed (e.g. via a header), it may not
be initialized until the corresponding module is imported. Any ideas
on how best to solve that?
> --
>
> --- You received this message because you are subscribed to the Google
> Groups "cython-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to cython-users...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Jeroen Demeyer

未読、
2017/06/18 5:35:012017/06/18
To: cython...@googlegroups.com
On 2017-06-17 00:45, Robert Bradshaw wrote:
> Even if a PyTypeObject name is exposed (e.g. via a header), it may not
> be initialized until the corresponding module is imported. Any ideas
> on how best to solve that?

Of course, there is no solution to that. But I am thinking about
standard Python types, which would be initialized when Python starts up.

Jeroen Demeyer

未読、
2017/07/07 11:21:032017/07/07
To: cython...@googlegroups.com
Moreover, PyType_Ready() on a type calls PyType_Ready() on the base type
tp_base if needed.

I'm still interested in this feature, do you think it could work?

Robert Bradshaw

未読、
2017/07/07 18:59:232017/07/07
To: cython...@googlegroups.com
Worth considering. On the other hand, how bad would it be to create a
module (.py files) that simply enumerates these types. (e.g. PyLong =
long, ...) and then use that as the name?

Jeroen Demeyer

未読、
2017/07/10 4:25:382017/07/10
To: cython...@googlegroups.com
On 2017-07-08 00:58, Robert Bradshaw wrote:
> Worth considering. On the other hand, how bad would it be to create a
> module (.py files)

Would it be possible to create a module in the "cython" package, say
cython.types defining a few of these?

Robert Bradshaw

未読、
2017/07/11 1:28:382017/07/11
To: cython...@googlegroups.com
Yes, that would also be possible. (Maybe cpython.builtin_types?)
全員に返信
投稿者に返信
転送
新着メール 0 件