[CDRIVER-3443] Incorrect #include pattern causes an extra file system read that is guaranteed to fail Created: 02/Dec/19  Updated: 28/Oct/23  Resolved: 19/Dec/19

Status: Closed
Project: C Driver
Component/s: Build
Affects Version/s: 1.15.2
Fix Version/s: 1.16.0

Type: Bug Priority: Minor - P4
Reporter: Andre M Assignee: Kevin Albertson
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

bson.h file located in /usr/include/libbson-1.0/bson/ has about to dozenĀ  #include's like these:

#include "bson/bson-macros.h"
#include "bson/bson-config.h"
#include "bson/bson-atomic.h"
...

This means that the C preprocessor will first attempt to open every header in the current directory first, will fail and only then will fall back onto the including project include search path to look for those headers, where it also fails on average for half of the paths on the include search path list. Same happens once more for mongoc/mongoc.h, so the pattern repeats over 40 times.

Given that bson/bson.h and mongoc/mongoc.h have already been found via the including project's search path once, they should include all of their internal headers directly via double quote search paths, like this:

#include "bson-macros.h"
#include "bson-config.h"
#include "bson-atomic.h"...

This guarantees that each header is directly included without falling back onto the including project's search path.



 Comments   
Comment by Githook User [ 10/Jan/20 ]

Author:

{'name': 'Jeremy Mikola', 'email': 'jmikola@gmail.com', 'username': 'jmikola'}

Message: CDRIVER-3443 use relative includes in opts templates
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/ac718f2c62acaed1641603fffc70d00a9014e68b

Comment by Andre M [ 19/Dec/19 ]

@kevin.albertson

Thank you, Kevin. Not only this change improves build speed, but also (and I forgot to mention this earlier), it prevents picking up wrong headers by accident. For example, if I had bson/bson-iter.h in my source tree for a ::bson_iter_t wrapper (nothing wrong with reusing a good file name), the original way of including could pick it up if that directory was in the search path first. Now once it finds bson.h, all other includes are locked in. Same for Mongo C headers.

Thanks again for looking into this. Much appreciated.

Comment by Kevin Albertson [ 19/Dec/19 ]

Thanks for reporting cis74633@bell.net. I agree this seems like a positive change. The include paths for the installed headers have been changed to be relative.

Comment by Githook User [ 19/Dec/19 ]

Author:

{'name': 'Kevin Albertson', 'email': 'kevin.albertson@mongodb.com', 'username': 'kevinAlbs'}

Message: CDRIVER-3443 make includes relative

Since compilers will check relative path first, use the relative include
path in installed headers.
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/ae0abf24e0e2edac13f49e9061d92b27724e76fd

Generated at Wed Feb 07 21:18:03 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.