Skip to content

Commit

Permalink
Merge branch 'main' into fix-burst-in-ws
Browse files Browse the repository at this point in the history
  • Loading branch information
wrieg123 authored Aug 9, 2024
2 parents e91797b + 5c081d8 commit 52b48d7
Show file tree
Hide file tree
Showing 63 changed files with 979 additions and 1,194 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ else()
if(CSP_BUILD_NO_CXX_ABI)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=0")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
if (COVERAGE)
# TODO windows
add_compile_options(--coverage)
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ build-debug: ## build the library ( DEBUG ) - May need a make clean when switch
build-conda: ## build the library in Conda
python setup.py build build_ext --csp-no-vcpkg --inplace

build-conda-debug: ## build the library ( DEBUG ) - in Conda
SKBUILD_CONFIGURE_OPTIONS="" DEBUG=1 python setup.py build build_ext --csp-no-vcpkg --inplace

install: ## install library
python -m pip install .

Expand Down
1 change: 0 additions & 1 deletion conda/dev-environment-unix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ dependencies:
- ruamel.yaml
- ruff>=0.3,<0.4
- scikit-build
- slack-sdk
- sqlalchemy
- tar
- threadpoolctl
Expand Down
1 change: 0 additions & 1 deletion conda/dev-environment-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ dependencies:
- ruamel.yaml
- ruff>=0.3,<0.4
- scikit-build
- slack-sdk
- sqlalchemy
- threadpoolctl
- tornado
Expand Down
2 changes: 1 addition & 1 deletion cpp/csp/adapters/kafka/KafkaAdapterManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct KafkaStatusMessageTypeTraits
using KafkaStatusMessageType = csp::Enum<KafkaStatusMessageTypeTraits>;

//Top level AdapterManager object for all kafka adapters in the engine
class KafkaAdapterManager final : public csp::AdapterManager
class CSP_PUBLIC KafkaAdapterManager final : public csp::AdapterManager
{
public:
KafkaAdapterManager( csp::Engine * engine, const Dictionary & properties );
Expand Down
4 changes: 2 additions & 2 deletions cpp/csp/adapters/parquet/DialectGenericListReaderInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class DialectGenericListReaderInterface
};

template< typename T >
class TypedDialectGenericListReaderInterface : public DialectGenericListReaderInterface
class CSP_PUBLIC TypedDialectGenericListReaderInterface : public DialectGenericListReaderInterface
{
public:
using Ptr = std::shared_ptr<TypedDialectGenericListReaderInterface<T>>;
Expand All @@ -45,4 +45,4 @@ class TypedDialectGenericListReaderInterface : public DialectGenericListReaderIn

}

#endif
#endif
2 changes: 1 addition & 1 deletion cpp/csp/adapters/parquet/ParquetInputAdapterManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace csp::adapters::parquet


//Top level AdapterManager object for all parquet adapters in the engine
class ParquetInputAdapterManager final : public csp::AdapterManager
class CSP_PUBLIC ParquetInputAdapterManager final : public csp::AdapterManager
{
public:
using GeneratorPtr = csp::Generator<std::string, csp::DateTime, csp::DateTime>::Ptr;
Expand Down
2 changes: 1 addition & 1 deletion cpp/csp/adapters/parquet/ParquetOutputAdapterManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ParquetOutputFilenameAdapter;
class ParquetDictBasketOutputWriter;

//Top level AdapterManager object for all parquet adapters in the engine
class ParquetOutputAdapterManager final : public csp::AdapterManager
class CSP_PUBLIC ParquetOutputAdapterManager final : public csp::AdapterManager
{
public:
using FileVisitorCallback = std::function<void(const std::string &)>;
Expand Down
2 changes: 1 addition & 1 deletion cpp/csp/adapters/parquet/ParquetReaderColumnAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ void ListColumnAdapter<ValueArrayType, ValueType>::readCurValue()
if( this -> m_curChunkArray -> IsValid( curRow ) )
{
auto values = this -> m_curChunkArray -> value_slice( curRow );
auto typedValues = std::dynamic_pointer_cast<ValueArrayType>( values );
auto typedValues = std::static_pointer_cast<ValueArrayType>( values );

auto arrayValue = m_listReader -> create( typedValues -> length() );
auto* internalBuffer = m_listReader -> getRawDataBuffer( arrayValue );
Expand Down
6 changes: 2 additions & 4 deletions cpp/csp/adapters/websocket/ClientAdapterManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ struct WebsocketClientStatusTypeTraits

using ClientStatusType = Enum<WebsocketClientStatusTypeTraits>;

class ClientAdapterManager final : public AdapterManager
class CSP_PUBLIC ClientAdapterManager final : public AdapterManager
{


public:
ClientAdapterManager(
Engine * engine,
Expand Down Expand Up @@ -78,4 +76,4 @@ class ClientAdapterManager final : public AdapterManager

}

#endif
#endif
4 changes: 2 additions & 2 deletions cpp/csp/core/Exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace csp
{

class Exception : public std::exception
class CSP_PUBLIC Exception : public std::exception
{
public:
Exception( const char * exType, const std::string & description, const char * file, const char * func, int line ) :
Expand Down Expand Up @@ -59,7 +59,7 @@ class Exception : public std::exception
};

#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
#define CSP_DECLARE_EXCEPTION( DerivedException, BaseException ) class DerivedException : public BaseException { public: DerivedException( const char * exType, const std::string &r, const char * file, const char * func, int line ) : BaseException( exType, r, file, func, line ) {} };
#define CSP_DECLARE_EXCEPTION( DerivedException, BaseException ) class CSP_PUBLIC DerivedException : public BaseException { public: DerivedException( const char * exType, const std::string &r, const char * file, const char * func, int line ) : BaseException( exType, r, file, func, line ) {} };

CSP_DECLARE_EXCEPTION( AssertionError, Exception )
CSP_DECLARE_EXCEPTION( RuntimeException, Exception )
Expand Down
10 changes: 6 additions & 4 deletions cpp/csp/core/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
#undef ERROR
#undef GetMessage

#define DLL_LOCAL
#define CSP_LOCAL
#define CSP_PUBLIC __declspec(dllexport)

#ifdef CSPTYPESIMPL_EXPORTS
#define CSPTYPESIMPL_EXPORT __declspec(dllexport)
Expand Down Expand Up @@ -90,10 +91,11 @@ inline uint8_t ffs(uint64_t n)

#else

#define CSPIMPL_EXPORT
#define CSPTYPESIMPL_EXPORT
#define CSPIMPL_EXPORT __attribute__ ((visibility ("default")))
#define CSPTYPESIMPL_EXPORT __attribute__ ((visibility ("default")))

#define DLL_LOCAL __attribute__ ((visibility ("hidden")))
#define CSP_LOCAL __attribute__ ((visibility ("hidden")))
#define CSP_PUBLIC __attribute__ ((visibility ("default")))

#define START_PACKED
#define END_PACKED __attribute__((packed))
Expand Down
2 changes: 1 addition & 1 deletion cpp/csp/engine/AdapterManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ bool ManagedSimInputAdapter::pushNullTick()
return true;
}

class AdapterManager : public EngineOwned
class CSP_PUBLIC AdapterManager : public EngineOwned
{
public:
AdapterManager( csp::Engine * );
Expand Down
2 changes: 1 addition & 1 deletion cpp/csp/engine/Feedback.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class FeedbackOutputAdapter final : public OutputAdapter
};

template<typename T>
class FeedbackInputAdapter final : public InputAdapter
class CSP_PUBLIC FeedbackInputAdapter final : public InputAdapter
{
public:
using InputAdapter::InputAdapter;
Expand Down
4 changes: 2 additions & 2 deletions cpp/csp/engine/Struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -756,13 +756,13 @@ class Struct
void decref()
{
//Work around GCC12 bug mis-identifying this code as use-after-free
#ifdef __linux__
#if defined(__linux__) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wuse-after-free"
#endif
if( --hidden() -> refcount == 0 )
delete this;
#ifdef __linux__
#if defined(__linux__) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif
}
Expand Down
14 changes: 12 additions & 2 deletions cpp/csp/python/Exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,28 @@
namespace csp::python
{

class PythonPassthrough : public csp::Exception
class CSP_PUBLIC PythonPassthrough : public csp::Exception
{
public:
PythonPassthrough( const char * exType, const std::string &r, const char * file,
const char * func, int line ) :
csp::Exception( exType, r, file, func, line )
{
//Fetch the current error to clear out the error indicator while the stack gets unwound
//We own the references to all the members assigned in PyErr_Fetch
//We need to hold the reference since PyErr_Restore takes back a reference to each of its arguments
PyErr_Fetch( &m_type, &m_value, &m_traceback );
}

PythonPassthrough( PyObject * pyException ) :
csp::Exception( "", "" )
{
// Note: all of these methods return strong references, so we own them like in the other constructor
m_type = PyObject_Type( pyException );
m_value = PyObject_Str( pyException );
m_traceback = PyException_GetTraceback( pyException );
}

void restore()
{
if( !description().empty() )
Expand All @@ -39,7 +50,6 @@ class PythonPassthrough : public csp::Exception
PyObject * m_type;
PyObject * m_value;
PyObject * m_traceback;

};

CSP_DECLARE_EXCEPTION( AttributeError, ::csp::Exception );
Expand Down
19 changes: 18 additions & 1 deletion cpp/csp/python/InitHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace csp::python
{

class DLL_LOCAL InitHelper
class CSP_LOCAL InitHelper
{
public:
~InitHelper() {}
Expand Down Expand Up @@ -111,4 +111,21 @@ inline bool InitHelper::execute( PyObject * module )
}

}

//PyMODINIT_FUNC in Python <3.9 doesn't export the function/make visible
//this is required since we build with hidden visibility by default
//the below macro code can be removed once 3.8 support is dropped
//
//see similar issues:
//https://github.com/scipy/scipy/issues/15996
//https://github.com/mesonbuild/meson/pull/10369

#if PY_VERSION_HEX < 0x03090000
#ifdef PyMODINIT_FUNC
#undef PyMODINIT_FUNC
#endif

#define PyMODINIT_FUNC extern "C" CSP_PUBLIC PyObject*
#endif

#endif
14 changes: 12 additions & 2 deletions cpp/csp/python/PyAdapterManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ class PyAdapterManager : public AdapterManager
static PyObject * PyAdapterManager_PyObject_starttime( PyAdapterManager_PyObject * self ) { return toPython( self -> manager -> starttime() ); }
static PyObject * PyAdapterManager_PyObject_endtime( PyAdapterManager_PyObject * self ) { return toPython( self -> manager -> endtime() ); }

static PyObject * PyAdapterManager_PyObject_shutdown_engine( PyAdapterManager_PyObject * self, PyObject * pyException )
{
CSP_BEGIN_METHOD;

self -> manager -> rootEngine() -> shutdown( PyEngine_shutdown_make_exception( pyException ) );

CSP_RETURN_NONE;
}

static int PyAdapterManager_init( PyAdapterManager_PyObject *self, PyObject *args, PyObject *kwds )
{
CSP_BEGIN_METHOD;
Expand All @@ -83,8 +92,9 @@ static int PyAdapterManager_init( PyAdapterManager_PyObject *self, PyObject *arg
}

static PyMethodDef PyAdapterManager_methods[] = {
{ "starttime", (PyCFunction) PyAdapterManager_PyObject_starttime, METH_NOARGS, "starttime" },
{ "endtime", (PyCFunction) PyAdapterManager_PyObject_endtime, METH_NOARGS, "endtime" },
{ "starttime", (PyCFunction) PyAdapterManager_PyObject_starttime, METH_NOARGS, "starttime" },
{ "endtime", (PyCFunction) PyAdapterManager_PyObject_endtime, METH_NOARGS, "endtime" },
{ "shutdown_engine", (PyCFunction) PyAdapterManager_PyObject_shutdown_engine, METH_O, "shutdown_engine" },
{NULL}
};

Expand Down
2 changes: 1 addition & 1 deletion cpp/csp/python/PyCspEnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct CSPTYPESIMPL_EXPORT PyCspEnumMeta : public PyHeapTypeObject
static PyTypeObject PyType;
};

//TODO Windows - need to figure out why adding DLL_PUBLIC to this class leads to weird compilation errors on CspEnumMeta's unordered_map...
//TODO Windows - need to figure out why adding CSP_PUBLIC to this class leads to weird compilation errors on CspEnumMeta's unordered_map...

//This is an extension of csp::CspEnumMeta for python dialect, we need it in order to
//keep a reference to the python enum type from conversion to/from csp::CspEnumMeta <-> PyObject properly
Expand Down
16 changes: 16 additions & 0 deletions cpp/csp/python/PyEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define _IN_CSP_PYTHON_PYENGINE_H

#include <csp/core/Time.h>
#include <csp/python/Exception.h>
#include <csp/engine/RootEngine.h>
#include <csp/python/PyObjectPtr.h>
#include <Python.h>
Expand Down Expand Up @@ -54,6 +55,21 @@ class CSPIMPL_EXPORT PyEngine final: public PyObject
Engine * m_engine;
};

inline std::exception_ptr PyEngine_shutdown_make_exception( PyObject * pyException )
{
if( !PyExceptionInstance_Check( pyException ) )
{
PyObjectPtr pyExceptionStr = PyObjectPtr::own( PyObject_Str( pyException ) );
if( !pyExceptionStr.ptr() )
CSP_THROW( PythonPassthrough, "" );
std::string pyExceptionString = PyUnicode_AsUTF8( pyExceptionStr.ptr() );
std::string desc = "Expected Exception object as argument for shutdown_engine: got " + pyExceptionString + " of type " + Py_TYPE( pyException ) -> tp_name;
return std::make_exception_ptr( csp::Exception( "TypeError", desc ) );
}
else
return std::make_exception_ptr( PythonPassthrough( pyException ) );
}

};

#endif
12 changes: 11 additions & 1 deletion cpp/csp/python/PyPushInputAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,21 @@ struct PyPushInputAdapter_PyObject
CSP_RETURN_NONE;
}

static PyObject * shutdown_engine( PyPushInputAdapter_PyObject * self, PyObject * pyException )
{
CSP_BEGIN_METHOD;

self -> adapter -> rootEngine() -> shutdown( PyEngine_shutdown_make_exception( pyException ) );

CSP_RETURN_NONE;
}

static PyTypeObject PyType;
};

static PyMethodDef PyPushInputAdapter_PyObject_methods[] = {
{ "push_tick", (PyCFunction) PyPushInputAdapter_PyObject::pushTick, METH_VARARGS, "push new tick" },
{ "push_tick", (PyCFunction) PyPushInputAdapter_PyObject::pushTick, METH_VARARGS, "push new tick" },
{ "shutdown_engine", (PyCFunction) PyPushInputAdapter_PyObject::shutdown_engine, METH_O, "shutdown_engine" },
{NULL}
};

Expand Down
14 changes: 12 additions & 2 deletions cpp/csp/python/PyPushPullInputAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,22 @@ struct PyPushPullInputAdapter_PyObject
CSP_RETURN_NONE;
}

static PyObject * shutdown_engine( PyPushPullInputAdapter_PyObject * self, PyObject * pyException )
{
CSP_BEGIN_METHOD;

self -> adapter -> rootEngine() -> shutdown( PyEngine_shutdown_make_exception( pyException ) );

CSP_RETURN_NONE;
}

static PyTypeObject PyType;
};

static PyMethodDef PyPushPullInputAdapter_PyObject_methods[] = {
{ "push_tick", (PyCFunction) PyPushPullInputAdapter_PyObject::pushTick, METH_VARARGS, "push new tick" },
{ "flag_replay_complete", (PyCFunction) PyPushPullInputAdapter_PyObject::flagReplayComplete, METH_VARARGS, "finish replay ticks" },
{ "push_tick", (PyCFunction) PyPushPullInputAdapter_PyObject::pushTick, METH_VARARGS, "push new tick" },
{ "flag_replay_complete", (PyCFunction) PyPushPullInputAdapter_PyObject::flagReplayComplete, METH_VARARGS, "finish replay ticks" },
{ "shutdown_engine", (PyCFunction) PyPushPullInputAdapter_PyObject::shutdown_engine, METH_O, "shutdown engine" },
{NULL}
};

Expand Down
2 changes: 1 addition & 1 deletion cpp/csp/python/adapters/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ if(CSP_BUILD_PARQUET_ADAPTER)
endif()
target_link_libraries(parquetadapterimpl csp_core csp_engine cspimpl csp_parquet_adapter)
target_include_directories(parquetadapterimpl PUBLIC ${ARROW_INCLUDE_DIR} ${PARQUET_INCLUDE_DIR} "${VENDORED_PYARROW_ROOT}")
target_compile_definitions(parquetadapterimpl PUBLIC ARROW_PYTHON_STATIC)
target_compile_definitions(parquetadapterimpl PUBLIC ARROW_PYTHON_STATIC -DARROW_PYTHON_EXPORT=)
install(TARGETS parquetadapterimpl RUNTIME DESTINATION ${CSP_RUNTIME_INSTALL_SUBDIR} )
endif()

Expand Down
Loading

0 comments on commit 52b48d7

Please sign in to comment.