Last active
August 31, 2021 20:52
-
-
Save straight-shoota/6484f5b1fa5a5d0c46a932c3f9f8909f to your computer and use it in GitHub Desktop.
Crystal i for linux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git c/src/compiler/crystal/repl/context.cr w/src/compiler/crystal/repl/context.cr | |
index 1cceb2c45..3451a87d0 100644 | |
--- c/src/compiler/crystal/repl/context.cr | |
+++ w/src/compiler/crystal/repl/context.cr | |
@@ -471,8 +472,14 @@ class Crystal::Repl::Context | |
return unless path && name | |
- # TODO: obviously support other platforms than darwin | |
- lib_path = File.join(path, "lib#{name}.dylib") | |
+ lib_path : String? | |
+ {% if flag?(:darwin) %} | |
+ lib_path = File.join(path, "lib#{name}.dylib") | |
+ {% elsif flag?(:unix) %} | |
+ lib_path = File.join(path, "lib#{name}.so") | |
+ {% else %} | |
+ {% raise "Can't load dynamic libraries" %} | |
+ {% end %} | |
return unless File.exists?(lib_path) | |
handle = LibC.dlopen(lib_path, LibC::RTLD_LAZY | LibC::RTLD_GLOBAL) | |
diff --git c/src/crystal/system/unix/file_descriptor.cr w/src/crystal/system/unix/file_descriptor.cr | |
index bc3576a2f..2000fed13 100644 | |
--- c/src/crystal/system/unix/file_descriptor.cr | |
+++ w/src/crystal/system/unix/file_descriptor.cr | |
@@ -64,11 +64,19 @@ module Crystal::System::FileDescriptor | |
end | |
private def system_info | |
- if LibC.fstat(fd, out stat) != 0 | |
- raise IO::Error.from_errno("Unable to get info") | |
- end | |
+ {% begin %} | |
+ {% if flag?(:interpreted) %} | |
+ ret = LibC.__fxstat(1, fd, out stat) | |
+ {% else %} | |
+ ret = LibC.fstat(fd, out stat) | |
+ {% end %} | |
- FileInfo.new(stat) | |
+ if ret != 0 | |
+ raise IO::Error.from_errno("Unable to get info") | |
+ end | |
+ | |
+ FileInfo.new(stat) | |
+ {% end %} | |
end | |
private def system_seek(offset, whence : IO::Seek) : Nil | |
diff --git c/src/crystal/system/unix/pthread.cr w/src/crystal/system/unix/pthread.cr | |
index 4af585abe..15545912e 100644 | |
--- c/src/crystal/system/unix/pthread.cr | |
+++ w/src/crystal/system/unix/pthread.cr | |
@@ -154,7 +154,7 @@ class Thread | |
raise RuntimeError.from_os_error("pthread_attr_destroy", Errno.new(ret)) unless ret == 0 | |
{% elsif flag?(:linux) %} | |
if LibC.pthread_getattr_np(@th, out attr) == 0 | |
- LibC.pthread_attr_getstack(pointerof(attr), pointerof(address), out _) | |
+ LibC.pthread_attr_getstack(pointerof(attr), pointerof(address), out x) | |
end | |
ret = LibC.pthread_attr_destroy(pointerof(attr)) | |
raise RuntimeError.from_os_error("pthread_attr_destroy", Errno.new(ret)) unless ret == 0 | |
diff --git c/src/lib_c/x86_64-linux-gnu/c/sys/stat.cr w/src/lib_c/x86_64-linux-gnu/c/sys/stat.cr | |
index 46c5d472c..446efef3d 100644 | |
--- c/src/lib_c/x86_64-linux-gnu/c/sys/stat.cr | |
+++ w/src/lib_c/x86_64-linux-gnu/c/sys/stat.cr | |
@@ -46,6 +46,7 @@ lib LibC | |
fun chmod(file : Char*, mode : ModeT) : Int | |
fun fstat(fd : Int, buf : Stat*) : Int | |
+ fun __fxstat(ver : Int, fd : Int, buf : Stat*) : Int | |
fun lstat(file : Char*, buf : Stat*) : Int | |
fun mkdir(path : Char*, mode : ModeT) : Int | |
fun mkfifo(path : Char*, mode : ModeT) : Int |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment