Skip to content

zend_hash_sort always returns SUCCESS #3936

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

Closed
wants to merge 4 commits into from

Conversation

rjhdby
Copy link

@rjhdby rjhdby commented Mar 11, 2019

zend_hash_sort (zend_hash_sort_ex) never returns FAILURE

@KalleZ
Copy link
Member

KalleZ commented Mar 11, 2019

Hmm, if it always returns true then perhaps we should simply change it to return void? However if its ZEND_API then most likely only master/PHP-7.4 only

@rjhdby
Copy link
Author

rjhdby commented Mar 11, 2019

@KalleZ Some extensions may use this return value

@KalleZ
Copy link
Member

KalleZ commented Mar 11, 2019

@rjhdby well yes, and if they do, then they should be encouraged to change it, hence why patching it in 7.4 or 8.0 makes sense to keep ABI, migration path is rather easy and still cross version compatible (as your patch already displays)

@rjhdby
Copy link
Author

rjhdby commented Mar 12, 2019

@KalleZ done

@cmb69
Copy link
Member

cmb69 commented Mar 17, 2019

If we're going to change the return type of zend_hash_sort_ex(), we should change the return type of zend_ts_hash_sort(), too.

Copy link
Member

@cmb69 cmb69 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@nikic
Copy link
Member

nikic commented Mar 22, 2019

Merged as e86cdce.

@nikic nikic closed this Mar 22, 2019
@Jan-E
Copy link
Contributor

Jan-E commented Jul 1, 2020

Do you all imply that a check like Solr does in https://github.com/php/pecl-search_engine-solr/blob/master/src/php7/php_solr_input_document.c#L658 is senseless?

	if (zend_hash_sort_ex(doc_entry->fields, zend_qsort, comparison_function, renumber TSRMLS_CC) == FAILURE) {

		RETURN_FALSE;
	}

	RETURN_TRUE;

Would this never return FALSE?

And/or Is the change in 33ef3d6 related?

@Jan-E
Copy link
Contributor

Jan-E commented Jul 1, 2020

And shouldn't this change be documented in UPGRADING.INTERNALS?

@cmb69
Copy link
Member

cmb69 commented Jul 1, 2020

@Jan-E the only reason zend_hash_sort() could ever return FAILURE was due to failure to allocate heap memory; since the ZendMM is infallible, this can no longer happen (as of PHP 5.5.0). However, since the return type is int before PHP 8, checking for FAILURE/SUCCESS makes sense; it no longer makes sense for PHP 8 (and actually triggers a compile error).

Anyway, the signature change is now documented: 942f341.

@carusogabriel carusogabriel added this to the PHP 8.0 milestone Jul 1, 2020
@Jan-E
Copy link
Contributor

Jan-E commented Jul 1, 2020

OK, so the new PHP8 (and even PHP7) code for Solr should be

	zend_hash_sort_ex(doc_entry->fields, zend_qsort, comparison_function, renumber TSRMLS_CC);

	RETURN_TRUE;

And a comparable change for ereg (yeah, I know):
http://git.php.net/?p=pecl/text/ereg.git;a=blob;f=ereg.c;h=5768a68344104715393627788f01147d32a41874;hb=refs/heads/master#l143

@cmb69
Copy link
Member

cmb69 commented Jul 1, 2020

yes :)

@Jan-E
Copy link
Contributor

Jan-E commented Jul 1, 2020

zend_hash_sort and zend_hash_sort compare function signature change

Did you mean to stress the change ;)

@cmb69
Copy link
Member

cmb69 commented Jul 1, 2020

Well, both the signature of zend_hash_function, and the signature of the zend_hash_sort compare function has been changed. Not sure how to express that better.

@Jan-E
Copy link
Contributor

Jan-E commented Jul 1, 2020

Or should it be read as

zend_hash_sort compare function and zend_hash_sort signature change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants