Skip to content

Commit d197ce4

Browse files
authored
Package Constant: Check missing dsc_address instead of dsc_dtype and restore impure after using existing request (#9065)
1 parent c8ef86c commit d197ce4

3 files changed

Lines changed: 19 additions & 24 deletions

File tree

src/dsql/PackageNodes.epp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ dsc* PackageReferenceNode::execute(thread_db* tdbb, Request* request) const
560560
Package* package = m_package(request->getResources());
561561
package->checkReload(tdbb);
562562

563-
dsc* constantDsc = package->findConstant(m_fullName)->makeValue(tdbb, request);
563+
dsc* constantDsc = package->findConstant(m_fullName)->makeValue(tdbb);
564564
if (constantDsc == nullptr || constantDsc->isNull())
565565
return nullptr;
566566

src/jrd/Package.epp

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -168,22 +168,23 @@ bid ConstantValue::getBlobId(thread_db* tdbb)
168168
return m_blrBlobId.isEmpty() ? getConstantBid(tdbb, name) : m_blrBlobId;
169169
}
170170

171-
dsc* ConstantValue::makeValue(thread_db* tdbb, Request* request)
171+
dsc* ConstantValue::makeValue(thread_db* tdbb)
172172
{
173173
{
174174
ReadLockGuard guard(m_makeValueLock, FB_FUNCTION);
175-
if (m_value.vlu_desc.dsc_dtype != dtype_unknown)
175+
if (m_value.vlu_desc.dsc_address != nullptr)
176176
return &m_value.vlu_desc;
177177
}
178178

179179
WriteLockGuard guard(m_makeValueLock, FB_FUNCTION);
180-
if (m_value.vlu_desc.dsc_dtype != dtype_unknown) // Extra check in case of two callers waiting
180+
if (m_value.vlu_desc.dsc_address != nullptr) // Extra check in case of two callers waiting
181181
return &m_value.vlu_desc;
182182

183183
Attachment* attachment = tdbb->getAttachment();
184184

185185
MemoryPool* csb_pool = attachment->att_database->createPool();
186186
Statement* handmadeStmt = nullptr;
187+
Request* request = nullptr;
187188
try
188189
{
189190
ContextPoolHolder context(tdbb, csb_pool);
@@ -195,28 +196,21 @@ dsc* ConstantValue::makeValue(thread_db* tdbb, Request* request)
195196
bid constantBid = getBlobId(tdbb);
196197

197198
MET_parse_blob(tdbb, &name.schema, nullptr, &constantBid, &csb, nullptr, false, false);
198-
fb_assert(csb->csb_node != nullptr);
199199

200-
if (request == nullptr)
201-
{
202-
// Came from Reload
203-
handmadeStmt = Statement::makeStatement(tdbb, csb, true);
204-
request = handmadeStmt->makeRootRequest(tdbb);
200+
handmadeStmt = Statement::makeStatement(tdbb, csb, true);
201+
request = handmadeStmt->makeRootRequest(tdbb);
205202

206-
AutoSetRestore2<Request*, thread_db> autoSetRequest(
207-
tdbb, &thread_db::getRequest, &thread_db::setRequest, request);
203+
AutoSetRestore2<Request*, thread_db> autoSetRequest(
204+
tdbb, &thread_db::getRequest, &thread_db::setRequest, request);
208205

209-
request->setUsed();
210-
request->setAttachment(attachment);
211-
attachment->att_requests.add(request);
206+
request->setUsed();
207+
request->setAttachment(attachment);
208+
attachment->att_requests.add(request);
212209

213-
TRA_attach_request(tdbb->getTransaction(), request);
210+
TRA_attach_request(tdbb->getTransaction(), request);
214211

215-
// Execute it here, while AutoSetRestore2 is active
216-
executeCsbNode(tdbb, csb);
217-
}
218-
else
219-
executeCsbNode(tdbb, csb);
212+
// Execute it while AutoSetRestore2 is active
213+
executeCsbNode(tdbb, csb);
220214
}
221215
catch (const Exception& ex)
222216
{
@@ -347,7 +341,7 @@ ScanResult Package::scan(thread_db* tdbb, ObjectBase::Flag flags)
347341
skipMakeValue);
348342

349343
if (skipMakeValue)
350-
this->m_callReload = true; // Value is necessary for to calculate hash
344+
this->m_callReload = true;
351345
}
352346
END_FOR
353347
}
@@ -426,7 +420,7 @@ ConstantValue& Package::addConstant(thread_db* tdbb,
426420
auto& value = constants.add(constName, isPrivate);
427421
value.updateValue(blrBlobId);
428422
if (!skipMakeValue)
429-
value.makeValue(tdbb, nullptr);
423+
value.makeValue(tdbb);
430424

431425
return value;
432426
}

src/jrd/Package.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class ConstantValue final : public Firebird::PermanentStorage
7373
delete m_value.vlu_string;
7474
m_value = {};
7575
m_value.vlu_desc = typeDesc;
76+
m_value.vlu_desc.dsc_address = nullptr; // Make sure to call makeValue
7677
}
7778

7879
void updateValue(const bid blobId)
@@ -82,7 +83,7 @@ class ConstantValue final : public Firebird::PermanentStorage
8283

8384
bid getBlobId(thread_db* tdbb);
8485

85-
dsc* makeValue(thread_db* tdbb, Request* request);
86+
dsc* makeValue(thread_db* tdbb);
8687

8788
private:
8889
void executeCsbNode(thread_db* tdbb, CompilerScratch* csb);

0 commit comments

Comments
 (0)