2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-19 04:22:16 +00:00

Merge branch 'develop'

This commit is contained in:
Stefan Seefeld
2017-11-11 08:04:54 -05:00
91 changed files with 457 additions and 86 deletions

View File

@@ -4,7 +4,7 @@ environment:
# /E:ON and /V:ON options are not enabled in the batch script intepreter
# See: http://stackoverflow.com/a/13751649/163740
CMD_IN_ENV: "cmd /E:ON /V:ON /C .\\ci\\run_with_env.cmd"
BOOST_PREFIX: C:\Libraries\boost_1_60_0
BOOST_PREFIX: C:\Libraries\boost_1_63_0
matrix:
@@ -15,7 +15,8 @@ environment:
- PYTHON: "C:\\Python27"
PYTHON_VERSION: "2.7.x" # currently 2.7.9
PYTHON_ARCH: "32"
ARCH: "x86"
MSVC: "14.0"
ARCH: x86
#- PYTHON: "C:\\Python27-x64"
# PYTHON_VERSION: "2.7.x" # currently 2.7.9
@@ -26,9 +27,11 @@ environment:
# PYTHON_VERSION: "3.5.x" # currently 3.4.3
# PYTHON_ARCH: "32"
#- PYTHON: "C:\\Python35-x64"
# PYTHON_VERSION: "3.5.x" # currently 3.4.3
# PYTHON_ARCH: "64"
- PYTHON: "C:\\Python36-x64"
PYTHON_VERSION: "3.6.x"
PYTHON_ARCH: "64"
MSVC: "12.0"
ARCH: x86_64
install:
# If there is a newer build queued for the same PR, cancel this one.
@@ -68,21 +71,22 @@ install:
# compiled extensions and are not provided as pre-built wheel packages,
# pip will build them from source using the MSVC compiler matching the
# target Python version and architecture
- easy_install scons
- |
curl -LfsS -o faber.tar.gz https://github.com/stefanseefeld/faber/archive/release/0.2.tar.gz
tar xf faber.tar.gz
CD faber-release-0.2
python setup.py install
CD ..
# report the available MSVC compilers
- python -m faber.tools.msvc
- easy_install sphinx
- pip install numpy
#- "%CMD_IN_ENV% pip install -r dev-requirements.txt"
build_script:
# Build the compiled extension
#- "%CMD_IN_ENV% python setup.py build"
- scons config arch=%ARCH% --boost-include=%BOOST_PREFIX%
- scons arch=%ARCH% --verbose
- faber --with-boost-include=%BOOST_PREFIX% target.arch=%ARCH% msvc.version=%MSVC%
test_script:
# Run the project tests
#- "%CMD_IN_ENV% python setup.py nosetests"
- scons test arch=%ARCH% --verbose
- faber --with-boost-include=%BOOST_PREFIX% test.report target.arch=%ARCH% msvc.version=%MSVC%
after_test:
# If tests are successful, create binary packages for the project.
@@ -97,4 +101,4 @@ after_test:
#on_success:
# - TODO: upload the content of dist/*.whl to a public wheelhouse
#
#

3
.ci/faber Normal file
View File

@@ -0,0 +1,3 @@
from faber.tools.python import python
p = python(command='$PYTHON')

View File

@@ -26,12 +26,10 @@ matrix:
- compiler: gcc
env: CXX=g++ PYTHON=python3 CXXFLAGS=-std=c++11
- compiler: clang
# clang generates an 'illegal instruction' error in the NumPy check.
# Perhaps we need to upgrade clang to a newer version ?
env: CXX=clang++ PYTHON=python3 CXXFLAGS=-std=c++98 OPTIONS=--no-numpy
env: CXX=clang++ PYTHON=python3 CXXFLAGS=-std=c++98
- compiler: clang
env: CXX=clang++ PYTHON=python3 CXXFLAGS=-std=c++11 OPTIONS=--no-numpy
- env: PYTHON=python DOC=1
env: CXX=clang++ PYTHON=python3 CXXFLAGS=-std=c++11
#- env: PYTHON=python DOC=1
addons:
@@ -77,16 +75,28 @@ install:
./bootstrap.sh
./b2 tools/bcp
mkdir -p $HOME/Boost
# Install Boost.Python prerequisites, but not Boost.Python itself.
dist/bin/bcp python tools/boostbook tools/quickbook $HOME/Boost &> /dev/null
rm -rf $HOME/Boost/boost/python*
popd
# Install Faber, the build tool.
date=2017-11-09
#wget https://github.com/stefanseefeld/faber/archive/snapshot/$date.tar.gz
wget https://github.com/stefanseefeld/faber/archive/release/0.2.tar.gz
tar xf 0.2.tar.gz
pushd faber-release-0.2
sudo python setup.py install
popd
fi
before_script:
- scons --version
- sed -e "s/\$PYTHON/$PYTHON/g" .ci/faber > ~/.faber
- $PYTHON --version
- faber -h
script:
- scons config --python=$PYTHON --boost-include=$HOME/Boost $OPTIONS
- if [ "$DOC" ]; then scons doc; else scons && scons test; fi
- faber --with-boost-include=$HOME/Boost test.report cxx.name=$CXX cxxflags=$CXXFLAGS
#- if [ "$DOC" ]; then scons doc; else scons && scons test; fi
after_success:
# Upload docs only when building upstream.

View File

@@ -15,7 +15,7 @@ def add_options(vars):
def check(context):
source = r"""#if __cplusplus < 201103L
source = r"""#if __cplusplus < 201103L && (!defined(_MSC_VER) || _MSC_VER < 1800)
#error no C++11
#endif"""

0
doc/html/images/python_cpp_mix.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 6.1 KiB

0
doc/internals.html Executable file → Normal file
View File

0
doc/internals.rst Executable file → Normal file
View File

80
fabscript Normal file
View File

@@ -0,0 +1,80 @@
# -*- python -*-
#
# Copyright (c) 2016 Stefan Seefeld
# All rights reserved.
#
# 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 faber.feature import set
from faber.types import cxx
from faber.tools.compiler import cxxflags, define, include
from faber.tools.python import python
from faber.config import report, cxx_checks
from faber.config.try_run import try_run
features += include('include')
features += define('BOOST_ALL_NO_LIB') # disable auto-linking
boost_include = options.get_with('boost-include')
if boost_include:
features += include(boost_include)
python = python.instance()
features |= set(python.include, python.linkpath, python.libs)
class has_numpy(try_run):
src = r"""
// If defined, enforces linking against PythonXXd.lib, which
// is usually not included in Python environments.
#undef _DEBUG
#include "Python.h"
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#include "numpy/arrayobject.h"
#if PY_VERSION_HEX >= 0x03000000
void *initialize() { import_array();}
#else
void initialize() { import_array();}
#endif
int main()
{
int result = 0;
Py_Initialize();
initialize();
if (PyErr_Occurred())
{
result = 1;
}
else
{
npy_intp dims = 2;
PyObject * a = PyArray_SimpleNew(1, &dims, NPY_INT);
if (!a) result = 1;
Py_DECREF(a);
}
Py_Finalize();
return result;
}
"""
def __init__(self, features=()):
inc = ''
try:
inc = python.check_python('import numpy; print(numpy.get_include())')
features |= include(inc)
except Exception:
# ignore errors, the check will fail during compilation...
pass
try_run.__init__(self, 'has_numpy', has_numpy.src, cxx, features,
if_=(include(inc), define('HAS_NUMPY')))
checks = [cxx_checks.has_cxx11(features, define('HAS_CXX11')),
has_numpy(features)]
config = report('config', checks)
src = module('src', features=config.use)
test = module('test', features=config.use)
default = src.default

0
include/boost/python/arg_from_python.hpp Executable file → Normal file
View File

0
include/boost/python/base_type_traits.hpp Executable file → Normal file
View File

0
include/boost/python/borrowed.hpp Executable file → Normal file
View File

0
include/boost/python/cast.hpp Executable file → Normal file
View File

0
include/boost/python/converter/arg_to_python.hpp Executable file → Normal file
View File

View File

0
include/boost/python/converter/pytype_function.hpp Executable file → Normal file
View File

View File

@@ -76,7 +76,7 @@ namespace detail
registry::lookup_shared_ptr(type_id<shared_ptr<T> >());
}
#if __cplusplus >= 201103L
#if !defined(BOOST_NO_CXX11_SMART_PTR)
template <class T>
inline void
register_shared_ptr0(std::shared_ptr<T>*)

0
include/boost/python/converter/return_from_python.hpp Executable file → Normal file
View File

View File

@@ -25,7 +25,7 @@ PyObject* shared_ptr_to_python(shared_ptr<T> const& x)
return converter::registered<shared_ptr<T> const&>::converters.to_python(&x);
}
#if __cplusplus >= 201103L
#if !defined(BOOST_NO_CXX11_SMART_PTR)
template <class T>
PyObject* shared_ptr_to_python(std::shared_ptr<T> const& x)
{

0
include/boost/python/def_visitor.hpp Executable file → Normal file
View File

View File

@@ -48,7 +48,7 @@ inline PyObject* get(mpl::int_<N>, PyObject* const& args_)
return PyTuple_GET_ITEM(args_,N);
}
inline unsigned arity(PyObject* const& args_)
inline Py_ssize_t arity(PyObject* const& args_)
{
return PyTuple_GET_SIZE(args_);
}

0
include/boost/python/detail/convertible.hpp Executable file → Normal file
View File

0
include/boost/python/detail/copy_ctor_mutates_rhs.hpp Executable file → Normal file
View File

0
include/boost/python/detail/def_helper_fwd.hpp Executable file → Normal file
View File

2
include/boost/python/detail/is_shared_ptr.hpp Executable file → Normal file
View File

@@ -13,7 +13,7 @@
namespace boost { namespace python { namespace detail {
BOOST_PYTHON_IS_XXX_DEF(shared_ptr, shared_ptr, 1)
#if __cplusplus >= 201103L
#if !defined(BOOST_NO_CXX11_SMART_PTR)
template <typename T>
struct is_shared_ptr<std::shared_ptr<T> > : std::true_type {};
#endif

0
include/boost/python/detail/is_wrapper.hpp Executable file → Normal file
View File

View File

0
include/boost/python/detail/prefix.hpp Executable file → Normal file
View File

0
include/boost/python/detail/python_type.hpp Executable file → Normal file
View File

0
include/boost/python/detail/sfinae.hpp Executable file → Normal file
View File

View File

@@ -7,7 +7,8 @@
# define BOOST_PYTHON_DETAIL_TYPE_TRAITS_HPP
#if __cplusplus < 201103L
#if __cplusplus < 201103L && (!defined(BOOST_MSVC) || BOOST_MSVC<=1600)
#define BOOST_PYTHON_USE_BOOST_TYPES
# include <boost/type_traits/transform_traits.hpp>
# include <boost/type_traits/same_traits.hpp>
# include <boost/type_traits/cv_traits.hpp>
@@ -34,7 +35,7 @@
namespace boost { namespace python { namespace detail {
#if __cplusplus < 201103L
#if defined(BOOST_PYTHON_USE_BOOST_TYPES)
using boost::alignment_of;
using boost::add_const;
using boost::add_cv;

0
include/boost/python/detail/unwind_type.hpp Executable file → Normal file
View File

0
include/boost/python/detail/unwrap_type_id.hpp Executable file → Normal file
View File

0
include/boost/python/detail/unwrap_wrapper.hpp Executable file → Normal file
View File

0
include/boost/python/detail/value_arg.hpp Executable file → Normal file
View File

0
include/boost/python/docstring_options.hpp Executable file → Normal file
View File

0
include/boost/python/handle_fwd.hpp Executable file → Normal file
View File

View File

@@ -45,7 +45,7 @@ namespace detail
template <class U>
void dispatch(U* x, detail::true_) const
{
#if __cplusplus < 201103L
#if defined(BOOST_NO_CXX11_SMART_PTR)
std::auto_ptr<U> owner(x);
dispatch(owner, detail::false_());
#else
@@ -63,7 +63,7 @@ namespace detail
void* memory = holder::allocate(this->m_self, offsetof(instance_t, storage), sizeof(holder));
try {
#if __cplusplus < 201103L
#if defined(BOOST_NO_CXX11_SMART_PTR)
(new (memory) holder(x))->install(this->m_self);
#else
(new (memory) holder(std::move(x)))->install(this->m_self);

View File

@@ -66,25 +66,9 @@ BOOST_PYTHON_DECL PyObject* init_module(char const* name, void(*)());
# endif
# if (defined(_WIN32) || defined(__CYGWIN__)) && !defined(BOOST_PYTHON_STATIC_MODULE)
# define BOOST_PYTHON_MODULE_INIT(name) \
void BOOST_PP_CAT(init_module_,name)(); \
extern "C" __declspec(dllexport) _BOOST_PYTHON_MODULE_INIT(name)
# elif BOOST_PYTHON_USE_GCC_SYMBOL_VISIBILITY
# define BOOST_PYTHON_MODULE_INIT(name) \
void BOOST_PP_CAT(init_module_,name)(); \
extern "C" __attribute__ ((__visibility__("default"))) _BOOST_PYTHON_MODULE_INIT(name)
# else
# define BOOST_PYTHON_MODULE_INIT(name) \
void BOOST_PP_CAT(init_module_,name)(); \
extern "C" _BOOST_PYTHON_MODULE_INIT(name)
# endif
# define BOOST_PYTHON_MODULE_INIT(name) \
void BOOST_PP_CAT(init_module_,name)(); \
extern "C" BOOST_SYMBOL_EXPORT _BOOST_PYTHON_MODULE_INIT(name)
# endif

View File

@@ -86,11 +86,11 @@ public:
/// @brief Copy the scalar (deep for all non-object fields).
ndarray copy() const;
/// @brief Return the size of the nth dimension.
Py_intptr_t shape(int n) const { return get_shape()[n]; }
/// @brief Return the size of the nth dimension. raises IndexError if k not in [-get_nd() : get_nd()-1 ]
Py_intptr_t shape(int n) const;
/// @brief Return the stride of the nth dimension.
Py_intptr_t strides(int n) const { return get_strides()[n]; }
/// @brief Return the stride of the nth dimension. raises IndexError if k not in [-get_nd() : get_nd()-1]
Py_intptr_t strides(int n) const;
/**
* @brief Return the array's raw data pointer.

View File

@@ -106,7 +106,7 @@ struct unary_ufunc
dtype in_dtype = dtype::get_builtin<TArgument>();
dtype out_dtype = dtype::get_builtin<TResult>();
ndarray in_array = from_object(input, in_dtype, ndarray::ALIGNED);
ndarray out_array = (output != object()) ?
ndarray out_array = ! output.is_none() ?
from_object(output, out_dtype, ndarray::ALIGNED | ndarray::WRITEABLE)
: zeros(in_array.get_nd(), in_array.get_shape(), out_dtype);
multi_iter iter = make_multi_iter(in_array, out_array);
@@ -171,7 +171,7 @@ struct binary_ufunc
ndarray in1_array = from_object(input1, in1_dtype, ndarray::ALIGNED);
ndarray in2_array = from_object(input2, in2_dtype, ndarray::ALIGNED);
multi_iter iter = make_multi_iter(in1_array, in2_array);
ndarray out_array = (output != object())
ndarray out_array = !output.is_none()
? from_object(output, out_dtype, ndarray::ALIGNED | ndarray::WRITEABLE)
: zeros(iter.get_nd(), iter.get_shape(), out_dtype);
iter = make_multi_iter(in1_array, in2_array, out_array);

0
include/boost/python/object.hpp Executable file → Normal file
View File

View File

@@ -83,7 +83,7 @@ inline void register_shared_ptr_from_python_and_casts(T*, Bases)
{
// Constructor performs registration
python::detail::force_instantiate(converter::shared_ptr_from_python<T, boost::shared_ptr>());
#if __cplusplus >= 201103L
#if !defined(BOOST_NO_CXX11_SMART_PTR)
python::detail::force_instantiate(converter::shared_ptr_from_python<T, std::shared_ptr>());
#endif

0
include/boost/python/object/function_doc_signature.hpp Executable file → Normal file
View File

0
include/boost/python/object/inheritance_query.hpp Executable file → Normal file
View File

View File

@@ -21,7 +21,7 @@ struct make_ptr_instance
template <class Arg>
static inline Holder* construct(void* storage, PyObject*, Arg& x)
{
#if __cplusplus < 201103L
#if defined(BOOST_NO_CXX11_SMART_PTR)
return new (storage) Holder(x);
#else
return new (storage) Holder(std::move(x));
@@ -58,7 +58,7 @@ struct make_ptr_instance
static inline PyTypeObject* get_derived_class_object(boost::python::detail::true_, U const volatile* x)
{
converter::registration const* r = converter::registry::query(
type_info(typeid(*get_pointer(x)))
type_info(typeid(*x))
);
return r ? r->m_class_object : 0;
}

View File

@@ -106,7 +106,7 @@ struct pointer_holder_back_reference : instance_holder
template <class Pointer, class Value>
inline pointer_holder<Pointer,Value>::pointer_holder(Pointer p)
#if __cplusplus < 201103L
#if defined(BOOST_NO_CXX11_SMART_PTR)
: m_p(p)
#else
: m_p(std::move(p))
@@ -116,7 +116,7 @@ inline pointer_holder<Pointer,Value>::pointer_holder(Pointer p)
template <class Pointer, class Value>
inline pointer_holder_back_reference<Pointer,Value>::pointer_holder_back_reference(Pointer p)
#if __cplusplus < 201103L
#if defined(BOOST_NO_CXX11_SMART_PTR)
: m_p(p)
#else
: m_p(std::move(p))

View File

@@ -135,7 +135,7 @@ struct py_function
{}
py_function(py_function const& rhs)
#if __cplusplus < 201103L
#if defined(BOOST_NO_CXX11_SMART_PTR)
: m_impl(rhs.m_impl)
#else
: m_impl(std::move(rhs.m_impl))
@@ -168,7 +168,7 @@ struct py_function
}
private:
#if __cplusplus < 201103L
#if defined(BOOST_NO_CXX11_SMART_PTR)
mutable std::auto_ptr<py_function_impl_base> m_impl;
#else
mutable std::unique_ptr<py_function_impl_base> m_impl;

0
include/boost/python/object/stl_iterator_core.hpp Executable file → Normal file
View File

0
include/boost/python/object_protocol_core.hpp Executable file → Normal file
View File

0
include/boost/python/raw_function.hpp Executable file → Normal file
View File

0
include/boost/python/refcount.hpp Executable file → Normal file
View File

0
include/boost/python/self.hpp Executable file → Normal file
View File

View File

@@ -111,7 +111,6 @@ struct most_derived
// 'default' calling convention
# define BOOST_PYTHON_FN_CC
# define BOOST_PYTHON_FN_CC_IS_DEFAULT
# define BOOST_PP_ITERATION_PARAMS_1 \
(3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/signature.hpp>))
@@ -119,7 +118,6 @@ struct most_derived
# include BOOST_PP_ITERATE()
# undef BOOST_PYTHON_FN_CC
# undef BOOST_PYTHON_FN_CC_IS_DEFAULT
// __cdecl calling convention
@@ -143,7 +141,6 @@ struct most_derived
# if defined(BOOST_PYTHON_ENABLE_STDCALL)
# define BOOST_PYTHON_FN_CC __stdcall
# define BOOST_PYTHON_FN_CC_IS_STDCALL
# define BOOST_PP_ITERATION_PARAMS_1 \
(3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/signature.hpp>))
@@ -151,7 +148,6 @@ struct most_derived
# include BOOST_PP_ITERATE()
# undef BOOST_PYTHON_FN_CC
# undef BOOST_PYTHON_FN_CC_IS_STDCALL
# endif // defined(BOOST_PYTHON_ENABLE_STDCALL)
@@ -160,14 +156,12 @@ struct most_derived
# if defined(BOOST_PYTHON_ENABLE_FASTCALL)
# define BOOST_PYTHON_FN_CC __fastcall
# define BOOST_PYTHON_FN_CC_IS_FASTCALL
# define BOOST_PP_ITERATION_PARAMS_1 \
(3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/signature.hpp>))
# include BOOST_PP_ITERATE()
# undef BOOST_PYTHON_FN_CC_IS_FASTCALL
# undef BOOST_PYTHON_FN_CC
# endif // defined(BOOST_PYTHON_ENABLE_FASTCALL)
@@ -190,8 +184,8 @@ struct most_derived
// as 'get_signature(RT(*)(T0...TN), void* = 0)' is the same
// function as 'get_signature(RT(__cdecl *)(T0...TN), void* = 0)',
// we don't define it multiple times (i.e. for __cdecl, __stdcall ...)
# if defined(BOOST_PYTHON_FN_CC_IS_DEFAULT)
// we don't define it twice
# if !defined(BOOST_PYTHON_FN_CC_IS_CDECL)
template <
class RT BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class T)>
@@ -204,7 +198,7 @@ get_signature(RT(BOOST_PYTHON_FN_CC *)(BOOST_PP_ENUM_PARAMS_Z(1, N, T)), void* =
>();
}
# endif // BOOST_PYTHON_FN_CC_IS_DEFAULT
# endif // !defined(BOOST_PYTHON_FN_CC_IS_CDECL)
# undef N
@@ -212,13 +206,11 @@ get_signature(RT(BOOST_PYTHON_FN_CC *)(BOOST_PP_ENUM_PARAMS_Z(1, N, T)), void* =
(3, (0, 3, <boost/python/signature.hpp>))
# include BOOST_PP_ITERATE()
#else // BOOST_PP_ITERATION_DEPTH() != 1
#else
# define N BOOST_PP_RELATIVE_ITERATION(1)
# define Q BOOST_PYTHON_CV_QUALIFIER(BOOST_PP_ITERATION())
# if defined(BOOST_PYTHON_FN_CC_IS_DEFAULT)
template <
class RT, class ClassT BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class T)>
inline BOOST_PYTHON_LIST_INC(BOOST_PP_INC(N))<
@@ -253,8 +245,6 @@ get_signature(
>();
}
# endif // BOOST_PYTHON_FN_CC_IS_DEFAULT
# undef Q
# undef N

0
include/boost/python/stl_iterator.hpp Executable file → Normal file
View File

View File

@@ -83,7 +83,7 @@ namespace detail
// copy constructor.
# if defined(__ICL) && __ICL < 600
typedef boost::shared_ptr<T> smart_pointer;
# elif __cplusplus < 201103L
# elif defined(BOOST_NO_CXX11_SMART_PTR)
typedef std::auto_ptr<T> smart_pointer;
# else
typedef std::unique_ptr<T> smart_pointer;

View File

@@ -118,7 +118,7 @@ struct object_manager_get_pytype<true>
PyTypeObject const* get_pytype(boost::type<shared_ptr<U> &> *) const {return converter::registered<U>::converters.to_python_target_type();}
template <class U>
PyTypeObject const* get_pytype(boost::type<const shared_ptr<U> &> *) const {return converter::registered<U>::converters.to_python_target_type();}
# if __cplusplus >= 201103L
# if !defined(BOOST_NO_CXX11_SMART_PTR)
template <class U>
PyTypeObject const* get_pytype(boost::type<std::shared_ptr<U> &> *) const {return converter::registered<U>::converters.to_python_target_type();}
template <class U>

0
include/boost/python/wrapper.hpp Executable file → Normal file
View File

View File

@@ -16,7 +16,7 @@ namespace python
object BOOST_PYTHON_DECL eval(str string, object global, object local)
{
return eval(python::extract<char const *>(string));
return eval(python::extract<char const *>(string), global, local);
}
object BOOST_PYTHON_DECL eval(char const *string, object global, object local)
@@ -39,7 +39,7 @@ object BOOST_PYTHON_DECL eval(char const *string, object global, object local)
object BOOST_PYTHON_DECL exec(str string, object global, object local)
{
return exec(python::extract<char const *>(string));
return exec(python::extract<char const *>(string), global, local);
}
object BOOST_PYTHON_DECL exec(char const *string, object global, object local)

58
src/fabscript Normal file
View File

@@ -0,0 +1,58 @@
# -*- python -*-
#
# Copyright (c) 2016 Stefan Seefeld
# All rights reserved.
#
# 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 faber.feature import set
from faber.artefacts.library import library
from faber.tools.compiler import define
root = module('..')
bpl = library('boost_python',
['list.cpp',
'long.cpp',
'dict.cpp',
'tuple.cpp',
'str.cpp',
'slice.cpp',
'converter/from_python.cpp',
'converter/registry.cpp',
'converter/type_id.cpp',
'object/enum.cpp',
'object/class.cpp',
'object/function.cpp',
'object/inheritance.cpp',
'object/life_support.cpp',
'object/pickle_support.cpp',
'errors.cpp',
'module.cpp',
'converter/builtin_converters.cpp',
'converter/arg_to_python_base.cpp',
'object/iterator.cpp',
'object/stl_iterator.cpp',
'object_protocol.cpp',
'object_operators.cpp',
'wrapper.cpp',
'import.cpp',
'exec.cpp',
'object/function_doc_signature.cpp'],
dependencies=root.config,
features=features + define('BOOST_PYTHON_SOURCE'))
bnl = library('boost_numpy',
['numpy/dtype.cpp',
'numpy/matrix.cpp',
'numpy/ndarray.cpp',
'numpy/numpy.cpp',
'numpy/scalars.cpp',
'numpy/ufunc.cpp',
bpl],
dependencies=root.config,
features=features + define('BOOST_NUMPY_SOURCE'),
condition=set.define.contains('HAS_NUMPY'))
default = [bpl, bnl]

0
src/numpy/dtype.cpp Executable file → Normal file
View File

View File

@@ -138,6 +138,30 @@ ndarray from_data_impl(void * data,
} // namespace detail
namespace {
int normalize_index(int n,int nlim) // wraps [-nlim:nlim) into [0:nlim), throw IndexError otherwise
{
if (n<0)
n += nlim; // negative indices work backwards from end
if (n < 0 || n >= nlim)
{
PyErr_SetObject(PyExc_IndexError, Py_None);
throw_error_already_set();
}
return n;
}
}
Py_intptr_t ndarray::shape(int n) const
{
return get_shape()[normalize_index(n,get_nd())];
}
Py_intptr_t ndarray::strides(int n) const
{
return get_strides()[normalize_index(n,get_nd())];
}
ndarray ndarray::view(dtype const & dt) const
{
return ndarray(python::detail::new_reference
@@ -170,7 +194,7 @@ python::object ndarray::get_base() const
void ndarray::set_base(object const & base)
{
Py_XDECREF(get_struct()->base);
if (base != object())
if (base.ptr())
{
Py_INCREF(base.ptr());
get_struct()->base = base.ptr();

View File

@@ -34,11 +34,17 @@ static PyMemberDef enum_members[] = {
extern "C"
{
static void
enum_dealloc(enum_object* self)
{
Py_XDECREF(self->name);
Py_TYPE(self)->tp_free((PyObject*)self);
}
static PyObject* enum_repr(PyObject* self_)
{
// XXX(bhy) Potentional memory leak here since PyObject_GetAttrString returns a new reference
// const char *mod = PyString_AsString(PyObject_GetAttrString( self_, const_cast<char*>("__module__")));
PyObject *mod = PyObject_GetAttrString( self_, "__module__");
object auto_free(handle<>(mod));
enum_object* self = downcast<enum_object>(self_);
if (!self->name)
{
@@ -88,7 +94,7 @@ static PyTypeObject enum_type_object = {
const_cast<char*>("Boost.Python.enum"),
sizeof(enum_object), /* tp_basicsize */
0, /* tp_itemsize */
0, /* tp_dealloc */
(destructor) enum_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */

0
src/wrapper.cpp Executable file → Normal file
View File

0
test/borrowed.cpp Executable file → Normal file
View File

0
test/class.py Executable file → Normal file
View File

0
test/cltree.cpp Executable file → Normal file
View File

0
test/copy_ctor_mutates_rhs.cpp Executable file → Normal file
View File

0
test/crossmod_exception_a.cpp Executable file → Normal file
View File

0
test/crossmod_exception_b.cpp Executable file → Normal file
View File

0
test/enable_shared_from_this.py Executable file → Normal file
View File

173
test/fabscript Normal file
View File

@@ -0,0 +1,173 @@
# -*- python -*-
#
# Copyright (c) 2016 Stefan Seefeld
# All rights reserved.
#
# 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 faber import platform
from faber.feature import set
from faber.tools.compiler import runpath
from faber.tools.python import python, pythonpath
from faber.artefacts.object import object
from faber.artefacts.binary import binary
from faber.artefacts.python import extension
from faber.test import test, report, fail
src = module('..src')
python_libs=python.instance().libs
features |= runpath(src.bpl.path, base='')
def extension_test(name, ext=[], script=None, np=False,
features=features, condition=None):
"""Create a Python extension test `name`.
Arguments:
* name: the name of the test.
* ext: extensions to be compiled, <name> if none are given.
* script: the test script to execute, <name>.py if none is given.
* np: if true, add boost_numpy to sources
* features: pre-defined features
* condition: any condition under which to run the test
Return:
* the test artefact"""
features=features.copy()
extensions = []
libs = [src.bnl, src.bpl] if np else [src.bpl]
for e in ext or [name]:
if type(e) is str: # build from a single source file
n = e if e != name else e + '_ext'
s = [e + '.cpp']
else: # build from a list of source files
n = e[0] if e[0] != name else e[0] + '_ext'
s = [n + '.cpp' for n in e]
e = extension(n, s + libs, features=features)
features |= pythonpath(e.path, base='')
extensions.append(e)
if not script:
script = name+'.py'
return test(name, script, run=python.run, dependencies=extensions,
features=features, condition=condition)
tests = []
for t in [('injected',),
('properties',),
('return_arg',),
('staticmethod',),
('boost_shared_ptr',),
('enable_shared_from_this',),
('andreas_beyer',),
('polymorphism',),
('polymorphism2',),
('wrapper_held_type',),
('minimal',),
('args',),
('raw_ctor',),
('exception_translator',),
('test_enum', ['enum_ext']),
('test_cltree', ['cltree']),
('newtest', ['m1', 'm2']),
('const_argument',),
('keywords_test', ['keywords']),
('test_pointer_adoption',),
('operators',),
('operators_wrapper',),
('callbacks',),
('defaults',),
('object',),
('list',),
('long',),
('dict',),
('tuple',),
('str',),
('slice',),
('virtual_functions',),
('back_reference',),
('implicit',),
('data_members',),
('ben_scott1',),
('bienstman1',),
('bienstman2',),
('bienstman3',),
('multi_arg_constructor',),
('iterator', ['iterator', 'input_iterator']),
('stl_iterator',),
('extract',),
('crossmod_opaque', ['crossmod_opaque_a', 'crossmod_opaque_b']),
('opaque',),
('voidptr',),
('pickle1',),
('pickle2',),
('pickle3',),
('pickle4',),
('nested',),
('docstring',),
('pytype_function',),
('vector_indexing_suite',),
('pointer_vector',),
('builtin_converters', [], 'test_builtin_converters.py'),
('map_indexing_suite',
[['map_indexing_suite', 'int_map_indexing_suite', 'a_map_indexing_suite']])]:
tests.append(extension_test(*t))
tests.append(extension_test('shared_ptr',
condition=set.define.contains('HAS_CXX11')))
tests.append(extension_test('polymorphism2_auto_ptr',
condition=set.define.contains('HAS_CXX11').not_()))
tests.append(extension_test('auto_ptr',
condition=set.define.contains('HAS_CXX11')))
import_ = binary('import_', ['import_.cpp', src.bpl], features=features|python_libs)
if platform.os == 'Windows':
command = """set PATH=$(runpath);%PATH%
$(>[1]) $(>[2])"""
else:
command = 'LD_LIBRARY_PATH=$(runpath) $(>[1]) $(>[2])'
tests.append(test('import', [import_, 'import_.py'],
run=action('run', command),
features=features))
tests.append(extension_test('calling_conventions',
condition=platform.os == 'Windows'))
tests.append(extension_test('calling_conventions_mf',
condition=platform.os == 'Windows'))
for t in ['destroy_test',
'pointer_type_id_test',
'bases',
'pointee',
'if_else',
'pointee',
'result',
'upcast',
'select_from_python_test']:
tests.append(test(t, binary(t, [t + '.cpp', src.bpl], features=features), features=features, run=True))
for t in ['indirect_traits_test',
'string_literal',
'borrowed',
'object_manager',
'copy_ctor_mutates_rhs',
'select_holder',
'select_arg_to_python_test']:
tests.append(test(t, object(t, [t + '.cpp'], features=features)))
for t in ['raw_pyobject_fail1',
'raw_pyobject_fail2',
'as_to_python_function',
'object_fail1']:
tests.append(test(t, object(t, [t + '.cpp'], features=features), expected=fail))
for t in ['numpy/dtype',
'numpy/ufunc',
'numpy/templates',
'numpy/ndarray',
'numpy/indexing',
'numpy/shapes']:
tests.append(extension_test(t, np=True,
condition=set.define.contains('HAS_NUMPY')))
default = report('report', tests, fail_on_failures=True)

0
test/injected.cpp Executable file → Normal file
View File

0
test/int_map_indexing_suite.cpp Executable file → Normal file
View File

0
test/keywords.cpp Executable file → Normal file
View File

View File

@@ -31,6 +31,9 @@ np::ndarray transpose(np::ndarray arr) { return arr.transpose();}
np::ndarray squeeze(np::ndarray arr) { return arr.squeeze();}
np::ndarray reshape(np::ndarray arr,p::tuple tup) { return arr.reshape(tup);}
Py_intptr_t shape_index(np::ndarray arr,int k) { return arr.shape(k); }
Py_intptr_t strides_index(np::ndarray arr,int k) { return arr.strides(k); }
BOOST_PYTHON_MODULE(ndarray_ext)
{
np::initialize();
@@ -43,4 +46,6 @@ BOOST_PYTHON_MODULE(ndarray_ext)
p::def("transpose", transpose);
p::def("squeeze", squeeze);
p::def("reshape", reshape);
p::def("shape_index", shape_index);
p::def("strides_index", strides_index);
}

View File

@@ -75,5 +75,38 @@ class TestNdarray(unittest.TestCase):
a2 = ndarray_ext.reshape(a1,(1,4))
self.assertEqual(a2.shape,(1,4))
def testShapeIndex(self):
a = numpy.arange(24)
a.shape = (1,2,3,4)
def shape_check(i):
print(i)
self.assertEqual(ndarray_ext.shape_index(a,i) ,a.shape[i] )
for i in range(4):
shape_check(i)
for i in range(-1,-5,-1):
shape_check(i)
try:
ndarray_ext.shape_index(a,4) # out of bounds -- should raise IndexError
self.assertTrue(False)
except IndexError:
pass
def testStridesIndex(self):
a = numpy.arange(24)
a.shape = (1,2,3,4)
def strides_check(i):
print(i)
self.assertEqual(ndarray_ext.strides_index(a,i) ,a.strides[i] )
for i in range(4):
strides_check(i)
for i in range(-1,-5,-1):
strides_check(i)
try:
ndarray_ext.strides_index(a,4) # out of bounds -- should raise IndexError
self.assertTrue(False)
except IndexError:
pass
if __name__=="__main__":
unittest.main()

0
test/object_fail1.cpp Executable file → Normal file
View File

0
test/object_manager.cpp Executable file → Normal file
View File

0
test/operators.cpp Executable file → Normal file
View File

0
test/polymorphism2.cpp Executable file → Normal file
View File

0
test/polymorphism2_auto_ptr.cpp Executable file → Normal file
View File

0
test/properties.cpp Executable file → Normal file
View File

0
test/pytype_function.py Executable file → Normal file
View File

0
test/raw_ctor.cpp Executable file → Normal file
View File

0
test/raw_pyobject_fail1.cpp Executable file → Normal file
View File

0
test/raw_pyobject_fail2.cpp Executable file → Normal file
View File

0
test/result.cpp Executable file → Normal file
View File

0
test/return_arg.cpp Executable file → Normal file
View File

0
test/stl_iterator.cpp Executable file → Normal file
View File

0
test/voidptr.cpp Executable file → Normal file
View File

0
test/wrapper_held_type.cpp Executable file → Normal file
View File