Skip to content

Commit cb1f828

Browse files
NoremosArtyom Abakumov
andauthored
Prohibit inheritance of interface with versioned methods (#8982)
* Prohibit inherence of interface with versioned methods * Add blank lines before version token and missing const qualifier --------- Co-authored-by: Artyom Abakumov <artyom.abakumov@red-soft.ru>
1 parent b137a21 commit cb1f828

File tree

4 files changed

+112
-101
lines changed

4 files changed

+112
-101
lines changed

extern/cloop/src/cloop/Parser.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ void Parser::parse()
116116
}
117117
}
118118

119+
static bool hasVersionedMethods(const Interface& interface)
120+
{
121+
const auto& methods = interface.methods;
122+
return methods.size() >= 2 && methods.front()->version != methods.back()->version;
123+
}
124+
119125
void Parser::parseInterface(bool exception)
120126
{
121127
auto newInterface = std::make_shared<Interface>();
@@ -140,6 +146,9 @@ void Parser::parseInterface(bool exception)
140146
error(token, string("Super interface '") + superName + "' not found.");
141147

142148
interface->super = static_cast<Interface*>(superIt->second.get());
149+
if (hasVersionedMethods(*interface->super))
150+
error(token, string("Inheriting from the interface '" + superName + "' is not possible because it contains versioned methods."));
151+
143152
interface->version = interface->super->version + 1;
144153
}
145154
else

src/include/firebird/FirebirdInterface.idl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,9 +1382,6 @@ interface TraceStatement : Versioned
13821382
{
13831383
int64 getStmtID();
13841384
PerformanceInfo* getPerf();
1385-
1386-
version: // 5.0 -> 6.0
1387-
PerformanceStats getPerfStats();
13881385
}
13891386

13901387
interface TraceSQLStatement : TraceStatement
@@ -1394,13 +1391,19 @@ interface TraceSQLStatement : TraceStatement
13941391
TraceParams getInputs();
13951392
const string getTextUTF8();
13961393
const string getExplainedPlan();
1394+
1395+
version: // 5.0 -> 6.0
1396+
PerformanceStats getPerfStats();
13971397
}
13981398

13991399
interface TraceBLRStatement : TraceStatement
14001400
{
14011401
const uchar* getData();
14021402
uint getDataLength();
14031403
const string getText();
1404+
1405+
version: // 5.0 -> 6.0
1406+
PerformanceStats getPerfStats();
14041407
}
14051408

14061409
interface TraceDYNRequest : Versioned

src/include/firebird/IdlFbInterfaces.h

Lines changed: 45 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5609,7 +5609,7 @@ namespace Firebird
56095609
}
56105610
};
56115611

5612-
#define FIREBIRD_ITRACE_STATEMENT_VERSION 3u
5612+
#define FIREBIRD_ITRACE_STATEMENT_VERSION 2u
56135613

56145614
class ITraceStatement : public IVersioned
56155615
{
@@ -5618,7 +5618,6 @@ namespace Firebird
56185618
{
56195619
ISC_INT64 (CLOOP_CARG *getStmtID)(ITraceStatement* self) CLOOP_NOEXCEPT;
56205620
PerformanceInfo* (CLOOP_CARG *getPerf)(ITraceStatement* self) CLOOP_NOEXCEPT;
5621-
IPerformanceStats* (CLOOP_CARG *getPerfStats)(ITraceStatement* self) CLOOP_NOEXCEPT;
56225621
};
56235622

56245623
protected:
@@ -5645,16 +5644,6 @@ namespace Firebird
56455644
PerformanceInfo* ret = static_cast<VTable*>(this->cloopVTable)->getPerf(this);
56465645
return ret;
56475646
}
5648-
5649-
IPerformanceStats* getPerfStats()
5650-
{
5651-
if (cloopVTable->version < 3)
5652-
{
5653-
return 0;
5654-
}
5655-
IPerformanceStats* ret = static_cast<VTable*>(this->cloopVTable)->getPerfStats(this);
5656-
return ret;
5657-
}
56585647
};
56595648

56605649
#define FIREBIRD_ITRACE_SQLSTATEMENT_VERSION 4u
@@ -5669,6 +5658,7 @@ namespace Firebird
56695658
ITraceParams* (CLOOP_CARG *getInputs)(ITraceSQLStatement* self) CLOOP_NOEXCEPT;
56705659
const char* (CLOOP_CARG *getTextUTF8)(ITraceSQLStatement* self) CLOOP_NOEXCEPT;
56715660
const char* (CLOOP_CARG *getExplainedPlan)(ITraceSQLStatement* self) CLOOP_NOEXCEPT;
5661+
IPerformanceStats* (CLOOP_CARG *getPerfStats)(ITraceSQLStatement* self) CLOOP_NOEXCEPT;
56725662
};
56735663

56745664
protected:
@@ -5713,6 +5703,16 @@ namespace Firebird
57135703
const char* ret = static_cast<VTable*>(this->cloopVTable)->getExplainedPlan(this);
57145704
return ret;
57155705
}
5706+
5707+
IPerformanceStats* getPerfStats()
5708+
{
5709+
if (cloopVTable->version < 4)
5710+
{
5711+
return 0;
5712+
}
5713+
IPerformanceStats* ret = static_cast<VTable*>(this->cloopVTable)->getPerfStats(this);
5714+
return ret;
5715+
}
57165716
};
57175717

57185718
#define FIREBIRD_ITRACE_BLRSTATEMENT_VERSION 4u
@@ -5725,6 +5725,7 @@ namespace Firebird
57255725
const unsigned char* (CLOOP_CARG *getData)(ITraceBLRStatement* self) CLOOP_NOEXCEPT;
57265726
unsigned (CLOOP_CARG *getDataLength)(ITraceBLRStatement* self) CLOOP_NOEXCEPT;
57275727
const char* (CLOOP_CARG *getText)(ITraceBLRStatement* self) CLOOP_NOEXCEPT;
5728+
IPerformanceStats* (CLOOP_CARG *getPerfStats)(ITraceBLRStatement* self) CLOOP_NOEXCEPT;
57285729
};
57295730

57305731
protected:
@@ -5757,6 +5758,16 @@ namespace Firebird
57575758
const char* ret = static_cast<VTable*>(this->cloopVTable)->getText(this);
57585759
return ret;
57595760
}
5761+
5762+
IPerformanceStats* getPerfStats()
5763+
{
5764+
if (cloopVTable->version < 4)
5765+
{
5766+
return 0;
5767+
}
5768+
IPerformanceStats* ret = static_cast<VTable*>(this->cloopVTable)->getPerfStats(this);
5769+
return ret;
5770+
}
57605771
};
57615772

57625773
#define FIREBIRD_ITRACE_DYNREQUEST_VERSION 2u
@@ -18062,7 +18073,6 @@ namespace Firebird
1806218073
this->version = Base::VERSION;
1806318074
this->getStmtID = &Name::cloopgetStmtIDDispatcher;
1806418075
this->getPerf = &Name::cloopgetPerfDispatcher;
18065-
this->getPerfStats = &Name::cloopgetPerfStatsDispatcher;
1806618076
}
1806718077
} vTable;
1806818078

@@ -18094,19 +18104,6 @@ namespace Firebird
1809418104
return static_cast<PerformanceInfo*>(0);
1809518105
}
1809618106
}
18097-
18098-
static IPerformanceStats* CLOOP_CARG cloopgetPerfStatsDispatcher(ITraceStatement* self) CLOOP_NOEXCEPT
18099-
{
18100-
try
18101-
{
18102-
return static_cast<Name*>(self)->Name::getPerfStats();
18103-
}
18104-
catch (...)
18105-
{
18106-
StatusType::catchException(0);
18107-
return static_cast<IPerformanceStats*>(0);
18108-
}
18109-
}
1811018107
};
1811118108

1811218109
template <typename Name, typename StatusType, typename Base = IVersionedImpl<Name, StatusType, Inherit<ITraceStatement> > >
@@ -18124,7 +18121,6 @@ namespace Firebird
1812418121

1812518122
virtual ISC_INT64 getStmtID() = 0;
1812618123
virtual PerformanceInfo* getPerf() = 0;
18127-
virtual IPerformanceStats* getPerfStats() = 0;
1812818124
};
1812918125

1813018126
template <typename Name, typename StatusType, typename Base>
@@ -18142,12 +18138,12 @@ namespace Firebird
1814218138
this->version = Base::VERSION;
1814318139
this->getStmtID = &Name::cloopgetStmtIDDispatcher;
1814418140
this->getPerf = &Name::cloopgetPerfDispatcher;
18145-
this->getPerfStats = &Name::cloopgetPerfStatsDispatcher;
1814618141
this->getText = &Name::cloopgetTextDispatcher;
1814718142
this->getPlan = &Name::cloopgetPlanDispatcher;
1814818143
this->getInputs = &Name::cloopgetInputsDispatcher;
1814918144
this->getTextUTF8 = &Name::cloopgetTextUTF8Dispatcher;
1815018145
this->getExplainedPlan = &Name::cloopgetExplainedPlanDispatcher;
18146+
this->getPerfStats = &Name::cloopgetPerfStatsDispatcher;
1815118147
}
1815218148
} vTable;
1815318149

@@ -18219,42 +18215,42 @@ namespace Firebird
1821918215
}
1822018216
}
1822118217

18222-
static ISC_INT64 CLOOP_CARG cloopgetStmtIDDispatcher(ITraceStatement* self) CLOOP_NOEXCEPT
18218+
static IPerformanceStats* CLOOP_CARG cloopgetPerfStatsDispatcher(ITraceSQLStatement* self) CLOOP_NOEXCEPT
1822318219
{
1822418220
try
1822518221
{
18226-
return static_cast<Name*>(self)->Name::getStmtID();
18222+
return static_cast<Name*>(self)->Name::getPerfStats();
1822718223
}
1822818224
catch (...)
1822918225
{
1823018226
StatusType::catchException(0);
18231-
return static_cast<ISC_INT64>(0);
18227+
return static_cast<IPerformanceStats*>(0);
1823218228
}
1823318229
}
1823418230

18235-
static PerformanceInfo* CLOOP_CARG cloopgetPerfDispatcher(ITraceStatement* self) CLOOP_NOEXCEPT
18231+
static ISC_INT64 CLOOP_CARG cloopgetStmtIDDispatcher(ITraceStatement* self) CLOOP_NOEXCEPT
1823618232
{
1823718233
try
1823818234
{
18239-
return static_cast<Name*>(self)->Name::getPerf();
18235+
return static_cast<Name*>(self)->Name::getStmtID();
1824018236
}
1824118237
catch (...)
1824218238
{
1824318239
StatusType::catchException(0);
18244-
return static_cast<PerformanceInfo*>(0);
18240+
return static_cast<ISC_INT64>(0);
1824518241
}
1824618242
}
1824718243

18248-
static IPerformanceStats* CLOOP_CARG cloopgetPerfStatsDispatcher(ITraceStatement* self) CLOOP_NOEXCEPT
18244+
static PerformanceInfo* CLOOP_CARG cloopgetPerfDispatcher(ITraceStatement* self) CLOOP_NOEXCEPT
1824918245
{
1825018246
try
1825118247
{
18252-
return static_cast<Name*>(self)->Name::getPerfStats();
18248+
return static_cast<Name*>(self)->Name::getPerf();
1825318249
}
1825418250
catch (...)
1825518251
{
1825618252
StatusType::catchException(0);
18257-
return static_cast<IPerformanceStats*>(0);
18253+
return static_cast<PerformanceInfo*>(0);
1825818254
}
1825918255
}
1826018256
};
@@ -18277,6 +18273,7 @@ namespace Firebird
1827718273
virtual ITraceParams* getInputs() = 0;
1827818274
virtual const char* getTextUTF8() = 0;
1827918275
virtual const char* getExplainedPlan() = 0;
18276+
virtual IPerformanceStats* getPerfStats() = 0;
1828018277
};
1828118278

1828218279
template <typename Name, typename StatusType, typename Base>
@@ -18294,10 +18291,10 @@ namespace Firebird
1829418291
this->version = Base::VERSION;
1829518292
this->getStmtID = &Name::cloopgetStmtIDDispatcher;
1829618293
this->getPerf = &Name::cloopgetPerfDispatcher;
18297-
this->getPerfStats = &Name::cloopgetPerfStatsDispatcher;
1829818294
this->getData = &Name::cloopgetDataDispatcher;
1829918295
this->getDataLength = &Name::cloopgetDataLengthDispatcher;
1830018296
this->getText = &Name::cloopgetTextDispatcher;
18297+
this->getPerfStats = &Name::cloopgetPerfStatsDispatcher;
1830118298
}
1830218299
} vTable;
1830318300

@@ -18343,42 +18340,42 @@ namespace Firebird
1834318340
}
1834418341
}
1834518342

18346-
static ISC_INT64 CLOOP_CARG cloopgetStmtIDDispatcher(ITraceStatement* self) CLOOP_NOEXCEPT
18343+
static IPerformanceStats* CLOOP_CARG cloopgetPerfStatsDispatcher(ITraceBLRStatement* self) CLOOP_NOEXCEPT
1834718344
{
1834818345
try
1834918346
{
18350-
return static_cast<Name*>(self)->Name::getStmtID();
18347+
return static_cast<Name*>(self)->Name::getPerfStats();
1835118348
}
1835218349
catch (...)
1835318350
{
1835418351
StatusType::catchException(0);
18355-
return static_cast<ISC_INT64>(0);
18352+
return static_cast<IPerformanceStats*>(0);
1835618353
}
1835718354
}
1835818355

18359-
static PerformanceInfo* CLOOP_CARG cloopgetPerfDispatcher(ITraceStatement* self) CLOOP_NOEXCEPT
18356+
static ISC_INT64 CLOOP_CARG cloopgetStmtIDDispatcher(ITraceStatement* self) CLOOP_NOEXCEPT
1836018357
{
1836118358
try
1836218359
{
18363-
return static_cast<Name*>(self)->Name::getPerf();
18360+
return static_cast<Name*>(self)->Name::getStmtID();
1836418361
}
1836518362
catch (...)
1836618363
{
1836718364
StatusType::catchException(0);
18368-
return static_cast<PerformanceInfo*>(0);
18365+
return static_cast<ISC_INT64>(0);
1836918366
}
1837018367
}
1837118368

18372-
static IPerformanceStats* CLOOP_CARG cloopgetPerfStatsDispatcher(ITraceStatement* self) CLOOP_NOEXCEPT
18369+
static PerformanceInfo* CLOOP_CARG cloopgetPerfDispatcher(ITraceStatement* self) CLOOP_NOEXCEPT
1837318370
{
1837418371
try
1837518372
{
18376-
return static_cast<Name*>(self)->Name::getPerfStats();
18373+
return static_cast<Name*>(self)->Name::getPerf();
1837718374
}
1837818375
catch (...)
1837918376
{
1838018377
StatusType::catchException(0);
18381-
return static_cast<IPerformanceStats*>(0);
18378+
return static_cast<PerformanceInfo*>(0);
1838218379
}
1838318380
}
1838418381
};
@@ -18399,6 +18396,7 @@ namespace Firebird
1839918396
virtual const unsigned char* getData() = 0;
1840018397
virtual unsigned getDataLength() = 0;
1840118398
virtual const char* getText() = 0;
18399+
virtual IPerformanceStats* getPerfStats() = 0;
1840218400
};
1840318401

1840418402
template <typename Name, typename StatusType, typename Base>

0 commit comments

Comments
 (0)