Opened 13 years ago

Last modified 12 years ago

#4125 new Patches

Boost.Python should use macros to access members of PyMethodObject

Reported by: Amaury Forgeot d'Arc <amauryfa@…> Owned by: Dave Abrahams
Milestone: Boost 1.43.0 Component: python USE GITHUB
Version: Boost 1.42.0 Severity: Problem
Keywords: Cc:

Description

In libs/python/src/wrapper.cpp, the members of PyMethodObject are accessed directly:

  ((PyMethodObject*)m.get())->im_self
  ((PyMethodObject*)m.get())->im_func

These accesses are not documented in the python API. I suggest to use the following macros instead, which have been existing since python 1.6 at least:

  PyMethod_GET_SELF(m.get())
  PyMethod_GET_FUNCTION(m.get())

When using CPython, these macros expand to exactly the same code.

The goal is to allow other implementations of python, like PyPy, to provide alternate compatible implementation of these macros, and thus be able to load modules compiled with Boost.Python.

Attachments (2)

4125-use-macros-instead-of-direct-access.patch (757 bytes ) - added by Matthew Bradbury <matt-bradbury@…> 12 years ago.
4125-use-macros-instead-of-direct-access.2.patch (757 bytes ) - added by Matthew Bradbury <matt-bradbury@…> 12 years ago.

Download all attachments as: .zip

Change History (3)

by Matthew Bradbury <matt-bradbury@…>, 12 years ago

by Matthew Bradbury <matt-bradbury@…>, 12 years ago

comment:1 by Matthew Bradbury <matt-bradbury@…>, 12 years ago

Type: BugsPatches
Note: See TracTickets for help on using tickets.