Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Aug 14 23:41
    HertzDevil synchronize #12337
  • Aug 14 22:42
    asterite synchronize #12375
  • Aug 14 19:25
    asterite synchronize #12375
  • Aug 14 18:06
    asterite synchronize #12375
  • Aug 14 18:05
    asterite closed #12383
  • Aug 14 18:05
    asterite closed #12387
  • Aug 14 18:05
    asterite closed #12388
  • Aug 14 15:16
    straight-shoota milestoned #12362
  • Aug 14 14:51
    HertzDevil synchronize #12362
  • Aug 14 14:50
    HertzDevil closed #10571
  • Aug 14 14:49
    HertzDevil closed #11825
  • Aug 14 14:47
    straight-shoota milestoned #11420
  • Aug 14 14:32
    straight-shoota closed #11954
  • Aug 14 14:32
    straight-shoota closed #12368
  • Aug 14 14:31
    straight-shoota closed #5044
  • Aug 14 14:31
    straight-shoota closed #10954
  • Aug 14 14:29
    straight-shoota milestoned #12388
  • Aug 14 14:28
    straight-shoota milestoned #12387
  • Aug 14 14:18
    straight-shoota synchronize #11420
  • Aug 14 14:15
    straight-shoota milestoned #12356
Ali Naqvi
@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
ddd
@Dan-Do
Yes, thanks.
Ali Naqvi
@naqvis
remember to use Time.monotonic
start = Time.monotonic
# do work
elapsed = Time.monotonic - start
ddd
@Dan-Do
:thumbsup:
George Dietrich
@Blacksmoke16
duration = Time.measure do
  # Do work
end
does literally the same thing, just via a built in method
Ali Naqvi
@naqvis
oh yeah ^
didactic-drunk
@didactic-drunk
How can i compare Pointer(UInt8)@0xffffffffffffffff with a platform type specific -1? mmap returns -1
From IRC (bridge bot)
@FromIRC
<yxhuvud> pointer.address.
<yxhuvud> and then go from there.
<yxhuvud> @didactic-drunk: btw, you are doing some fairly interesting stuff in concurrent.cr.
Ali Naqvi
@naqvis
@didactic-drunk Pointer(UInt8) with signed value? how can that happen?
From IRC (bridge bot)
@FromIRC
<yxhuvud> @naqvis: -1 would be the error code of mmap.
Ali Naqvi
@naqvis
point i'm making is unsigned int can't have signed values, so pointer type he is using is wrong
From IRC (bridge bot)
@FromIRC
<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.
Ali Naqvi
@naqvis
in that case shouldn't the Pointer#null? be used to validate the pointer?
From IRC (bridge bot)
@FromIRC
<yxhuvud> but it isn't a null pointer.
<yxhuvud> (unless the machine is very weird and happen to define ffffffffffffffff to be null)
Ali Naqvi
@naqvis
true but 0xffffffffffffffff is normally segfault
so either that is a dangling pointer or some other issues
Quinton Miller
@HertzDevil
c libraries have this weird habit of casting special values to void* directly
From IRC (bridge bot)
@FromIRC
<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.
Quinton Miller
@HertzDevil
including posix's c libraries
or should i say api
From IRC (bridge bot)
@FromIRC
<yxhuvud> Yes. And io_uring and a bunch of others.
Quinton Miller
@HertzDevil
so @naqvis it is not so much an "issue" as it is part of c's tradition
Ali Naqvi
@naqvis
:P , yeah and C do that for reference types
i mean for FFI where you know C is returning a reference then isn't out a better choice?
From IRC (bridge bot)
@FromIRC
<yxhuvud> Not really an option for mmap.
Ali Naqvi
@naqvis
just looked into mmap manpage :P
@didactic-drunk you can do a comparison against Pointer(Void).new(-1)
Quinton Miller
@HertzDevil
for the record, that constructor calls -1.to_u64!
Ali Naqvi
@naqvis
Quinton Miller
@HertzDevil
well since crystal always maps Void to Nil you can "dereference" any Pointer(Void) and it'll be nil
0xffff_ffff_ffff_ffff is definitely -1.to_u64!
Ali Naqvi
@naqvis
but isn't Pointer(Void).new(-1) equivalent to C (void *) -1?
Quinton Miller
@HertzDevil
iso c says nothing about the size of a void*
crystal more or less defines the pointer size to always be 8 bytes
From IRC (bridge bot)
@FromIRC
<yxhuvud> hertzdevil: not only that, iso c doesn't even define what the value of a null pointer actually is.
Quinton Miller
@HertzDevil
0 is definitely not a null pointer on cc65 targetting the nes
Ali Naqvi
@naqvis

test.c

void* test() {
  return ((void *) -1);
}

test.cr

@[Link(ldflags: "-L#{__DIR__}/ -ltest.o ")]
lib Test
  fun test : Void*
end

p! Test.test == Pointer(Void).new(-1) # => true
Quinton Miller
@HertzDevil
that's due to the abi, not the c standard
Ali Naqvi
@naqvis
yeah true, but this does answer the original question on how to find out if mmap failed
Quinton Miller
@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
Ali Naqvi
@naqvis

https://man7.org/linux/man-pages/man2/mmap.2.html

On error, the value MAP_FAILED (that is, (void *) -1) is returned, and errno is set to indicate the error.

Quinton Miller
@HertzDevil
what's doable is still doing that and then comparing your pointer to the return value of test instead
and not to a Pointer(Void) created in crystal
for portability
Ali Naqvi
@naqvis
but invoking FFI, crystal is yielding the same result as it do for Pointer(Void)
p! Test.test # => Pointer(Void)@0xffffffffffffffff