Skip to content
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

PHP-1230: Store WriteResult in WriteException struct instead of property #17

Closed
wants to merge 1 commit into from

Conversation

jmikola
Copy link
Member

@jmikola jmikola commented Sep 30, 2014

@jmikola jmikola changed the title PHP-1230: Store WriteResult in WriteException struct instead of property [WIP] PHP-1230: Store WriteResult in WriteException struct instead of property Sep 30, 2014
@coveralls
Copy link

Coverage Status

Coverage decreased (-3.34%) when pulling 373c6bf on php1230-writeexception into deafb8d on master.

@bjori
Copy link
Contributor

bjori commented Sep 30, 2014

========DIFF========

023+ Segmentation fault (core dumped)

========DONE========

FAIL MongoDB\Manager::executeWriteBatch() with duplicate key errors (ordered) [tests/standalone/manager-executeWriteBatch-002.phpt]

Seems relevant?

@jmikola
Copy link
Member Author

jmikola commented Sep 30, 2014

Yes, both of the write error tests fail due to a segfault in _zend_mm_free_int:

  • manager-executeWriteBatch-002.phpt
  • manager-executeWriteBatch-003.phpt

I pasted the backtrace in IRC yesterday: http://pastebin.com/FVEWyZdv

@jmikola
Copy link
Member Author

jmikola commented Oct 1, 2014

@bjori: I believe I found the problem. Valgrind turned up some of the following errors:

Invalid (read|write) of size 8
Address 0x79dfdf0 is 0 bytes after a block of size 32 alloc'd

The 32-byte block is the default struct with a single zend_object std property. That struct contains 4 pointer fields, so it's 32-bytes (on 64-bit). This means our php_phongo_writeexception_t struct was never getting allocated in the first place. Furthermore, our create_object handler, which does the allocation and memset, was never invoked.

I discovered that the create_object handler cannot be changed when inheriting a class. I'm not sure why this is required, as a child class could assume the responsibility to ensure its struct only extends the parent. Anyway, when WriteException's MINIT does:

ce.create_object = php_phongo_writeexception_create_object;
php_phongo_writeexception_ce = zend_register_internal_class_ex(&ce, spl_ce_RuntimeException, NULL TSRMLS_CC);

We specify a create_object handler, and it promptly gets reverted by zend_register_internal_class_ex(). That function invokes zend_do_inheritance(), which in turn calls do_inherit_parent_constructor() and reaches this lovely bit of code:

/* You cannot change create_object */
ce->create_object = ce->parent->create_object;

Given this limitation, I think we're stuck with using object properties then. Do you concur?

@jmikola jmikola changed the title [WIP] PHP-1230: Store WriteResult in WriteException struct instead of property PHP-1230: Store WriteResult in WriteException struct instead of property Oct 2, 2014
@jmikola
Copy link
Member Author

jmikola commented Oct 2, 2014

Closing this for now. If we come up with a work-around in the future we can revisit this.

See #19 instead.

@jmikola jmikola closed this Oct 2, 2014
@jmikola jmikola deleted the php1230-writeexception branch November 17, 2014 17:33
@jmikola jmikola restored the php1230-writeexception branch December 12, 2014 21:14
@bjori bjori deleted the php1230-writeexception branch January 5, 2015 21:09
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.

None yet

3 participants