Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-1042

mongo c++ headers have a #define for malloc, this breaks code compilation with certain boost headers

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.5.1
    • Affects Version/s: None
    • Component/s: Internal Client
    • None
    • Environment:
      Ubuntu Lucid running mongo-stable

      When building a very simple app which includes mongo headers and other boost headers, the app fails to build. The problem is that mongo headers have a #define for malloc which is forced upon your program silently.

      This piece of code will fail to compile. The error will indicate that malloc is now mongo::ourmalloc which is most certainly NOT what the user wants. It also causes a conflict with the boost header which has a member function called malloc.

      #include <mongo/client/dbclient.h>
      #include <boost/pool/pool.hpp>

      int main(int argc, char* argv[])
      {
      malloc();
      return 0;
      }

      error when building:
      In file included from /usr/include/boost/pool/pool.hpp:34,
      from shit.c:2:
      /usr/include/boost/pool/simple_segregated_storage.hpp:99: error: invalid use of '::'
      In file included from shit.c:2:
      /usr/include/boost/pool/pool.hpp:54: error: invalid use of '::'
      /usr/include/boost/pool/pool.hpp:65: error: invalid use of '::'
      /usr/include/boost/pool/pool.hpp:219: error: invalid use of '::'
      /usr/include/mongo/client/../util/allocator.h: In function 'int main(int, char**)':
      /usr/include/mongo/client/../util/allocator.h:22: error: too few arguments to function 'void* mongo::ourmalloc(size_t)'
      shit.c:6: error: at this point in file

      The expected error here is error: too few arguments to function 'void* malloc(size_t)' when the systems (proper) malloc is used

            Assignee:
            mathias@mongodb.com Mathias Stearn
            Reporter:
            shtylman Roman Shtylman
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: