<doublec>
although that's about getting 'ref' access to a 'ref' field in an 'iso' object
<doublec>
But to do it you need to have a recover block where you convert the iso to a ref. Access the field (since it's a ref now you can access fields) and then return it back as an iso.
<TJ800X>
Ok. I will have to take it piece-by-piece.
<TJ800X>
About the val. How do convert it to a ref type? Do I do it inside a recover block somehow?
<TJ800X>
I was just about to say....I should get me a shovel for this rabbit hole!
<jemc>
however, I can say as a quick and dirty answer that the most common reason to see an error like that is that you're trying to grab a mutable field (`ref`) from an object inside its read-only method (`fun box`)
<jemc>
note that the default *receiver capability* of a `fun` is `box` - usually when you see that error it means you need to turn it into a `fun ref`
<jemc>
are you already familiar with the concept of the *receiver capability* of a method?
<TJ800X>
I'm trying to run a function that mutates the object.
<TJ800X>
Yes.
<TJ800X>
I already added the ref capability to the function.
<doublec>
tj800x: you've got the ref in the wrong place
<doublec>
tj800x: you have "fun make_ts():U128 ref"
<doublec>
tj800x: I had "fun ref make_ts():U128"
<doublec>
tj800x: The first makes the result a U128 ref
<doublec>
tj800x: The second makes the 'this' a ref.
<doublec>
tj800x: ie. the receiver is a ref
<TJ800X>
Okay. Now it compiles.
<TJ800X>
Thanks so much. I'd be interested in any other thoughts on the code. This is a big effort for me. I appreciate all the experience and help I get on here.
<doublec>
np, happy to help :)
_whitelogger has joined #ponylang
papey_lap has joined #ponylang
k0nsl has quit [Quit: “If we don't believe in freedom of expression for people we despise, we don't believe in it at all — Noam Chomsky”]
<jemc>
vaninwagen: note the error says you can't do it *in a try expression*
<jemc>
this is because the compiler has to assume the try expression could error out at any time, including the possibility of erroring out *after the consume*, but *before the assignment* - this would leave the compiler not knowing statically whether that reference is safe to use again
<jemc>
does that make sense?
<jemc>
that is, you can definitely do that kind of pattern, but it can't be in a try expression
smoon has joined #ponylang
<vaninwagen>
jemc makes total sense
<vaninwagen>
SeanTAllen thx, will try that :)
<vaninwagen>
SeanTAllen does destructive read really work here if i have a method which consumes a var and i want to assign it's return value to that var?
smoon has quit [Quit: smoon]
<emilbayes>
jemc: ping?
<emilbayes>
jemc: Or I'll just ask
<emilbayes>
jemc: Why did you decide to go with you own _make_buffer in pony-sodium instead of using ByteSeq?
smoon has joined #ponylang
smoon has quit [Quit: smoon]
<jemc>
emilbayes: how would you use ByteSeq in its place?
<emilbayes>
jemc: I was thinking String ref or Array[U8 val] ref
<emilbayes>
jemc: But I'm still learning pony so I might be wrong
amclain has joined #ponylang
<jemc>
I think we had a discussion about this at one point, and I mentioned I'd be open to letting it take a type parameter
<jemc>
though note that strings and arrays can be converted between eachother without copying the underlying buffer
<emilbayes>
jemc: ah yeah I think you're right
<jemc>
so the API should be usable already, even if a bit more cumbersome
<emilbayes>
jemc: I have toyed aroud with implementing the crypto_pwhash function but can't get it to work
<jemc>
what's going wrong?
<emilbayes>
jemc: eg. I pass it a string to store the hash in, hash.space() is 32 before passing to libsodium, but hash.space() is 33 after
<emilbayes>
but the hash itself is still hash.size() == 0
<emilbayes>
the main actor might look a bit woonky because I messed around so much
<emilbayes>
oh, and I forgot use "debug"
vaninwagen has quit [Ping timeout: 240 seconds]
<emilbayes>
jemc: I'm also not sure what pattern is better when I get to other functions like pwhash_verify, which takes a password and a hash (and the settings). Should it take password as ref for consistency or as val because of least privilege?
<emilbayes>
jemc: does it make sense or do you not have time to look at it right now?
<jemc>
looking now
papey_lap has quit [Quit: WeeChat 1.9]
papey_lap has joined #ponylang
<jemc>
emilbayes: hm, my version of libsodium doesn't hav the `crypto_pwhash` functions - they must be new-ish :/
<jemc>
at any rate, note that the `String` class does some silly fiddling with the allocation length to account for a null terminator
<jemc>
this is one reason why I use a `_make_buffer` method internally
<emilbayes>
jemc: Ah
<emilbayes>
jemc: I think pwhash came in 1.0.10, but that version is over a year old :)
<emilbayes>
1.0.12 is latest
<jemc>
it's also for convenience, though - in C it is quite common to pass in an "out" argument, but in Pony it's somewhat non-idiomatic (unless it's in the hot path, and you're really pressed for avoiding memory allocations and want to reuse the buffers)
<emilbayes>
jemc: Yeah
<emilbayes>
jemc: Maybe I'm falling on old habits, but I help maintain the node.js bindings and we do it there to not deviate too much from the C api
<emilbayes>
jemc: But I guess the cost of any of the crypto ops is much greater than allocating internally to the function
<emilbayes>
jemc: The upside of letting the user pass in a out variable though is that it allows us to expose libsodium protected memory. Then the user can choose to use a normal ByteSeq or a SecureSeq (which I would implement)
<jemc>
that could be enough of an upside to make the change - though I think I'd like to work out the design of the `SecureSeq` class first before changing the API of the other pieces of the package
<emilbayes>
jemc: The protected memory stuff is like a custom malloc, all it takes as input is a length
<emilbayes>
then it has some apis around locking and unlocking the memory, R/W access and such
<emilbayes>
oh yeah, there's memory locking too, but I guess you could have a function allocated whatever you need and lock it right after it is returned to you
<emilbayes>
i don't know if a swap can happen in the time between pony allocs and the "whatever" is returned to you
<jemc>
I don't have much time at the moment to read through those docs today, but if you were planning on doing a Pony wrapper for it, I'd be interested to see what you think that API should look like
<emilbayes>
jemc: Maybe I should take a stab at that in the meantime, do a PR and we can go from there?
<jemc>
sounds good - but yeah, let's tackle the issue of adding the secure memory class separately from the issue of making the other types compatible with using it
Matthias247 has quit [Read error: Connection reset by peer]
jmiven has quit [Quit: co'o]
jmiven has joined #ponylang
tj800x_ has joined #ponylang
smoon has joined #ponylang
<tj800x_>
How do I convert from a U128 to an array of U8s? I've tried a few things, but can't get it to go.
<jemc>
be careful of the byte order, though - you've got to know whether you want big-endian or little-endian
<tj800x_>
Yes, I've got some control over that. I basically get to decide the endian-ness for my library. I think I'm using little-endianness, but after I've played with the library a bit I might change my mind.
<tj800x_>
I think I found a pretty obscure bug that causes the compiler to return without error. I'm doing something patently stupid. I know there are a ton of important things to be worked on. Should I report the bug or not?
<tj800x_>
I don't want to waste people's time.
<jemc>
sure, if you think you've found a compiler crash, please do report it
<tj800x_>
It happens when passing in a bad precision value into the Format library. Like I said, patently stupid of me, but that's what learners do.
<Praetonus>
tj800x_: This isn't a compiler bug, it's crashing at runtime
<jemc>
tj800x_: actually, the issue is that you told it to allocate an 8-gigabyte string :)
<tj800x_>
LOL. Fun stuff!
<jemc>
the cause is that `USize(-1) == USize.max_value()`
<tj800x_>
That can't be good. I'm not sure. My latest gist env.out.prints before and after, and I'm not getting anything outputted. I suppose the first output might not be getting flushed.
<jemc>
do you have a local pony environment you can run it on?
<tj800x_>
Sure do. Will do.
<jemc>
(I imagine the web sandbox doesn't take kindly to an 8-GB memory allocation
<tj800x_>
bin bash: line 1: 30940 Segmentation fault: 11 stupidgames
<tj800x_>
Leave it to a newbie to wreck it good.
<tj800x_>
IdiotGuard++
<tj800x_>
For the record -- those above negative comments were self-directed. This is a great community and I appreciate it.
<jemc>
no worries - I was trying to think if there's something that could be done as a sanity check in `Format` against very large values of `width`, but it seems that `width` is used for padding, and I'm not sure where to draw a "sane" limit for padding a string
<Praetonus>
jemc: There's a bug in String.reserve too. If the reserved size is USize.max_value, the function will add 1 for the null terminator and overflow, resulting in a String that thinks it has lots of memory available but actually didn't allocate anything