cpython icon indicating copy to clipboard operation
cpython copied to clipboard

Should we allow relative includes? (i.e. #include "../_ssl.h")

Open skirpichev opened this issue 1 year ago • 1 comments

Feature or enhancement

Proposal:

          Can we avoid the relative include? They tend to produce problems further down the road.

Originally posted by @erlend-aasland in https://github.com/python/cpython/pull/120894#discussion_r1658402167

There are few more examples:

$ git grep '#include .*\.\.\/'
Include/internal/mimalloc/mimalloc/track.h:#include "../src/prim/windows/etw.h"
Modules/_blake2/blake2b_impl.c:#include "../hashlib.h"
Modules/_blake2/blake2s_impl.c:#include "../hashlib.h"
Modules/_ctypes/callproc.c:#include "../_complex.h"          // complex
Modules/_hacl/internal/Hacl_Hash_MD5.h:#include "../Hacl_Hash_MD5.h"
Modules/_hacl/internal/Hacl_Hash_SHA1.h:#include "../Hacl_Hash_SHA1.h"
Modules/_hacl/internal/Hacl_Hash_SHA2.h:#include "../Hacl_Hash_SHA2.h"
Modules/_hacl/internal/Hacl_Hash_SHA3.h:#include "../Hacl_Hash_SHA3.h"
Modules/_ssl/cert.c:#include "../_ssl.h"
Modules/_ssl/misc.c:#include "../_ssl.h"
Modules/_testinternalcapi/set.c:#include "../_testcapi/util.h"  // NULLABLE, RETURN_INT
Objects/mimalloc/prim/osx/prim.c:#include "../unix/prim.c"
Parser/lexer/lexer.c:#include "../tokenizer/helpers.h"
Parser/tokenizer/file_tokenizer.c:#include "../lexer/state.h"
Parser/tokenizer/file_tokenizer.c:#include "../lexer/lexer.h"
Parser/tokenizer/file_tokenizer.c:#include "../lexer/buffer.h"
Parser/tokenizer/helpers.c:#include "../lexer/state.h"
Parser/tokenizer/helpers.h:#include "../lexer/state.h"
Parser/tokenizer/readline_tokenizer.c:#include "../lexer/lexer.h"
Parser/tokenizer/readline_tokenizer.c:#include "../lexer/state.h"
Parser/tokenizer/readline_tokenizer.c:#include "../lexer/buffer.h"
Parser/tokenizer/string_tokenizer.c:#include "../lexer/state.h"
Parser/tokenizer/utf8_tokenizer.c:#include "../lexer/state.h"
Python/Python-tokenize.c:#include "../Parser/lexer/state.h"
Python/Python-tokenize.c:#include "../Parser/lexer/lexer.h"
Python/Python-tokenize.c:#include "../Parser/tokenizer/tokenizer.h"
Python/Python-tokenize.c:#include "../Parser/pegen.h"      // _PyPegen_byte_offset_to_character_offset()

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

skirpichev avatar Jul 01 '24 12:07 skirpichev

Note that mimalloc is copied from upstream, I don't think we should be changing it here.

kumaraditya303 avatar Jul 03 '24 07:07 kumaraditya303

Same for HACL*.

picnixz avatar Jul 15 '25 11:07 picnixz

It seems like we have multiple C files using relative includes, and I'm not aware of any practical issue, so I suggest to simply closing this issue.

vstinner avatar Aug 05 '25 12:08 vstinner

@erlend-aasland, could you more elaborate about problems, mentioned in your comment?

skirpichev avatar Aug 05 '25 12:08 skirpichev

@erlend-aasland, could you more elaborate about problems, mentioned in your comment?

I don't remember the reason for raising this issue. I'm fine with closing the issue, as Victor suggests.

erlend-aasland avatar Aug 06 '25 08:08 erlend-aasland