-
Notifications
You must be signed in to change notification settings - Fork 209
PHPC-239: Cursor refcount issues #35
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
--TEST-- | ||
PHPC-239: Iterator segfault | ||
--SKIPIF-- | ||
<?php require __DIR__ . "/../utils/basic-skipif.inc"; CLEANUP(STANDALONE)?> | ||
--FILE-- | ||
<?php | ||
require_once __DIR__ . "/../utils/basic.inc"; | ||
|
||
class Address implements BSON\Persistable { | ||
protected $streetAddress; | ||
protected $city; | ||
protected $postalCode; | ||
|
||
function __construct($streetAddress, $city, $postalCode) { | ||
$this->streetAddress = $streetAddress; | ||
$this->city = $city; | ||
$this->postalCode = $postalCode; | ||
|
||
} | ||
function bsonUnserialize(array $array) { | ||
foreach($array as $k => $v) { | ||
$this->{$k} = $v; | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
function bsonSerialize() { | ||
return get_object_vars($this); | ||
} | ||
} | ||
|
||
class Person implements BSON\Persistable { | ||
protected $_id; | ||
protected $username; | ||
protected $email; | ||
protected $name; | ||
protected $addresses = array(); | ||
|
||
function __construct($username, $email, $name) { | ||
$this->username = $username; | ||
$this->email = $email; | ||
$this->name = $name; | ||
|
||
/* Pregenerate our ObjectID */ | ||
$this->_id = new BSON\ObjectID(); | ||
} | ||
function addAddress(Address $address) { | ||
$this->addresses[] = $address; | ||
} | ||
|
||
function bsonUnserialize(array $array) { | ||
foreach($array as $k => $v) { | ||
$this->{$k} = $v; | ||
} | ||
} | ||
|
||
function bsonSerialize() { | ||
return get_object_vars($this); | ||
} | ||
|
||
function getName() { | ||
return $this->name; | ||
} | ||
} | ||
|
||
|
||
$bulk = new MongoDB\Driver\BulkWrite; | ||
|
||
|
||
$lair77 = new Person('lair77', 'claire77@example.net', 'Claire Corwin'); | ||
$hillardhaven = new Address('4527 Kohler Square Apt. 316', 'Hillardhaven', '02622-5175'); | ||
$lair77->addAddress($hillardhaven); | ||
$prudencemouth = new Address('7042 Freida Springs', 'Prudencemouth', '94805'); | ||
$lair77->addAddress($prudencemouth); | ||
$bulk->insert($lair77); | ||
|
||
|
||
|
||
$hartmann = new Person('hartmann', 'hartmann@example.org', 'Hartmann Dedrick'); | ||
$leannefurt = new Address('151 Delbert Hills Suite 923', 'Leannefurt', '22036'); | ||
$hartmann->addAddress($leannefurt); | ||
$bulk->insert($hartmann); | ||
|
||
|
||
$dropcoll = new MongoDB\Driver\Command(array("drop" => COLLECTION_NAME)); | ||
$query = new MongoDB\Driver\Query(array()); | ||
$queryHartmann = new MongoDB\Driver\Query(array("username" => "hartmann")); | ||
|
||
|
||
|
||
$m = new MongoDB\Driver\Manager(STANDALONE); | ||
try { | ||
$m->executeCommand(DATABASE_NAME, $dropcoll); | ||
} catch(Exception $e) {} | ||
|
||
$m->executeBulkWrite(NS, $bulk); | ||
|
||
|
||
$res = $m->executeQuery(NS, $query); | ||
foreach($res as $person) { | ||
var_dump($person->getName()); | ||
} | ||
foreach($res as $person) { | ||
echo "This will never happen: "; | ||
echo $person->getName(), "\n"; | ||
} | ||
|
||
echo "-----\n"; | ||
$cursor = $m->executeQuery(NS, $queryHartmann); | ||
foreach($cursor as $hartmann) { | ||
echo $hartmann->getName(), "\n"; | ||
} | ||
|
||
foreach($cursor as $hartmann) { | ||
echo "This will never happen: "; | ||
echo $hartmann->getName(), "\n"; | ||
} | ||
foreach($cursor as $hartmann) { | ||
echo "This will never happen: "; | ||
echo $hartmann->getName(), "\n"; | ||
} | ||
echo "All Good!\n"; | ||
?> | ||
===DONE=== | ||
<?php exit(0); ?> | ||
--EXPECT-- | ||
string(13) "Claire Corwin" | ||
string(16) "Hartmann Dedrick" | ||
----- | ||
Hartmann Dedrick | ||
All Good! | ||
===DONE=== |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Since this only frees
cursor->visitor_data.zchild
if it's not null, was there a specific reason to move it up? I've no objection if it was just for style points, but I'm curious if there was another reason.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.
cursor_it->cursor is the php_phongo_cursor_t* of the cursor_it->intern.data zval*.
If you destroy the zval first, the php_phongo_cursor_t* will be invalid.