Skip to content

Migrated to PHP 7 and added tests.#3

Merged
nikic merged 9 commits intonikic:masterfrom
DrDub:master
Jan 7, 2023
Merged

Migrated to PHP 7 and added tests.#3
nikic merged 9 commits intonikic:masterfrom
DrDub:master

Conversation

@DrDub
Copy link
Contributor

@DrDub DrDub commented Dec 21, 2022

The zval change impacted this code throughout, this close to a rewrite.

I know this is very old code, but I'm looking at whether it can help speed up the tensor library in Rubix/ML. A contiguous C array of floats is exactly what we need to interface to the linear algebra C libraries.

The zval change impacted this code throughout.
@DrDub
Copy link
Contributor Author

DrDub commented Dec 27, 2022

Thanks so much for your thorough review.

I realize the initial code in the PR did not pass all the tests under a version of PHP compiled without debug enabled. I'll see if fixing the issues you mention helps otherwise I might ask for more help.

Any further comments will be appreciated.

@DrDub
Copy link
Contributor Author

DrDub commented Dec 28, 2022

OK, all tests now pass both with a php binary with debug enabled or disabled.

Together with the changes you identified, I added the destructor call for the buffer zval in array_buffer_view_free and fixed some bugs in array_buffer_view_read_dimension and buffer_view_iterator_dtor.

The code now compiles without warnings, which I should have heed before as they pointed to the array_buffer_view_read_dimension bug.

size_t length;

/* For Iterator methods */
size_t current_offset;
Copy link
Owner

Choose a reason for hiding this comment

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

Orthogonal to your changes, but BufferView should really be implementing IteratorAggregate, not Iterator. It doesn't make a lot of sense that the view itself has a current position, as opposed to an iterator over the view having a position.

This is easy in PHP 8 because it's possible to automatically create an InternalIterator object from the buffer_view_iterator, but in earlier versions it requires actually implementing the iterator class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After this, I want to do a migration to PHP 8, maybe leave that change for then? Otherwise I can give this a try now, just let me know.

Something else we need for Rubix is for Buffer to implement the Countable interface, that's also next for me but I hope the current migration is solid before adding changes.

}
}
if(Z_TYPE_P(zbuf) != IS_STRING) {
zend_throw_exception(NULL, "Could not unserialize buffer: not a string", 0);
Copy link
Owner

Choose a reason for hiding this comment

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

I think we're leaking zbuf here? (Not sure about previous branch, would have to check what php_var_unserialize does on error...)

Same also for some cases below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point.

Looking at the code in ext/standard/var_unserializer.c, this zbuf is a pointer inside the var hash which in turn has its destructors called in the var_destroy function (chained from the PHP_VAR_UNSERIALIZE_DESTROY on the exit). So it should be fine.

DrDub and others added 5 commits January 5, 2023 02:41
Co-authored-by: Nikita Popov <github@npopov.com>
Co-authored-by: Nikita Popov <github@npopov.com>
Co-authored-by: Nikita Popov <github@npopov.com>
Co-authored-by: Nikita Popov <github@npopov.com>
@DrDub
Copy link
Contributor Author

DrDub commented Jan 5, 2023

I added the latest changes. Slowly gaining on my understanding of PHP internals. Thanks so much for your guidance.

@nikic nikic merged commit d4f2cf5 into nikic:master Jan 7, 2023
@nikic
Copy link
Owner

nikic commented Jan 7, 2023

Thanks!

It would probably be good to add some basic Github Actions setup to check that things build with versions which are intended to be supported. Always a bit tricky with differences across versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants