Skip to content

Commit b0027d5

Browse files
authored
Merge pull request #1682 from Shaikh-Ubaid/lcompilers_fast_alloc
Add back LCOMPILERS_FAST_ALLOC #ifdef
2 parents 3e8af73 + 471639b commit b0027d5

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ set(WITH_WHEREAMI yes
8989
set(WITH_ZLIB yes
9090
CACHE BOOL "Compile with ZLIB Library")
9191

92+
set(WITH_LCOMPILERS_FAST_ALLOC yes
93+
CACHE BOOL "Compile with fast allocator")
94+
9295
# Build to wasm
9396
set(LPYTHON_BUILD_TO_WASM no
9497
CACHE BOOL "Compile LPython To WASM")
@@ -97,6 +100,7 @@ if (LPYTHON_BUILD_TO_WASM)
97100
set(HAVE_BUILD_TO_WASM yes)
98101
SET(WITH_WHEREAMI no)
99102
SET(WITH_ZLIB no)
103+
SET(WITH_LCOMPILERS_FAST_ALLOC no)
100104
add_definitions("-DHAVE_BUILD_TO_WASM=1")
101105
endif()
102106

@@ -112,6 +116,10 @@ if (WITH_ZLIB)
112116
find_package(StaticZLIB REQUIRED)
113117
endif()
114118

119+
if (WITH_LCOMPILERS_FAST_ALLOC)
120+
add_definitions("-DLCOMPILERS_FAST_ALLOC=1")
121+
endif()
122+
115123
# LLVM
116124
set(WITH_LLVM no CACHE BOOL "Build with LLVM support")
117125
set(WITH_TARGET_AARCH64 no CACHE BOOL "Enable target AARCH64")

src/libasr/alloc.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,25 @@ class Allocator
5252
// force new_chunk() not to get inlined, but there is no standard way of
5353
// doing it. This try/catch approach effectively achieves the same using
5454
// standard C++.
55+
#ifdef LCOMPILERS_FAST_ALLOC
5556
try {
57+
#endif
5658
LCOMPILERS_ASSERT(start != nullptr);
5759
size_t addr = current_pos;
5860
current_pos += align(s);
59-
if (size_current() > size_total()) throw std::bad_alloc();
61+
if (size_current() > size_total()) {
62+
#ifdef LCOMPILERS_FAST_ALLOC
63+
throw std::bad_alloc();
64+
#else
65+
return new_chunk(s);
66+
#endif
67+
}
6068
return (void*)addr;
69+
#ifdef LCOMPILERS_FAST_ALLOC
6170
} catch (const std::bad_alloc &e) {
6271
return new_chunk(s);
6372
}
73+
#endif
6474
}
6575

6676
void *new_chunk(size_t s) {

0 commit comments

Comments
 (0)