Added a better check for openssl
[folly.git] / folly / Malloc.h
index f8398911f9558664eb7c351b3afca70c01405908..8092ab0b197772df2397bad9c514541ab49fe8f5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2015 Facebook, Inc.
+ * 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.
@@ -17,8 +17,7 @@
 // Functions to provide smarter use of jemalloc, if jemalloc is being used.
 // http://www.canonware.com/download/jemalloc/jemalloc-latest/doc/jemalloc.html
 
-#ifndef FOLLY_MALLOC_H_
-#define FOLLY_MALLOC_H_
+#pragma once
 
 /**
  * Define various MALLOCX_* macros normally provided by jemalloc.  We define
@@ -40,6 +39,7 @@
 #if defined(_GLIBCXX_USE_FB) && !defined(_LIBSTDCXX_FBSTRING)
 
 #include <folly/detail/Malloc.h>
+#include <folly/portability/BitsFunctexcept.h>
 
 #include <string>
 
@@ -86,13 +86,18 @@ extern "C" int mallctlbymib(const size_t*, size_t, void*, size_t*, void*,
 __attribute__((__weak__));
 
 #include <bits/functexcept.h>
+
 #define FOLLY_HAVE_MALLOC_H 1
-#else
+
+#else // !defined(_LIBSTDCXX_FBSTRING)
+
 #include <folly/detail/Malloc.h> /* nolint */
+#include <folly/portability/BitsFunctexcept.h> /* nolint */
+
 #endif
 
 // for malloc_usable_size
-// NOTE: FreeBSD 9 doesn't have malloc.h.  It's defitions
+// NOTE: FreeBSD 9 doesn't have malloc.h.  Its definitions
 // are found in stdlib.h.
 #if FOLLY_HAVE_MALLOC_H
 #include <malloc.h>
@@ -116,7 +121,8 @@ namespace folly {
 #endif
 
 // Cannot depend on Portability.h when _LIBSTDCXX_FBSTRING.
-#ifdef __GNUC__
+// Disabled for nvcc because it fails on attributes on lambdas.
+#if defined(__GNUC__) && !defined(__NVCC__)
 #define FOLLY_MALLOC_NOINLINE __attribute__((__noinline__))
 #else
 #define FOLLY_MALLOC_NOINLINE
@@ -177,6 +183,10 @@ inline bool usingJEMalloc() noexcept {
 }
 
 inline size_t goodMallocSize(size_t minSize) noexcept {
+  if (minSize == 0) {
+    return 0;
+  }
+
   if (!usingJEMalloc()) {
     // Not using jemalloc - no smarts
     return minSize;
@@ -274,5 +284,3 @@ _GLIBCXX_END_NAMESPACE_VERSION
 } // folly
 
 #endif // !defined(_GLIBCXX_USE_FB) || defined(_LIBSTDCXX_FBSTRING)
-
-#endif // FOLLY_MALLOC_H_