[libc-commits] [libc] [llvm] [libc] Make rpc_server.h independent from libc internals (PR #190423)
Matt Arsenault via libc-commits
libc-commits at lists.llvm.org
Mon Apr 6 07:31:07 PDT 2026
================
@@ -9,15 +9,778 @@
#ifndef LLVM_LIBC_SHARED_RPC_SERVER_H
#define LLVM_LIBC_SHARED_RPC_SERVER_H
-#include "libc_common.h"
-#include "src/__support/RPC/rpc_server.h"
+#include "rpc.h"
+#include "rpc_opcodes.h"
-namespace LIBC_NAMESPACE_DECL {
-namespace shared {
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
-using LIBC_NAMESPACE::rpc::handle_libc_opcodes;
+#ifdef _WIN32
+#define flockfile _lock_file
+#define funlockfile _unlock_file
+#define fwrite_unlocked _fwrite_nolock
+#endif
-} // namespace shared
-} // namespace LIBC_NAMESPACE_DECL
+namespace rpc {
+
+// Minimal replacement for 'std::vector' that works for trivial types.
+template <typename T> class TempVector {
+ T *data_;
+ size_t current;
+ size_t capacity;
+
+public:
+ inline TempVector() : data_(nullptr), current(0), capacity(0) {}
+
+ inline ~TempVector() { free(data_); }
+
+ inline void push_back(const T &value) {
+ if (current == capacity)
+ grow();
+ data_[current++] = value;
+ }
+
+ inline void pop_back() { --current; }
+
+ inline bool empty() const { return current == 0; }
+
+ inline size_t size() const { return current; }
+
+ inline T &operator[](size_t index) { return data_[index]; }
+
+ inline T &back() { return data_[current - 1]; }
+
+private:
+ inline void grow() {
+ size_t new_capacity = capacity ? capacity * 2 : 1;
+ void *new_data = realloc(data_, new_capacity * sizeof(T));
+ data_ = static_cast<T *>(new_data);
+ capacity = new_capacity;
+ }
+};
+
+struct TempStorage {
+ inline char *alloc(size_t size) {
+ storage.push_back(reinterpret_cast<char *>(malloc(size)));
+ return storage.back();
+ }
+
+ inline ~TempStorage() {
+ for (size_t i = 0; i < storage.size(); ++i)
----------------
arsenm wrote:
Range loop
https://github.com/llvm/llvm-project/pull/190423
More information about the libc-commits
mailing list