-
Notifications
You must be signed in to change notification settings - Fork 7.9k
proc_open refactoring (1) #5507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
6c91aec
to
b0f9b8f
Compare
Still fixing this up, sorry... |
b0f9b8f
to
905e4a9
Compare
AppVeyor failure may be legit, seems like it's hanging? |
It seems to me that the refactoring doesn't take into account that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some quick notes, I'll have to check this more carefully.
ext/standard/proc_open.c
Outdated
add_assoc_long(return_value, "termsig", termsig); | ||
add_assoc_long(return_value, "stopsig", stopsig); | ||
add_assoc_long(return_value, "termsig", termsig); | ||
add_assoc_long(return_value, "stopsig", stopsig); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This alignment is not necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean you don't want things to be aligned (if it means adding whitespace)? Of course it's not necessary; I just did it because personally I find it easier to work on code that way.
If you don't like it, please just mention.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this project, unless there is a strong reason to do it, I'd avoid alignment. (This is a complication of tab indentation, which means that half the people end up trying to tab-align as well, and we get a mess in the end. Every time I edit aligned code, I have to check a few lines to figure out whether it is predominantly tab-aligned or space-aligned.)
You mean the bit where all open file handles are closed if spawning a process fails on Windows? The refactored code uses a macro which expands to But if there is any other place which I missed, I would appreciate being reminded. |
proc_open() is a huge function. Pulling out various pieces into helper functions will make it much easier to read and follow.
Still fixing things up... will push an update soon. |
ab74c7b
to
0c74bd2
Compare
I think we're ready for more code review. Thanks very much for the great suggestions for improvement made thus far. |
CI failure on Azure: In one of the jobs, |
Another branch is ready which enables PTY support (with a simplified implementation suggested by @nikic). It's based on this one, so maybe I should wait for this one to be reviewed before pushing it... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good, a few notes.
ext/standard/proc_open.c
Outdated
add_assoc_long(return_value, "termsig", termsig); | ||
add_assoc_long(return_value, "stopsig", stopsig); | ||
add_assoc_long(return_value, "termsig", termsig); | ||
add_assoc_long(return_value, "stopsig", stopsig); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this project, unless there is a strong reason to do it, I'd avoid alignment. (This is a complication of tab indentation, which means that half the people end up trying to tab-align as well, and we get a mess in the end. Every time I edit aligned code, I have to check a few lines to figure out whether it is predominantly tab-aligned or space-aligned.)
ext/standard/proc_open.c
Outdated
/* zend_strings which may be allocated while processing the descriptorspec | ||
* we need to make sure that each one allocated is released once and only once */ | ||
zend_string *ztype = NULL, *zmode = NULL, *zfile = NULL; | ||
#define cleanup_zend_string(ptr) do { if (ptr != NULL) { zend_string_release(ptr); ptr = NULL; } } while(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is zend_tmp_string_release()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Though the macros are still needed.
The point of these macros is that the function is loaded with goto exit_fail;
s and it would be cumbersome to ensure that the correct zend_strings
are released at each such point. So when releasing them, we set the pointer to NULL
so there's no danger of freeing them twice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. I don't really like this, but let's leave it for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the interest of reducing non-local state, I've moved the code that uses these strings into a separate function in 2dc4481.
ext/standard/proc_open.c
Outdated
if (!ztarget) { | ||
zend_value_error("Missing redirection target"); | ||
goto exit_fail; | ||
} | ||
if (Z_TYPE_P(ztarget) != IS_LONG) { | ||
zend_value_error("Redirection target must be an integer"); | ||
zend_value_error("Redirection target must be an integer; got %s", zend_get_type_by_const(Z_TYPE_P(ztarget))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zend_value_error("Redirection target must be an integer; got %s", zend_get_type_by_const(Z_TYPE_P(ztarget))); | |
zend_value_error("Redirection target must be of type int, %s given", zend_get_type_by_const(Z_TYPE_P(ztarget))); |
is the usual phrasing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this part is not done yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I was still running make test
and hadn't pushed yet when you made this comment.
Every time proc_open() is called on Windows, an identical SECURITY_ATTRIBUTES struct is initialized. It is never modified, just used to tell CreateProcessW() that subprocesses are allowed to inherit file handles from the parent. Just allocate one of them statically and be done with it.
This field has 3 possible values: DESC_FILE, DESC_PIPE, and DESC_REDIRECT, but the code only cares about whether the value is DESC_PIPE or not. Therefore, make the code simpler and clearer by converting the field to a boolean called 'is_pipe'.
Setting these pointers to NULL after freeing them was necessary because if an error occurred later on, they could be double-freed after 'goto exit_fail'. It is simpler to free them after all possible sources of error are past.
I've noticed there is also a TODO comment left behind:
Do you think that would be a good idea? (Deprecating the |
This fix courtesy of Nikita Popov.
5cd6a91
to
c1922e8
Compare
May be, but I think that should be discussed on the internals@ mailing list first. |
I must say I love the thorough code reviews on this project. |
Code cleanup and reorganization in
proc_open.c
, in readiness to implement PTY support.Code review will be easier if you look through commit by commit. However, if you want them squashed together before actually merging, that is fine.