Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-2797

Fix include header checks

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.14.0
    • Affects Version/s: None
    • Component/s: libbson, libmongoc
    • None

      We have checks to prevent public headers getting included directly in client code outside of bson.h and mongoc.h:

      #if !defined(MONGOC_INSIDE) && !defined(MONGOC_COMPILATION)
      #error "Only <mongoc.h> can be included directly."
      #endif
      

      However, some public headers omit the checks like bson-writer.c and mongoc-change-stream.h.

      And a lot of them define this check after the ifdef guard. Example:

      #ifndef MONGOC_APM_H
      #define MONGOC_APM_H
      
      #if !defined(MONGOC_INSIDE) && !defined(MONGOC_COMPILATION)
      #error "Only <mongoc.h> can be included directly."
      #endif
      /* ... */
      
      #endif /* MONGOC_APM_H */
      

      So client code can do something like:

      #include <mongoc.h>
      #include <mongoc-apm.h>
      

      And it compiles without issue. This is because mongoc.h includes mongoc-apm.h, which defines MONGOC_APM_H. So when the client code includes mongoc-apm.h directly, no error occurs.

      This check should probably be defined outside of the ifdef guard, which only a few files do (e.g. mongoc-rand.h).

            Assignee:
            kevin.albertson@mongodb.com Kevin Albertson
            Reporter:
            kevin.albertson@mongodb.com Kevin Albertson
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: