-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove most unused LibC
bindings
#11955
base: master
Are you sure you want to change the base?
Conversation
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)
end Alternatively; lib LibC
{% if LibC.c_function_exists? %}
fun spork(prongs : Int)
{% end %}
end Bonus 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
,DivT
c/time.cr
:clock_settime
,gmtime_r
,localtime_r
,mktime
,timegm
,timezone
,tzset
,Tm
,$daylight
,$timezone
,$tzname
c/netdb.cr
:getnameinfo
c/sys/select.cr
:select
,FdSet
c/sys/stat.cr
:mkfifo
,mknod
,umask
These 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 theSyscall
module is still experimental.