ChanServ changed the topic of #crystal-lang to: The Crystal programming language | | Fund Crystal's development: | GH: | Docs: | Gitter:
deavmi has joined #crystal-lang
<FromGitter> <naqvis> @elorest
deavmi has quit [Quit: No Ping reply in 180 seconds.]
deavmi has joined #crystal-lang
jhass[m] has quit [Ping timeout: 244 seconds]
arestifo has joined #crystal-lang
f1refly has quit [Ping timeout: 252 seconds]
arestifo has quit [Quit: Textual IRC Client:]
f1refly has joined #crystal-lang
postmodern has quit [Quit: Leaving]
jhass[m] has joined #crystal-lang
<yxhuvud> wyhaines: typeof(array.first), but yes, it is not super pretty.
f1refly has quit [Read error: Connection reset by peer]
f1refly has joined #crystal-lang
deavmi has quit [Quit: Eish! Load shedding.]
deavmi has joined #crystal-lang
<yxhuvud> hrrm. Monkeypatching certain things would be easier if didn't execute as much directly in the top scope. :(
<FromGitter> <wyhaines> Ah yeah. Forgot that you can do that even on an empty array. That is a bit better. :)
Guest4764 has joined #crystal-lang
Guest4764 has quit [Client Quit]
<FromGitter> <Dan-Do> Can we spawn fibers on GPU instead of CPU?
<FromGitter> <Blacksmoke16> no
<FromGitter> <Blacksmoke16> i remember seeing a shard that allowed using GPU for stuff, but not sure if it's applicable here
<FromGitter> <Dan-Do> 💭
<FromGitter> <Dan-Do> thinking :)
<FromGitter> <Dan-Do> okay, can we do this?
<FromGitter> <Dan-Do> ```code paste, see link``` []
<FromGitter> <Blacksmoke16> for what reason?
<FromGitter> <Dan-Do> I don't know it is because of db, or pooling or business logic processing...
<FromGitter> <Dan-Do> the `call_next(context)` is more or less like your Athena's Controller
<FromGitter> <naqvis> @Dan-Do there is no way, timeout will happen on channel, so it got no relation with any specific fiber
<FromGitter> <Blacksmoke16> not entirely, thats more of how the other frameworks work. I.e. an `Array(HTTP::Handler)`
<FromGitter> <naqvis> what you need is detailed logging inside your logic, so that you can capture detailed information and see what is happening or what is causing the delay
<FromGitter> <Dan-Do> Ok I will go with logging. Can I narrow the log by just logging the fibers which has running time longer than ex 30.seconds
<FromGitter> <Dan-Do> I don't see any method like `Fiber.current.running_time`
<FromGitter> <naqvis> no
<FromGitter> <naqvis> simple approach would be ⏎ ⏎ 1) start the timer before you call call_next ⏎ 2) Log fiber-id and other specific details like what work its doing ⏎ 3) after method returns, log the time it took to process the request []
<FromGitter> <Dan-Do> Yes, thanks.
<FromGitter> <naqvis> remember to use `Time.monotonic` ⏎ ⏎ ```start = Time.monotonic ⏎ # do work ⏎ elapsed = Time.monotonic - start``` []
<FromGitter> <Dan-Do> 👍
<FromGitter> <Blacksmoke16> ```duration = Time.measure do ⏎ # Do work ⏎ end``` []
<FromGitter> <Blacksmoke16> does literally the same thing, just via a built in method
<FromGitter> <naqvis> oh yeah ^
avane has quit [*.net *.split]
avane has joined #crystal-lang
<FromGitter> <didactic-drunk> How can i compare `Pointer(UInt8)@0xffffffffffffffff` with a platform type specific `-1`? `mmap` returns `-1`
<yxhuvud> pointer.address.
<yxhuvud> and then go from there.
<yxhuvud> didactic-drunk: btw, you are doing some fairly interesting stuff in
<FromGitter> <naqvis> @didactic-drunk `Pointer(UInt8)` with signed value? how can that happen?
<yxhuvud> naqvis: -1 would be the error code of mmap.
<FromGitter> <naqvis> point i'm making is unsigned int can't have signed values, so pointer type he is using is wrong
<yxhuvud> I mean, it is pointing *to* an uint8. But the address ffffffffffffffff is clearly not a pointer as it isn't a valid address.
<FromGitter> <naqvis> in that case shouldn't the `Pointer#null?` be used to validate the pointer?
<yxhuvud> but it isn't a null pointer.
<yxhuvud> (unless the machine is very weird and happen to define ffffffffffffffff to be null)
<FromGitter> <naqvis> true but `0xffffffffffffffff` is normally segfault
<FromGitter> <naqvis> so either that is a dangling pointer or some other issues
<FromGitter> <HertzDevil> c libraries have this weird habit of casting special values to `void*` directly
<yxhuvud> No, it is the return code from a syscall. It is very common to let negative result values indicate error status and positive be some other type.
<FromGitter> <HertzDevil> including posix's c libraries
<FromGitter> <HertzDevil> or should i say api
<yxhuvud> Yes. And io_uring and a bunch of others.
<FromGitter> <HertzDevil> so @naqvis it is not so much an "issue" as it is part of c's tradition
<FromGitter> <naqvis> :P , yeah and C do that for reference types
<FromGitter> <naqvis> i mean for FFI where you know C is returning a reference then isn't `out` a better choice?
<yxhuvud> Not really an option for mmap.
<FromGitter> <naqvis> just looked into `mmap` manpage :P
<FromGitter> <naqvis> @didactic-drunk you can do a comparison against `Pointer(Void*).new(-1)`
<FromGitter> <HertzDevil> for the record, that constructor calls `-1.to_u64!`
<FromGitter> <naqvis> does it ? ⏎
<FromGitter> <HertzDevil> well since crystal always maps `Void` to `Nil` you can "dereference" any `Pointer(Void)` and it'll be nil
<FromGitter> <HertzDevil> `0xffff_ffff_ffff_ffff` is definitely `-1.to_u64!`
<FromGitter> <naqvis> but isn't `Pointer(Void).new(-1)` equivalent to C `(void *) -1 `?
<FromGitter> <HertzDevil> iso c says nothing about the size of a `void*`
<FromGitter> <HertzDevil> crystal more or less defines the pointer size to always be 8 bytes
<yxhuvud> hertzdevil: not only that, iso c doesn't even define what the value of a null pointer actually is.
<FromGitter> <HertzDevil> 0 is definitely not a null pointer on cc65 targetting the nes
f1reflyylmao has joined #crystal-lang
f1refly has quit [Ping timeout: 268 seconds]
f1reflyylmao is now known as f1refly
<FromGitter> <naqvis> test.c ⏎ ⏎ ```code paste, see link``` []
<FromGitter> <HertzDevil> that's due to the abi, not the c standard
<FromGitter> <naqvis> yeah true, but this does answer the original question on how to find out if `mmap` failed
<FromGitter> <HertzDevil> it will break silently if c's `void*` is smaller than crystal's `Pointer(Void)` and zero extension is performed instead of sign extension
<FromGitter> <naqvis> ⏎ ⏎ > On error, the value MAP_FAILED (that is, (void *) -1) is returned, and errno is set to indicate the error.
<FromGitter> <HertzDevil> what's doable is still doing that and then comparing your pointer to the return value of `test` instead
<FromGitter> <HertzDevil> and not to a `Pointer(Void)` created in crystal
<FromGitter> <HertzDevil> for portability
<FromGitter> <naqvis> but invoking FFI, crystal is yielding the same result as it do for `Pointer(Void)` ⏎ `p! Test.test # => Pointer(Void)@0xffffffffffffffff`
<FromGitter> <naqvis> is crystal doing some conversions behind the scenes?
<FromGitter> <didactic-drunk> I think `0x0` is a valid mapping/success return value for `mmap` so `-1` is used.
<FromGitter> <naqvis> yeah, make sense
<FromGitter> <didactic-drunk> Will `Pointer(UInt8).new(-1)` end up optimized to a constant single value or should I store a copy for comparison?
<FromGitter> <naqvis> should be same for each invocation
<FromGitter> <naqvis> as we are giving the same address
<FromGitter> <naqvis> but for easy maintenance, better to have constant defined like MMAP_FAILED
postmodern has joined #crystal-lang
<FromGitter> <foxxx0> Hi, I'm trying to spawn a long-running process in the background that occasionally prints something on stdout. i want to have that Fiber blocking until the next line on stdout, which works fine using `#gets` on the stdout pipe. however, as soon as this fiber is part of my multi-fiber application, the other fibers seem to be blocked too
<FromGitter> <foxxx0> source code with the problematic fiber highlighted:
<FromGitter> <elorest> I was already using an
<FromGitter> <didactic-drunk> Is it possible to have multiple flags type params filled using symbols?
<FromGitter> <elorest> Oh really? That's probably more what I was looking for. I didn't realize calling first on an empty array would be ok. Would that work for a hash value as well?
edegaru has joined #crystal-lang
<FromGitter> <elorest> That's great. Thank you. Pretty much the answer I was looking for.
edegaru has quit [Read error: Connection reset by peer]