[pywin32-bugs] [ pywin32-Bugs-2016768 ] issues with 1-based indexed collections
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: SourceForge.net <no...@so...> - 2008-07-12 18:54:53
|
Bugs item #2016768, was opened at 2008-07-13 04:54 Message generated for change (Comment added) made by mhammond You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=551954&aid=2016768&group_id=78018 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: com Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Mark Hammond (mhammond) Assigned to: Nobody/Anonymous (nobody) Summary: issues with 1-based indexed collections Initial Comment: A report from a thread entitled "[python-win32] problem with win32com and one-based indexed collections" in July 2007. Full details in next comment. ---------------------------------------------------------------------- >Comment By: Mark Hammond (mhammond) Date: 2008-07-13 04:55 Message: Logged In: YES user_id=14198 Originator: YES >From initial bug report on the python-win32 mailing list: I have run across what I believe may be a shortcoming with win32com when trying to call functions that expect one-based indexed arrays as input. The function I'm trying to invoke which demonstrates the problem is defined in my documentation as follows: HRESULT SyncRead( [in] SHORT Source, [in] LONG NumItems, [in] SAFEARRAY(LONG) * ServerHandles, [out] SAFEARRAY(VARIANT) * Values, [out] SAFEARRAY(LONG) * Errors, [out,optional] VARIANT * Qualities, [out,optional] VARIANT * TimeStamps); In Python, this looks like: server_handles = [16384,16385] num_items = 2 values, errors, qualities, timestamps = groups.SyncRead(2, num_items, server_handles) The num_items parameter is supposed to tell the function the total number sever_handles being passed in. Anyway, the above code always throws a com exception and fails. I am assuming this issue is due to the SyncRead function using one-based indexing for its array collection. However, if I append an extra "dummy" argument to the beginning of the server_handles list, it will always work. server_handles = [0, 16384,16385] num_items = 2 values, errors, qualities, timestamps = groups.SyncRead(2, num_items, server_handles) The above example is a very poor solution since it appears to produce a slow memory leak in my application. Every 10 to 12 times the SyncRead call is invoked using the exact same server_handles, memory consumption increases by 4kb. This memory leak problem does not happen when called from VB. As an amusing test, I tried setting the variables passed to the function as follows: server_handles = [0, 16384, 16385, 0, 0, 0, 0, 0, 0, 0, 0, 0] num_items = 2 This makes an even bigger memory leak, leading me to believe any extra elements passed in the list beyond the num_items passed will always be allocated but never freed. Does Mark or anyone else know how to correctly pass a collection to a COM call using one-based indexing that won't cause a mem leak? I couldn't find any mention of this issue in the Python Win32 book other than an Excel example which didn't seem to apply. -BB ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=551954&aid=2016768&group_id=78018 |