-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move CPP functions wrapper to dedicated file (#452)
Move CPP function wrapper to dedicated file. Next, will do the same for the PG wrapper.
- Loading branch information
Showing
19 changed files
with
114 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#pragma once | ||
|
||
extern "C" { | ||
struct ErrorData; | ||
} | ||
|
||
namespace pgduckdb::pg { | ||
const char* GetErrorDataMessage(ErrorData* error_data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#pragma once | ||
|
||
extern "C" { | ||
#include "postgres.h" | ||
} | ||
|
||
namespace pgduckdb { | ||
|
||
template <typename Func, Func func, typename... FuncArgs> | ||
typename std::invoke_result<Func, FuncArgs...>::type | ||
__CPPFunctionGuard__(const char *func_name, FuncArgs... args) { | ||
const char *error_message = nullptr; | ||
try { | ||
return func(args...); | ||
} catch (duckdb::Exception &ex) { | ||
duckdb::ErrorData edata(ex.what()); | ||
error_message = pstrdup(edata.Message().c_str()); | ||
} catch (std::exception &ex) { | ||
const auto msg = ex.what(); | ||
if (msg[0] == '{') { | ||
duckdb::ErrorData edata(ex.what()); | ||
error_message = pstrdup(edata.Message().c_str()); | ||
} else { | ||
error_message = pstrdup(ex.what()); | ||
} | ||
} | ||
|
||
elog(ERROR, "(PGDuckDB/%s) %s", func_name, error_message); | ||
} | ||
|
||
} | ||
|
||
#define InvokeCPPFunc(FUNC, ...) pgduckdb::__CPPFunctionGuard__<decltype(&FUNC), &FUNC>(__FUNCTION__, __VA_ARGS__) | ||
|
||
// Wrappers | ||
|
||
#define DECLARE_PG_FUNCTION(func_name) \ | ||
PG_FUNCTION_INFO_V1(func_name); \ | ||
Datum func_name##_cpp(PG_FUNCTION_ARGS); \ | ||
Datum func_name(PG_FUNCTION_ARGS) { \ | ||
return InvokeCPPFunc(func_name##_cpp, fcinfo); \ | ||
} \ | ||
Datum func_name##_cpp(PG_FUNCTION_ARGS __attribute__((unused))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include "pgduckdb/pg/error_data.hpp" | ||
|
||
extern "C" { | ||
#include "postgres.h" | ||
} | ||
|
||
namespace pgduckdb::pg { | ||
const char* GetErrorDataMessage(ErrorData* error_data) { | ||
return error_data->message; | ||
} | ||
} // namespace pgduckdb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters