Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: "Martin Phillips" Newsgroups: comp.lang.python Subject: Copying void * string to Date: Wed, 10 Feb 2016 12:07:49 -0000 Lines: 43 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de XQVY+PH3zwXsN+4bMBUWrgmr/DGPjkOcxcWntniIaZOQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'memory.': 0.05; 'dynamically': 0.07; 'strings.': 0.07; 'terminated': 0.07; 'wrapper': 0.07; 'func': 0.09; 'pointers': 0.09; 'subject:string': 0.09; 'python': 0.10; 'def': 0.13; 'func.restype': 0.16; 'item)': 0.16; 'item):': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject: * ': 0.16; 'variable.': 0.16; 'string': 0.17; 'pointer': 0.18; 'string,': 0.18; 'variable': 0.18; 'library': 0.20; 'martin': 0.22; 'advance.': 0.23; 'sets': 0.23; 'allocated': 0.27; 'function': 0.28; 'code': 0.30; 'problem': 0.33; 'null': 0.33; 'library.': 0.35; 'url:org': 0.36; 'to:addr:python-list': 0.36; 'thanks': 0.37; 'url:rec-html40': 0.37; 'charset:us-ascii': 0.37; 'several': 0.38; 'test': 0.39; 'unable': 0.39; 'to:addr:python.org': 0.40; 'url:schemas': 0.40; 'url:office': 0.40; 'received:109': 0.75; 'received:81.31': 0.84; 'searches.': 0.84 X-Mailer: Microsoft Outlook 14.0 Thread-Index: AdFj+nA0np+cBrAhSjunRGxD6H+U+g== Content-Language: en-gb X-Mailman-Approved-At: Wed, 10 Feb 2016 09:28:19 -0500 X-Content-Filtered-By: Mailman/MimeDel 2.1.21rc2 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21rc2 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:102762 I am writing a Python wrapper to go around a C library. I have encountered a problem that I have been unable to resolve with countless web searches. Several functions in the C library return pointers to dynamically allocated w_char null terminated strings. I need to copy the string to a Python variable and call an existing library function that will free the dynamically allocate memory. My test code for this is def Test(fno, item): func = mylib. MyFunc func.restype = ct.c_void_p s = func(fno, item) result = s mylib.free(s) return result The problem is with the line that sets the result variable. I need this to make a copy of the dynamically allocated string, not the pointer to it. Thanks in advance. Martin