Remove most unused LibC bindings#11955
Remove most unused LibC bindings#11955HertzDevil wants to merge 6 commits intocrystal-lang:masterfrom
LibC bindings#11955Conversation
I have plans for those. |
|
I'm not sure about how to proceed with this. It's definitely nice to remove unused code. But we can't exclude that these bindings are used in some Crystal code, despite lib bindings being undocumented. Removing them would risk break existing code that is just using C bindings provided in stdlib in good faith. So I believe this is a breaking change that should only happen in a major release. So we'd have to schedule this for 2.0. In the mean time, we could consider adding support for I think the underlying problem is that libc is just a huge library and stdlib contains bindings for some of it in Perhaps we should move all of stdlib's lib bindings to a different name than |
|
The major problem I face is platform specific or variant libc calls. Crystal has a platform specific file/dir structure for libc. Shards are left to reimplement platform specific binding on their own. The most common patterns I see are If only there was a standardized way to query a lib for functions or conditionally bind them lib LibC
fun spork?(prongs : Int)
bind? spork(prongs : Int)
endAlternatively; lib LibC
{% if LibC.c_function_exists? %}
fun spork(prongs : Int)
{% end %}
endBonus if someone comes up with a way to query for variant params or types. See |
|
Detection of symbols in linked libraries is not really possible at compile time. |
|
Check my proposal for how to more easily do C bindings... I think that solves all issues. |
|
Ah, nevermind. It's something I different. But I think we could have a macro call for this. |
|
Related discussion of I think that change is fine, except for the C primitive aliases like |
Those are:
c/stdlib.cr:atof,div,putenv,DivTc/time.cr:clock_settime,gmtime_r,localtime_r,mktime,timegm,timezone,tzset,Tm,$daylight,$timezone,$tznamec/netdb.cr:getnameinfoc/sys/select.cr:select,FdSetc/sys/stat.cr:mkfifo,mknod,umaskThese functions are not removed despite also being unused:
getrlimit: Used by Add LibC.setrlimit/LibC.getrlimit to all linux/bsd platforms #10569.lockf: Kept because an outstanding TODO refers to it.syscall: Kept because theSyscallmodule is still experimental.