-
-
Notifications
You must be signed in to change notification settings - Fork 261
Move impure-related string allocation to helper methods #8609
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -573,22 +573,10 @@ void EVL_make_value(thread_db* tdbb, const dsc* desc, impure_value* value, Memor | |
|
|
||
| // Allocate a string block of sufficient size. | ||
|
|
||
| VaryingString* string = value->vlu_string; | ||
| if (!pool) | ||
| pool = tdbb->getDefaultPool(); | ||
|
|
||
| if (string && string->str_length < length) | ||
| { | ||
| delete string; | ||
| string = NULL; | ||
| } | ||
|
|
||
| if (!string) | ||
| { | ||
| if (!pool) | ||
| pool = tdbb->getDefaultPool(); | ||
|
|
||
| string = value->vlu_string = FB_NEW_RPT(*pool, length) VaryingString(); | ||
| string->str_length = length; | ||
| } | ||
| VaryingString* string = value->getAllocateString(from.dsc_length, *pool); | ||
|
||
|
|
||
| value->vlu_desc.dsc_length = length; | ||
| UCHAR* target = string->str_data; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -168,6 +168,13 @@ struct impure_value | |
| void make_double(const double val); | ||
| void make_decimal128(const Firebird::Decimal128 val); | ||
| void make_decimal_fixed(const Firebird::Int128 val, const signed char scale); | ||
|
|
||
| template<class T> | ||
| VaryingString* getAllocateString(T requeuedLength, MemoryPool& pool) = delete; // Prevent dangerous length shrink | ||
| VaryingString* getAllocateString(USHORT requeuedLength, MemoryPool& pool); | ||
|
||
|
|
||
| void makeImpureDscAddress(MemoryPool& pool); | ||
| void allocateTextImpureDscAddress(MemoryPool& pool); | ||
|
||
| }; | ||
|
|
||
| // Do not use these methods where dsc_sub_type is not explicitly set to zero. | ||
|
|
@@ -221,6 +228,40 @@ inline void impure_value::make_decimal_fixed(const Firebird::Int128 val, const s | |
| this->vlu_desc.dsc_address = reinterpret_cast<UCHAR*>(&this->vlu_misc.vlu_int128); | ||
| } | ||
|
|
||
| inline VaryingString* impure_value::getAllocateString(USHORT requeuedLength, MemoryPool& pool) | ||
|
||
| { | ||
| if (vlu_string && vlu_string->str_length < requeuedLength) | ||
| { | ||
| delete vlu_string; | ||
| vlu_string = nullptr; | ||
| } | ||
|
|
||
| if (!vlu_string) | ||
| { | ||
| vlu_string = FB_NEW_RPT(pool, requeuedLength) VaryingString(); | ||
| vlu_string->str_length = requeuedLength; | ||
| } | ||
|
|
||
| return vlu_string; | ||
| } | ||
|
|
||
| inline void impure_value::makeImpureDscAddress(MemoryPool& pool) | ||
| { | ||
| if (vlu_desc.hasDynamicLength()) | ||
| { | ||
| // If the data type is any of the string types, allocate space to hold value. | ||
| allocateTextImpureDscAddress(pool); | ||
| } | ||
| else | ||
| vlu_desc.dsc_address = (UCHAR*) &vlu_misc; | ||
| } | ||
|
|
||
| inline void impure_value::allocateTextImpureDscAddress(MemoryPool& pool) | ||
| { | ||
| vlu_desc.dsc_address = getAllocateString(vlu_desc.dsc_length, pool)->str_data; | ||
| } | ||
|
|
||
|
|
||
| struct impure_value_ex : public impure_value | ||
| { | ||
| SINT64 vlux_count; | ||
|
|
||
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.
This does not look proper to me, as
CHARis not dynamic-length generally (except inside the impure). IMHO, it should be up to the caller (impure class) to check what string types are stored as variable-length.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.
By this method I mean that dsc_length of content is not fixed. Now I remembered that there is an array
type_lengthsthat checks exactly this, so I replace this method with the array