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)
@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.
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
@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.
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.
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.
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)
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
@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.
@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.
@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?
@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 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.
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?