Robert Bradshaw wrote:
> On May 6, 2009, at 12:48 PM, Dag Sverre Seljebotn wrote:
>
>> Robert Bradshaw wrote:
>>> Just trying to get a syntax, how about
>>>
>>> cdef extern from "header.h":
>>> cdef cclass MyClass[TemplateParamers](BaseCPPClass):
>>> int member
>>> int method(int)
>>>
>>> The only concern I have is whether or not "cdef cclass" is to similar
>>> to "cdef class" (probably not). Any other ideas?
>>
>> cdef cppclass?
>
> I don't like this one, but I think just for aesthetic reasons. Nor
> cpp_class.
Myself I'm used to a .cpp suffix on C++ files; I suppose people who are
used to the competing .cc will have stronger associations with your
proposal. "cclass" gives me no associations at all initially.
>> Yes, I think cclass is to similar to class.
>>
>> Anyway, when I proposed a Fortran syntax earlier you and Stefan made a
>> good point about the language specification belonging in the "cdef
>> extern"
>> part, as, after all, the "header.h" file contains only C++ code.
>
> Will the compiler need to know that header.h is C++ code? If not, I
> see no reason to declare it.
No -- it's just the fact that usually all classes within the extern block
will be a C++ class. I was thinking just plain "cdef class" could then
change meaning, which would have a happy association with the
heap-allocation thing (which C++ classes would share with existing cdef
classes).
cdef extern "C++" from "myheader.h":
cdef class A: ...
OTOH, if heap-allocation-and-refcounted semantics isn't selected, one
should use "cdef struct" instead, like Lisandro suggests.
In the unlikely event that you have both a C++ class and a Python
extension class in the same header you can always repeat the extern
statement.
After all, C++ uses
extern "C" {
}
to interface with C.
>
>> Also consider that C++ needs namespace specifications, for instance
>>
>> cdef extern ...:
>> namespace std:
>> cdef cppclass vector[T]: ...
>>
>> or
>>
>> cdef cclass std::vector[T]: ...
>
> Yep. That too. I'm a fan of both declarations. (Or even rolling the
> "namespace" into the cdef extern statement.)
FWIW I don't like the second one.
I like rolling it into the extern statement. A single header file can
declare things for many namespaces, but it is not common and you can
always use two cdef extern blocks for the same header in such cases.
Dag Sverre
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev