-
Notifications
You must be signed in to change notification settings - Fork 8k
Add sapi_windows_console_size() #17057
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1774,6 +1774,48 @@ PHP_FUNCTION(sapi_windows_vt100_support) | |
} | ||
} | ||
} | ||
|
||
PHP_FUNCTION(sapi_windows_console_size) | ||
{ | ||
zval *zsrc; | ||
php_stream *stream; | ||
zend_long fileno; | ||
int width, height; | ||
zval ztmp; | ||
|
||
ZEND_PARSE_PARAMETERS_START(1, 1) | ||
Z_PARAM_RESOURCE(zsrc) | ||
ZEND_PARSE_PARAMETERS_END(); | ||
|
||
php_stream_from_zval(stream, zsrc); | ||
|
||
/* get the fd. | ||
* NB: Most other code will NOT use the PHP_STREAM_CAST_INTERNAL flag when casting. | ||
* It is only used here so that the buffered data warning is not displayed. | ||
*/ | ||
if (php_stream_can_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL) == SUCCESS) { | ||
php_stream_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL, (void*)&fileno, 0); | ||
} else if (php_stream_can_cast(stream, PHP_STREAM_AS_FD | PHP_STREAM_CAST_INTERNAL) == SUCCESS) { | ||
php_stream_cast(stream, PHP_STREAM_AS_FD | PHP_STREAM_CAST_INTERNAL, (void*)&fileno, 0); | ||
} else { | ||
php_error_docref(NULL, E_WARNING, "not able to analyze the specified stream"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After reading https://bugs.php.net/bug.php?id=79805, I think the warning should be dropped (we only warn about this when |
||
RETURN_FALSE; | ||
} | ||
|
||
if (!php_win32_console_fileno_is_console(fileno)) { | ||
RETURN_FALSE; | ||
} | ||
|
||
if (!php_win32_console_size(fileno, &width, &height)) { | ||
RETURN_FALSE; | ||
} | ||
|
||
array_init(return_value); | ||
cmb69 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
ZVAL_LONG(&ztmp, width); | ||
zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &ztmp); | ||
ZVAL_LONG(&ztmp, height); | ||
zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &ztmp); | ||
} | ||
#endif | ||
|
||
#ifdef HAVE_SHUTDOWN | ||
|
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 had copied this code from
sapi_windows_vt100_support()
without thinking. Now I had a closer look, and wondered why we even try to cast toPHP_STREAM_AS_FD_FOR_SELECT
(we don't actually want to select). Looking at the implementation ofphp_stdiop_cast()
it's clear: this cast won't flush (what we indeed don't want), but other possibly castable stream might not implementPHP_STREAM_AS_FD_FOR_SELECT
. So these two cast attempts make some sense (although they rely on a leaky abstraction).Then I wondered why we first check if we can cast and then actually do cast. Regarding the implementation that makes not much sense, but for the sake of abstraction it is correct. On the other hand, asking whether we can cast to
PHP_STREAM_AS_FD
actually flushes (for stdio stream), so this is somewhat (s/somewhat/completely) broken anyway.Well, probably best to leave as is for now.