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


Groups > comp.lang.python > #28024

Re: ctypes - python2.7.3 vs python3.2.3

Date 2012-08-28 22:59 +0100
From MRAB <python@mrabarnett.plus.com>
Subject Re: ctypes - python2.7.3 vs python3.2.3
References <18eb8025-7545-4d10-9e76-2e41deaadb69@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.3903.1346191160.4697.python-list@python.org> (permalink)

Show all headers | View raw


On 28/08/2012 22:35, Rolf wrote:
> ctypes works as I would expect with python2.7.3.
>
> However, when I upgrade to python3.2.3 things don't seem to work right. Look below for details.
>
> I am not sure where I am going wrong.
>
> Shared Library
> ==============
> #include <stdint.h>
> #include <string.h>
>
> extern "C"
> {
>     int main();
>     uint32_t myfunction (char **);
> }
>
> uint32_t myfunction (char ** _mydata)
> {
>     char mydata[16];
>
>     strcpy(mydata, "Hello Dude!");
>
>     *_mydata = mydata;
>
>     return 0;
> }
>
> int main()
> {
>     return 0;
> }
>
[snip]
What you're doing in 'myfunction' looks wrong to start with. It's
returning the address of the local array 'mydata' which allocated on
the stack when the function is entered. When the function is left it's
deallocated, so the address becomes a dangling pointer. That it gave a
reasonable result with Python 2.7.3 is down to pure luck.

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


Thread

ctypes - python2.7.3 vs python3.2.3 Rolf <rolfb@personalized-books.com> - 2012-08-28 14:35 -0700
  Re: ctypes - python2.7.3 vs python3.2.3 John Gordon <gordon@panix.com> - 2012-08-28 21:51 +0000
    Re: ctypes - python2.7.3 vs python3.2.3 Jan Kuiken <jan.kuiken@quicknet.nl> - 2012-08-29 23:25 +0200
      Re: ctypes - python2.7.3 vs python3.2.3 John Gordon <gordon@panix.com> - 2012-09-07 19:04 +0000
  Re: ctypes - python2.7.3 vs python3.2.3 MRAB <python@mrabarnett.plus.com> - 2012-08-28 22:59 +0100

csiph-web