Ensure valid PG::Result data pointer #42
Merged
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.
Allocation of the ruby typed data object VALUE is now done within the function that assigns the PGresult retrieved from libpq. Therefore the data pointer of the PG::Result instance is always valid.
There's no need to check the 'this' pointer at every use any longer.
These 'this' pointer checks were introduced at commit de2487c, when we moved to a variable size data memory. This variable memory allows us to store the field_names once per PG::Result and reuse them several times. However this also moved the memory allocation out of PG::Result#allocate, so that we had to check for validity of the pointer.
This patch removes
PG::Result.allocate
andPG::Result.new
, which is obvoiusly an API change. However although these methods were callable, the resulting object wasn't usable at all. Not evenPG::Result#inspect
did work. I therefore beleave that no one out there calls these methods and that we are safe to remove them within the pg-1.x series.This also changes the base class of PG::Result to rb_cData as recommended in Ruby MRI. This change undefs the alloc function internally. It is also visible in ruby space:
PG::Result.ancestors
changes from[PG::Result, PG::Constants, Enumerable, Object, JSON::Ext::Generator::GeneratorMethods::Object, Kernel, BasicObject]
to[PG::Result, PG::Constants, Enumerable, Data, Object, JSON::Ext::Generator::GeneratorMethods::Object, Kernel, BasicObject]
.I also think that this is no change that legitimate a jump to pg-2.0.
@ged, @cbandy Is it OK for you to merge this?