aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-09-08 22:38:36 +0200
committerJay Berkenbilt <ejb@ql.org>2022-09-08 23:35:27 +0200
commitb0f054e600bd07f540ac0a081dd8b5a8cc561617 (patch)
tree5e539e77e5b2fc3f54e1380eb2b9877662bc43ef /libqpdf
parent5911a348a5ae9065610be5fe5f251cab399a52b8 (diff)
downloadqpdf-b0f054e600bd07f540ac0a081dd8b5a8cc561617.tar.zst
Add ability to initialize Pl_Function with a C-style function
Diffstat (limited to 'libqpdf')
-rw-r--r--libqpdf/Pl_Function.cc30
1 files changed, 30 insertions, 0 deletions
diff --git a/libqpdf/Pl_Function.cc b/libqpdf/Pl_Function.cc
index 32fcccf1..5f2dc042 100644
--- a/libqpdf/Pl_Function.cc
+++ b/libqpdf/Pl_Function.cc
@@ -15,6 +15,36 @@ Pl_Function::Pl_Function(char const* identifier, Pipeline* next, writer_t fn) :
{
}
+Pl_Function::Pl_Function(
+ char const* identifier, Pipeline* next, writer_c_t fn, void* udata) :
+ Pipeline(identifier, next),
+ m(new Members(nullptr))
+{
+ m->fn = [identifier, fn, udata](unsigned char const* data, size_t len) {
+ int code = fn(data, len, udata);
+ if (code != 0) {
+ throw std::runtime_error(
+ std::string(identifier) + " function returned code " +
+ QUtil::int_to_string(code));
+ }
+ };
+}
+
+Pl_Function::Pl_Function(
+ char const* identifier, Pipeline* next, writer_c_char_t fn, void* udata) :
+ Pipeline(identifier, next),
+ m(new Members(nullptr))
+{
+ m->fn = [identifier, fn, udata](unsigned char const* data, size_t len) {
+ int code = fn(reinterpret_cast<char const*>(data), len, udata);
+ if (code != 0) {
+ throw std::runtime_error(
+ std::string(identifier) + " function returned code " +
+ QUtil::int_to_string(code));
+ }
+ };
+}
+
Pl_Function::~Pl_Function()
{
// Must be explicit and not inline -- see QPDF_DLL_CLASS in