Skip to content

Commit

Permalink
fix string
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippGrulich committed Aug 16, 2024
1 parent 3b68608 commit 555f91d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
9 changes: 5 additions & 4 deletions nautilus/include/nautilus/function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@

namespace nautilus {

[[maybe_unused]] static uint64_t func_counter;

template <typename R, typename... FunctionArguments>
std::string getFunctionName(R (*fnptr)(FunctionArguments...)) {
Dl_info info;
dladdr(reinterpret_cast<void*>(fnptr), &info);
if (info.dli_sname != nullptr) {
return info.dli_sname;
}
return "xxx";
return "func" + std::to_string(func_counter++);
}

template <typename R, typename... FunctionArguments>
Expand Down Expand Up @@ -73,8 +75,7 @@ auto getArgumentReferences(std::string_view, void*, const ValueArguments&... arg
template <typename R, typename... FunctionArguments>
class CallableRuntimeFunction {
public:
explicit CallableRuntimeFunction(R (*fnptr)(FunctionArguments...), std::string& functionName)
: fnptr(fnptr), functionName(functionName) {};
explicit CallableRuntimeFunction(R (*fnptr)(FunctionArguments...), std::string& functionName) : fnptr(fnptr), functionName(functionName) {};

template <typename Arg>
auto transform(Arg argument) {
Expand Down Expand Up @@ -105,7 +106,7 @@ class CallableRuntimeFunction {
auto ptr = (void*) fnptr;
auto functionArgumentReferences = getArgumentReferences("functionName", (void*) fnptr, args...);
tracing::traceCall(functionName, ptr, Type::v, functionArgumentReferences);
return;
return;
}
#endif
fnptr(transform((args))...);
Expand Down
12 changes: 6 additions & 6 deletions nautilus/include/nautilus/std/ostream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,25 +88,25 @@ class val<std::basic_ostream<CharT, Traits>> {
static void pipe(std::basic_ostream<CharT, Traits>* ptr, T value) {
auto& s = *ptr;
s << value;
};
}

static void flash(std::basic_ostream<CharT, Traits>* ptr) {
ptr->flush();
};
}

static void put(std::basic_ostream<CharT, Traits>* ptr, CharT ch) {
ptr->put(ch);
};
}
static void write(std::basic_ostream<CharT, Traits>* ptr, const CharT* ch, size_t count) {
ptr->write(ch, count);
};
}

static void tellp(std::basic_ostream<CharT, Traits>* ptr) {
ptr->tellp();
};
}
static void seekp(std::basic_ostream<CharT, Traits>* ptr, typename Traits::pos_type pos) {
ptr->seekp(pos);
};
}
};

} // namespace nautilus
6 changes: 3 additions & 3 deletions nautilus/include/nautilus/std/string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class val<std::basic_string<CharT, Traits>> {
using const_pointer = typename base_type::const_pointer;

public:
val<std::basic_string<CharT, Traits>>(val<std::basic_string<CharT, Traits>*> str) : data_ptr(str) {
val(val<std::basic_string<CharT, Traits>*> str) : data_ptr(str) {
}
val<std::basic_string<CharT, Traits>>(val<const CharT*> s) : data_ptr(nullptr) {
val(val<const CharT*> s) : data_ptr(nullptr) {
data_ptr = invoke(+[](const CharT* s) -> base_type* { return new base_type(s); }, s);
}

Expand Down Expand Up @@ -110,7 +110,7 @@ class val<std::basic_string<CharT, Traits>> {
return invoke(+[](base_type* ptr) -> size_type { return ptr->capacity(); }, data_ptr);
}

~val<std::basic_string<CharT, Traits>>() {
~val() {
invoke(+[](base_type* ptr) -> void { delete ptr; }, data_ptr);
}

Expand Down
6 changes: 3 additions & 3 deletions nautilus/include/nautilus/std/string_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ class val<std::basic_string_view<CharT, Traits>> {
using pointer = typename base_type::pointer;
using const_pointer = typename base_type::const_pointer;

val<std::basic_string_view<CharT, Traits>>() : data_ptr(nullptr) {
val() : data_ptr(nullptr) {
auto string_vew = new std::basic_string_view<CharT, Traits>();
data_ptr = val<base_type*>(string_vew);
}

val<std::basic_string_view<CharT, Traits>>(val<const CharT*> s, val<size_type> count) : data_ptr(nullptr) {
val(val<const CharT*> s, val<size_type> count) : data_ptr(nullptr) {
// call new on val<base_type *>
auto raw_s = details::getRawValue(s);
auto raw_count = details::getRawValue(count);
auto string_vew = new std::basic_string_view<CharT, Traits>(raw_s, raw_count);
data_ptr = val<base_type*>(string_vew);
}

val<std::basic_string_view<CharT, Traits>>(val<const CharT*> s) : data_ptr(nullptr) {
val(val<const CharT*> s) : data_ptr(nullptr) {
// call new on val<base_type *>
//auto raw_s = details::getRawValue(s);
//auto string_vew = new std::basic_string_view<CharT, Traits>(raw_s);
Expand Down

0 comments on commit 555f91d

Please sign in to comment.