[comtypes-users] __del__ called more than once on a comtypes COM POINTER object

2009-09-12 Thread James Teh
Hi Thomas,

In NVDA, we sometimes see access violation and vtable errors in __del__ 
on comtypes COM POINTER objects and intermittant crashes. I eventually 
figured that this might relate to Release() being called too many times. 
I then discovered that __del__ on these objects is sometimes called more 
than once. (We never call __del__ ourselves, so this is happening 
elsewhere.) As I understand it, Python should only ever call it once.

I discovered this using the following rather nasty monkey patch before 
any COM objects are used:

from comtypes import _compointer_base
_cpbDel = _compointer_base.__del__
def newCpbDel(self):
assert not hasattr(self, "_deleted"), "compointer already deleted"
_cpbDel(self)
self._deleted = True
newCpbDel.__name__ = "__del__"
_compointer_base.__del__ = newCpbDel
del _compointer_base

This assertion does get raised. While I have come up with an exact set 
of steps to reproduce with NVDA and Firefox, I haven't yet managed to 
narrow it down to a programmatic test case due to the sheer number of 
interactions and code paths. I can tell you that we use QueryInterface 
quite a bit if that helps in any way.

Can you think of any reason this might be happening? Is there any code 
in the ctypes POINTER type that calls __del__?

Thanks.

Jamie

-- 
James Teh
Email/MSN Messenger/Jabber: ja...@jantrid.net
Web site: http://www.jantrid.net/


--
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
___
comtypes-users mailing list
comtypes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/comtypes-users


Re: [comtypes-users] __del__ called more than once on a comtypes COM POINTER object

2009-09-16 Thread Thomas Heller
James Teh schrieb:
> Hi Thomas,
> 
> In NVDA, we sometimes see access violation and vtable errors in __del__ 
> on comtypes COM POINTER objects and intermittant crashes. I eventually 
> figured that this might relate to Release() being called too many times. 
> I then discovered that __del__ on these objects is sometimes called more 
> than once. (We never call __del__ ourselves, so this is happening 
> elsewhere.) As I understand it, Python should only ever call it once.

Well, __del__ could revive the object, but comtypes doesn't do this afaik.

> I discovered this using the following rather nasty monkey patch before 
> any COM objects are used:
> 
> from comtypes import _compointer_base
> _cpbDel = _compointer_base.__del__
> def newCpbDel(self):
>   assert not hasattr(self, "_deleted"), "compointer already deleted"
>   _cpbDel(self)
>   self._deleted = True
> newCpbDel.__name__ = "__del__"
> _compointer_base.__del__ = newCpbDel
> del _compointer_base
> 
> This assertion does get raised. While I have come up with an exact set 
> of steps to reproduce with NVDA and Firefox, I haven't yet managed to 
> narrow it down to a programmatic test case due to the sheer number of 
> interactions and code paths. I can tell you that we use QueryInterface 
> quite a bit if that helps in any way.
> 
> Can you think of any reason this might be happening? Is there any code 
> in the ctypes POINTER type that calls __del__?

No, and no.  It would be great if you can provide some code that
has this problem.

-- 
Thanks,
Thomas


--
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
___
comtypes-users mailing list
comtypes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/comtypes-users