9src/cc: pcc produces $O.out, keeps .6 objects; use basename for prog…#135
Conversation
… detection
- Use basename of argv[0] (strip path prefix) so /amd64/bin/ape/pcc is
detected as "pcc" correctly
- pcc output: smprint("%s.out", ot->o) e.g. "6.out" — matches Plan9 6l default
and what mkmany expects
- pcc keeps .6 object files after linking (Plan9 native convention);
only cc mode removes the intermediate .o (APE configure-compat mode)
https://claude.ai/code/session_01WGAwvvTwDg2yknFkmZ3qzs
There was a problem hiding this comment.
Code Review
This pull request modifies the compiler wrapper to distinguish between POSIX mode (cc) and Plan 9 native mode (pcc) by inspecting the program name. It adjusts the default output filename and object extension accordingly, and restricts intermediate file cleanup to POSIX mode. Review feedback identifies a potential null pointer dereference if the argument list is empty and suggests consolidating redundant string comparisons while adding necessary error handling for memory allocation in the pcc mode path.
| prog = utfrrune(argv[0], '/'); | ||
| prog = prog ? prog+1 : argv[0]; |
There was a problem hiding this comment.
| objext = (strcmp(prog, "cc") == 0) ? "o" : ot->o; | ||
| oname = (strcmp(prog, "cc") == 0) ? "a.out" : smprint("%s.out", ot->o); |
There was a problem hiding this comment.
The strcmp(prog, "cc") check is performed twice. Consolidating this into an if-else block would improve readability and avoid redundant string comparisons. Additionally, smprint can return NULL if memory allocation fails; its return value should be checked to prevent a potential null pointer dereference later when oname is used.
if(strcmp(prog, "cc") == 0){
objext = "o";
oname = "a.out";
}else{
objext = ot->o;
if((oname = smprint("%s.out", ot->o)) == NULL){
fprint(2, "out of memory\n");
exits("mem");
}
}
… detection
https://claude.ai/code/session_01WGAwvvTwDg2yknFkmZ3qzs