sqlite3_shim_fixups.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef THIRD_PARTY_SQLITE_SQLITE3_SHIM_FIXUPS_H_
  5. #define THIRD_PARTY_SQLITE_SQLITE3_SHIM_FIXUPS_H_
  6. // This file contains various fixups for the amalgamated SQLite code.
  7. // It is intended to be included in sqlite3_shim.c only.
  8. #if defined(SQLITE_OMIT_COMPILEOPTION_DIAGS)
  9. // When SQLITE_OMIT_COMPILEOPTION_DIAGS is defined, sqlite3.h emits macros
  10. // instead of declarations for sqlite3_compileoption_{get,used}().
  11. //
  12. // In order to avoid a macro redefinition warning, we must undo the #define in
  13. // rename_exports.h.
  14. #if defined(sqlite3_compileoption_get)
  15. #undef sqlite3_compileoption_get
  16. #else
  17. #error "This workaround is no longer needed."
  18. #endif // !defined(sqlite3_compileoption_get)
  19. #if defined(sqlite3_compileoption_used)
  20. #undef sqlite3_compileoption_used
  21. #else
  22. #error "This workaround is no longer needed."
  23. #endif // !defined(sqlite3_compileoption_used)
  24. #endif // defined(SQLITE_OMIT_COMPILEOPTION_DIAGS)
  25. // Linux-specific configuration fixups.
  26. #if defined(__linux__)
  27. // features.h, included below, indirectly includes sys/mman.h. The latter header
  28. // only defines mremap if _GNU_SOURCE is defined. Depending on the order of the
  29. // files in the amalgamation, removing the define below may result in a build
  30. // error on Linux.
  31. #if defined(__GNUC__) && !defined(_GNU_SOURCE)
  32. #define _GNU_SOURCE
  33. #endif
  34. #include <features.h>
  35. // SQLite wants to track malloc sizes. On OSX it uses malloc_size(), on Windows
  36. // _msize(), elsewhere it handles it manually by enlarging the malloc and
  37. // injecting a field. Enable malloc_usable_size() for Linux.
  38. //
  39. // malloc_usable_size() is not exported by the Android NDK. It is not
  40. // implemented by uclibc.
  41. #if !defined(__UCLIBC__) && !defined(__ANDROID__)
  42. #define HAVE_MALLOC_H 1
  43. #define HAVE_MALLOC_USABLE_SIZE 1
  44. #endif
  45. #endif // defined(__linux__)
  46. // For unfortunately complex reasons, Chrome has release builds where
  47. // DCHECK_IS_ON() (so we want SQLITE_DEBUG to be on) but NDEBUG is also defined.
  48. // This causes declarations for mutex-checking functions used by SQLITE_DEBUG
  49. // code (sqlite3_mutex_held, sqlite3_mutex_notheld) to be omitted, resulting in
  50. // warnings.
  51. //
  52. // The easiest solution for now is to undefine NDEBUG when SQLITE_DEBUG is
  53. // defined. The #undef only takes effect for the SQLite implementation (included
  54. // below), and does not impact any dependency.
  55. #if defined(SQLITE_DEBUG) && defined(NDEBUG)
  56. #undef NDEBUG
  57. #endif // defined(SQLITE_DEBUG) && defined(NDEBUG)
  58. #endif // THIRD_PARTY_SQLITE_SQLITE3_SHIM_FIXUPS_H_