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


Groups > comp.lang.python > #52442

Re: Calling Python macro from ctypes

From Stefan Behnel <stefan_ml@behnel.de>
Subject Re: Calling Python macro from ctypes
Date 2013-08-13 10:11 +0200
References <5208b297$0$29885$c3e8da3$5496439d@news.astraweb.com> <mailman.495.1376307727.1251.python-list@python.org> <5209d161$0$29885$c3e8da3$5496439d@news.astraweb.com>
Newsgroups comp.lang.python
Message-ID <mailman.521.1376381506.1251.python-list@python.org> (permalink)

Show all headers | View raw


Steven D'Aprano, 13.08.2013 08:25:
> On Mon, 12 Aug 2013 13:42:14 +0200, Peter Otten wrote:
>> Steven D'Aprano wrote:
>>
>>> Is it possible to call a Python macro from ctypes? For example, Python
>>> 3.3 introduces some new macros for querying the internal representation
>>> of strings:
>>>
>>> http://www.python.org/dev/peps/pep-0393/#new-api
> [...]
> 
>> That's not possible. It may look like a function, but a preprocessor
>> replaces the C macro in the C source before compilation.
> 
> That's what I feared.
> 
> In that case, how would I use ctypes to access the underlying fields in 
> the new string implementation?

I'd personally use Cython (no surprise here), but in order to use something
like ctypes, which works at the ABI level, not the API level, and doesn't
use a C compiler to get things properly configured for the local platform,
you'd have to manually define the actual PyObject struct in order to access
its fields directly.

The macros are there to give you source code level portability for that,
but if you start defining the struct layout statically, you're pretty much
on your own when it comes to stuff like different CPython versions, debug
builds, etc.

Could you describe your use case a little deeper? Maybe there's a better
way all together to do what you want.

Stefan

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


Thread

Calling Python macro from ctypes Steven D'Aprano <steve@pearwood.info> - 2013-08-12 10:01 +0000
  Re: Calling Python macro from ctypes Peter Otten <__peter__@web.de> - 2013-08-12 13:42 +0200
    Re: Calling Python macro from ctypes Steven D'Aprano <steve@pearwood.info> - 2013-08-13 06:25 +0000
      Re: Calling Python macro from ctypes Stefan Behnel <stefan_ml@behnel.de> - 2013-08-13 10:11 +0200
        Re: Calling Python macro from ctypes Steven D'Aprano <steve@pearwood.info> - 2013-08-13 09:13 +0000
      Re: Calling Python macro from ctypes Peter Otten <__peter__@web.de> - 2013-08-13 12:25 +0200
  Re: Calling Python macro from ctypes Dave Angel <davea@davea.name> - 2013-08-12 17:11 +0000

csiph-web