[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:
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:
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: |
| 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: Since compilers will check relative path first, use the relative include |