mirror of
https://github.com/boostorg/python.git
synced 2026-01-19 16:32:16 +00:00
Respect alignment of by-value storage.
This commit is contained in:
@@ -132,6 +132,7 @@ bpl-test crossmod_exception
|
||||
|
||||
[ bpl-test object ]
|
||||
[ bpl-test class ]
|
||||
[ bpl-test aligned_class ]
|
||||
[ bpl-test list ]
|
||||
[ bpl-test long ]
|
||||
[ bpl-test dict ]
|
||||
|
||||
33
test/aligned_class.cpp
Normal file
33
test/aligned_class.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
#include <boost/python/module.hpp>
|
||||
#include <boost/python/def.hpp>
|
||||
#include <boost/python/object.hpp>
|
||||
#include <boost/python/class.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
|
||||
using namespace boost::python;
|
||||
|
||||
struct BOOST_ALIGNMENT(32) X
|
||||
{
|
||||
int x;
|
||||
BOOST_ALIGNMENT(32) float f;
|
||||
X(int n, float _f) : x(n), f(_f)
|
||||
{
|
||||
BOOST_ASSERT((reinterpret_cast<uintptr_t>(&f) % 32) == 0);
|
||||
}
|
||||
};
|
||||
|
||||
int x_function(X& x) { return x.x;}
|
||||
float f_function(X& x) { return x.f;}
|
||||
|
||||
BOOST_PYTHON_MODULE(aligned_class_ext)
|
||||
{
|
||||
class_<X>("X", init<int, float>());
|
||||
def("x_function", x_function);
|
||||
def("f_function", f_function);
|
||||
}
|
||||
|
||||
#include "module_tail.cpp"
|
||||
44
test/aligned_class.py
Executable file
44
test/aligned_class.py
Executable file
@@ -0,0 +1,44 @@
|
||||
# Distributed under the Boost
|
||||
# Software License, Version 1.0. (See accompanying
|
||||
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
'''
|
||||
>>> from aligned_class_ext import *
|
||||
|
||||
Ensure sanity:
|
||||
|
||||
>>> x = X(42, 16)
|
||||
>>> x_function(x)
|
||||
42
|
||||
>>> f_function(x)
|
||||
16.0
|
||||
|
||||
Demonstrate extraction in the presence of metaclass changes:
|
||||
|
||||
>>> class MetaX(X.__class__):
|
||||
... def __new__(cls, *args):
|
||||
... return super(MetaX, cls).__new__(cls, *args)
|
||||
>>> class XPlusMetatype(X):
|
||||
... __metaclass__ = MetaX
|
||||
>>> x = XPlusMetatype(42, 16)
|
||||
>>> x_function(x)
|
||||
42
|
||||
>>> f_function(x)
|
||||
16.0
|
||||
|
||||
|
||||
'''
|
||||
|
||||
def run(args = None):
|
||||
import sys
|
||||
import doctest
|
||||
|
||||
if args is not None:
|
||||
sys.argv = args
|
||||
return doctest.testmod(sys.modules.get(__name__))
|
||||
|
||||
if __name__ == '__main__':
|
||||
print("running...")
|
||||
import sys
|
||||
status = run()[0]
|
||||
if (status == 0): print("Done.")
|
||||
sys.exit(status)
|
||||
@@ -79,6 +79,8 @@ for t in [('injected',),
|
||||
('callbacks',),
|
||||
('defaults',),
|
||||
('object',),
|
||||
('class',),
|
||||
('aligned_class',),
|
||||
('list',),
|
||||
('long',),
|
||||
('dict',),
|
||||
|
||||
Reference in New Issue
Block a user