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

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python@mrabarnett.plus.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; '"c"': 0.07; '#include': 0.07; 'main()': 0.07; 'python': 0.09; '(char': 0.09; 'extern': 0.09; 'subject:ctypes': 0.09; 'library': 0.15; 'stack': 0.15; '"hello': 0.16; '2.7.3': 0.16; 'dangling': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'uint32_t': 0.16; 'wrote:': 0.17; 'char': 0.17; 'skip:= 10': 0.20; 'ctypes': 0.22; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; 'looks': 0.26; 'right.': 0.27; 'pointer.': 0.29; 'received:192.168.1.3': 0.29; 'array': 0.29; 'becomes': 0.30; 'function': 0.30; 'expect': 0.31; 'allocated': 0.33; 'int': 0.33; 'to:addr:python-list': 0.33; 'wrong': 0.34; 'returning': 0.35; 'doing': 0.35; 'subject:: ': 0.38; 'things': 0.38; 'sure': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'where': 0.40; 'received:192.168': 0.40; 'address': 0.60; 'gave': 0.65; 'header :Reply-To:1': 0.68; 'reply-to:no real name:2**0': 0.72; 'reply- to:addr:python.org': 0.84
X-CM-Score 0.00
X-CNFS-Analysis v=2.0 cv=W6e6pGqk c=1 sm=1 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=DKcI9XZsuF4A:10 a=TIOiKRZ-eEAA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=-tyVo4VwCBAA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=eV1Az30t_BrPassdGbkA:9 a=wPNLvfGTeEIA:10 a=caIXieK2IQyTP5S5:21 a=QsvZBSsdEVuu2nmI:21 a=0nF1XD0wxitMEM03M9B4ZQ==:117
X-AUTH mrabarnett:2500
Date Tue, 28 Aug 2012 22:59:16 +0100
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:14.0) Gecko/20120713 Thunderbird/14.0
MIME-Version 1.0
To python-list@python.org
Subject Re: ctypes - python2.7.3 vs python3.2.3
References <18eb8025-7545-4d10-9e76-2e41deaadb69@googlegroups.com>
In-Reply-To <18eb8025-7545-4d10-9e76-2e41deaadb69@googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
Reply-To python-list@python.org
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3903.1346191160.4697.python-list@python.org> (permalink)
Lines 40
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1346191160 news.xs4all.nl 6887 [2001:888:2000:d::a6]:40624
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:28024

Show key headers only | 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