Perl 6 - the future is here, just unevenly distributed

IRC log for #perl6-lwp-gsoc, 2014-07-02

| Channels | #perl6-lwp-gsoc index | Today | | Search | Google Search | Plain-Text | summary

All times shown according to UTC.

Time Nick Message
01:56 FROGGS_ joined #perl6-lwp-gsoc
04:18 dalek joined #perl6-lwp-gsoc
06:28 sergot FROGGS_: unfortunately I couldn't continue yesterday, I'd do this today
06:33 sergot Ok, reading #moar's log and I'll try
06:41 sergot int8, int16, int32, int64 all have 64 in ss.bits
06:47 sergot hm, no
06:47 sergot I was wrong
06:47 sergot :)
06:47 FROGGS_ joined #perl6-lwp-gsoc
06:48 sergot FROGGS: have just started working on nativecast
06:48 FROGGS sergot: awesome :o)
06:48 sergot May I ask a question?
06:48 sergot This is my idea:
06:48 FROGGS sergot: you can also push your stuff to a branch in moarvm, that'd help reviewing it
06:48 FROGGS sure, aks
06:48 FROGGS aks*
06:48 FROGGS ask*
06:48 FROGGS damn :o)
06:48 sergot :)
06:49 sergot if some types are MVM_REPR_ID_P6int, then, I should check what they are (char, int etc) inside the case MVM_REPR_ID_P6int, right?
06:49 FROGGS no
06:50 FROGGS did you mean P6opaque by any chance?
06:50 sergot hmm, no
06:50 FROGGS because the problem is that you do not get a P6int, right? you only get a P6opqaue AFAIK
06:50 FROGGS at least that is what you said yesterday
06:51 FROGGS or do you get P6int for native ints?
06:51 sergot no, I said I got P6int
06:51 sergot :)
06:52 FROGGS but only for natives, right?
06:52 sergot right
06:52 FROGGS I mean, I cannot be totally off, not this early :o)
06:52 FROGGS ohh, doog
06:52 FROGGS good
06:52 sergot Is Int native?
06:52 FROGGS no
06:53 FROGGS the lowercase ints and nums are natives
06:53 FROGGS Int and Num are P6bigints in a P6opaque
06:53 sergot right, so I get P6int (8) only for native ints
06:53 FROGGS yes
06:53 FROGGS so, you have a case for MVM_REPR_ID_P6int
06:54 sergot and 9 for native nums, it's P6num probably
06:54 FROGGS then you have to obtain the storage spec to know how many bits it can handle
06:54 FROGGS yes
06:55 sergot ok, I got this, printing it as SS.BITS: 8 for int8
06:55 sergot 32 for int32 and so on...
06:55 FROGGS nice
06:56 FROGGS so add another switch for that ss.bits, and call the appropriate ....
06:56 FROGGS umm, wait
06:57 FROGGS we're going to call make_int_result in any case for P6ints?
06:57 sergot true
06:57 FROGGS okay, than you don't need the storage spec here
06:59 sergot Yes, I did this, but
06:59 sergot :q
06:59 FROGGS yeah? *g*
06:59 sergot oh.. vim is not here
07:00 sergot I got 'This representation (P6int) cannot unbox to other types' when printing nqp::nativecall(..., ...(inthere))
07:00 sergot it works if I dont print it
07:00 sergot say it , actually :)
07:01 sergot nqp::nativecast(nqp::decont(int32), nqp::decont(2));
07:02 sergot another problem is:
07:02 sergot nqp::decont('b') - this is still P6int, but it gives this error: This type cannot unbox to a native integer - (not saying anything)
07:04 sergot probably because of ->get_int()
07:04 FROGGS for the second problem: that it is P6int is because the other argument is a native int, and you only check that other argument
07:05 FROGGS nqp::nativecast(nqp::decont(int32), nqp::decont(2)); <-- here, we expect to get a OpaquePointer as second arg, no?
07:05 sergot switch (REPR(res_type)->ID) {
07:05 FROGGS at least, that is the only thing our C code can handle
07:05 FROGGS sergot: yes, what is res_type?
07:05 sergot hmm
07:05 FROGGS is that the first or second param?
07:16 sergot the first one
07:16 sergot obj is the second one
07:17 sergot I ' ll push my changes
07:17 sergot give me a minute
07:18 FROGGS see, and the first one you pass is int32, so that you pass 'a' does not change the return target
07:28 sergot What about the first probem?
07:28 sergot problem
07:33 FROGGS <FROGGS> nqp::nativecast(nqp::decont(int32), nqp::decont(2)); <-- here, we expect to get a OpaquePointer as second arg, no?
07:33 FROGGS that is the first problem, right?
07:34 FROGGS <FROGGS> at least, that is the only thing our C code can handle
07:34 sergot yes, probably. still have a problem
07:34 sergot look:
07:34 sergot ok, I'll push my changes first
07:35 FROGGS btw, we only need to native-cast pointers... it does not make sense to cast a numeric value
07:36 FROGGS so, when you have a pointer that points to a long, then we need to make that case work
07:36 FROGGS still, second arg would be an OpaquePointer then
07:38 sergot https://github.com/sergot/MoarVM/commit/82be7ca9dd32e9fdffa01a79702a451db7a9ddd7
07:38 sergot You're right
07:38 sergot https://github.com/sergot/MoarVM/blob/master/src/core/nativecall.c#L755
07:39 FROGGS /o\
07:39 sergot look:
07:40 sergot sub SSL_shutdown(SSL) returns OpaquePointer is native('libssl')                    { * } # should return int32
07:40 sergot my $shutdown = SSL_shutdown($ssl);
07:40 sergot nqp::nativecast(nqp::decont(int32), nqp::decont($shutdown));
07:40 sergot got:
07:40 sergot This representation (CPointer) cannot unbox to a native int
07:41 FROGGS why do you want to unbox that CPointer to an int at all?
07:41 FROGGS like in here: printf("VALUE: %d\n", (int)REPR(obj)->box_funcs.get_int(tc, STABLE(obj), obj, OBJECT_BODY(obj)));
07:42 FROGGS sergot: you know a bit of C, right? so let's talk C for a minute:
07:42 sergot I thought I know C quite good :)
07:42 FROGGS long *thingy = 42;
07:42 FROGGS what it thingy?
07:42 FROGGS is*
07:43 sergot it is a pointer
07:43 FROGGS correct, like our OpaquePointer
07:43 FROGGS how to you access its value?
07:43 FROGGS do*
07:43 FROGGS damn fat fingers
07:44 sergot by dereferencing, *thingy
07:44 FROGGS correct
07:44 FROGGS so you do not try to unbox it to an int
07:44 FROGGS so....
07:44 FROGGS what is cpointer_body->ptr ?
07:45 sergot It's a pointer as well
07:45 sergot to our value
07:45 FROGGS correct!
07:45 FROGGS how do we get its value? :D
07:45 sergot *cpointer_body->ptr :)
07:46 FROGGS yes
07:46 FROGGS pass that to make_int_result
07:46 FROGGS but:
07:46 FROGGS MVMnum64 is for nums btw, please don't mix ints and nums
07:49 sergot oh, ok
07:49 sergot Anyway, I treated it too much complicated..
07:51 FROGGS yes
07:51 sergot int nnn = (MVMint64)cpointer_body->ptr;
07:51 FROGGS which can happen when you see all these boxing and unboxing functions...
07:52 FROGGS you have to deref it
07:52 FROGGS and, do not assing to int, this can be something else than MVMint64
07:52 sergot okok, it's just a draft
07:53 FROGGS perhaps we even need a switch(ss.bits) to do the cast before the deref right
07:54 sergot We cannot derefer void *
07:55 sergot soo, we have to cast it, to MVMint64 *
07:55 sergot and then derefer
07:55 FROGGS and what if it points to a char?
07:55 FROGGS we have to cast according to the ss.bits, no?
07:56 sergot that's right, I meant the thing you said before this, 09:52 < FROGGS> you have to deref it
07:56 FROGGS yes
07:56 FROGGS right
07:56 sergot anyway, (MVMint64) should do the job for us
07:56 sergot I think
07:57 sergot Ok, I'll do the ss.bits first
07:57 FROGGS you can also try the simple case first
07:57 FROGGS and then we see if we SEGV for int8 or get garbage...
07:58 FROGGS I think we need extensive nativecall tests for this, so that we add C function that malloc a char * and return its addr for example
07:59 FROGGS we cannot test this properly with libopenssl, because we probably have not function that returns a char *
08:00 sergot true
08:01 sergot make_int_result gets MVMint64 anyways
08:01 FROGGS yes, but how does the C compiler know that you want to read a single byte when you deref a char * as MVMint64?
08:01 sergot so, actually we dont have to care about ss.bits
08:02 sergot yes, you're right, I'm a little back
08:05 sergot anyway, it sounds like a lot of work to do
08:08 FROGGS na, it is just about 10 lines of code
08:10 sergot hm, ok :)
08:10 sergot so, what should I do now?
08:11 sergot Write this "test" stuff?
08:11 FROGGS you already have the ss.bits, make a switch(ss.bits), and do the right casts in the cases
08:11 sergot ok
08:11 FROGGS yes, probably a simple test with a char *
08:12 FROGGS in the NativeCall repo perhaps, that would be the easiest
08:14 sergot FROGGS: refresh
08:14 sergot I've just added the switch statement
08:14 sergot but...
08:14 FROGGS you have to deref
08:14 FROGGS and the cast is wrong
08:14 sergot As I wrote earlier, we get "src/core/nativecall.c:763:5: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]"
08:15 FROGGS you are casting a pointer to an int
08:15 FROGGS value = *(MVMint8 *)cpointer_body->ptr;
08:15 sergot damn, wait a minute
08:15 sergot I thought (MVMint8) will do this for us
08:15 FROGGS no that is not a pointer
08:16 FROGGS that is just like char
08:16 sergot I had *(MVMint? *) before and it caused a segfault.
08:16 sergot that was my first thought about *(MVM *)
08:17 FROGGS the segfault might be because we are trying to read to much
08:17 sergot ok
08:17 FROGGS like it return an char * and we're requesting more than one byte or so
08:18 sergot refresh
08:18 FROGGS and please, value is not an int, it should be MVMint64
08:18 sergot ok
08:18 FROGGS otherwise we would truncate the value in 32bit platforms
08:18 FROGGS on*
08:19 FROGGS okay... now it segfaults?
08:19 sergot done
08:19 FROGGS (I can't try easily)
08:19 sergot yes
08:23 FROGGS what is your test case that segfaults?
08:24 dalek openssl: 4b89c37 | sergot++ | test.p6:
08:24 dalek openssl: just testing
08:24 dalek openssl: review: https://github.com/sergot/openssl/commit/4b89c372e7
08:24 sergot https://github.com/sergot/openssl/blob/master/test.p6#L130
08:25 FROGGS does it print SS.BITS: 32 before segfaulting?
08:25 sergot yes it does
08:25 FROGGS and it does not print VALUE:... ?
08:25 sergot true
08:25 FROGGS ummm
08:26 FROGGS I know what it is
08:26 FROGGS SSL_shutdown usually returns an int32, right?
08:26 sergot right
08:26 FROGGS is that a pointer type?
08:27 sergot no, it's not
08:27 FROGGS that is why it is not a good thing you test with openssl
08:27 FROGGS because you do not get a pointer that points to an int32
08:27 FROGGS so you use the value of 1, treat it as a memory address, and then try to resolv its value
08:28 FROGGS you really need a function that returns an int* of some size
08:28 sergot sounds reasonable :)
08:29 FROGGS you can use this as a preset:
08:29 FROGGS https://github.com/jnthn/zavolaj/blob/master/t/03-simple-returns.c
08:29 FROGGS https://github.com/jnthn/zavolaj/blob/master/t/03-simple-returns.t
08:29 FROGGS adjust both, and name them 09-nativecast.{c,t}
08:30 FROGGS these tests need to be in NativeCall anyway
08:30 sergot ok, so I should make all those functions return pointer to values, right?
08:30 sergot pointers to value*
08:31 FROGGS right
08:32 FROGGS we can only handle pointers... it does not make any sense to native-cast a value to a value :o)
08:32 sergot ok, thanks FROGGS++
08:33 sergot I hope you're not mad because of me :))
08:35 FROGGS no, I'm not :o)
08:35 FROGGS no worries :o)
08:35 sergot great, thanks :)
08:47 sergot FROGGS: :(
08:47 sergot agrh
08:48 sergot This representation (P6int) cannot unbox to other types
08:48 sergot when
08:48 sergot 11 is nqp::nativecast(nqp::decont(int32), nqp::decont(ReturnInt())), 101, 'returning int works';
08:48 sergot https://github.com/sergot/zavolaj
08:48 sergot https://github.com/sergot/zavolaj/commit/4cff92b623d30621d0a55a5a38d09212d0e23d43
08:49 FROGGS ummm, you are returning a local memory address here: https://github.com/sergot/zavolaj/blob/master/t/09-nativecast.c#L12
08:49 FROGGS this address is only valid within that function
08:54 FROGGS the C compiler should warn that you return a local address... but the output is probably not shown
08:55 sergot oh, right
08:56 sergot So, I'm afraid I'm not aware of how to return it as no local address.
08:57 FROGGS how would you request a piece of memory in C?
08:58 sergot with &
08:58 FROGGS ... to store something there, like a integer
08:58 FROGGS sergot: no
08:59 FROGGS say you need 10 bytes of mem, how do you do that?
08:59 sergot calloc(10, sizeof(something)) to allocate some memory
09:00 sergot or malloc, alloc etc
09:00 FROGGS right
09:00 FROGGS what does malloc return?
09:00 sergot address to our piece of memory
09:00 FROGGS nice
09:00 sergot s/our/requested/
09:01 FROGGS and will this memory vanish when we exit the function?
09:01 sergot it will be cleared only with free()
09:01 sergot :)
09:02 sergot vanished
09:02 FROGGS so, the pointer could be passed happily around, right?
09:02 sergot so:
09:03 sergot 12     int *i = malloc(sizeof(int));
09:03 sergot 13     *i = 101;
09:03 sergot 14     return i;
09:03 sergot ? :)
09:04 FROGGS yes :o)
09:04 sergot \o/ thanks
09:04 sergot but...
09:04 FROGGS *g*
09:04 FROGGS but?
09:04 sergot still
09:04 sergot This representation (P6int) cannot unbox to other types
09:05 FROGGS you have committed?
09:07 sergot yes, have just pushed
09:07 sergot https://github.com/sergot/zavolaj/commit/5fb409ad4455a1887b2d8e4a55d0638bf0d1ec2d
09:08 FROGGS when does this happen? for the very first test?
09:08 sergot yes
09:08 sergot the same as it segfaulted - right after printing SS>BITS
09:08 sergot SS.BITS
09:08 sergot on
09:08 sergot after printing the value
09:08 sergot I forgot I removed this
09:09 sergot Yes, it happens after printing the value
09:09 FROGGS so it probably fails in make_int_result
09:10 sergot Hm, I dont think so
09:10 sergot this works:
09:10 sergot 11 nqp::nativecast(nqp::decont(int32), nqp::decont(ReturnInt()));
09:11 sergot it fails on is, say etc.
09:11 FROGGS but that is your test, no?
09:11 sergot i removed "is"
09:11 FROGGS ahh
09:11 FROGGS add a nqp::p6box_i() around the nativecast call in the test file
09:12 sergot yay, it works \o/
09:12 FROGGS \o/
09:13 sergot is it always _i? even for int16, int8 etc.?
09:15 FROGGS yes, _i is for int
09:16 FROGGS there is also _n and _s
09:16 FROGGS for num and str
09:16 sergot https://github.com/sergot/zavolaj/commit/f6cbbf76a7e96ca2feb2ef97e62c2e4b4a2252e1
09:16 sergot is it ok?
09:17 sergot accidentally passed first 3
09:18 sergot I should add tests for CArray, CStruct
09:18 sergot and ... ? something else?
09:18 sergot CPointer?
09:18 sergot no :)
09:26 sergot ok, I made it passes first 5 tests
09:26 FROGGS CPointer too
09:27 sergot FROGGS: I really appreciate your help
09:27 FROGGS because you could ship your own class that has the same REPR as OpaquePointer, and that should work too
09:27 sergot I learn a lot !
09:27 FROGGS I hope so :P
09:28 sergot One things looks strange to me...
09:28 sergot Why string is P6num?
09:28 FROGGS its not
09:28 sergot the sixth test shows that it is
09:28 sergot I got this:
09:28 sergot ok 5 - returning float works
09:28 sergot 9
09:28 sergot SS.BITS: 64
09:28 sergot VALUE: 9.8001e+252
09:28 sergot This representation (P6num) cannot unbox to a native string in block  at t/09-nativecast.t:26
09:28 sergot # Looks like you planned 7 tests, but ran 5
09:29 sergot 9 == P6num
09:29 sergot I added "            case MVM_REPR_ID_P6num: {
09:29 sergot "
09:29 FROGGS well, you are passing 'num' here: https://github.com/sergot/zavolaj/blob/master/t/09-nativecast.t#L26
09:29 FROGGS should be str
09:29 sergot aaaaa
09:29 FROGGS hehe
09:31 sergot you're right - I make such mistakes because I think that everything is much more complex than it actually is.
09:31 sergot so, I'm really sorry for that
09:31 FROGGS you will learn to keep a clear mind even when the task sounds highly complicated
09:32 FROGGS because after you split the task into doable parts, every small part has its own not-so-bad problems that want solving
09:32 FROGGS that's why it is important to thing about how to solve the task (vaguely)
09:33 FROGGS then sketch the tasks you can split it into
09:33 FROGGS stub these functions for example (with a comment perhaps what goes in and what comes out)
09:34 FROGGS and then you only care about filling that little function (== small problem) with life
09:34 FROGGS and at the end you put everything together and hunt bugs down, because there will always be bugs
09:34 FROGGS and then you have solved a huge tasks bit by bit, only by caring about small parts and small steps that are doable
09:35 sergot Sounds good, thank you FROGGS++
09:35 FROGGS pleasure :o)
09:36 sergot another with with strings:
09:36 sergot https://github.com/sergot/MoarVM/blob/master/src/core/nativecall.c#L714
09:36 sergot it takes one more argument
09:36 sergot it is body->ret_type
09:37 FROGGS hmmm
09:37 FROGGS I guess the encoding is hidden in it, which is interesting at that point
09:37 FROGGS sergot: pass MVM_NATIVECALL_ARG_UTF8STR for now
09:38 sergot okok
09:38 FROGGS (small steps, you see)
09:39 FROGGS got it from here: https://github.com/sergot/MoarVM/blob/master/src/core/nativecall.c#L128
09:39 FROGGS and utf8 is always a good default :o)
09:39 FROGGS later we will care about this, and try to figure out the requested encoding of a native str
09:43 sergot awesome
09:45 sergot so, I must handle the case, when we get nullstring
09:47 FROGGS a null pointer, yes
09:47 FROGGS ahh no, you don't have to
09:48 FROGGS the function called by make_str_result will give you something valid for this case
09:48 FROGGS at least you don't have to care about that in C land
09:49 FROGGS note that this test is about Str, not str: https://github.com/sergot/zavolaj/blob/master/t/03-simple-returns.t
09:49 FROGGS so we might want to do Str also
09:53 sergot Can we treat Str as the same as str in our switch?
09:54 FROGGS I think so
09:56 FROGGS it might be a MVM_REPR_ID_MVMCStr or a MVM_REPR_ID_P6str, I'm not sure
09:57 FROGGS lunch &
09:57 sergot true
10:05 sergot hmmm, actually... Str is MVM_REPR_ID_P6opaque
10:19 sergot and it causes segfault on empty string
10:24 sergot all uppercased types are P6opaque
11:00 FROGGS then you have to check if the P6opaque can box a str, using its storage spec
11:00 sergot ok :)
11:08 FROGGS same for Int, you query it if it can box an Int
11:08 FROGGS and then do the stuff you did earlier... REPR(obj)->box_funcs.get_int(...
11:12 sergot that's what I'm doing :)
11:12 sergot but... :)
11:12 sergot hehe
11:12 sergot Do I have to write again the same?
11:13 sergot It break the DRY rule.
11:13 sergot but I don't like goto either
11:13 sergot Ok, I'll just copy it for now.
11:14 FROGGS DRY?
11:15 sergot Dont Repeat Yourself
11:15 FROGGS ahh
11:15 FROGGS make it work, then clean it up
11:15 sergot ok :)
11:15 FROGGS should also be a rule :o)
11:15 FROGGS ang avoid goto, also a rule :P
11:15 FROGGS and*
11:16 sergot yes :)
11:17 sergot Ok, it works with the p6opaque
11:17 sergot still have a problem with the segfault :)
11:17 sergot when have null pointer
11:17 FROGGS ahh
11:17 FROGGS hmmm
11:17 FROGGS can you commit your stuff?
11:17 sergot no, wait.
11:17 sergot it doesnt work
11:17 FROGGS k
11:17 FROGGS can you commit your stuff?
11:17 sergot yes
11:18 sergot https://github.com/sergot/MoarVM/commit/5f201d2c6da8e491d662eec55bc100e379886a05
11:19 sergot https://github.com/sergot/MoarVM/blob/master/src/core/nativecall.c#L764
11:20 FROGGS that typecast is wrong: https://github.com/sergot/MoarVM/blob/master/src/core/nativecall.c#L803
11:20 sergot I have to get the value here: https://github.com/sergot/MoarVM/blob/master/src/core/nativecall.c#L773 in another way
11:20 FROGGS should not be a problem though
11:20 sergot ok, we have 2 errors, let's do the segfaulty one
11:20 FROGGS yes
11:21 sergot Why is it wrong?
11:22 FROGGS I guess we need gdb to tell us
11:22 sergot oh
11:22 sergot sounds scary ;)
11:23 FROGGS no, it is just a tool
11:23 sergot Yes, I know gdb
11:23 sergot bu
11:23 sergot but
11:24 sergot I have never used it in such a big project
11:24 FROGGS it will at least point you to the right line number... what can be wrong with that? :o)
11:26 FROGGS ohh, I have to recompile nqp
11:27 sergot I just dont know how to run it when we dont execute our program directly.
11:27 sergot I mean
11:27 sergot we run perl6 not the vm direcrly, does it matter?
11:28 FROGGS 'perl6' is a shell script that invokes the vm
11:28 FROGGS do:
11:28 FROGGS which perl6
11:28 FROGGS cat <what you got>
11:29 FROGGS you get:
11:29 FROGGS exec /home/froggs/dev/nqp/install/bin/moar  --execname="$0" --libpath="/home/froggs/dev/nqp/install/languages/nqp/lib" --libpath="/home/froggs/dev/nqp/install/languages/perl6/lib" --libpath="/home/froggs/dev/nqp/install/languages/perl6/runtime" /home/froggs/dev/nqp/install/languages/perl6/runtime/perl6.moarvm "$@"
11:29 FROGGS then only copy the stuff after 'exec' and before '"$@"'
11:29 sergot oh, ok, nice
11:29 FROGGS so I do:
11:29 FROGGS gdb --args /home/froggs/dev/nqp/install/bin/moar  --execname="$0" --libpath="/home/froggs/dev/nqp/install/languages/nqp/lib" --libpath="/home/froggs/dev/nqp/install/languages/perl6/lib" --libpath="/home/froggs/dev/nqp/install/languages/perl6/runtime" /home/froggs/dev/nqp/install/languages/perl6/runtime/perl6.moarvm -Ilib t/09...
11:30 sergot 0x00007ffff79aee76 in make_str_result () from /home/likewise-open/ALLEGROGROUP/filip.sergot/p6/MoarVM/install/lib/libmoar.so
11:31 FROGGS ahh, you don't have a debug build of moarvm
11:33 sergot yes, I'll do this
11:34 FROGGS I don't get a segfault, I get:
11:34 FROGGS SS.BITS: 64
11:34 FROGGS VALUE: 9.8001e+252
11:34 FROGGS This representation (P6num) cannot unbox to a native string
11:34 FROGGS in block  at t/09-nativecast.t:26
11:34 FROGGS perhaps you have unpushed changes?
11:34 sergot pull and try again now
11:38 sergot does moar have any make option to compile it with -g?
11:39 FROGGS it fails in this branch:
11:39 FROGGS case MVM_REPR_ID_MVMCStr:
11:39 FROGGS case MVM_REPR_ID_P6str: {
11:40 FROGGS sergot: it has a configure option --debug
11:40 FROGGS --debug=3 is a good choice
11:41 sergot yes, because we have 'str' there, it'll fail with 'Str' too, but in case MVM_REPR_ID_P6opaque:
11:41 FROGGS you are using 'str' in the exploding test, not Str
11:41 FROGGS still good to know :o)
11:43 sergot have just checked, and the result is the same with Str
11:49 sergot any ideas? :)
11:50 FROGGS I just see that cpointer_body->ptr is not NULL for some reason
11:53 FROGGS ahhhhhh
11:54 FROGGS hmmm, no
11:54 FROGGS well, perhaps
12:05 sergot oh
12:12 FROGGS okay, there were several problems
12:12 FROGGS first the gc issues:
12:12 FROGGS res_type if protected here: https://github.com/sergot/MoarVM/blob/master/src/core/nativecall.c#L763
12:13 FROGGS that in case we trigger a gc run in the following block, this object would be safe to use
12:13 FROGGS but we didn't do that with obj yet, and we have to
12:17 sergot ok, so MVMROOT for obj, right?
12:18 sergot if so, then it's done
12:18 FROGGS right
12:18 FROGGS okay, next
12:19 sergot https://github.com/sergot/MoarVM/commit/ce820bd9676e9e12b3b89f226d501a7b88807018
12:19 FROGGS in case for the null string, we don't get an OpaquePointer instance having a zero in it, we get an OpaquePointer type object (undef)
12:20 FROGGS se we have to check for that case
12:22 sergot okay
12:22 sergot is it the same even when we use str instaed of Str?
12:22 sergot oh, it is I think
12:23 FROGGS yes
12:24 sergot so, we must check if it's undef before calling make_str_result
12:24 FROGGS because this is about checking the OpaquePointer, no matter what type we want to cast into
12:24 FROGGS so it is a general problem
12:24 FROGGS we can do that at the very beginning I think
12:25 sergot oh, right
12:25 sergot Do you know how, or should we figure it out?
12:25 FROGGS after that https://github.com/sergot/MoarVM/blob/master/src/core/nativecall.c#L760
12:25 FROGGS I know how, sec
12:26 FROGGS this is what I did right before make_str_result: char *value = IS_CONCRETE(obj) ? (char *)cpointer_body->ptr : NULL;
12:27 FROGGS and I think we can't do that upfront
12:27 FROGGS yes, we can do that
12:28 sergot IS_CONCRETE? :)
12:28 FROGGS do: void *cpointer_ptr = IS_CONCRETE(obj) ? cpointer_body->ptr : NULL;
12:28 FROGGS yes :o)
12:29 FROGGS the P6 object header has flags that tells if it is a type object or an instance
12:29 sergot ok, I did this
12:30 FROGGS here https://github.com/sergot/MoarVM/blob/master/src/core/nativecall.c#L775
12:30 sergot so, I'm changing every instance of cpoointer_body->ptr to cpointer_ptr
12:30 FROGGS you can change it to value = *(MVMint8 *)cpointer_ptr;
12:31 FROGGS and in case we do not access obj in the block anymore, you can strip the MVMROOT(tc, obj again :o)
12:31 FROGGS sergot: yes
12:32 sergot hmm, why there? why not just under    if (REPR(obj)->ID == MVM_REPR_ID_MVMCPointer)
12:32 sergot ?
12:32 sergot cpointer_body = (MVMCPointerBody *)OBJECT_BODY(obj);
12:32 sergot oh, I see I think
12:32 FROGGS the CPointer case is when you want to cast something *to* a cpointer
12:32 FROGGS but here is is about strings
12:33 sergot and line 775 is a case 8, it's not about strings
12:34 FROGGS you know what, we can also just return res_type if the pointer is not IS_CONTRETE... like in here:
12:34 FROGGS https://github.com/sergot/MoarVM/blob/master/src/core/nativecall.c#L766
12:35 sergot ok
12:35 FROGGS sergot: I know that at line 775 it is about int8, but when the OpaquePointer contains garbage when it is a type object, then you can also not use its memory address
12:36 sergot ok, so I should add it to every case, right?
12:36 FROGGS no
12:36 FROGGS <FROGGS> you know what, we can also just return res_type if the pointer is not IS_CONTRETE... like in here:
12:36 FROGGS <FROGGS> https://github.com/sergot/MoarVM/blob/master/src/core/nativecall.c#L766
12:36 FROGGS we can care about that once, at the beginning
12:37 FROGGS if the OpaquePointer is 'undef', we return res_type
12:37 FROGGS otherwise, we obtain the cpointer_ptr, and go on
12:38 sergot ooook :)
12:39 sergot if (!IS_CONCRETE(obj)) return res_type;
12:39 sergot then?
12:40 sergot seems to work
12:44 sergot now we have: Cannot unbox a type object
12:44 sergot and still the first test (when we use Int) there is: #      got: '139698106269797'
12:45 sergot I assume it is the address of our OpaquePointer
12:52 FROGGS sergot: yes, your test is wrong
12:52 FROGGS you shall not p6box_s a Str, only str and only when it isnt a type object
12:52 FROGGS the Int test is another story
12:53 sergot So, we should never nativecast it to Str?
12:53 sergot s/it/something/
12:56 sergot "Cannot unbox a type object" appears even when we have 'str' there.
13:00 FROGGS correct
13:00 FROGGS only p6box an instance
13:00 FROGGS that logic needs to go to the nativecast sub that NativeCall needs to export then
13:04 sergot hm ok
13:04 sergot :)
13:12 sergot meanwhile I did this:
13:12 sergot https://github.com/sergot/zavolaj/commit/39a95aa44984896ac1f63fb8ac9d2a4d40f15086
13:14 sergot So, my currect task is to write sub nativecast in NativeCall.pm6, right?
13:14 FROGGS yeah
13:15 FROGGS you could also write: i->i = 100;
13:15 sergot there is "Cannot unbox a type object" even if the returned string isint empty.
13:15 sergot yes
13:15 FROGGS that msg is weird
13:17 sergot IS_CONCRETE returns 0 even if we have non-empty string
13:17 sergot I guess
13:21 FROGGS by non-empty string you are talking about an opaquepointer that is pointing to a string?
13:23 sergot yes
13:23 sergot I think :)
13:31 sergot Can MVMROOT cause a segfault?
13:43 FROGGS no, it is a macro
13:43 FROGGS okay, gtg now, see you in a bit
13:57 sergot ok :)
14:12 sergot ok, all pushed my changes
14:12 sergot I pushed*
14:12 sergot Will continue this later :)
14:12 sergot &
14:31 FROGGS joined #perl6-lwp-gsoc
14:40 FROGGS k
21:25 sergot oh, it's too late now !
21:26 FROGGS for what?
21:26 FROGGS it is never too late :o)
21:26 sergot for programming, I have to get early tomorrow  :-(
21:27 sergot haha :-D
21:27 FROGGS ohh, okay :o)
21:27 sergot I ll start coding early too :-)
21:29 sergot good night o/
21:29 FROGGS gnight

| Channels | #perl6-lwp-gsoc index | Today | | Search | Google Search | Plain-Text | summary