[C++-sig] [Py++] Don't transform char* to c_char_p

Nikolaus Rath Nikolaus at rath.org
Thu Dec 24 00:55:25 CET 2009


Roman Yakovenko <roman.yakovenko at gmail.com> writes:
> On Wed, Dec 23, 2009 at 9:21 PM, Nikolaus Rath <Nikolaus at rath.org> wrote:
>> It would be great if there was a way to tell Py++ that it should not
>> represent the C char * type to the ctypes c_char_p, because the later is
>> supposed to be used only for \0 terminated strings. A general char*
>> should be translated to POINTER(c_char).
>
> Yes I do. I saw your post and the issue(
> http://bugs.python.org/issue7569 ). I think it is a good think.
>
> I have only one problem: in Py++( pygccxml) types are "singletones".
> What is the best interface for the user to customize such thing?
> Should Py++ generate POINTER(c_char) in all cases by default?
>
> I would like to know your opinion.

I think POINTER(c_char) should indeed be the default because it is the
safer choice.

Maybe a parameter a new keyword parameter in the ctypes_module_builder_t
constructor would be a good way to customize this.

On the other hand, the only situation were the user can actually notice
this change would be in a Python callback function that's called from C,
because it will receive a ctypes object rather than a Python string. But
a string can still easily be obtained with string_at (while the reverse
is not possible). So maybe it is also possible to always generate
POINTER(c_char) without the option to change this to c_char_p.


Best,

   -Nikolaus

-- 
 »Time flies like an arrow, fruit flies like a Banana.«

  PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6  02CF A9AD B7F8 AE4E 425C



More information about the Cplusplus-sig mailing list