[Cython] Seemingly incorrect specialization of templates

Vinay Sajip vinay_sajip at yahoo.co.uk
Mon Dec 16 11:09:51 CET 2013


Given this code in Cython/Includes/libcpp/utility.pxd:

cdef extern from "<utility>" namespace "std":
    cdef cppclass pair[T, U]:
        T first
        U second
        # rest omitted

when the following code in Cython/Includes/libcpp/map.pxd is seen:

from utility cimport pair

cdef extern from "<map>" namespace "std":
    cdef cppclass map[T, U]:
        cppclass iterator:
            pair[T, U]& operator*() nogil
            # rest omitted

The line "pair[T, U]& operator*() nogil" causes a specialization
of pair[T, U] to be created, but using placeholders rather than actual
types. This seems wrong - can someone here confirm whether this is
intentional?

This led to a problem where the generated C++ code for a genuine
specialisation instead generated a declaration like "pair<T, U>" instead
of using the actual arguments. Given this code in
Cython/Includes/libcpp/utility.pxd:

cdef extern from "<utility>" namespace "std":
    cdef cppclass pair[T, U]:
        T first
        U second
        # rest omitted

when the following code in Cython/Includes/libcpp/map.pxd is seen:

from utility cimport pair

cdef extern from "<map>" namespace "std":
    cdef cppclass map[T, U]:
        cppclass iterator:
            pair[T, U]& operator*() nogil
            # rest omitted

The line "pair[T, U]& operator*() nogil" causes a specialization
of pair[T, U] to be created, but using placeholders rather than actual
types. This seems wrong - can someone here confirm whether this is
intentional?

This caused a problem where the generated C++ code for a genuine
specialisation instead generated a declaration like "pair<T, U>" instead
of using the actual arguments.Given this code in
Cython/Includes/libcpp/utility.pxd:

cdef extern from "<utility>" namespace "std":
    cdef cppclass pair[T, U]:
        T first
        U second
        # rest omitted

when the following code in Cython/Includes/libcpp/map.pxd is seen:

from utility cimport pair

cdef extern from "<map>" namespace "std":
    cdef cppclass map[T, U]:
        cppclass iterator:
            pair[T, U]& operator*() nogil
            # rest omitted

The line "pair[T, U]& operator*() nogil" causes a specialization
of pair[T, U] to be created, but using placeholders rather than actual
types. This seems wrong - can someone here confirm whether this is
intentional?

This caused a problem where the generated C++ code for a genuine
specialisation instead generated a declaration like "pair<T, U>" instead
of using the actual arguments.

The specialize call occurs in Nodes.py:TemplatedTypeNode.analyse, where the
template_types passed to specialize are actually all instances of
TemplatePlaceholderType.

Regards,

Vinay Sajip
Given this code in Cython/Includes/libcpp/utility.pxd:

cdef extern from "<utility>" namespace "std":
    cdef cppclass pair[T, U]:
        T first
        U second
        # rest omitted

when the following code in Cython/Includes/libcpp/map.pxd is seen:

from utility cimport pair

cdef extern from "<map>" namespace "std":
    cdef cppclass map[T, U]:
        cppclass iterator:
            pair[T, U]& operator*() nogil
            # rest omitted

The line "pair[T, U]& operator*() nogil" causes a specialization
of pair[T, U] to be created, but using placeholders rather than actual
types. This seems wrong - can someone here confirm whether this is
intentional?

This caused a problem where the generated C++ code for a genuine
specialisation instead generated a declaration like "pair<T, U>" instead
of using the actual arguments. This, of course, failed in g++.

The specialize call occurs in Nodes.py:TemplatedTypeNode.analyse, where the
template_types passed to specialize are actually all instances of
TemplatePlaceholderType. It seems like just the base_type could be used.

Regards,

Vinay Sajip


The specialize call occurs in Nodes.py:TemplatedTypeNode.analyse, where the
template_types passed to specialize are actually all instances of
TemplatePlaceholderType.

Regards,

Vinay Sajip


The specialize call occurs in Nodes.py:TemplatedTypeNode.analyse, where the
template_types passed to specialize are actually all instances of
TemplatePlaceholderType.

Regards,

Vinay Sajip




More information about the cython-devel mailing list