<FromGitter>
<j8r> I will remove thr not found handler, and just create an Exception without raising
<FromGitter>
<j8r> Thanks
<FromGitter>
<j8r> That was I thought others do
<FromGitter>
<Blacksmoke16> are deff multiple ways to handle it, depends on what your goals are i guess
<FromGitter>
<j8r> It would be ok :)
<FromGitter>
<j8r> They are both global handlers
<FromGitter>
<j8r> Hum actually not
<FromGitter>
<j8r> Not Found can't be attached to a controller, obviously
<FromGitter>
<Blacksmoke16> well to be fair, not found can be used for more than just routing
<FromGitter>
<Blacksmoke16> i.e. `GET /user/1111111` => `404 User with that ID could not be found`
<FromGitter>
<j8r> Yes, I mean when a route is not found
<FromGitter>
<j8r> That's just a code at the end
<FromGitter>
<j8r> Sure
<FromGitter>
<j8r> I think there is no way to create a new hash each time to extend a generic union :|
<FromGitter>
<j8r> No other way I meant
<FromGitter>
<Blacksmoke16> can you not make the hash like `Hash(String, Node)` or something?
<FromGitter>
<Blacksmoke16> im not following where the union is coming from, could have a parent controller type or module or something to type things as
ur5us has joined #crystal-lang
<FromGitter>
<j8r> I comes from the return type of the Proc
<FromGitter>
<Blacksmoke16> oh?
<FromGitter>
<Blacksmoke16> what does that have to do with routing tho?
ur5us has quit [Remote host closed the connection]
<FromGitter>
<Blacksmoke16> if the value is `Node(Action(T))`
<FromGitter>
<j8r> Yes, it is a generic
<FromGitter>
<j8r> For example
<FromGitter>
<Blacksmoke16> and cant just type the hash as like `String, Node`?
<FromGitter>
<j8r> I don't think so
<FromGitter>
<Blacksmoke16> fwiw my `Route` thing has a parent type `Action` that is just used for typing stuff
<FromGitter>
<j8r> `Hash(String, Node(Action(String))`, and to include `Node(Action(Bool))`
<FromGitter>
<Blacksmoke16> so my radix tree type is like `Radix::Tree(Action).new`
<FromGitter>
<Blacksmoke16> id just try that, should help
<postmodern>
hmm pointerto is indeed not what i'm looking for. any changes to the struct wrapped in the class aren't persisting
ur5us has quit [Ping timeout: 240 seconds]
postmodern has quit [Quit: Leaving]
postmodern has joined #crystal-lang
<postmodern>
is there a way to define a type that's just a restricted set of numbers, but without defining an enum and having to pass around elements from that enum?
<postmodern>
like say i have a method that should only accept 16, 32, 64. What's the simplest way to implement that?
<jhass>
I don't think there is
<jhass>
you could make a macro that validates the value before passing it on
<postmodern>
jhass, are there examples of how to use Box?
<jhass>
well the API is pretty minimal, Box.box(your_struct) gives you a pointer. I guess the gotcha is that the pointer is pointing to a Box wrapping your struct rather than the struct directly. So it's only good for passing to C land if the library treats it as an opaque pointer
<jhass>
I guess you could hack yourself a pointer to the struct with box = Box.box(my_struct); ptr = pointerof(box.@object)
<jhass>
just a generic class to hold something and given it's a class, it's on the heap
<jhass>
just if you go with above hack you need to make sure to keep a reference to the box for the GC not to collect it
<postmodern>
hmm that doesn't seem like what i want
<postmodern>
need to both pass a persistent struct to C, allow it to be modified by C land, then inspect the changes, rinse & repeat
<jhass>
mh, I would expect it to be suitable. Maybe not the cleanest but...
<jhass>
so the call site to C land has to return inbetween?
<jhass>
mh
<jhass>
well I think if you'd just wrap your C calls into a class that also holds the struct it should be fine no?
<jhass>
something like class Thingie; @data = LibThingie::Data.new; def pass; LibThingie.pass(pointerof(@data)); end; def inspect; @data.foo; end; end;
<jhass>
important bit being a class and not a struct
<jhass>
then just make sure to have one global, or whatever its lifetime is, reference to your instance of Thingie
<jhass>
if that doesn't work I'd rather double check my struct is big enough / defined correctly in general
<jhass>
lots of C libs I've seen do some typedef wizardy to add some padding for library internal/private data
<jhass>
and then the Crystal allocated struct might not account for that causing the library to access uninitialized/garbage memory
<postmodern>
jhass, yeah it's libudis86, where you typically allocate the UD struct on the stack, pass in a pointer. you also set callbacks which passes the same pointer back to your callback. http://udis86.sourceforge.net/manual/libudis86.html
<jhass>
well that should be as simple as fun ud_init(out obj : UdT)
<postmodern>
i'm using pointerof(@struct) in the class, but changes are not persisting when i check the fields of the struct
<postmodern>
jhass, from what i can tell, __UD_STANDALONE__ is an optional -D that gets passed in. it should be off by default.
<jhass>
well I tried without and got 16 out of pc, with it I got 0 & 23 as expected
<jhass>
note that the __UD_STANDALONE__ is a compile time setting of the .so you link against
<jhass>
also note the difference in asm_buf_int that we have
<postmodern>
jhass, hmm still getting 0 after wrapping everything in pointerof()
<jhass>
those are the two factors I see that could make your pc offset wrong
<postmodern>
hmm good point
<jhass>
could be version differences, I don't know
<jhass>
I just installed whatever I found in the AUR
<jhass>
btw are you even supposed to access those fields in regular usage or is the struct meant to be opaque?
<jhass>
I don't remember whether the typedef ud_t struct ud; hides the fields in C land
<postmodern>
with it hardcoded enabled and disabled, i still get 0
<jhass>
can you gist your libudis86/types.h?
<postmodern>
the struct is exposed via the headers so i'm assuming they are public. the author started adding _ prefixes to certain fields to denote privateness
<jhass>
oh my insn_offset also is a UInt64 instead of a UInt16
<postmodern>
jhass, added types.cr
<jhass>
haha, I meant the actual types.h you translated from :)
<postmodern>
ok added both types.h and extern.h
<jhass>
so it's the same as mine
<jhass>
try correcting insn_offset to UInt64 :)
<postmodern>
did that and still getting 0
<jhass>
huh, with & without inp_file?
<jhass>
and you did correct asm_buff_int too right?
<postmodern>
both
<postmodern>
aaah getting back 16, but that's not exactly the same as 0x400000
<postmodern>
should contain that value since pc is UInt64
<jhass>
16 I got when I had inp_file missing 🤔
<jhass>
so of by a 4 bytes I guess?
<jhass>
btw I had a mistake too, made asm_buf LibC::Char instead of LibC::Char*, just turned out to be alright due to same size :D
<postmodern>
0x400000 >> 18 just so happens to be 16
<postmodern>
do C structs have a size method i could check and compare against C's sizeof(struct ud)?
<jhass>
yes, just sizeof(LibUD::UD)!
<jhass>
there's offsetof too, so you can start to bisect
<jhass>
anyway, I'm unable to spot further differences :/
<postmodern>
hmm 592 doesn't look right, considering C says 632. Also having issues with my ruby FFI implementation giving me 600 bytes... :/
<postmodern>
i'm assuming crystal's sizeof accounts for alignment/padding?
<jhass>
I hope so, I think it just wraps the LLVM IR primitive
<jhass>
my offsetof(LibUd::UD, @pc) is 376 fwiw
Nicolab has joined #crystal-lang
<postmodern>
jhass, oh could I use the awesome Hexdump module in stdlib to just dump the bytes of the struct out and see if they are even getting set, or misaligned?
<jhass>
that ought to be possible somehow
<postmodern>
368 offset in my env :|?
<postmodern>
i'm doing this in a VM, so no crazy architectures or byte packing
<jhass>
still can do def hexdump(value : T) forall T; Bytes.new(pointerof(value).as(UInt8*), sizeof(T)).hexdump; end to dump anything I think
<jhass>
anyways, I'd get the offsetof of each field up to pc in Crystal and C and see where they diverge
<jhass>
the one before the first one that mismatches should be too short
<jhass>
(or even on missing there)
<jhass>
hahah
<jhass>
you're actually missing inp_peek!
<jhass>
I didn't search for missing fields yet
<jhass>
postmodern:^
<jhass>
no wait, I'm confused
<jhass>
you have it, I don't
<jhass>
yet you're too short still?
<jhass>
well maybe you're not, just compared to me
<jhass>
but then if I have less something else seems to be too short
<jhass>
less fields I mean
<jhass>
haha, this is confusing
alexherbo2 has joined #crystal-lang
<FromGitter>
<636f7374> Fuck, my credit card was stolen yesterday. Fortunately, that credit card didn't have much balance. Today, I want to buy a domain name and find that the balance is insufficient. The little bastard in the Philippines.
<postmodern>
jhass, well i wrote two programs to enumate offsetof and they are exactly the same.
<jhass>
huh, weird
<jhass>
well we certainly discovered some problems there, so it definitely was part of the problem
<postmodern>
also not seeing any difference between before and after hexdumps, which leads me to believe the writes are never happening on the original struct
<jhass>
still those (out @ud)'s in your real code?
<jhass>
try turning them back into pointerof's
<postmodern>
jhass, fully replaced with pointerof, still the same behavior
<jhass>
huh
<postmodern>
also odd there's a bit of garbage data in the struct at BEFORE and AFTER. This seems to be as ud_init isn't actually writing back to the struct, but a copy, despite passing pointerof()
<jhass>
I don't know, it works in my hack script from earlier as I expect
<postmodern>
jhass, printing 16 isn't working though, because we're assigning pc to 0x40000
<postmodern>
jhass, can you copy/paste my gist and see if that works
<jhass>
not sure it's complete enough to actually run?
<postmodern>
jhass, what does the compiler say is missing?
<jhass>
I didn't have time to try yet, sorry
<jhass>
meanwhile I'm curious if https://p.jhass.eu/7l.cr does work for you (after adding the insp_peek that I don't have)
<jhass>
with that I do see fefefe at 178
<FromGitter>
<wout> Hi all, is there a way for HTTP::Client to use verify_mode = OpenSSL::SSL::VERIFY_PEER with a ca_file, just as Ruby's Net::HTTP?
<postmodern>
jhass, inp_peek is in my code as well at 187
<jhass>
yes but not in mine!
<postmodern>
jhass, er ud_struct.cr:20
<jhass>
for some reason my headder doesn't have it, I suspect different versions
<postmodern>
jhass, i'm using fedora's udis86-devel 1.7.2
<jhass>
mh, AUR package is at 1.7.2 too
<jhass>
weird
<FromGitter>
<j8r> @Blacksmoke16 The `abstract struct Action`didn't work (because of `abstract def` inside), but with a module it did :)
<postmodern>
jhass, i can try running it against upstream udis86 linked locally. however i strongly suspect the problem is that the C library isn't writing back to the original struct.
<jhass>
well I got your code to run and it's not writing either for me apparently
<FromGitter>
<j8r> @tenebrousedge but then the struct has to old the return type has a generic
<FromGitter>
<j8r> like `Action(T)`, with `Proc(T)` inside
<FromGitter>
<tenebrousedge> whaaaaaaat
<FromGitter>
<tenebrousedge> o______o
<jhass>
postmodern: I hope the journey was insightful anyways :D
<jhass>
still no clue what's up with that inp_peek but ok
<FromGitter>
<Daniel-Worrall> Couldn't you set it as a class method so you don't need to instantiate
<FromGitter>
<Daniel-Worrall> Or even as a module? Hmm
<FromGitter>
<Daniel-Worrall> Can you have a generic module
<postmodern>
jhass, i mean it's technically allowed to call the getter method from within the setter method, and without parenthesis. preventing such an edge case would likely add a ton of annoying rules to the language.
<postmodern>
jhass, i'm just happy i can continue working on this library and get it released soon
<jhass>
<3
<jhass>
and you learned about offsetof, sizeof, out and Box on the way!
<FromGitter>
<Blacksmoke16> @j8r yea are some bugs around that. Sometimes inheritance works others a module works
<FromGitter>
<Blacksmoke16> i originally used class methods for the actions, then you dont have to worry about newing up the controller, but ofc DI doesnt work then; which if you dont care about could be a solution
<FromGitter>
<wout> @tenebrousedge Great, thanks! Works liek a charm. :)
<FromGitter>
<Blacksmoke16> trying to reduce it further
<FromGitter>
<Blacksmoke16> something within the `#resolve` method the compiler doesnt like
<FromGitter>
<Blacksmoke16> but i dont know why its complaining since there isnt any type restrictions for it to complain about
<FromGitter>
<asterite> compiler bug related to caching, probably generics
<FromGitter>
<Blacksmoke16> ill make an issue
postmodern has quit [Quit: Leaving]
<FromGitter>
<Blacksmoke16> actually this is interesting, it compiles when using a module, but then `Int32?` param type is used twice https://play.crystal-lang.org/#/r/8kjb
<FromGitter>
<Blacksmoke16> so it doesn't go thru the correct `from_parameter` method
<FromGitter>
<Blacksmoke16> i imagine those are two separate issues?
HumanGeek has quit [Remote host closed the connection]
HumanGeek has joined #crystal-lang
<FromGitter>
<asterite> I think it's a bug related to subclasses of modules or generic types affecting methods that were already typed
<FromGitter>
<asterite> reporting it as two issues or one is similar
<FromGitter>
<Blacksmoke16> I'll put them in one then for now. can always split one out if a fix fixes one but not the other
<FromGitter>
<Blacksmoke16> which prob *should* work since the parent is abstract?
<FromGitter>
<asterite> abstract types must have everything initialized in their constructors
<FromGitter>
<asterite> regardless of their subtypes
<FromGitter>
<Blacksmoke16> ah right, makes sense
<FromGitter>
<636f7374> 1) 33 has been released? I haven't even noticed that I am now testing.
<FromGitter>
<j8r> Alpine will drop aarch64 to bump to Crystal 0.33
sagax has quit [Remote host closed the connection]
sagax has joined #crystal-lang
<FromGitter>
<tenebrousedge> ```code paste, see link``` ⏎ ⏎ The error in the second case is that @a is used before it is defined, rendering it nilable. Is there a particularly good reason for that being an error? [https://gitter.im/crystal-lang/crystal?at=5e4989bdb3023d5025f3e327]
<FromGitter>
<j8r> The `@` inside the constructors are a shortcut, it works when done inside the block
<FromGitter>
<j8r> Basically, it's reweitten to `@a = a` and `@b = b`
<FromGitter>
<tenebrousedge> that's fine, but I think that it should work the way I wrote it
<FromGitter>
<j8r> there was a talk for maybe removing the `@` syntax
<FromGitter>
<j8r> because there are some corner cases like taht
* FromGitter
* tenebrousedge sighs
<FromGitter>
<tenebrousedge> of course there was
<FromGitter>
<tenebrousedge> ah! now this is a good reason
<FromGitter>
<tenebrousedge> > This is because any method call could potentially affect that instance variable, rendering it nil. Another reason is that another thread could change that instance variable after checking the condition.
_ht has quit [Ping timeout: 272 seconds]
_ht has joined #crystal-lang
<FromGitter>
<watzon> What would be an alternative to the `@` syntax?