Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: 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; 'python.': 0.04; 'subject:module': 0.04; 'attribute': 0.07; 'something,': 0.07; 'const': 0.09; 'content-type:multipart/signed': 0.09; 'filename:fname piece:signature': 0.09; 'pointers': 0.09; 'unsigned': 0.09; 'this:': 0.15; '*c*': 0.16; 'assertion': 0.16; 'build.': 0.16; 'content-type:application/pgp-signature': 0.16; 'dirname': 0.16; 'filename:fname piece:asc': 0.16; 'filename:fname:signature.asc': 0.16; 'pyobject': 0.16; 'pyobject*': 0.16; 'self,': 0.16; 'subject:question': 0.16; 'wrap': 0.18; 'extension': 0.21; 'calls.': 0.23; 'way?': 0.23; 'hopefully': 0.24; 'static': 0.24; 'module': 0.26; 'stuff': 0.26; "i'm": 0.27; 'earlier': 0.28; 'pass': 0.28; 'module.': 0.28; 'class': 0.29; '(and': 0.29; '(so': 0.30; 'args)': 0.30; 'null;': 0.30; 'pretty': 0.30; "i've": 0.31; 'skip:( 20': 0.31; 'idea': 0.32; 'header:User-Agent:1': 0.33; 'to:addr:python-list': 0.33; 'calling': 0.34; 'something': 0.35; 'but': 0.37; 'received:128': 0.37; 'received:192': 0.38; 'doing': 0.39; 'missing': 0.39; 'might': 0.40; 'to:addr:python.org': 0.40; 'got': 0.40; 'custom': 0.61; 'here': 0.64; 'bridge': 0.80; 'canonical': 0.91 Date: Sun, 15 Jan 2012 01:37:22 -0600 From: Evan Driscoll User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0) Gecko/20111222 Thunderbird/9.0.1 MIME-Version: 1.0 To: python-list@python.org Subject: Extension module question X-Enigmail-Version: 1.3.4 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig92B47A97224A2B6C2FC03161" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 63 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1326613079 news.xs4all.nl 6979 [2001:888:2000:d::a6]:42731 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:18999 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig92B47A97224A2B6C2FC03161 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable As I hinted at in an earlier email, I'm working on a module which will allow calling readdir() (and FindFirstFile on Windows, hopefully pretty uniformly) from Python. The responses I got convinced me that it was a good idea to write a C-to-Python bridge as an extension module. What I'm not sure about is how to store pointers to *C* stuff between calls. In particular, opendir() returns a DIR* which you then need to pass to calls to readdir() in the future (and closedir()). So I've got this: static PyObject* py_opendir(PyObject* self, PyObject* args) { const char* dirname =3D 0; if (!PyArg_ParseTuple(args, "s", &dirname)) { return NULL; } // Eventually want to Py_BEGIN_ALLOW_THREADS here DIR* directory =3D opendir(dirname); =20 PyObject out =3D PyBuildValue( ???, directory ); return out; } but I don't know what to build. (I might want to wrap it in a custom handle class or something, but I still need to know how to build the value I eventually store in an attribute of that class.) My best idea is to use an unsigned long (so "k") and add a static assertion that sizeof(long)=3D=3Dsizeof(void*). Is this the canonical way= of doing something like this, or am I missing a better way? Evan --------------enig92B47A97224A2B6C2FC03161 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAgAGBQJPEoI5AAoJEAOzoR8eZTzguAoH/2KUxzE5mruwRrZOelKRjL7e 1HXXx9NP7PwhSzzSBwcBsgrgwyRexAOHRS9VPwrVghYv1m/WKsbBto71bFf+Y/5I 5+DU1m58qhYBssqGSH75HG7XzetF7zy/HHoMcjO+v7D50YQxsBBhNzw3Hb8Y8Bfy MZYbjiiVwCWiFjL9K8QhfiDxnnV1oXpv19u7Az4W5M//+iYWD7WR6swnz4I+DGH/ zO/ITIR0O0GWdCPw7/HGF4Hy3u8qtX6sL6Al5OCGos/41Om51mK/Uj7APE89aBBL IKmoJiGD6saGMR5tasA5IL7w+3Bo9CHg+KXa2HCNNzLxO7DfBPRpo3uBm9amGSg= =Y/HB -----END PGP SIGNATURE----- --------------enig92B47A97224A2B6C2FC03161--