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


Groups > comp.lang.python > #102762 > unrolled thread

Copying void * string to

Started by"Martin Phillips" <martinphillips@ladybridge.com>
First post2016-02-10 12:07 +0000
Last post2016-02-10 12:07 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

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

#102762 — Copying void * string to

From"Martin Phillips" <martinphillips@ladybridge.com>
Date2016-02-10 12:07 +0000
SubjectCopying void * string to
Message-ID<mailman.11.1455114500.22075.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web