Skip to content

Add a custom Fast ZPP specifier for php_streams #17962

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

Merged
merged 8 commits into from
Mar 3, 2025
20 changes: 8 additions & 12 deletions ext/bz2/bz2.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,16 +303,15 @@ static PHP_MINFO_FUNCTION(bz2)
/* {{{ Reads up to length bytes from a BZip2 stream, or 1024 bytes if length is not specified */
PHP_FUNCTION(bzread)
{
zval *bz;
zend_long len = 1024;
php_stream *stream;
zend_string *data;

if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "r|l", &bz, &len)) {
RETURN_THROWS();
}

php_stream_from_zval(stream, bz);
ZEND_PARSE_PARAMETERS_START(1, 2)
PHP_Z_PARAM_STREAM(stream)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(len)
ZEND_PARSE_PARAMETERS_END();

if (len < 0) {
zend_argument_value_error(2, "must be greater than or equal to 0");
Expand Down Expand Up @@ -563,17 +562,14 @@ PHP_FUNCTION(bzdecompress)
The central error handling interface, does the work for bzerrno, bzerrstr and bzerror */
static void php_bz2_error(INTERNAL_FUNCTION_PARAMETERS, int opt)
{
zval *bzp; /* BZip2 Resource Pointer */
php_stream *stream;
const char *errstr; /* Error string */
int errnum; /* Error number */
struct php_bz2_stream_data_t *self;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &bzp) == FAILURE) {
RETURN_THROWS();
}

php_stream_from_zval(stream, bzp);
ZEND_PARSE_PARAMETERS_START(1, 1)
PHP_Z_PARAM_STREAM(stream)
ZEND_PARSE_PARAMETERS_END();

if (!php_stream_is(stream, PHP_STREAM_IS_BZIP2)) {
zend_argument_type_error(1, "must be a bz2 stream");
Expand Down
60 changes: 40 additions & 20 deletions ext/ftp/php_ftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -566,19 +566,24 @@ PHP_FUNCTION(ftp_systype)
/* {{{ Retrieves a file from the FTP server and writes it to an open file */
PHP_FUNCTION(ftp_fget)
{
zval *z_ftp, *z_file;
zval *z_ftp;
ftpbuf_t *ftp;
ftptype_t xtype;
php_stream *stream;
char *file;
size_t file_len;
zend_long mode=FTPTYPE_IMAGE, resumepos=0;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ors|ll", &z_ftp, php_ftp_ce, &z_file, &file, &file_len, &mode, &resumepos) == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(3, 5)
Z_PARAM_OBJECT_OF_CLASS(z_ftp, php_ftp_ce)
PHP_Z_PARAM_STREAM(stream)
Z_PARAM_STRING(file, file_len)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(mode)
Z_PARAM_LONG(resumepos)
ZEND_PARSE_PARAMETERS_END();

GET_FTPBUF(ftp, z_ftp);
php_stream_from_res(stream, Z_RES_P(z_file));
XTYPE(xtype, mode);

/* ignore autoresume if autoseek is switched off */
Expand Down Expand Up @@ -610,19 +615,24 @@ PHP_FUNCTION(ftp_fget)
/* {{{ Retrieves a file from the FTP server asynchronly and writes it to an open file */
PHP_FUNCTION(ftp_nb_fget)
{
zval *z_ftp, *z_file;
zval *z_ftp;
ftpbuf_t *ftp;
ftptype_t xtype;
php_stream *stream;
char *file;
size_t file_len;
zend_long mode=FTPTYPE_IMAGE, resumepos=0, ret;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ors|ll", &z_ftp, php_ftp_ce, &z_file, &file, &file_len, &mode, &resumepos) == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(3, 5)
Z_PARAM_OBJECT_OF_CLASS(z_ftp, php_ftp_ce)
PHP_Z_PARAM_STREAM(stream)
Z_PARAM_STRING(file, file_len)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(mode)
Z_PARAM_LONG(resumepos)
ZEND_PARSE_PARAMETERS_END();

GET_FTPBUF(ftp, z_ftp);
php_stream_from_res(stream, Z_RES_P(z_file));
XTYPE(xtype, mode);

/* ignore autoresume if autoseek is switched off */
Expand Down Expand Up @@ -848,19 +858,24 @@ PHP_FUNCTION(ftp_nb_continue)
/* {{{ Stores a file from an open file to the FTP server */
PHP_FUNCTION(ftp_fput)
{
zval *z_ftp, *z_file;
zval *z_ftp;
ftpbuf_t *ftp;
ftptype_t xtype;
size_t remote_len;
zend_long mode=FTPTYPE_IMAGE, startpos=0;
php_stream *stream;
char *remote;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "Osr|ll", &z_ftp, php_ftp_ce, &remote, &remote_len, &z_file, &mode, &startpos) == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(3, 5)
Z_PARAM_OBJECT_OF_CLASS(z_ftp, php_ftp_ce)
Z_PARAM_STRING(remote, remote_len)
PHP_Z_PARAM_STREAM(stream)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(mode)
Z_PARAM_LONG(startpos)
ZEND_PARSE_PARAMETERS_END();

GET_FTPBUF(ftp, z_ftp);
php_stream_from_zval(stream, z_file);
XTYPE(xtype, mode);

/* ignore autoresume if autoseek is switched off */
Expand Down Expand Up @@ -895,7 +910,7 @@ PHP_FUNCTION(ftp_fput)
/* {{{ Stores a file from an open file to the FTP server nbronly */
PHP_FUNCTION(ftp_nb_fput)
{
zval *z_ftp, *z_file;
zval *z_ftp;
ftpbuf_t *ftp;
ftptype_t xtype;
size_t remote_len;
Expand All @@ -904,11 +919,16 @@ PHP_FUNCTION(ftp_nb_fput)
php_stream *stream;
char *remote;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "Osr|ll", &z_ftp, php_ftp_ce, &remote, &remote_len, &z_file, &mode, &startpos) == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(3, 5)
Z_PARAM_OBJECT_OF_CLASS(z_ftp, php_ftp_ce)
Z_PARAM_STRING(remote, remote_len)
PHP_Z_PARAM_STREAM(stream)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(mode)
Z_PARAM_LONG(startpos)
ZEND_PARSE_PARAMETERS_END();

GET_FTPBUF(ftp, z_ftp);
php_stream_from_res(stream, Z_RES_P(z_file));
XTYPE(xtype, mode);

/* ignore autoresume if autoseek is switched off */
Expand Down
14 changes: 8 additions & 6 deletions ext/hash/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -707,18 +707,20 @@ PHP_FUNCTION(hash_update)
/* {{{ Pump data into the hashing algorithm from an open stream */
PHP_FUNCTION(hash_update_stream)
{
zval *zhash, *zstream;
zend_object *hash_obj;
php_hashcontext_object *hash;
php_stream *stream = NULL;
zend_long length = -1, didread = 0;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "Or|l", &zhash, php_hashcontext_ce, &zstream, &length) == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(2, 3)
Z_PARAM_OBJ_OF_CLASS(hash_obj, php_hashcontext_ce)
PHP_Z_PARAM_STREAM(stream)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(length)
ZEND_PARSE_PARAMETERS_END();

hash = php_hashcontext_from_object(Z_OBJ_P(zhash));
hash = php_hashcontext_from_object(hash_obj);
PHP_HASHCONTEXT_VERIFY(hash);
php_stream_from_zval(stream, zstream);

while (length) {
char buf[1024];
Expand Down
5 changes: 1 addition & 4 deletions ext/pgsql/pgsql.c
Original file line number Diff line number Diff line change
Expand Up @@ -6265,22 +6265,19 @@ PHP_FUNCTION(pg_put_copy_end)

PHP_FUNCTION(pg_socket_poll)
{
zval *z_socket;
php_stream *stream;
php_socket_t socket;
zend_long read, write;
zend_long ts = -1;

ZEND_PARSE_PARAMETERS_START(3, 4)
Z_PARAM_RESOURCE(z_socket)
PHP_Z_PARAM_STREAM(stream)
Z_PARAM_LONG(read)
Z_PARAM_LONG(write)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(ts)
ZEND_PARSE_PARAMETERS_END();

php_stream_from_zval(stream, z_socket);

if (php_stream_cast(stream, PHP_STREAM_AS_SOCKETD, (void **)&socket, 0)) {
zend_argument_type_error(1, "invalid resource socket");
RETURN_THROWS();
Expand Down
Loading
Loading