Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #102762

Copying void * string to

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From "Martin Phillips" <martinphillips@ladybridge.com>
Newsgroups comp.lang.python
Subject Copying void * string to
Date Wed, 10 Feb 2016 12:07:49 -0000
Lines 43
Message-ID <mailman.11.1455114500.22075.python-list@python.org> (permalink)
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 <martinphillips@ladybridge.com>
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 <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:102762

Show key headers only | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Copying void * string to "Martin Phillips" <martinphillips@ladybridge.com> - 2016-02-10 12:07 +0000

csiph-web