[libunwind] Use placement new to avoid dependency C++ library

The rest of libunwind already uses placement new, these are the only
places where non-placement new is being used introducing undesirable
C++ library dependency.

Differential Revision: https://reviews.llvm.org/D57251

llvm-svn: 352245
This commit is contained in:
Petr Hosek 2019-01-25 21:39:46 +00:00
parent 1f9bc2854f
commit 90bcfaa2a0
1 changed files with 10 additions and 7 deletions

View File

@ -14,8 +14,6 @@
#ifndef NDEBUG #ifndef NDEBUG
#include <cstdlib> // getenv #include <cstdlib> // getenv
#endif #endif
#include <new>
#include <algorithm>
#include "libunwind_ext.h" #include "libunwind_ext.h"
#include "config.h" #include "config.h"
@ -122,12 +120,14 @@ static bool is64bit(task_t task) {
_LIBUNWIND_EXPORT unw_addr_space_t unw_create_addr_space_for_task(task_t task) { _LIBUNWIND_EXPORT unw_addr_space_t unw_create_addr_space_for_task(task_t task) {
#if __i386__ #if __i386__
if (is64bit(task)) { if (is64bit(task)) {
unw_addr_space_x86_64 *as = new unw_addr_space_x86_64(task); unw_addr_space_x86_64 *as = malloc(sizeof(unw_addr_space_x86_64));
new (as) unw_addr_space_x86_64(task);
as->taskPort = task; as->taskPort = task;
as->cpuType = CPU_TYPE_X86_64; as->cpuType = CPU_TYPE_X86_64;
//as->oas //as->oas
} else { } else {
unw_addr_space_i386 *as = new unw_addr_space_i386(task); unw_addr_space_i386 *as = malloc(sizeof(unw_addr_space_i386));
new (as) unw_addr_space_i386(task);
as->taskPort = task; as->taskPort = task;
as->cpuType = CPU_TYPE_I386; as->cpuType = CPU_TYPE_I386;
//as->oas //as->oas
@ -144,18 +144,21 @@ _LIBUNWIND_EXPORT void unw_destroy_addr_space(unw_addr_space_t asp) {
#if __i386__ || __x86_64__ #if __i386__ || __x86_64__
case CPU_TYPE_I386: { case CPU_TYPE_I386: {
unw_addr_space_i386 *as = (unw_addr_space_i386 *)asp; unw_addr_space_i386 *as = (unw_addr_space_i386 *)asp;
delete as; as->~unw_addr_space_i386();
free(as);
} }
break; break;
case CPU_TYPE_X86_64: { case CPU_TYPE_X86_64: {
unw_addr_space_x86_64 *as = (unw_addr_space_x86_64 *)asp; unw_addr_space_x86_64 *as = (unw_addr_space_x86_64 *)asp;
delete as; as->~unw_addr_space_x86_64();
free(as);
} }
break; break;
#endif #endif
case CPU_TYPE_POWERPC: { case CPU_TYPE_POWERPC: {
unw_addr_space_ppc *as = (unw_addr_space_ppc *)asp; unw_addr_space_ppc *as = (unw_addr_space_ppc *)asp;
delete as; as->~unw_addr_space_ppc();
free(as);
} }
break; break;
} }