Re: Accessing __slots__ from C

2008-12-09 Thread Mike Kolbet
-- http://mail.python.org/mailman/listinfo/python-list

Re: Accessing __slots__ from C

2008-09-16 Thread Chris
Hrvoje Niksic xemacs.org> writes: ... > > You are getting that error because Carl forgot to cast the descriptor > > to the appropriate C type, in this case PyMemberDescrObject. The last > > line is also incorrect, I think. Try something like this: ... The code you gave was great, thanks! Now we

Re: Accessing __slots__ from C

2008-09-12 Thread Carl Banks
On Sep 12, 10:01 am, Hrvoje Niksic <[EMAIL PROTECTED]> wrote: > Chris <[EMAIL PROTECTED]> writes: > >> descr = GetAttrString(cls,"varname"); > >> offset = descr->d_member->offset; > >> slotvar = (PyObject*)(((char*)obj)+offset) > > > Unfortunately, I am inexperienced at this kind of thing, so I was

Re: Accessing __slots__ from C

2008-09-12 Thread Hrvoje Niksic
Hrvoje Niksic <[EMAIL PROTECTED]> writes: > Chris <[EMAIL PROTECTED]> writes: > >>> descr = GetAttrString(cls,"varname"); >>> offset = descr->d_member->offset; >>> slotvar = (PyObject*)(((char*)obj)+offset) >> >> Unfortunately, I am inexperienced at this kind of thing, so I wasn't >> able to get s

Re: Accessing __slots__ from C

2008-09-12 Thread Hrvoje Niksic
Chris <[EMAIL PROTECTED]> writes: >> descr = GetAttrString(cls,"varname"); >> offset = descr->d_member->offset; >> slotvar = (PyObject*)(((char*)obj)+offset) > > Unfortunately, I am inexperienced at this kind of thing, so I wasn't > able to get something working. Maybe someone could tell me what's

Re: Accessing __slots__ from C

2008-09-12 Thread Hrvoje Niksic
Chris <[EMAIL PROTECTED]> writes: >> In my experience, as long as you're >> accessing simple slots, you should notice a difference. > > (I'm not sure what you mean by a 'simple slot'. I mean a slot defined by __slots__ = slot1, slot2, slot3, ..., without descriptors or specific __getattribute__ c

Re: Accessing __slots__ from C

2008-09-12 Thread Chris
Hrvoje Niksic xemacs.org> writes: ... > Chris users.sourceforge.net> writes: > > >> PyObject_GetAttrString is convenient, but it creates a Python string > >> only so it can intern it (and in most cases throw away the freshly > >> created version). For maximum efficiency, pre-create the string >

Re: Accessing __slots__ from C

2008-09-12 Thread Chris
Carl Banks gmail.com> writes: ... > You can determine the offset the of the slot in the object structure > by > querying the member descriptor of the type object. That sounds like just the kind of thing we were looking for - thanks! > descr = GetAttrString(cls,"varname"); > offset = descr->d_mem

Re: Accessing __slots__ from C

2008-09-12 Thread Hrvoje Niksic
Chris <[EMAIL PROTECTED]> writes: >> PyObject_GetAttrString is convenient, but it creates a Python string >> only so it can intern it (and in most cases throw away the freshly >> created version). For maximum efficiency, pre-create the string >> object using PyString_InternFromString, and use tha

Re: Accessing __slots__ from C

2008-09-11 Thread Christian Heimes
Chris wrote: Ok, thanks for the confirmation. We'd been hoping to avoid creating such a struct... Don't worry, a C extension with its own struct isn't hard to write. Your C code can access the member variables w/o using any Python API. You'll get the full speed of C. :] Christian -- http:/

Re: Accessing __slots__ from C

2008-09-11 Thread Carl Banks
On Sep 10, 7:41 am, Chris <[EMAIL PROTECTED]> wrote: > Hi, > > I'd like to be able to access an attribute of a particular Python > object as fast as possible from some C code. > > I wondered if using __slots__ to store the attribute would allow me to > do this in a faster way. > > The reason I'd li

Re: Accessing __slots__ from C

2008-09-11 Thread Chris
Hrvoje Niksic xemacs.org> writes: ... > [ You can use the capi-sig for questions like this; see > http://mail.python.org/mailman/listinfo/capi-sig ] Thanks, I had no idea about that. > PyObject_GetAttrString is convenient, but it creates a Python string > only so it can intern it (and in most

Re: Accessing __slots__ from C

2008-09-11 Thread Chris
Christian Heimes cheimes.de> writes: ... > You can use slots to increase the performance but it doesn't work > like you think. If you need it *really* fast than write a C > Extension, store the data in a C struct and access the data via > PyMemberDef. Ok, thanks for the confirmation. We'd been ho

Re: Accessing __slots__ from C

2008-09-11 Thread Hrvoje Niksic
[ You can use the capi-sig for questions like this; see http://mail.python.org/mailman/listinfo/capi-sig ] Chris <[EMAIL PROTECTED]> writes: > I'd like to be able to access an attribute of a particular Python > object as fast as possible from some C code. > > I wondered if using __slots__ to sto

Re: Accessing __slots__ from C

2008-09-10 Thread Christian Heimes
Chris wrote: Hi, I'd like to be able to access an attribute of a particular Python object as fast as possible from some C code. I wondered if using __slots__ to store the attribute would allow me to do this in a faster way. The reason I'd like to do this is because I need to access the attribu