Skip to content

Commit 68e97cd

Browse files
committed
Add StringPtr struct
1 parent 6334ea9 commit 68e97cd

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ target_sources(scratchcpp
3838
include/scratchcpp/value.h
3939
include/scratchcpp/valuedata.h
4040
include/scratchcpp/value_functions.h
41+
include/scratchcpp/stringptr.h
4142
include/scratchcpp/entity.h
4243
include/scratchcpp/variable.h
4344
include/scratchcpp/list.h

include/scratchcpp/stringptr.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
#pragma once
4+
5+
#include "global.h"
6+
7+
namespace libscratchcpp
8+
{
9+
10+
extern "C"
11+
{
12+
/*! \brief The StringPtr struct holds a string data pointer and string size */
13+
struct LIBSCRATCHCPP_EXPORT StringPtr
14+
{
15+
// NOTE: Constructors and destructors only work in C++ code and are not supposed to be used in LLVM IR
16+
StringPtr() = default;
17+
StringPtr(const StringPtr &) = delete;
18+
19+
~StringPtr()
20+
{
21+
if (data && allocatedSize > 0)
22+
free(data);
23+
}
24+
25+
// NOTE: Any changes must also be done in the LLVM code builder!
26+
char16_t *data = nullptr;
27+
size_t size = 0;
28+
size_t allocatedSize = 0;
29+
};
30+
}
31+
32+
} // namespace libscratchcpp

0 commit comments

Comments
 (0)