Skip to content

Commit cf85f59

Browse files
committed
Work in progress
1 parent 5c82cfb commit cf85f59

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1804
-1020
lines changed

src/common/TextType.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ class TextType
9595
BYTE getCanonicalWidth() const;
9696
USHORT getFlags() const;
9797

98+
const char* c_name() const
99+
{
100+
return name.c_str();
101+
}
102+
98103
public:
99104
Firebird::MetaString name;
100105

src/common/classes/Bits.h

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/*
2+
* PROGRAM: JRD Access Method
3+
* MODULE: Bits.h
4+
* DESCRIPTION: Arbitrary size bitmask
5+
*
6+
* The contents of this file are subject to the Initial
7+
* Developer's Public License Version 1.0 (the "License");
8+
* you may not use this file except in compliance with the
9+
* License. You may obtain a copy of the License at
10+
* http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
11+
*
12+
* Software distributed under the License is distributed AS IS,
13+
* WITHOUT WARRANTY OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing rights
15+
* and limitations under the License.
16+
*
17+
* The Original Code was created by Alexander Peshkoff
18+
* for the Firebird Open Source RDBMS project.
19+
*
20+
* Copyright (c) 2016, 2022 Alexander Peshkoff <peshkoff@mail.ru>
21+
* and all contributors signed below.
22+
*
23+
* All Rights Reserved.
24+
* Contributor(s): ______________________________________.
25+
*
26+
*/
27+
28+
#ifndef COMMON_CLASSES_BITS_H
29+
#define COMMON_CLASSES_BITS_H
30+
31+
namespace Firebird {
32+
33+
// Arbitrary size bitmask
34+
template <unsigned N>
35+
class Bits
36+
{
37+
static const unsigned shift = 3;
38+
static const unsigned bitmask = (1 << shift) - 1;
39+
40+
static const unsigned L = (N >> shift) + (N & bitmask ? 1 : 0);
41+
42+
public:
43+
static const unsigned BYTES_COUNT = L;
44+
45+
Bits()
46+
{
47+
clearAll();
48+
}
49+
50+
Bits(const Bits& b)
51+
{
52+
assign(b);
53+
}
54+
55+
Bits& operator=(const Bits& b)
56+
{
57+
assign(b);
58+
return *this;
59+
}
60+
61+
Bits& set(unsigned i)
62+
{
63+
fb_assert(i < N);
64+
if (i < N)
65+
data[index(i)] |= mask(i);
66+
return *this;
67+
}
68+
69+
Bits& setAll()
70+
{
71+
memset(data, ~0, sizeof data);
72+
return *this;
73+
}
74+
75+
Bits& clear(unsigned i)
76+
{
77+
fb_assert(i < N);
78+
if (i < N)
79+
data[index(i)] &= ~mask(i);
80+
return *this;
81+
}
82+
83+
Bits& clearAll()
84+
{
85+
memset(data, 0, sizeof data);
86+
return *this;
87+
}
88+
89+
bool test(unsigned int i) const
90+
{
91+
fb_assert(i < N);
92+
if (i >= N)
93+
return false;
94+
return data[index(i)] & mask(i);
95+
}
96+
97+
void load(const void* from)
98+
{
99+
memcpy(data, from, sizeof data);
100+
}
101+
102+
void store(void* to) const
103+
{
104+
memcpy(to, data, sizeof data);
105+
}
106+
107+
Bits& operator|=(const Bits& b)
108+
{
109+
for (unsigned n = 0; n < L; ++n)
110+
data[n] |= b.data[n];
111+
return *this;
112+
}
113+
114+
private:
115+
UCHAR data[L];
116+
117+
void assign(const Bits& b)
118+
{
119+
memcpy(data, b.data, sizeof data);
120+
}
121+
122+
static unsigned index(unsigned i)
123+
{
124+
return i >> shift;
125+
}
126+
127+
static UCHAR mask(unsigned i)
128+
{
129+
return 1U << (i & bitmask);
130+
}
131+
};
132+
133+
} // namespace Firebird
134+
135+
#endif // COMMON_CLASSES_BITS_H
136+

src/dsql/BoolNodes.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ bool ComparativeBoolNode::stringBoolean(thread_db* tdbb, Request* request, dsc*
835835
type1 = desc1->dsc_sub_type == isc_blob_text ? desc1->dsc_blob_ttype() : ttype_none;
836836
}
837837

838-
Collation* obj = INTL_texttype_lookup(tdbb, type1);
838+
HazardPtr<Collation> obj = INTL_texttype_lookup(tdbb, type1);
839839
CharSet* charset = obj->getCharSet();
840840

841841
VaryStr<TEMP_STR_LENGTH> escapeTemp;
@@ -1041,7 +1041,7 @@ bool ComparativeBoolNode::sleuth(thread_db* tdbb, Request* request, const dsc* d
10411041
else
10421042
ttype = INTL_TTYPE(desc1);
10431043

1044-
Collation* obj = INTL_texttype_lookup(tdbb, ttype);
1044+
HazardPtr<Collation> obj = INTL_texttype_lookup(tdbb, ttype);
10451045

10461046
// Get operator definition string (control string)
10471047

src/dsql/ExprNodes.cpp

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3534,8 +3534,9 @@ ValueExprNode* CastNode::pass1(thread_db* tdbb, CompilerScratch* csb)
35343534
// Are we using a collation?
35353535
if (TTYPE_TO_COLLATION(ttype) != 0)
35363536
{
3537-
CMP_post_resource(&csb->csb_resources, INTL_texttype_lookup(tdbb, ttype),
3538-
Resource::rsc_collation, ttype);
3537+
Collation* collation = csb->csb_resources.registerResource(tdbb, Resource::rsc_collation,
3538+
INTL_texttype_lookup(tdbb, ttype), ttype);
3539+
csb->csb_resources.postResource(tdbb, Resource::rsc_collation, collation, ttype);
35393540
}
35403541

35413542
return this;
@@ -4837,7 +4838,8 @@ DmlNode* DefaultNode::parse(thread_db* tdbb, MemoryPool& pool, CompilerScratch*
48374838
if (csb->csb_g_flags & csb_get_dependencies)
48384839
{
48394840
CompilerScratch::Dependency dependency(obj_relation);
4840-
dependency.relation = MetadataCache::lookup_relation(tdbb, relationName).unsafePointer();
4841+
auto rel = MetadataCache::lookup_relation(tdbb, relationName);
4842+
dependency.relation = csb->csb_resources.registerResource(tdbb, Resource::rsc_relation, rel, rel->rel_id);
48414843
dependency.subName = FB_NEW_POOL(pool) MetaName(fieldName);
48424844
csb->csb_dependencies.push(dependency);
48434845
}
@@ -4846,11 +4848,11 @@ DmlNode* DefaultNode::parse(thread_db* tdbb, MemoryPool& pool, CompilerScratch*
48464848

48474849
while (true)
48484850
{
4849-
HazardPtr<jrd_rel> relation = MetadataCache::lookup_relation(tdbb, relationName);
4851+
auto relation = MetadataCache::lookup_relation(tdbb, relationName);
48504852

48514853
if (relation && relation->rel_fields)
48524854
{
4853-
int fieldId = MET_lookup_field(tdbb, relation.unsafePointer(), fieldName);
4855+
int fieldId = MET_lookup_field(tdbb, relation.getPointer(), fieldName);
48544856

48554857
if (fieldId >= 0)
48564858
{
@@ -6579,7 +6581,8 @@ ValueExprNode* FieldNode::pass1(thread_db* tdbb, CompilerScratch* csb)
65796581
try
65806582
{
65816583
ThreadStatusGuard local_status(tdbb);
6582-
collation = INTL_texttype_lookup(tdbb, ttype);
6584+
collation = csb->csb_resources.registerResource(tdbb, Resource::rsc_collation,
6585+
INTL_texttype_lookup(tdbb, ttype), ttype);
65836586
}
65846587
catch (Exception&)
65856588
{
@@ -6590,7 +6593,7 @@ ValueExprNode* FieldNode::pass1(thread_db* tdbb, CompilerScratch* csb)
65906593
}
65916594

65926595
if (collation)
6593-
CMP_post_resource(&csb->csb_resources, collation, Resource::rsc_collation, ttype);
6596+
csb->csb_resources.postResource(tdbb, Resource::rsc_collation, collation, ttype);
65946597
}
65956598

65966599
// if this is a modify or store, check REFERENCES access to any foreign keys
@@ -10691,9 +10694,10 @@ dsc* StrCaseNode::execute(thread_db* tdbb, Request* request) const
1069110694
if (request->req_flags & req_null)
1069210695
return NULL;
1069310696

10694-
TextType* textType = INTL_texttype_lookup(tdbb, value->getTextType());
10697+
HazardPtr<Collation> textType = INTL_texttype_lookup(tdbb, value->getTextType());
1069510698
CharSet* charSet = textType->getCharSet();
10696-
auto intlFunction = (blrOp == blr_lowcase ? &TextType::str_to_lower : &TextType::str_to_upper);
10699+
// auto intlFunction = (blrOp == blr_lowcase ? &TextType::str_to_lower : &TextType::str_to_upper);
10700+
auto intlFunction = (blrOp == blr_lowcase ? &Collation::str_to_lower : &Collation::str_to_upper);
1069710701

1069810702
if (value->isBlob())
1069910703
{
@@ -10723,7 +10727,7 @@ dsc* StrCaseNode::execute(thread_db* tdbb, Request* request) const
1072310727

1072410728
if (len)
1072510729
{
10726-
len = (textType->*intlFunction)(len, buffer.begin(), buffer.getCapacity(), buffer.begin());
10730+
len = (textType.getPointer()->*intlFunction)(len, buffer.begin(), buffer.getCapacity(), buffer.begin());
1072710731
newBlob->BLB_put_data(tdbb, buffer.begin(), len);
1072810732
}
1072910733
}
@@ -10745,7 +10749,7 @@ dsc* StrCaseNode::execute(thread_db* tdbb, Request* request) const
1074510749
desc.setTextType(ttype);
1074610750
EVL_make_value(tdbb, &desc, impure);
1074710751

10748-
len = (textType->*intlFunction)(len, ptr, desc.dsc_length, impure->vlu_desc.dsc_address);
10752+
len = (textType.getPointer()->*intlFunction)(len, ptr, desc.dsc_length, impure->vlu_desc.dsc_address);
1074910753

1075010754
if (len == INTL_BAD_STR_LENGTH)
1075110755
status_exception::raise(Arg::Gds(isc_arith_except));
@@ -11999,7 +12003,7 @@ dsc* SubstringSimilarNode::execute(thread_db* tdbb, Request* request) const
1199912003
return NULL;
1200012004

1200112005
USHORT textType = exprDesc->getTextType();
12002-
Collation* collation = INTL_texttype_lookup(tdbb, textType);
12006+
HazardPtr<Collation> collation = INTL_texttype_lookup(tdbb, textType);
1200312007
CharSet* charSet = collation->getCharSet();
1200412008

1200512009
MoveBuffer exprBuffer;
@@ -12561,7 +12565,7 @@ dsc* TrimNode::execute(thread_db* tdbb, Request* request) const
1256112565
return NULL;
1256212566

1256312567
USHORT ttype = INTL_TEXT_TYPE(*valueDesc);
12564-
TextType* tt = INTL_texttype_lookup(tdbb, ttype);
12568+
HazardPtr<Collation> tt = INTL_texttype_lookup(tdbb, ttype);
1256512569
CharSet* cs = tt->getCharSet();
1256612570

1256712571
const UCHAR* charactersAddress;
@@ -12757,8 +12761,9 @@ DmlNode* UdfCallNode::parse(thread_db* tdbb, MemoryPool& pool, CompilerScratch*
1275712761
HazardPtr<Function> func;
1275812762
if (!node->function)
1275912763
{
12760-
func = Function::lookup(tdbb, name, false); // !!!!!!!!!!!!!!!!!!! resource
12761-
node->function = func.unsafePointer();
12764+
func = Function::lookup(tdbb, name, false);
12765+
if (func)
12766+
node->function = csb->csb_resources.registerResource(tdbb, Resource::rsc_function, func, func->getId());
1276212767
}
1276312768

1276412769
Function* function = node->function;
@@ -12883,8 +12888,8 @@ ValueExprNode* UdfCallNode::copy(thread_db* tdbb, NodeCopier& copier) const
1288312888
node->function = function;
1288412889
else
1288512890
{
12886-
HazardPtr<Function> func = Function::lookup(tdbb, name, false); // !!!!!!!!!!!!!!!!!!! resource
12887-
node->function = func.unsafePointer();
12891+
HazardPtr<Function> func = Function::lookup(tdbb, name, false);
12892+
node->function = copier.csb->csb_resources.registerResource(tdbb, Resource::rsc_function, func, func->getId());
1288812893
}
1288912894
return node;
1289012895
}
@@ -12944,7 +12949,7 @@ ValueExprNode* UdfCallNode::pass1(thread_db* tdbb, CompilerScratch* csb)
1294412949
csb->csb_external.insert(idx, temp);
1294512950
}
1294612951

12947-
CMP_post_resource(&csb->csb_resources, function, Resource::rsc_function, function->getId());
12952+
csb->csb_resources.postResource(tdbb, Resource::rsc_function, function.getObject(), function->getId());
1294812953
}
1294912954

1295012955
return this;

src/dsql/StmtNodes.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2926,14 +2926,15 @@ DmlNode* ExecProcedureNode::parse(thread_db* tdbb, MemoryPool& pool, CompilerScr
29262926
{
29272927
SET_TDBB(tdbb);
29282928

2929-
HazardPtr<jrd_prc> proc;
29302929
jrd_prc* procedure = NULL;
2930+
HazardPtr<jrd_prc> proc;
29312931
QualifiedName name;
29322932

29332933
if (blrOp == blr_exec_pid)
29342934
{
29352935
const USHORT pid = csb->csb_blr_reader.getWord();
2936-
if (!(proc = MetadataCache::lookup_procedure_id(tdbb, pid, false, false, 0)))
2936+
proc = MetadataCache::lookup_procedure_id(tdbb, pid, false, false, 0);
2937+
if (!proc)
29372938
name.identifier.printf("id %d", pid);
29382939
}
29392940
else
@@ -2958,7 +2959,7 @@ DmlNode* ExecProcedureNode::parse(thread_db* tdbb, MemoryPool& pool, CompilerScr
29582959
}
29592960

29602961
if (proc && !procedure)
2961-
procedure = proc.unsafePointer();
2962+
procedure = csb->csb_resources.registerResource(tdbb, Resource::rsc_procedure, proc, proc->getId());
29622963

29632964
if (!procedure)
29642965
PAR_error(csb, Arg::Gds(isc_prcnotdef) << Arg::Str(name.toString()));
@@ -3183,7 +3184,7 @@ ExecProcedureNode* ExecProcedureNode::pass1(thread_db* tdbb, CompilerScratch* cs
31833184
{
31843185
// Post access to procedure.
31853186
CMP_post_procedure_access(tdbb, csb, procedure);
3186-
CMP_post_resource(&csb->csb_resources, procedure, Resource::rsc_procedure, procedure->getId());
3187+
csb->csb_resources.postResource(tdbb, Resource::rsc_procedure, procedure.getObject(), procedure->getId());
31873188
}
31883189

31893190
doPass1(tdbb, csb, inputSources.getAddress());
@@ -7806,7 +7807,7 @@ bool StoreNode::pass1Store(thread_db* tdbb, CompilerScratch* csb, StoreNode* nod
78067807

78077808
if (!relSource)
78087809
{
7809-
CMP_post_resource(&csb->csb_resources, relation, Resource::rsc_relation, relation->rel_id);
7810+
csb->csb_resources.postResource(tdbb, Resource::rsc_relation, relation, relation->rel_id);
78107811

78117812
if (!relation->rel_view_rse)
78127813
{
@@ -7827,7 +7828,7 @@ bool StoreNode::pass1Store(thread_db* tdbb, CompilerScratch* csb, StoreNode* nod
78277828
{
78287829
// ASF: This code is responsible to make view's WITH CHECK OPTION to work as constraints.
78297830

7830-
CMP_post_resource(&csb->csb_resources, relation, Resource::rsc_relation, relation->rel_id);
7831+
csb->csb_resources.postResource(tdbb, Resource::rsc_relation, relation, relation->rel_id);
78317832

78327833
// Set up the new target stream.
78337834

@@ -10855,7 +10856,9 @@ static void preprocessAssignments(thread_db* tdbb, CompilerScratch* csb,
1085510856
}
1085610857
else if (relation->rel_view_rse && fld->fld_source_rel_field.first.hasData())
1085710858
{
10858-
relation = MetadataCache::lookup_relation(tdbb, fld->fld_source_rel_field.first).unsafePointer();
10859+
HazardPtr<jrd_rel> rel = MetadataCache::lookup_relation(tdbb, fld->fld_source_rel_field.first);
10860+
relation = rel ? csb->csb_resources.registerResource(tdbb,
10861+
Resource::rsc_relation, rel, rel->rel_id) : nullptr;
1085910862

1086010863
fb_assert(relation);
1086110864
if (!relation)

src/dsql/dsql.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,12 +527,12 @@ class dsql_ctx : public pool_alloc<dsql_type_ctx>
527527
return *this;
528528
}
529529

530-
Firebird::string getObjectName() const
530+
const char* getObjectName() const
531531
{
532532
if (ctx_relation)
533533
return ctx_relation->rel_name.c_str();
534534
if (ctx_procedure)
535-
return ctx_procedure->prc_name.toString();
535+
return ctx_procedure->prc_name.c_str();
536536
return "";
537537
}
538538

src/include/fb_blk.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ enum BlockType
3434
type_att,
3535
type_sym,
3636
type_irl,
37-
type_idl,
3837
type_sdw,
3938
type_blf,
4039
type_arr,

src/jrd/Attachment.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ namespace Replication
6262
class TableMatcher;
6363
}
6464

65-
class CharSetContainer;
66-
6765
namespace Jrd
6866
{
6967
class thread_db;

0 commit comments

Comments
 (0)