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


Groups > comp.lang.python > #80201

Re: Python extension using a C library with one 'hello' function

Return-Path <jason.swails@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'causing': 0.04; 'subject:Python': 0.06; 'incompatible': 0.07; 'received:198': 0.07; "subject:' ": 0.07; 'setup.py': 0.09; 'subject:using': 0.09; 'python': 0.11; 'changes': 0.15; 'build_ext': 0.16; 'skip:/ 60': 0.16; 'subject:library': 0.16; 'wrote:': 0.18; 'module': 0.19; '>>>': 0.22; 'import': 0.22; 'aug': 0.22; 'creating': 0.23; 'pointer': 0.24; 'rid': 0.24; 'fine': 0.24; "i've": 0.25; 'extension': 0.26; 'header:In-Reply-To:1': 0.27; 'linux': 0.33; 'running': 0.33; 'computer.': 0.33; 'skip:b 30': 0.33; 'maybe': 0.34; 'subject:with': 0.35; 'received:google.com': 0.35; 'building': 0.35; 'subject:one': 0.36; 'operating': 0.37; 'skip:- 20': 0.37; 'message-id:@gmail.com': 0.38; 'jason': 0.38; 'to:addr :python-list': 0.38; 'to:addr:python.org': 0.39; 'more': 0.64; 'world': 0.66; 'subject:hello': 0.83; '2014,': 0.84; 'improvement': 0.84; 'on?': 0.91; 'skip:\xe2 30': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:subject:from:to:date:in-reply-to:references:content-type :mime-version:content-transfer-encoding; bh=YpbAX7kiphLa2n12dkWISxSYpmqGEdrz5Gm+pd0G9JM=; b=swSD8wXjULVIptvaWTEq5n/3LRwsESdskwIzLsjxIZfZQCthLucXgDgwq30LC+PPO0 0Ro5cx2xbrbqx3VSTK5IUTQCRVbo+BiXfEEfBnBQlBjMyvFk1CtHZu+ucqcc05SFAKug cC1MkG2QxMYJ1nNOzjKlunRxF1qgoF1gJVg0sjDa74HPazzGAjIrwjOForkf9LOdMgKG +4NvoCsm+Nhos2bkLJemxSpgT5XznAs3LQLQDTKx29aoehIlTsmliJI4vq+G0KomF3TY j+Iju2YIKYOKVyhahGvWNxuBT1tuJIpA5QwvTKsDNRYVOgwOa8D3B9Xa1DazbH3wdF00 3PEA==
X-Received by 10.224.165.77 with SMTP id h13mr35505060qay.0.1415118538238; Tue, 04 Nov 2014 08:28:58 -0800 (PST)
Subject Re: Python extension using a C library with one 'hello' function
From Jason Swails <jason.swails@gmail.com>
To python-list@python.org
Date Tue, 04 Nov 2014 11:28:57 -0500
In-Reply-To <m3au1u$u36$1@dont-email.me>
References <m3ab5o$kuo$1@dont-email.me> <mailman.15452.1415115002.18130.python-list@python.org> <m3au1u$u36$1@dont-email.me>
Content-Type text/plain; charset="UTF-8"
X-Mailer Evolution 3.12.4
Mime-Version 1.0
Content-Transfer-Encoding 8bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.15456.1415118546.18130.python-list@python.org> (permalink)
Lines 40
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1415118546 news.xs4all.nl 2935 [2001:888:2000:d::a6]:36125
X-Complaints-To abuse@xs4all.nl
Path csiph.com!usenet.pasdenom.info!bete-des-vosges.org!feed.ac-versailles.fr!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Xref csiph.com comp.lang.python:80201

Show key headers only | View raw


On Tue, 2014-11-04 at 21:45 +0630, Veek M wrote:
> Jason Swails wrote:
> 
> > I've submitted a PR to your github repo showing you the changes
> > necessary to get your module working on my computer.
> 
> Segfaults :p which is an improvement :)

What operating system are you running this on?  It works fine for me on
Linux:

bash$ ls
hello.c  hello.h  hello.py  pyhello.c  setup.py
bash$ python3.4 setup.py build_ext --inplace
running build_ext
building '_hello' extension
creating build
creating build/temp.linux-x86_64-3.4
x86_64-pc-linux-gnu-gcc -pthread -fPIC -I/usr/include/python3.4 -c pyhello.c -o build/temp.linux-x86_64-3.4/pyhello.o
pyhello.c:15:5: warning: initialization from incompatible pointer type [enabled by default]
     {"hello", py_hello, METH_NOARGS, py_hello_doc},
     ^
pyhello.c:15:5: warning: (near initialization for ‘hellomethods[0].ml_meth’) [enabled by default]
x86_64-pc-linux-gnu-gcc -pthread -fPIC -I/usr/include/python3.4 -c hello.c -o build/temp.linux-x86_64-3.4/hello.o
x86_64-pc-linux-gnu-gcc -pthread -shared build/temp.linux-x86_64-3.4/pyhello.o build/temp.linux-x86_64-3.4/hello.o -L/usr/lib64 -lpython3.4 -o /home/swails/BugHunter/CAPI/Python/junk/hello/_hello.cpython-34.so
bash$ python3.4
Python 3.4.1 (default, Aug 24 2014, 10:04:41) 
[GCC 4.7.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import hello
>>> hello.hello()
hello world
0

You can get rid of the warning by casting py_hello to (PyCFunction)...
maybe that's causing your segfault?

All the best,
Jason

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


Thread

Python extension using a C library with one 'hello' function Veek M <vek.m1234@gmail.com> - 2014-11-04 16:22 +0630
  Re: Python extension using a C library with one 'hello' function Chris Angelico <rosuav@gmail.com> - 2014-11-05 01:57 +1100
  Re: Python extension using a C library with one 'hello' function Søren <sd@syntonetic.com> - 2014-11-04 13:11 +0100
    Re: Python extension using a C library with one 'hello' function Veek M <vek.m1234@gmail.com> - 2014-11-04 21:46 +0630
  Re: Python extension using a C library with one 'hello' function Jason Swails <jason.swails@gmail.com> - 2014-11-04 10:30 -0500
    Re: Python extension using a C library with one 'hello' function Veek M <vek.m1234@gmail.com> - 2014-11-04 21:45 +0630
      Re: Python extension using a C library with one 'hello' function Jason Swails <jason.swails@gmail.com> - 2014-11-04 11:28 -0500
        Re: Python extension using a C library with one 'hello' function Veek M <vek.m1234@gmail.com> - 2014-11-04 22:13 +0630
        Re: Python extension using a C library with one 'hello' function Veek M <vek.m1234@gmail.com> - 2014-11-04 22:39 +0630
          Re: Python extension using a C library with one 'hello' function Jason Swails <jason.swails@gmail.com> - 2014-11-04 12:28 -0500
    Re: Python extension using a C library with one 'hello' function Veek M <vek.m1234@gmail.com> - 2014-11-04 23:03 +0630
      Re: Python extension using a C library with one 'hello' function Jason Swails <jason.swails@gmail.com> - 2014-11-04 13:28 -0500

csiph-web