Commit 86017162 authored by Christopher Dykes's avatar Christopher Dykes Committed by Facebook Github Bot 7

Create a malloc.h portability header

Summary:Let's break OSX!

Alright, maybe not. Neither OSX nor Windows define malloc_usable_size, so we implement them based on what is available on the respective platforms.
This moves the implementation for OSX out of Portability.h and into the new header, so it likely breaks something on OSX, although I'm not sure what.

Reviewed By: yfeldblum

Differential Revision: D3019938

fb-gh-sync-id: df95faef09535098fb73b7b3479d7a73f6b49712
fbshipit-source-id: df95faef09535098fb73b7b3479d7a73f6b49712
parent 7f38b123
......@@ -273,6 +273,7 @@ nobase_follyinclude_HEADERS = \
portability/Environment.h \
portability/GFlags.h \
portability/IOVec.h \
portability/Malloc.h \
portability/Memory.h \
portability/String.h \
portability/Strings.h \
......@@ -414,6 +415,7 @@ libfolly_la_SOURCES = \
MacAddress.cpp \
MemoryMapping.cpp \
portability/Environment.cpp \
portability/Malloc.cpp \
portability/String.cpp \
portability/Strings.cpp \
portability/SysFile.cpp \
......
......@@ -25,10 +25,6 @@
#include <folly/CPortability.h>
#ifdef __APPLE__
# include <malloc/malloc.h>
#endif
#if FOLLY_HAVE_SCHED_H
#include <sched.h>
#endif
......@@ -355,13 +351,6 @@ using namespace FOLLY_GFLAGS_NAMESPACE;
#include <TargetConditionals.h>
#endif
// MacOS doesn't have malloc_usable_size()
#if defined(__APPLE__) && !defined(FOLLY_HAVE_MALLOC_USABLE_SIZE)
inline size_t malloc_usable_size(void* ptr) {
return malloc_size(ptr);
}
#endif
// RTTI may not be enabled for this compilation unit.
#if defined(__GXX_RTTI) || defined(__cpp_rtti) || \
(defined(_MSC_VER) && defined(_CPPRTTI))
......
/*
* Copyright 2016 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <folly/portability/Malloc.h>
#if defined(__APPLE__) && !defined(FOLLY_HAVE_MALLOC_USABLE_SIZE)
#include <malloc/malloc.h>
extern "C" size_t malloc_usable_size(void* ptr) {
return malloc_size(ptr);
}
#elif defined(_WIN32)
extern "C" size_t malloc_usable_size(void* addr) {
return _msize(addr);
}
#endif
/*
* Copyright 2016 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <malloc.h>
#include <folly/portability/Config.h>
#if defined(__APPLE__) && !defined(FOLLY_HAVE_MALLOC_USABLE_SIZE)
// MacOS doesn't have malloc_usable_size()
extern "C" size_t malloc_usable_size(void* ptr);
#elif defined(_WIN32)
extern "C" size_t malloc_usable_size(void* ptr);
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment