Python: Updated boost to 1.58 - Kivy support in python wrapper

This commit is contained in:
Philippe Tillet
2015-08-14 22:09:54 -07:00
parent 8c7259bb3d
commit e912beaac3
2830 changed files with 14024 additions and 384984 deletions

View File

@@ -70,7 +70,6 @@ execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c"
"from distutils import sysconfig as s;import sys;import struct;
print('.'.join(str(v) for v in sys.version_info));
print(s.PREFIX);
print(s.get_python_inc());
print(s.get_python_inc(plat_specific=True));
print(s.get_python_lib(plat_specific=True));
print(s.get_config_var('SO'));
@@ -97,11 +96,10 @@ string(REGEX REPLACE "\n" ";" _PYTHON_VALUES ${_PYTHON_VALUES})
list(GET _PYTHON_VALUES 0 _PYTHON_VERSION_LIST)
list(GET _PYTHON_VALUES 1 PYTHON_PREFIX)
list(GET _PYTHON_VALUES 2 PYTHON_INCLUDE_DIR)
list(GET _PYTHON_VALUES 3 PYTHON_PLATFORM_INCLUDE_DIR)
list(GET _PYTHON_VALUES 4 PYTHON_SITE_PACKAGES)
list(GET _PYTHON_VALUES 5 PYTHON_MODULE_EXTENSION)
list(GET _PYTHON_VALUES 6 PYTHON_IS_DEBUG)
list(GET _PYTHON_VALUES 7 PYTHON_SIZEOF_VOID_P)
list(GET _PYTHON_VALUES 3 PYTHON_SITE_PACKAGES)
list(GET _PYTHON_VALUES 4 PYTHON_MODULE_EXTENSION)
list(GET _PYTHON_VALUES 5 PYTHON_IS_DEBUG)
list(GET _PYTHON_VALUES 6 PYTHON_SIZEOF_VOID_P)
# Make sure the Python has the same pointer-size as the chosen compiler
if(NOT ${PYTHON_SIZEOF_VOID_P} MATCHES ${CMAKE_SIZEOF_VOID_P})
@@ -165,7 +163,7 @@ MARK_AS_ADVANCED(
# cache entries because they are meant to specify the location of a single
# library. We now set the variables listed by the documentation for this
# module.
SET(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR};${PYTHON_PLATFORM_INCLUDE_DIR}")
SET(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
SET(PYTHON_LIBRARIES "${PYTHON_LIBRARY}")
SET(PYTHON_DEBUG_LIBRARIES "${PYTHON_DEBUG_LIBRARY}")

View File

@@ -3,7 +3,7 @@ macro( addPythonExe _name _srccpp )
ADD_EXECUTABLE(${_name} ${_srccpp})
# make the pyd library link against boost_numpy python and boost
TARGET_LINK_LIBRARIES(${_name} boost_numpy ${PYTHON_LIBRARIES} ${Boost_LIBRARIES})
TARGET_LINK_LIBRARIES(${_name} boost_numpy)
# put the example target into a VS solution folder named example (should
# be a no-op for Linux)
@@ -14,7 +14,7 @@ macro( addPythonMod _name _srccpp )
PYTHON_ADD_MODULE(${_name} ${_srccpp})
# make the pyd library link against boost_numpy python and boost
TARGET_LINK_LIBRARIES(${_name} boost_numpy ${PYTHON_LIBRARIES} ${Boost_LIBRARIES})
TARGET_LINK_LIBRARIES(${_name} boost_numpy)
# put the example target into a VS solution folder named example (should
# be a no-op for Linux)

View File

@@ -111,8 +111,11 @@ BOOST_PYTHON_MODULE(example) {
int main(int argc, char **argv)
{
// This line makes our module available to the embedded Python intepreter.
PyImport_AppendInittab("example", &initexample);
# if PY_VERSION_HEX >= 0x03000000
PyImport_AppendInittab("example", &PyInit_example);
# else
PyImport_AppendInittab("example", &initexample);
# endif
// Initialize the Python runtime.
Py_Initialize();

View File

@@ -17,8 +17,7 @@ add_library(boost_numpy ${LIBRARY_TYPE}
ufunc.cpp
numpy.cpp
)
TARGET_LINK_LIBRARIES(boost_numpy ${Boost_LIBRARIES})
target_link_libraries(boost_numpy ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})
install(TARGETS boost_numpy
ARCHIVE DESTINATION lib

View File

@@ -5,8 +5,18 @@
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
Import("env")
import sys
import os
Import(['env', 'EXT_SUFFIX', 'LIB_SUFFIX', 'OBJ_SUFFIX'])
lib = env.SharedLibrary("boost_numpy", Glob("*.cpp"))
LIB_BOOST_NUMPY = ('boost_numpy' + LIB_SUFFIX)
sourcefiles = Glob("*.cpp")
if os.name == 'nt':
lib = env.StaticLibrary(LIB_BOOST_NUMPY, source=sourcefiles)
else:
mods = [g.name.replace('.cpp', '') for g in sourcefiles]
for m in mods:
env.SharedObject (target=m+OBJ_SUFFIX, source=m+'.cpp')
lib = env.SharedLibrary(LIB_BOOST_NUMPY, source=[m+OBJ_SUFFIX for m in mods])
Return("lib")

View File

@@ -2,7 +2,9 @@
// 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)
#ifdef _MSC_VER
#include <boost/cstdint.hpp>
#endif
#define BOOST_NUMPY_INTERNAL
#include <boost/numpy/internal.hpp>
@@ -55,6 +57,7 @@ BUILTIN_INT_DTYPE(8);
BUILTIN_INT_DTYPE(16);
BUILTIN_INT_DTYPE(32);
BUILTIN_INT_DTYPE(64);
BUILTIN_FLOAT_DTYPE(16);
BUILTIN_FLOAT_DTYPE(32);
BUILTIN_FLOAT_DTYPE(64);
BUILTIN_COMPLEX_DTYPE(64);
@@ -87,10 +90,32 @@ python::detail::new_reference dtype::convert(python::object const & arg, bool al
int dtype::get_itemsize() const { return reinterpret_cast<PyArray_Descr*>(ptr())->elsize;}
bool equivalent(dtype const & a, dtype const & b) {
// On Windows x64, the behaviour described on
// http://docs.scipy.org/doc/numpy/reference/c-api.array.html for
// PyArray_EquivTypes unfortunately does not extend as expected:
// "For example, on 32-bit platforms, NPY_LONG and NPY_INT are equivalent".
// This should also hold for 64-bit platforms (and does on Linux), but not
// on Windows. Implement an alternative:
#ifdef _MSC_VER
if (sizeof(long) == sizeof(int) &&
// Manually take care of the type equivalence.
((a == dtype::get_builtin<long>() || a == dtype::get_builtin<int>()) &&
(b == dtype::get_builtin<long>() || b == dtype::get_builtin<int>()) ||
(a == dtype::get_builtin<unsigned int>() || a == dtype::get_builtin<unsigned long>()) &&
(b == dtype::get_builtin<unsigned int>() || b == dtype::get_builtin<unsigned long>()))) {
return true;
} else {
return PyArray_EquivTypes(
reinterpret_cast<PyArray_Descr*>(a.ptr()),
reinterpret_cast<PyArray_Descr*>(b.ptr())
);
}
#else
return PyArray_EquivTypes(
reinterpret_cast<PyArray_Descr*>(a.ptr()),
reinterpret_cast<PyArray_Descr*>(b.ptr())
);
#endif
}
namespace {
@@ -114,9 +139,13 @@ public:
static void * convertible(PyObject * obj) {
if (obj->ob_type == get_pytype()) {
return obj;
} else {
return 0;
} else {
dtype dt(python::detail::borrowed_reference(obj->ob_type));
if (equivalent(dt, dtype::get_builtin<T>())) {
return obj;
}
}
return 0;
}
static void convert(PyObject * obj, pyconv::rvalue_from_python_stage1_data* data) {
@@ -148,6 +177,13 @@ void dtype::register_scalar_converters() {
array_scalar_converter<npy_int16>::declare();
array_scalar_converter<npy_uint32>::declare();
array_scalar_converter<npy_int32>::declare();
#ifdef _MSC_VER
// Since the npy_(u)int32 types are defined as long types and treated
// as being different from the int32 types, these converters must be declared
// explicitely.
array_scalar_converter<boost::uint32_t>::declare();
array_scalar_converter<boost::int32_t>::declare();
#endif
array_scalar_converter<npy_uint64>::declare();
array_scalar_converter<npy_int64>::declare();
array_scalar_converter<float>::declare();

View File

@@ -12,19 +12,19 @@ namespace boost
namespace numpy
{
#if PY_MAJOR_VERSION >= 3
int
#else
void
#endif
do_import_array()
{
import_array();
#if PY_MAJOR_VERSION == 2
static void wrap_import_array() {
import_array();
}
#else
static void * wrap_import_array() {
import_array();
}
#endif
void initialize(bool register_scalar_converters)
{
do_import_array();
wrap_import_array();
import_ufunc();
if (register_scalar_converters)
dtype::register_scalar_converters();