Skip to content

Commit

Permalink
Add libarrow_python-specific visibility macros so that global data me…
Browse files Browse the repository at this point in the history
…mbers from arrow.dll can be accessed correctly in arrow_python.dll

Change-Id: Ib5748ce1cf9aebd60f8cec20ee4ee03617bec983
  • Loading branch information
wesm committed Dec 2, 2018
1 parent 062c383 commit 91dbea8
Show file tree
Hide file tree
Showing 18 changed files with 158 additions and 116 deletions.
3 changes: 2 additions & 1 deletion cpp/src/arrow/python/CMakeLists.txt
Expand Up @@ -76,7 +76,7 @@ ADD_ARROW_LIB(arrow_python

foreach(LIB_TARGET ${ARROW_PYTHON_LIBRARIES})
target_compile_definitions(${LIB_TARGET}
PRIVATE ARROW_EXPORTING)
PRIVATE ARROW_PYTHON_EXPORTING)
endforeach()

if (ARROW_BUILD_STATIC AND MSVC)
Expand Down Expand Up @@ -112,6 +112,7 @@ install(FILES
pyarrow.h
serialize.h
type_traits.h
visibility.h
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/arrow/python")

# pkg-config support
Expand Down
12 changes: 6 additions & 6 deletions cpp/src/arrow/python/arrow_to_pandas.h
Expand Up @@ -27,7 +27,7 @@
#include <string>
#include <unordered_set>

#include "arrow/util/visibility.h"
#include "arrow/python/visibility.h"

namespace arrow {

Expand Down Expand Up @@ -57,16 +57,16 @@ struct PandasOptions {
use_threads(false) {}
};

ARROW_EXPORT
ARROW_PYTHON_EXPORT
Status ConvertArrayToPandas(PandasOptions options, const std::shared_ptr<Array>& arr,
PyObject* py_ref, PyObject** out);

ARROW_EXPORT
ARROW_PYTHON_EXPORT
Status ConvertChunkedArrayToPandas(PandasOptions options,
const std::shared_ptr<ChunkedArray>& col,
PyObject* py_ref, PyObject** out);

ARROW_EXPORT
ARROW_PYTHON_EXPORT
Status ConvertColumnToPandas(PandasOptions options, const std::shared_ptr<Column>& col,
PyObject* py_ref, PyObject** out);

Expand All @@ -76,15 +76,15 @@ Status ConvertColumnToPandas(PandasOptions options, const std::shared_ptr<Column
// BlockManager structure of the pandas.DataFrame used as of pandas 0.19.x.
//
// tuple item: (indices: ndarray[int32], block: ndarray[TYPE, ndim=2])
ARROW_EXPORT
ARROW_PYTHON_EXPORT
Status ConvertTableToPandas(PandasOptions options, const std::shared_ptr<Table>& table,
MemoryPool* pool, PyObject** out);

/// Convert a whole table as efficiently as possible to a pandas.DataFrame.
///
/// Explicitly name columns that should be a categorical
/// This option is only used on conversions that are applied to a table.
ARROW_EXPORT
ARROW_PYTHON_EXPORT
Status ConvertTableToPandas(PandasOptions options,
const std::unordered_set<std::string>& categorical_columns,
const std::shared_ptr<Table>& table, MemoryPool* pool,
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/arrow/python/benchmark.h
Expand Up @@ -20,7 +20,7 @@

#include "arrow/python/platform.h"

#include "arrow/util/visibility.h"
#include "arrow/python/visibility.h"

namespace arrow {
namespace py {
Expand All @@ -29,7 +29,7 @@ namespace benchmark {
// Micro-benchmark routines for use from ASV

// Run PandasObjectIsNull() once over every object in *list*
ARROW_EXPORT
ARROW_PYTHON_EXPORT
void Benchmark_PandasObjectIsNull(PyObject* list);

} // namespace benchmark
Expand Down
18 changes: 9 additions & 9 deletions cpp/src/arrow/python/common.h
Expand Up @@ -26,16 +26,16 @@
#include "arrow/python/config.h"

#include "arrow/buffer.h"
#include "arrow/python/visibility.h"
#include "arrow/util/macros.h"
#include "arrow/util/visibility.h"

namespace arrow {

class MemoryPool;

namespace py {

ARROW_EXPORT Status ConvertPyError(StatusCode code = StatusCode::UnknownError);
ARROW_PYTHON_EXPORT Status ConvertPyError(StatusCode code = StatusCode::UnknownError);

// Catch a pending Python exception and return the corresponding Status.
// If no exception is pending, Status::OK() is returned.
Expand All @@ -47,14 +47,14 @@ inline Status CheckPyError(StatusCode code = StatusCode::UnknownError) {
}
}

ARROW_EXPORT Status PassPyError();
ARROW_PYTHON_EXPORT Status PassPyError();

// TODO(wesm): We can just let errors pass through. To be explored later
#define RETURN_IF_PYERROR() ARROW_RETURN_NOT_OK(CheckPyError());

#define PY_RETURN_IF_ERROR(CODE) ARROW_RETURN_NOT_OK(CheckPyError(CODE));

class ARROW_EXPORT PyAcquireGIL {
class ARROW_PYTHON_EXPORT PyAcquireGIL {
public:
PyAcquireGIL() : acquired_gil_(false) { acquire(); }

Expand Down Expand Up @@ -85,7 +85,7 @@ class ARROW_EXPORT PyAcquireGIL {

// A RAII primitive that DECREFs the underlying PyObject* when it
// goes out of scope.
class ARROW_EXPORT OwnedRef {
class ARROW_PYTHON_EXPORT OwnedRef {
public:
OwnedRef() : obj_(NULLPTR) {}
OwnedRef(OwnedRef&& other) : OwnedRef(other.detach()) {}
Expand Down Expand Up @@ -126,7 +126,7 @@ class ARROW_EXPORT OwnedRef {
// Same as OwnedRef, but ensures the GIL is taken when it goes out of scope.
// This is for situations where the GIL is not always known to be held
// (e.g. if it is released in the middle of a function for performance reasons)
class ARROW_EXPORT OwnedRefNoGIL : public OwnedRef {
class ARROW_PYTHON_EXPORT OwnedRefNoGIL : public OwnedRef {
public:
OwnedRefNoGIL() : OwnedRef() {}
OwnedRefNoGIL(OwnedRefNoGIL&& other) : OwnedRef(other.detach()) {}
Expand Down Expand Up @@ -226,10 +226,10 @@ struct PyBytesView {
};

// Return the common PyArrow memory pool
ARROW_EXPORT void set_default_memory_pool(MemoryPool* pool);
ARROW_EXPORT MemoryPool* get_memory_pool();
ARROW_PYTHON_EXPORT void set_default_memory_pool(MemoryPool* pool);
ARROW_PYTHON_EXPORT MemoryPool* get_memory_pool();

class ARROW_EXPORT PyBuffer : public Buffer {
class ARROW_PYTHON_EXPORT PyBuffer : public Buffer {
public:
/// While memoryview objects support multi-dimensional buffers, PyBuffer only supports
/// one-dimensional byte buffers.
Expand Down
6 changes: 3 additions & 3 deletions cpp/src/arrow/python/config.h
Expand Up @@ -21,7 +21,7 @@
#include "arrow/python/platform.h"

#include "arrow/python/numpy_interop.h"
#include "arrow/util/visibility.h"
#include "arrow/python/visibility.h"

#if PY_MAJOR_VERSION >= 3
#define PyString_Check PyUnicode_Check
Expand All @@ -30,10 +30,10 @@
namespace arrow {
namespace py {

ARROW_EXPORT
ARROW_PYTHON_EXPORT
extern PyObject* numpy_nan;

ARROW_EXPORT
ARROW_PYTHON_EXPORT
void set_numpy_nan(PyObject* obj);

} // namespace py
Expand Down
16 changes: 8 additions & 8 deletions cpp/src/arrow/python/decimal.h
Expand Up @@ -20,8 +20,8 @@

#include <string>

#include "arrow/python/visibility.h"
#include "arrow/type.h"
#include "arrow/util/visibility.h"

namespace arrow {

Expand All @@ -38,21 +38,21 @@ class OwnedRef;
namespace internal {

// \brief Import the Python Decimal type
ARROW_EXPORT
ARROW_PYTHON_EXPORT
Status ImportDecimalType(OwnedRef* decimal_type);

// \brief Convert a Python Decimal object to a C++ string
// \param[in] python_decimal A Python decimal.Decimal instance
// \param[out] The string representation of the Python Decimal instance
// \return The status of the operation
ARROW_EXPORT
ARROW_PYTHON_EXPORT
Status PythonDecimalToString(PyObject* python_decimal, std::string* out);

// \brief Convert a C++ std::string to a Python Decimal instance
// \param[in] decimal_constructor The decimal type object
// \param[in] decimal_string A decimal string
// \return An instance of decimal.Decimal
ARROW_EXPORT
ARROW_PYTHON_EXPORT
PyObject* DecimalFromString(PyObject* decimal_constructor,
const std::string& decimal_string);

Expand All @@ -61,21 +61,21 @@ PyObject* DecimalFromString(PyObject* decimal_constructor,
// \param[in] arrow_type An instance of arrow::DecimalType
// \param[out] out A pointer to a Decimal128
// \return The status of the operation
ARROW_EXPORT
ARROW_PYTHON_EXPORT
Status DecimalFromPythonDecimal(PyObject* python_decimal, const DecimalType& arrow_type,
Decimal128* out);

// \brief Check whether obj is an instance of Decimal
ARROW_EXPORT
ARROW_PYTHON_EXPORT
bool PyDecimal_Check(PyObject* obj);

// \brief Check whether obj is nan. This function will abort the program if the argument
// is not a Decimal instance
ARROW_EXPORT
ARROW_PYTHON_EXPORT
bool PyDecimal_ISNAN(PyObject* obj);

// \brief Helper class to track and update the precision and scale of a decimal
class ARROW_EXPORT DecimalMetadata {
class ARROW_PYTHON_EXPORT DecimalMetadata {
public:
DecimalMetadata();
DecimalMetadata(int32_t precision, int32_t scale);
Expand Down
12 changes: 6 additions & 6 deletions cpp/src/arrow/python/deserialize.h
Expand Up @@ -23,8 +23,8 @@
#include <vector>

#include "arrow/python/serialize.h"
#include "arrow/python/visibility.h"
#include "arrow/status.h"
#include "arrow/util/visibility.h"

namespace arrow {

Expand All @@ -43,7 +43,7 @@ namespace py {
/// \param[in] src a RandomAccessFile
/// \param[out] out the reconstructed data
/// \return Status
ARROW_EXPORT
ARROW_PYTHON_EXPORT
Status ReadSerializedObject(io::RandomAccessFile* src, SerializedPyObject* out);

/// \brief Reconstruct SerializedPyObject from representation produced by
Expand All @@ -56,7 +56,7 @@ Status ReadSerializedObject(io::RandomAccessFile* src, SerializedPyObject* out);
/// num_tensors * 2 + num_buffers in length
/// \param[out] out the reconstructed object
/// \return Status
ARROW_EXPORT
ARROW_PYTHON_EXPORT
Status GetSerializedFromComponents(int num_tensors, int num_ndarrays, int num_buffers,
PyObject* data, SerializedPyObject* out);

Expand All @@ -72,18 +72,18 @@ Status GetSerializedFromComponents(int num_tensors, int num_ndarrays, int num_bu
/// \param[out] out The returned object
/// \return Status
/// This acquires the GIL
ARROW_EXPORT
ARROW_PYTHON_EXPORT
Status DeserializeObject(PyObject* context, const SerializedPyObject& object,
PyObject* base, PyObject** out);

/// \brief Reconstruct Ndarray from Arrow-serialized representation
/// \param[in] object Object to deserialize
/// \param[out] out The deserialized tensor
/// \return Status
ARROW_EXPORT
ARROW_PYTHON_EXPORT
Status DeserializeNdarray(const SerializedPyObject& object, std::shared_ptr<Tensor>* out);

ARROW_EXPORT
ARROW_PYTHON_EXPORT
Status NdarrayFromBuffer(std::shared_ptr<Buffer> src, std::shared_ptr<Tensor>* out);

} // namespace py
Expand Down
30 changes: 15 additions & 15 deletions cpp/src/arrow/python/helpers.h
Expand Up @@ -27,9 +27,9 @@

#include <numpy/halffloat.h>

#include "arrow/python/visibility.h"
#include "arrow/type.h"
#include "arrow/util/macros.h"
#include "arrow/util/visibility.h"

namespace arrow {

Expand All @@ -40,28 +40,28 @@ class OwnedRef;
// \brief Get an arrow DataType instance from Arrow's Type::type enum
// \param[in] type One of the values of Arrow's Type::type enum
// \return A shared pointer to DataType
ARROW_EXPORT std::shared_ptr<DataType> GetPrimitiveType(Type::type type);
ARROW_PYTHON_EXPORT std::shared_ptr<DataType> GetPrimitiveType(Type::type type);

// \brief Construct a np.float16 object from a npy_half value.
ARROW_EXPORT PyObject* PyHalf_FromHalf(npy_half value);
ARROW_PYTHON_EXPORT PyObject* PyHalf_FromHalf(npy_half value);

// \brief Convert a Python object to a npy_half value.
ARROW_EXPORT Status PyFloat_AsHalf(PyObject* obj, npy_half* out);
ARROW_PYTHON_EXPORT Status PyFloat_AsHalf(PyObject* obj, npy_half* out);

namespace internal {

// \brief Import a Python module
// \param[in] module_name The name of the module
// \param[out] ref The OwnedRef containing the module PyObject*
ARROW_EXPORT
ARROW_PYTHON_EXPORT
Status ImportModule(const std::string& module_name, OwnedRef* ref);

// \brief Import an object from a Python module
// \param[in] module A Python module
// \param[in] name The name of the object to import
// \param[out] ref The OwnedRef containing the \c name attribute of the Python module \c
// module
ARROW_EXPORT
ARROW_PYTHON_EXPORT
Status ImportFromModule(const OwnedRef& module, const std::string& name, OwnedRef* ref);

// \brief Check whether obj is an integer, independent of Python versions.
Expand All @@ -74,11 +74,11 @@ inline bool IsPyInteger(PyObject* obj) {
}

// \brief Use pandas missing value semantics to check if a value is null
ARROW_EXPORT
ARROW_PYTHON_EXPORT
bool PandasObjectIsNull(PyObject* obj);

// \brief Check whether obj is a floating-point NaN
ARROW_EXPORT
ARROW_PYTHON_EXPORT
bool PyFloat_IsNaN(PyObject* obj);

inline bool IsPyBinary(PyObject* obj) {
Expand All @@ -93,19 +93,19 @@ template <typename Int>
Status CIntFromPython(PyObject* obj, Int* out, const std::string& overflow_message = "");

// \brief Convert a Python unicode string to a std::string
ARROW_EXPORT
ARROW_PYTHON_EXPORT
Status PyUnicode_AsStdString(PyObject* obj, std::string* out);

// \brief Convert a Python bytes object to a std::string
ARROW_EXPORT
ARROW_PYTHON_EXPORT
std::string PyBytes_AsStdString(PyObject* obj);

// \brief Call str() on the given object and return the result as a std::string
ARROW_EXPORT
ARROW_PYTHON_EXPORT
Status PyObject_StdStringStr(PyObject* obj, std::string* out);

// \brief Return the repr() of the given object (always succeeds)
ARROW_EXPORT
ARROW_PYTHON_EXPORT
std::string PyObject_StdStringRepr(PyObject* obj);

// \brief Cast the given size to int32_t, with error checking
Expand All @@ -121,12 +121,12 @@ inline Status CastSize(Py_ssize_t size, int32_t* out,

// \brief Print the Python object's __str__ form along with the passed error
// message
ARROW_EXPORT
ARROW_PYTHON_EXPORT
Status InvalidValue(PyObject* obj, const std::string& why);

ARROW_EXPORT
ARROW_PYTHON_EXPORT
Status IntegerScalarToDoubleSafe(PyObject* obj, double* result);
ARROW_EXPORT
ARROW_PYTHON_EXPORT
Status IntegerScalarToFloat32Safe(PyObject* obj, float* result);

} // namespace internal
Expand Down
6 changes: 3 additions & 3 deletions cpp/src/arrow/python/inference.cc
Expand Up @@ -583,13 +583,13 @@ Status InferArrowTypeAndSize(PyObject* obj, int64_t* size,
return Status::OK();
}

ARROW_EXPORT
ARROW_PYTHON_EXPORT
bool IsPyBool(PyObject* obj) { return internal::PyBoolScalar_Check(obj); }

ARROW_EXPORT
ARROW_PYTHON_EXPORT
bool IsPyInt(PyObject* obj) { return internal::PyIntScalar_Check(obj); }

ARROW_EXPORT
ARROW_PYTHON_EXPORT
bool IsPyFloat(PyObject* obj) { return internal::PyFloatScalar_Check(obj); }

} // namespace py
Expand Down

0 comments on commit 91dbea8

Please sign in to comment.