aboutsummaryrefslogtreecommitdiff
path: root/.venv/lib/python3.12/site-packages/greenlet/greenlet_allocator.hpp
diff options
context:
space:
mode:
authorS. Solomon Darnell2025-03-28 21:52:21 -0500
committerS. Solomon Darnell2025-03-28 21:52:21 -0500
commit4a52a71956a8d46fcb7294ac71734504bb09bcc2 (patch)
treeee3dc5af3b6313e921cd920906356f5d4febc4ed /.venv/lib/python3.12/site-packages/greenlet/greenlet_allocator.hpp
parentcc961e04ba734dd72309fb548a2f97d67d578813 (diff)
downloadgn-ai-master.tar.gz
two version of R2R are hereHEADmaster
Diffstat (limited to '.venv/lib/python3.12/site-packages/greenlet/greenlet_allocator.hpp')
-rw-r--r--.venv/lib/python3.12/site-packages/greenlet/greenlet_allocator.hpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/.venv/lib/python3.12/site-packages/greenlet/greenlet_allocator.hpp b/.venv/lib/python3.12/site-packages/greenlet/greenlet_allocator.hpp
new file mode 100644
index 00000000..b452f544
--- /dev/null
+++ b/.venv/lib/python3.12/site-packages/greenlet/greenlet_allocator.hpp
@@ -0,0 +1,63 @@
+#ifndef GREENLET_ALLOCATOR_HPP
+#define GREENLET_ALLOCATOR_HPP
+
+#define PY_SSIZE_T_CLEAN
+#include <Python.h>
+#include <memory>
+#include "greenlet_compiler_compat.hpp"
+
+
+namespace greenlet
+{
+ // This allocator is stateless; all instances are identical.
+ // It can *ONLY* be used when we're sure we're holding the GIL
+ // (Python's allocators require the GIL).
+ template <class T>
+ struct PythonAllocator : public std::allocator<T> {
+
+ PythonAllocator(const PythonAllocator& UNUSED(other))
+ : std::allocator<T>()
+ {
+ }
+
+ PythonAllocator(const std::allocator<T> other)
+ : std::allocator<T>(other)
+ {}
+
+ template <class U>
+ PythonAllocator(const std::allocator<U>& other)
+ : std::allocator<T>(other)
+ {
+ }
+
+ PythonAllocator() : std::allocator<T>() {}
+
+ T* allocate(size_t number_objects, const void* UNUSED(hint)=0)
+ {
+ void* p;
+ if (number_objects == 1)
+ p = PyObject_Malloc(sizeof(T));
+ else
+ p = PyMem_Malloc(sizeof(T) * number_objects);
+ return static_cast<T*>(p);
+ }
+
+ void deallocate(T* t, size_t n)
+ {
+ void* p = t;
+ if (n == 1) {
+ PyObject_Free(p);
+ }
+ else
+ PyMem_Free(p);
+ }
+ // This member is deprecated in C++17 and removed in C++20
+ template< class U >
+ struct rebind {
+ typedef PythonAllocator<U> other;
+ };
+
+ };
+}
+
+#endif