Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52412
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Subject | Re: Calling Python macro from ctypes |
| Date | 2013-08-12 13:42 +0200 |
| Organization | None |
| References | <5208b297$0$29885$c3e8da3$5496439d@news.astraweb.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.495.1376307727.1251.python-list@python.org> (permalink) |
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
>
>
> So I try this in 3.3:
>
> py> import ctypes
> py> ctypes.pythonapi.PyUnicode_MAX_CHAR_VALUE
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "/usr/local/lib/python3.3/ctypes/__init__.py", line 366, in
> __getattr__
> func = self.__getitem__(name)
> File "/usr/local/lib/python3.3/ctypes/__init__.py", line 371, in
> __getitem__
> func = self._FuncPtr((name_or_ordinal, self))
> AttributeError: python3.3: undefined symbol: PyUnicode_MAX_CHAR_VALUE
That's not possible. It may look like a function, but a preprocessor
replaces the C macro in the C source before compilation. An example of very
bad usage of macros, just to drive the point home:
$ cat macro.c
#define IF(expr) if (expr) {
#define ENDIF ;}
main()
{
IF(1>0)
printf("It worked\n")
ENDIF
}
And here's what the compiler sees:
$ gcc -E -P macro.c
main()
{
if (1>0) {
printf("It worked\n")
;}
}
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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