Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7757912

Browse files
authored
feat/fix/chore: various improvements (#16)
* fix: header cleanup and fixes to manifest and current pluginmanifest - serialize the header value correctlycurrent_plugin - when outputting, check against output range correctly* feat: Plugin::reset, std::move with plugin* fix: Function namespace constructor - actually construct* protect Buffer class members* chore: remove ManifestKey, the size of the stl containers and std::optional is sufficient to check if an item is empty* chore: use std::unique_ptr to manage plugin lifetime instead of destructor. prevents copying Plugin* chore: make std::string no longer required for plugin calls* feat: implement WasmSourceBytes* chore: make jsoncpp a private dependency* chore: move Plugin::CancelHandle::cancel out of header* chore: only use ExtismSize with libextism api / use size_t when referring to items in native memory* fix: callback on osx?* chore: return false in CurrentPlugin::Output if out of bounds, std::move and std::string_view cleanup
1 parent9477fef commit7757912

File tree

8 files changed

+330
-201
lines changed

8 files changed

+330
-201
lines changed

‎CMakeLists.txt‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.18)
22
include_guard(GLOBAL)
3-
set (CMAKE_CXX_STANDARD14)
3+
set (CMAKE_CXX_STANDARD17)
44

55
# extism-cpp library
66
project(extism-cppVERSION 1.0.0 DESCRIPTION"C++ bindings for libextism")
@@ -51,7 +51,8 @@ set_target_properties(extism-cpp PROPERTIES PUBLIC_HEADER src/extism.hpp)
5151
target_include_directories(extism-cppPUBLIC
5252
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
5353
)
54-
target_link_libraries(extism-cppPUBLIC extism-shared jsoncpp_lib)
54+
target_link_libraries(extism-cppPUBLIC extism-shared)
55+
target_link_libraries(extism-cppPRIVATE jsoncpp_lib)
5556
set_target_properties(extism-cpp
5657
PROPERTIESNO_SONAME 1
5758
)
@@ -68,10 +69,10 @@ target_include_directories(extism-cpp-static PUBLIC
6869
)
6970
target_link_libraries(extism-cpp-staticPUBLIC extism-static)
7071
if(TARGET jsoncpp_static)
71-
target_link_libraries(extism-cpp-staticPUBLIC jsoncpp_static)
72+
target_link_libraries(extism-cpp-staticPRIVATE jsoncpp_static)
7273
else()
7374
message(WARNING"jsoncpp_static not found, linking jsoncpp_lib instead")
74-
target_link_libraries(extism-cpp-staticPUBLIC jsoncpp_lib)
75+
target_link_libraries(extism-cpp-staticPRIVATE jsoncpp_lib)
7576
endif()
7677
configure_file(extism-cpp-static.pc.in extism-cpp-static.pc @ONLY)
7778
list(APPEND CMAKE_TARGETS extism-cpp-static)

‎example.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ int main(int argc, char *argv[]) {
3939
Pluginplugin(wasm,true, functions);
4040

4141
constchar *input = argc >1 ? argv[1] :"this is a test";
42-
ExtismSize length =strlen(input);
42+
size_t length =strlen(input);
4343

4444
extism::Buffer output = plugin.call("count_vowels", (uint8_t *)input, length);
4545
std::cout << (char *)output.data << std::endl;

‎src/current_plugin.cpp‎

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
11

22
#include"extism.hpp"
3+
#include<cstring>
4+
#include<string_view>
35

46
namespaceextism {
57

6-
uint8_t *CurrentPlugin::memory() {
8+
uint8_t *CurrentPlugin::memory()const{
79
returnextism_current_plugin_memory(this->pointer);
810
}
9-
uint8_t *CurrentPlugin::memory(MemoryHandle offs) {
11+
uint8_t *CurrentPlugin::memory(MemoryHandle offs)const{
1012
returnthis->memory() + offs;
1113
}
1214

13-
ExtismSizeCurrentPlugin::memoryLength(MemoryHandle offs) {
15+
ExtismSizeCurrentPlugin::memoryLength(MemoryHandle offs)const{
1416
returnextism_current_plugin_memory_length(this->pointer, offs);
1517
}
1618

17-
MemoryHandleCurrentPlugin::memoryAlloc(ExtismSize size) {
19+
MemoryHandleCurrentPlugin::memoryAlloc(ExtismSize size)const{
1820
returnextism_current_plugin_memory_alloc(this->pointer, size);
1921
}
2022

21-
voidCurrentPlugin::memoryFree(MemoryHandle handle) {
23+
voidCurrentPlugin::memoryFree(MemoryHandle handle)const{
2224
extism_current_plugin_memory_free(this->pointer, handle);
2325
}
2426

25-
voidCurrentPlugin::output(const std::string &s,size_t index) {
26-
this->output((constuint8_t *)s.c_str(), s.size(), index);
27+
boolCurrentPlugin::output(std::string_view s,size_t index)const {
28+
returnthis->output(reinterpret_cast<constuint8_t *>(s.data()), s.size(),
29+
index);
2730
}
2831

29-
voidCurrentPlugin::output(constuint8_t *bytes,size_t len,size_t index) {
30-
if (index <this->nInputs) {
32+
boolCurrentPlugin::output(constuint8_t *bytes,size_t len,
33+
size_t index)const {
34+
if (index <this->nOutputs) {
3135
auto offs =this->memoryAlloc(len);
3236
memcpy(this->memory() + offs, bytes, len);
3337
this->outputs[index].v.i64 = offs;
38+
returntrue;
3439
}
40+
returnfalse;
3541
}
3642

37-
voidCurrentPlugin::output(const Json::Value &&v,size_t index) {
38-
Json::FastWriter writer;
39-
const std::string s = writer.write(v);
40-
this->output(s, index);
41-
}
42-
43-
uint8_t *CurrentPlugin::inputBytes(size_t *length,size_t index) {
43+
uint8_t *CurrentPlugin::inputBytes(size_t *length,size_t index)const {
4444
if (index >=this->nInputs) {
4545
returnnullptr;
4646
}
@@ -54,27 +54,27 @@ uint8_t *CurrentPlugin::inputBytes(size_t *length, size_t index) {
5454
returnthis->memory() + inp.v.i64;
5555
}
5656

57-
BufferCurrentPlugin::inputBuffer(size_t index) {
57+
BufferCurrentPlugin::inputBuffer(size_t index)const{
5858
size_t length =0;
5959
auto ptr =inputBytes(&length, index);
6060
returnBuffer(ptr, length);
6161
}
6262

63-
std::stringCurrentPlugin::inputString(size_t index) {
63+
std::string_viewCurrentPlugin::inputStringView(size_t index)const {
6464
size_t length =0;
65-
char *buf =(char *)this->inputBytes(&length, index);
66-
returnstd::string(buf, length);
65+
autobuf =reinterpret_cast<char *>(this->inputBytes(&length, index));
66+
returnstd::string_view(buf, length);
6767
}
6868

69-
const Val &CurrentPlugin::inputVal(size_t index) {
69+
const Val &CurrentPlugin::inputVal(size_t index)const{
7070
if (index >= nInputs) {
7171
throwError("Input out of bounds");
7272
}
7373

7474
returnthis->inputs[index];
7575
}
7676

77-
Val &CurrentPlugin::outputVal(size_t index) {
77+
Val &CurrentPlugin::outputVal(size_t index)const{
7878
if (index >= nOutputs) {
7979
throwError("Output out of bounds");
8080
}

‎src/extism.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ inline bool setLogFile(const char *filename, const char *level) {
88
}
99

1010
// Get libextism version
11-
inline std::stringversion() {returnstd::string(extism_version()); }
11+
inline std::string_viewversion() {returnextism_version(); }
1212
};// namespace extism

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp