@@ -198,165 +198,6 @@ class MemoryAllocator {
198
198
int32_t prof_id_ = -1 ;
199
199
};
200
200
201
- #if ET_HAVE_GNU_STATEMENT_EXPRESSIONS
202
- /* *
203
- * Tries allocating from the specified MemoryAllocator*.
204
- *
205
- * - On success, returns a pointer to the allocated buffer.
206
- * - On failure, executes the provided code block, which must return or panic.
207
- *
208
- * Example:
209
- * @code
210
- * char* buf = ET_TRY_ALLOCATE_OR(
211
- * memory_allocator, bufsize, {
212
- * *out_err = Error::MemoryAllocationFailed;
213
- * return nullopt;
214
- * });
215
- * @endcode
216
- */
217
- #define ET_TRY_ALLOCATE_OR (memory_allocator__, nbytes__, ...) \
218
- ({ \
219
- void * et_try_allocate_result = memory_allocator__->allocate (nbytes__); \
220
- if (et_try_allocate_result == nullptr && nbytes__ > 0 ) { \
221
- __VA_ARGS__ \
222
- /* The args must return. */ \
223
- ET_UNREACHABLE (); \
224
- } \
225
- et_try_allocate_result; \
226
- })
227
-
228
- /* *
229
- * Tries allocating an instance of type__ from the specified MemoryAllocator*.
230
- *
231
- * - On success, returns a pointer to the allocated buffer. Note that the memory
232
- * will not be initialized.
233
- * - On failure, executes the provided code block, which must return or panic.
234
- *
235
- * Example:
236
- * @code
237
- * char* buf = ET_TRY_ALLOCATE_INSTANCE_OR(
238
- * memory_allocator,
239
- * MyType,
240
- * { *out_err = Error::MemoryAllocationFailed; return nullopt; });
241
- * @endcode
242
- */
243
- #define ET_TRY_ALLOCATE_INSTANCE_OR (memory_allocator__, type__, ...) \
244
- ({ \
245
- type__* et_try_allocate_result = \
246
- memory_allocator__->allocateInstance <type__>(); \
247
- if (et_try_allocate_result == nullptr ) { \
248
- __VA_ARGS__ \
249
- /* The args must return. */ \
250
- ET_UNREACHABLE (); \
251
- } \
252
- et_try_allocate_result; \
253
- })
254
-
255
- /* *
256
- * Tries allocating multiple elements of a given type from the specified
257
- * MemoryAllocator*.
258
- *
259
- * - On success, returns a pointer to the allocated buffer.
260
- * - On failure, executes the provided code block, which must return or panic.
261
- *
262
- * Example:
263
- * @code
264
- * Tensor* tensor_list = ET_TRY_ALLOCATE_LIST_OR(
265
- * memory_allocator, Tensor, num_tensors, {
266
- * *out_err = Error::MemoryAllocationFailed;
267
- * return nullopt;
268
- * });
269
- * @endcode
270
- */
271
- #define ET_TRY_ALLOCATE_LIST_OR (memory_allocator__, type__, nelem__, ...) \
272
- ({ \
273
- type__* et_try_allocate_result = \
274
- memory_allocator__->allocateList <type__>(nelem__); \
275
- if (et_try_allocate_result == nullptr && nelem__ > 0 ) { \
276
- __VA_ARGS__ \
277
- /* The args must return. */ \
278
- ET_UNREACHABLE (); \
279
- } \
280
- et_try_allocate_result; \
281
- })
282
- #else // !ET_HAVE_GNU_STATEMENT_EXPRESSIONS
283
- /* *
284
- * The recommended alternative for statement expression-incompatible compilers
285
- * is to directly allocate the memory.
286
- */
287
- #define ET_TRY_ALLOCATE_OR (memory_allocator__, nbytes__, ...) \
288
- memory_allocator__->allocate (nbytes__);
289
-
290
- /* *
291
- * The recommended alternative for statement expression-incompatible compilers
292
- * is to directly allocate the memory.
293
- */
294
- #define ET_TRY_ALLOCATE_INSTANCE_OR (memory_allocator__, type__, ...) \
295
- memory_allocator__->allocateInstance<type__>();
296
-
297
- /* *
298
- * The recommended alternative for statement expression-incompatible compilers
299
- * is to directly use allocate the memory.
300
- */
301
- #define ET_TRY_ALLOCATE_LIST_OR (memory_allocator__, type__, nelem__, ...) \
302
- memory_allocator__->allocateList<type__>(nelem__);
303
-
304
- #endif // !ET_HAVE_GNU_STATEMENT_EXPRESSIONS
305
-
306
- /* *
307
- * Tries allocating from the specified MemoryAllocator*.
308
- *
309
- * - On success, returns a pointer to the allocated buffer.
310
- * - On failure, returns `Error::MemoryAllocationFailed` from the calling
311
- * function, which must be declared to return `executorch::runtime::Error`.
312
- *
313
- * Example:
314
- * @code
315
- * char* buf = ET_ALLOCATE_OR_RETURN_ERROR(memory_allocator, bufsize);
316
- * @endcode
317
- */
318
- #define ET_ALLOCATE_OR_RETURN_ERROR (memory_allocator__, nbytes__ ) \
319
- ET_TRY_ALLOCATE_OR (memory_allocator__, nbytes__, { \
320
- return ::executorch::runtime::Error::MemoryAllocationFailed; \
321
- })
322
-
323
- /* *
324
- * Tries allocating an instance of type__ from the specified MemoryAllocator*.
325
- *
326
- * - On success, returns a pointer to the allocated buffer. Note that the memory
327
- * will not be initialized.
328
- * - On failure, returns `Error::MemoryAllocationFailed` from the calling
329
- * function, which must be declared to return `executorch::runtime::Error`.
330
- *
331
- * Example:
332
- * @code
333
- * char* buf = ET_ALLOCATE_INSTANCE_OR_RETURN_ERROR(memory_allocator, MyType);
334
- * @endcode
335
- */
336
- #define ET_ALLOCATE_INSTANCE_OR_RETURN_ERROR (memory_allocator__, type__ ) \
337
- ET_TRY_ALLOCATE_INSTANCE_OR (memory_allocator__, type__, { \
338
- return ::executorch::runtime::Error::MemoryAllocationFailed; \
339
- })
340
-
341
- /* *
342
- * Tries allocating multiple elements of a given type from the specified
343
- * MemoryAllocator*.
344
- *
345
- * - On success, returns a pointer to the allocated buffer.
346
- * - On failure, returns `Error::MemoryAllocationFailed` from the calling
347
- * function, which must be declared to return `executorch::runtime::Error`.
348
- *
349
- * Example:
350
- * @code
351
- * Tensor* tensor_list = ET_ALLOCATE_LIST_OR_RETURN_ERROR(
352
- * memory_allocator, Tensor, num_tensors);
353
- * @endcode
354
- */
355
- #define ET_ALLOCATE_LIST_OR_RETURN_ERROR (memory_allocator__, type__, nelem__ ) \
356
- ET_TRY_ALLOCATE_LIST_OR (memory_allocator__, type__, nelem__, { \
357
- return ::executorch::runtime::Error::MemoryAllocationFailed; \
358
- })
359
-
360
201
} // namespace runtime
361
202
} // namespace executorch
362
203
0 commit comments