Re: ctypes & allocated memory

2020-06-07 Thread Miki Tebeka
Hi, > But the problem is that by specifying the type as ctypes.c_char_p, > ctypes will hide that pointer from you and return a Python object > instead. I'm not sure how ctypes is doing it under the hood, but I > suspect ctypes is doing it's own strdup of the string on conversion, and > managing

Re: ctypes & allocated memory

2020-06-07 Thread Michael Torrie
On 6/7/20 2:25 PM, Barry wrote: >> Does ctypes, when using restype, frees allocated memory? >> >> For example, will the memory allocated by "strdup" be freed after the "del" >> statement? If not, how can I free it? > > See https://linux.die.net/man/3/strdup that tells you to use free() to delete

Re: ctypes & allocated memory

2020-06-07 Thread Barry
> On 7 Jun 2020, at 14:23, Miki Tebeka wrote: > > Hi, > > Does ctypes, when using restype, frees allocated memory? > > For example, will the memory allocated by "strdup" be freed after the "del" > statement? If not, how can I free it? See https://linux.die.net/man/3/strdup that tells you

Re: ctypes & allocated memory

2020-06-07 Thread Michael Torrie
On 6/7/20 7:15 AM, Miki Tebeka wrote: > Hi, > > Does ctypes, when using restype, frees allocated memory? > > For example, will the memory allocated by "strdup" be freed after the "del" > statement? If not, how can I free it? I don't think so. I did a quick google search and came up with this

Re: ctypes & allocated memory

2020-06-07 Thread Miki Tebeka
> Does ctypes, when using restype, frees allocated memory? > > For example, will the memory allocated by "strdup" be freed after the "del" > statement? If not, how can I free it? I've tried the following program and I'm more confused now :) Can anyone explain the output? --- import ctypes

ctypes & allocated memory

2020-06-07 Thread Miki Tebeka
Hi, Does ctypes, when using restype, frees allocated memory? For example, will the memory allocated by "strdup" be freed after the "del" statement? If not, how can I free it? --- import ctypes libc = ctypes.cdll.LoadLibrary('libc.so.6') strdup = libc.strdup strdup.argtypes = [ctypes.c_char_p]