Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #91538
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'modified': 0.05; '#include': 0.07; 'executes': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:module': 0.09; 'python': 0.11; '2.7': 0.13; 'def': 0.14; 'foo;': 0.16; 'from:addr:behnel.de': 0.16; 'from:addr:stefan_ml': 0.16; 'from:name:stefan behnel': 0.16; 'missing?': 0.16; 'readability.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'stefan': 0.18; 'extension': 0.20; 'trying': 0.22; 'void': 0.22; 'module': 0.23; 'slightly': 0.23; "i've": 0.24; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'error': 0.27; "i'm": 0.29; 'initialized': 0.29; 'code:': 0.29; 'function': 0.30; 'that.': 0.30; '[1]': 0.32; 'int': 0.33; 'file': 0.34; 'wrong': 0.35; 'to:addr:python-list': 0.35; 'files,': 0.35; 'problem.': 0.35; 'but': 0.36; 'url:org': 0.36; 'faster': 0.36; "didn't": 0.37; 'subject:: ': 0.37; "won't": 0.38; 'version': 0.38; 'received:org': 0.38; 'to:addr:python.org': 0.39; 'subject:with': 0.40; 'received:de': 0.40; 'called': 0.40; 'your': 0.60; "you'll": 0.61 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Stefan Behnel <stefan_ml@behnel.de> |
| Subject | Re: Building an extension module with SWIG |
| Date | Sat, 30 May 2015 21:05:39 +0200 |
| References | <mkco9p$gf8$1@speranza.aioe.org> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | ipservice-092-211-042-169.092.211.pools.vodafone-ip.de |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 |
| In-Reply-To | <mkco9p$gf8$1@speranza.aioe.org> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| 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.229.1433012748.5151.python-list@python.org> (permalink) |
| Lines | 53 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1433012748 news.xs4all.nl 2960 [2001:888:2000:d::a6]:39279 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:91538 |
Show key headers only | View raw
garyr schrieb am 30.05.2015 um 18:22:
> I'm trying to create an extension module using SWIG. I've
> succeeded in generating a pyd file but when I import the module I get the
> error message: "SystemError: dynamic module not initialized properly." I
> added an initfoo() function but that didn't solve the problem. Below are the
> various files, a slightly modified version of a SWIG exmaple.
> I'm using Python 2.7
>
> What am I missing?
>
> //foo.c:
> #include "foo.h"
> double Foo;
> void initfoo()
> {
> Foo = 3.0;
> }
This is wrong and you also won't need that.
> int gcd(int x, int y) {
> int g;
> g = y;
> while (x > 0) {
> g = x;
> x = y % x;
> y = g;
> }
> return g;
> }
> [...]
Just in case you're not bound to SWIG yet, here's a Cython [1] version of
your code:
# put this in a file called "foo.pyx"
def gcd(int x, int y):
while x > 0:
y, x = x, y % x
return y
Compile it ("cythonize -b foo.pyx") and you'll get an extension module that
executes faster than what SWIG would give you and keeps everything in one
file to improve readability.
Stefan
[1] http://cython.org/
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Building an extension module with SWIG "garyr" <garyr@fidalgo.net> - 2015-05-30 09:22 -0700
Re: Building an extension module with SWIG Stefan Behnel <stefan_ml@behnel.de> - 2015-05-30 21:05 +0200
Re: Building an extension module with SWIG "garyr" <garyr@fidalgo.net> - 2015-05-30 13:48 -0700
Re: Building an extension module with SWIG "garyr" <garyr@fidalgo.net> - 2015-05-30 15:55 -0700
Re: Building an extension module with SWIG Stefan Behnel <stefan_ml@behnel.de> - 2015-05-31 07:28 +0200
Re: Building an extension module with SWIG "garyr" <garyr@fidalgo.net> - 2015-05-30 18:54 -0700
csiph-web