« first day (5051 days earlier)      last day (27 days later) » 

12:10 AM
Seems it just magically works if I do make clean... sigh
12:42 AM
OK I got the function name from op1 and the arg from op2. Now I just need to do reflection. But so help me if I have to code it in the zend_vm_def.h file, I might not survive.
Also I couldn't help but notice that ZEND_CALL_TRAMPOLINE magically gets the function name from EX(func). But I guess I can't do that...
(and some other opcodes do sick things with void pointers to achieve the same)
 
5 hours later…
6:14 AM
@QuolonelQuestions What system are you on? Nowadays, modifying headers should rebuild all files including it. But yes, if the sizes across compilation units don't match, you'll get crashes.
6:25 AM
@QuolonelQuestions Why do you need the function name? EX(func) refers to the current function. You need EX(call).
Btw, there also seem to be some cases where getDefaultValue doesn't work. github.com/php/php-src/commit/…
 
2 hours later…
8:14 AM
@IluTov Good to know, although that is a very edgy edge case
@IluTov Yes, it would be nice if it noticed the change. I'm using nmake on Windows
One of the last surviving Windows developers of our age
@QuolonelQuestions Maybe try WSL :P At least if you want anybody to help you. :D
D:
I replaced the function name op with EX(call) and that works. I imagine I would need to do that eventually anyway, since just having a function name is not going to work for anonymous functions
In the end, my compile function is now super simple

static void zend_compile_default(znode *result, zend_ast *ast)
{
zend_op *opline = zend_emit_op_tmp(result, ZEND_FETCH_DEFAULT_ARG, NULL, NULL);
opline->op1.num = CG(arg_num);
}
Can you only call C functions from the VM handler if they're inline?
9:42 AM
@QuolonelQuestions Just fyi, CG(arg_num) will likely not be enough. You'll need a stack (or linked list like CG(context)) because of things like foo(bar('baz', 'qux') | default), where the second arg of bar() would adjust arg_num to 2, but default needs for it to be restored back to 1.
@QuolonelQuestions No.
Or I guess just backup/restore in zend_compile_args(), using the C stack.
9:59 AM
@IluTov so I should be able to just call the reflection API directly then?
@IluTov I don't really know anything about C so I don't know what that means :<
@IluTov good to know, but as you might expect, I'll focus on the trivial cases first, for now 😆
I did figure out that you use -> when it's a pointer and . when it's a struct, so I guess that's something :^)
@QuolonelQuestions Oh ok, I wasn't aware you know no C. foo->bar is just sugar for (*foo).bar.
10:27 AM
Almost none. One thing I do know is you can't just magic variables out of thin air like in PHP :^)
Although, you sort of can, just so long as you never use the word new
10:58 AM
Oh wait, apparently that's C++ anyway
 
9 hours later…
7:46 PM
Why can you only get one thing from the CG() at a time? What if you want to see the state of the entire structure?
@QuolonelQuestions This is C, so technically you can just take the address of the first member of the struct.
Is it C? I don't really know C, but I don't even recognise this as a C thing. The whole superglobals in CG, EG and EX seems really alien to me. I have no idea how they work or how you would set them up, just that they do (somehow) work...
I don't love the way these macros work, personally. I'd prefer that they gave a pointer to the whole struct, EG()->vm_interrupt and that there was also an API function for it.
As soon as I see extern my eyes glaze over and I pretend I didn't see anything...
Fortunately zend_lineno has been the first member of the struct for all of PHP 7 and 8: heap.space/….
7:51 PM
How does the first member help me get all of the members?
&CG(zend_lineno) will give you a pointer to the whole _zend_compiler_globals struct.
Let me try it
Well you gotta cast it though.
(struct _zend_compiler_globals *) &CG(zend_lineno)
Oh :^) This didn't work compiler_globals *cg = &CG(zend_lineno);
Why do you need to put struct in the cast? Doesn't it know it's a struct?
This is fine too: (zend_compiler_globals *) &CG(zend_lineno).
zend_compiler_globals is a typedef for struct _zend_compiler_globals.
The code is a bit brittle. Depending on if you have C11+ available, you might want a _Static_assert(offsetof(struct _zend_compiler_globals, zend_lineno) == 0, "Expected zend_lineno to be the first member of the struct, did it change upstream?"); or similar.
7:57 PM
It doesn't seem to work right. All I see is garbage that I know is wrong in the structure
I don't need it to be robust; I'm only using it for debugging. But I do need it to work
Shame I can't do the same for EX/EG at all, since AFAIK these only apply during the execute phase but I can't see any locals in the VM with my debugger for some reason
That is, any breakpoints in zend_vm_execute.h will be hit, but I can only see the stack frames, with none of the state whatsoever
This is so weird. When I view my new arg_num entry in zend_compiler_globals as you instructed, the debugger shows its value to be 3452816845, which I guess is just garbage data. But CG(arg_num) gives me the correct value (1)
8:49 PM
So I'm pretty sure I want to call get_parameter_default() but it's in php_reflection, so I can't call it from zend_vm_dev.h can I?
Look at the zend_execute_API.h to know what you can call from the VM
Uh... I don't have that file
I only have the .c file
@QuolonelQuestions Did you build with -g?
I don't know what -g is xd
--enable-debug on the configure line should probably do the right thing. But you can verify in the make output.
If you have a -O2 in there, you are likely in a world of pain :-)
8:53 PM
I did do --enable-debug
It doesn't matter that I'm on Windows does it?
No results for -O2 in Makefile
I can't comment on Windows development.
I don't think anyone in here really can.
Well I guess I don't need the H file. I can still see everything in the C file
So it looks like I can use this API to take one step back and literally call class methods like I'm a PHP user
@QuolonelQuestions Erf I always forget the corresponding header fo that is zend_execute.h ....
I don't really need to bounce through the first level of that interface, since I already have a pointer to the function I want to get the default for, but I guess I have no choice...
I was hoping to be able to make a lower level call
I think @Dharman compiles on Windows? Otherwise @cmb (if he still reads this chat) could help
8:59 PM
I don't think I'm having any problems compiling on Windows if you just got the file name wrong :^)
I compile on WSL nowadays
We were talking about debug mode
I can still compile on pure Windows if need be, but I prefer not to
Well, except for the occasional time when it doesn't notice headers have changed
Ah the sensible option
9:00 PM
If I compile in WSL, it's not going to make a Windows binary is it?
@Girgias I have not seen cmb in this chat since he's been back. I don't think the mention will do anything for users that have not been seen recently either.
No, but you can just run it in WSL
Well that's... suck
But I can't debug from my editor in WSL I wouldn't think
Or maybe I can since IntelliJ has good support for WSL in some languages
Don't think C is one of them, though...
9:15 PM
So... just to be clear... there's no way to directly call a static function from the Reflection extension, right? I have to go through its public API
@QuolonelQuestions I don't think it's legal for Zend/* to know about ext/*.
Makes sense
@QuolonelQuestions Should be an API func or be in core header for something in ext/ to use it. So if it's static inline in a header, you can call that in ext/reflection, but if is static without inline, no, you would need to expose it.
No, the other way around
I want to call the reflection function from the VM
Seems I need to use zend_fetch_class_by_name
Or maybe the one without the "_by_name" suffix. I don't really know what the difference is since they both accept a name parameter lol
Well you can just look what the C implementation of the reflection function is
9:24 PM
@QuolonelQuestions They both eventually call zend_lookup_class_ex. They are helpers for common use cases. Pick whatever helper is best.
@Girgias It's complex and it branches depending on whether I'm looking up an internal or userland function. No way am I ever duplicating it
@QuolonelQuestions "Duplicating" depending on what it is you can just move the implementation to Zend and make it a Zend API that is called by reflection
Well I just want to call ReflectionParameter::getDefaultValue basically, but... it is a lot of code
I understand what you mean by inverting the dependency so reflection depends on Zend instead of the other way around, but do you still think that's a good idea in this particular case?
Well, I dont' know what you're doing, but Zend should not depend on any code from an API
The headers (and thus dependencies) are already a mess just within Zend, let's not add more stuff to the mix
Well it was Ilija's idea so it can't be too bad. I'm not playing with any headers, just invoking the method using the API you just told me about
That isn't to say your idea wouldn't be a worthwhile optimization but for now I'll keep it simple
9:31 PM
Sure, one can always clean up the code later
Being a janitor is my speciality seemingly
Damn beta3 already :D
@Girgias There's already cases where we depend on headers from required extensions. But it it really bothers you the relevant code could be moved to Zend/.
@IluTov In Zend? I didn't know that
Not many, but a few. Search for ext/ within Zend/
I've mostly looked at ext/standard these past couple of days
Oh indeed, 4 includes
9:48 PM
@Girgias if you wanna janny my code later, feel free 😆
10:00 PM
@IluTov question/rubber ducking: why do we use php_addcslashes() for dumping string in zend_dump_const(), but don't do it for var_dump()? 3v4l.org/OHJsc
@IluTov It appears the one you added to Zend/zend_object_handlers.c as part of property hooks is not actually necessary. At least the build succeeds for me.
Yeah I found that one, was planning on removing it
@TimWolla Oh, I think it's a left-over to check for scope or something.
The zend_system_id.c are hash related, although I feel like I've seen multiple implementation of php_hash_bin2hex
@Girgias Probably because any changes to debugging output was controversial in the past, but also, meh.
10:14 PM
Well... I can't even call get_parameter_default() if I DO include `ext/reflection/php_reflection.h`, because it's not IN the header file :<
Is this basically how you do private functions in C?
static function in a .c file are private
So it would seem
10:33 PM
@TimWolla do you know why Go Kudo forced the little endianness for php_random_bin2hex_le()?
Well I also don't totally understand why it is exported as a PHPAPI either, but minor details
11:08 PM
Ah peak GitHub is down
11:30 PM
This is gonna leak isn't it...
>zend_fetch_class(ZSTR_INIT_LITERAL("ReflectionParameter", 0), ZEND_FETCH_CLASS_DEFAULT)
Do I just need to zval_ptr_dtor_str it?

« first day (5051 days earlier)      last day (27 days later) »