[Py++] Don't transform char* to c_char_p
Hi Roman, I know you are busy, so I have already monkeypatched pyplusplus locally for my purposes. But maybe you are interested to add this feature add some point in the future: 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). Best, -Nikolaus -- »Time flies like an arrow, fruit flies like a Banana.« PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C
On Wed, Dec 23, 2009 at 9:21 PM, Nikolaus Rath <Nikolaus@rath.org> wrote:
Hi Roman,
Good evening.
I know you are busy, so I have already monkeypatched pyplusplus locally for my purposes. But maybe you are interested to add this feature add some point in the future:
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. Thank you. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/
Roman Yakovenko <roman.yakovenko@gmail.com> writes:
On Wed, Dec 23, 2009 at 9:21 PM, Nikolaus Rath <Nikolaus@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
On Thu, Dec 24, 2009 at 1:55 AM, Nikolaus Rath <Nikolaus@rath.org> wrote:
I think POINTER(c_char) should indeed be the default because it is the safer choice.
Unfortunately, I don't agree with you. It is a safer choice - right, but it should not be the default.
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.
I added new functionality, which allows to generate POINTER( c_char ) instead of c_char_p. The relevant commit are: * http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1786&view=rev * http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1790&view=rev The functionality should be used like: mb = ctypes_module_builder_t( ... ) mb.treat_char_ptr_as_binary_data = True HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/
Roman Yakovenko <roman.yakovenko@gmail.com> writes:
On Thu, Dec 24, 2009 at 1:55 AM, Nikolaus Rath <Nikolaus@rath.org> wrote:
I think POINTER(c_char) should indeed be the default because it is the safer choice.
Unfortunately, I don't agree with you. It is a safer choice - right, but it should not be the default.
Don't worry, I don't care what the default is as long as I can change it :-).
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.
I added new functionality, which allows to generate POINTER( c_char ) instead of c_char_p.
Works like a charm, thanks a lot! Best, -Nikolaus -- »Time flies like an arrow, fruit flies like a Banana.« PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C
participants (2)
-
Nikolaus Rath -
Roman Yakovenko