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
portability/Environment.h \
portability/GFlags.h \
portability/IOVec.h \
+ portability/Malloc.h \
portability/Memory.h \
portability/String.h \
portability/Strings.h \
MacAddress.cpp \
MemoryMapping.cpp \
portability/Environment.cpp \
+ portability/Malloc.cpp \
portability/String.cpp \
portability/Strings.cpp \
portability/SysFile.cpp \
#include <folly/CPortability.h>
-#ifdef __APPLE__
-# include <malloc/malloc.h>
-#endif
-
#if FOLLY_HAVE_SCHED_H
#include <sched.h>
#endif
#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))
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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