Re: [Cython] Surprising behaviour wrt. generated tp_clear and tp_dealloc functions

2013-07-16 Thread Torsten Landschoff
Hi Stefan,

On 07/14/2013 10:39 AM, Stefan Behnel wrote:
> Torsten Landschoff, 11.07.2013 00:10:
>> I attached my current (trivial) patch. Currently I only support a decorator
>>
>> @cython.noclear
>> cdef class ...
>>
>> to inhibit generation of tp_clear.
> Thanks, looks ok to me. Please open a pull request on github for it.
I'd like to remove some code duplication I introduced in my changes and
add the feature to exclude specific attributes from clearing.
>> Before I continue with this approach I am wondering about the API. Is
>> noclear usable as a name? I think not because nobody will know what it
>> is talking about.
> I think that name is as good as any. It could be "no_gc_clear", if you find
> that clearer. It hints at GC, at least. I think that should be part of the
> name somehow.
Agreed.
So there will be the following decorator:

@cython.no_gc_clear
class ...

to disable generation of the clear method and

@cython.no_gc
class ...

to disable GC entirely. Okay for you?

I'd also like to support

@cython.no_gc_clear("keepthis", "keepthat")

to omit specific attributes from clear handling. I am not sure though
how to declare that decorator in directive_types. Would something like
this work:

directive_types = {
'final' : bool,  # final cdef classes and methods
# ...
'no_gc_clear': one_of('bool', 'list'),
# ...
}

?? How would I tell the parser that it should accept the strings as
*args of the decorator (if you know what I mean)?
> Please also document it somewhere in the extension types doc section (in
> the user guide):
>
> https://github.com/cython/cython/blob/master/docs/src/userguide/extension_types.rst
Thanks for the pointer, I was wondering about the right documentation
set to change.

Greetings, Torsten

-- 
DYNAmore Gesellschaft fuer Ingenieurdienstleistungen mbH
Torsten Landschoff

Office Dresden
Tel: +49-(0)351-4519587
Fax: +49-(0)351-4519561

mailto:torsten.landsch...@dynamore.de
http://www.dynamore.de

DYNAmore Gesellschaft für FEM Ingenieurdienstleistungen mbH
Registration court: Stuttgart, HRB 733694
Managing director: Prof. Dr. Karl Schweizerhof, Dipl.-Math. Ulrich Franz

___
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] Difference between Cython / Python isinstance() vs. NumPy scalars, NumPy bug!

2013-07-16 Thread Yury V. Zaytsev
On Mon, 2013-07-15 at 17:54 +0200, Yury V. Zaytsev wrote:
> 
> 1) What's the best way to get Cython to generate (b) instead of (a)?

As it appears, it doesn't really matter, because I've realized that I
can import numpy without actually introducing a compile-time dependency
on numpy as long as I don't cimport numpy.

NumPy objects have a very handy item() method, which "copies an element
of an array to a standard Python scalar and returns it", so at this
point I can use the standard isinstance() checks against built-ins!

> 2) Shall I open a bug against Python and suggest to investigate why
> PyType_FastSubclass is not really equivalent to PyObject_TypeCheck as
> it should be for the built-in types?

FYI, this seems to be a problem with NumPy:

https://github.com/numpy/numpy/pull/3526

Hope this helps,

-- 
Sincerely yours,
Yury V. Zaytsev



___
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel