Cheng Shao pushed to branch wip/remove-legacy-define-in-foreign-stub at Glasgow Haskell Compiler / GHC
Commits:
af3e2a55 by Cheng Shao at 2025-12-03T22:07:55+01:00
compiler: remove unused CPP code in foreign stub
This patch removes unused CPP code in the generated foreign stub:
- `#define IN_STG_CODE 0` is not needed, since `Rts.h` already
includes this definition
- The `if defined(__cplusplus)` code paths are not needed, since we
don't generate C++ stubs and don't include C++ headers in our stubs
- - - - -
1 changed file:
- compiler/GHC/Driver/CodeOutput.hs
Changes:
=====================================
compiler/GHC/Driver/CodeOutput.hs
=====================================
@@ -322,37 +322,27 @@ outputForeignStubs logger tmpfs dflags unit_state mod location stubs
Just stub_h -> do
OsPath.createDirectoryIfMissing True (OsPath.takeDirectory stub_h)
outputForeignStubs_help (OsPath.unsafeDecodeUtf stub_h) stub_h_output_w
- ("#include \n" ++ cplusplus_hdr) cplusplus_ftr
+ "#include \n"
putDumpFileMaybe logger Opt_D_dump_foreign
"Foreign export stubs" FormatC stub_c_output_d
stub_c_file_exists
<- outputForeignStubs_help stub_c stub_c_output_w
- ("#define IN_STG_CODE 0\n" ++
- "#include \n" ++
- rts_includes ++
- ffi_includes ++
- cplusplus_hdr)
- cplusplus_ftr
- -- We're adding the default hc_header to the stub file, but this
- -- isn't really HC code, so we need to define IN_STG_CODE==0 to
- -- avoid the register variables etc. being enabled.
+ (rts_includes ++
+ ffi_includes)
return (stub_h_file_exists, if stub_c_file_exists
then Just stub_c
else Nothing )
- where
- cplusplus_hdr = "#if defined(__cplusplus)\nextern \"C\" {\n#endif\n"
- cplusplus_ftr = "#if defined(__cplusplus)\n}\n#endif\n"
-- It is more than likely that the stubs file will
-- turn out to be empty, in which case no file should be created.
-outputForeignStubs_help :: FilePath -> String -> String -> String -> IO Bool
-outputForeignStubs_help _fname "" _header _footer = return False
-outputForeignStubs_help fname doc_str header footer
- = do writeFile fname (header ++ doc_str ++ '\n':footer ++ "\n")
+outputForeignStubs_help :: FilePath -> String -> String -> IO Bool
+outputForeignStubs_help _fname "" _header = return False
+outputForeignStubs_help fname doc_str header
+ = do writeFile fname (header ++ doc_str ++ "\n")
return True
-- -----------------------------------------------------------------------------
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/af3e2a558fd489da67599bec7d0c5b23...
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/af3e2a558fd489da67599bec7d0c5b23...
You're receiving this email because of your account on gitlab.haskell.org.