Skip to content

Commit

Permalink
Fixed CORE-4068 - create package fails on creating header as soon as …
Browse files Browse the repository at this point in the history
…there is at least 1 procedure name.
  • Loading branch information
asfernandes committed Mar 27, 2013
1 parent 28f05f1 commit 850e529
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 78 deletions.
3 changes: 1 addition & 2 deletions builds/posix/Makefile.in.plugins_examples
Expand Up @@ -52,8 +52,7 @@ LINK_PLUGIN_SYMBOLS = $(call LIB_LINK_MAPFILE,../$(PLUGIN_VERS))

.PHONY: all udrcpp_example dc_example kh_example

#all: udrcpp_example dc_example kh_example
all: dc_example kh_example
all: udrcpp_example dc_example kh_example


UDR_Objects = $(call makeObjects,../examples/udr,UdrCppExample.cpp)
Expand Down
10 changes: 5 additions & 5 deletions src/jrd/ExtEngineManager.cpp
Expand Up @@ -439,7 +439,7 @@ ExtEngineManager::Trigger::Trigger(thread_db* tdbb, MemoryPool& pool, ExtEngineM

if (relation)
{
format = Routine::createFormat(pool, metadata->triggerFields);
format = Routine::createFormat(pool, metadata->triggerFields, false);

for (unsigned i = 0; i < format->fmt_count / 2; ++i)
fieldsPos.add(i);
Expand Down Expand Up @@ -671,8 +671,8 @@ void ExtEngineManager::makeFunction(thread_db* tdbb, Jrd::Function* udf,

try
{
udf->setInputFormat(Routine::createFormat(pool, metadata->inputParameters));
udf->setOutputFormat(Routine::createFormat(pool, metadata->outputParameters));
udf->setInputFormat(Routine::createFormat(pool, metadata->inputParameters, false));
udf->setOutputFormat(Routine::createFormat(pool, metadata->outputParameters, false));

udf->fun_external = FB_NEW(getPool()) Function(tdbb, this, attInfo->engine,
metadata.release(), externalFunction, udf);
Expand Down Expand Up @@ -744,8 +744,8 @@ void ExtEngineManager::makeProcedure(thread_db* tdbb, jrd_prc* prc,

try
{
prc->setInputFormat(Routine::createFormat(pool, metadata->inputParameters));
prc->setOutputFormat(Routine::createFormat(pool, metadata->outputParameters));
prc->setInputFormat(Routine::createFormat(pool, metadata->inputParameters, false));
prc->setOutputFormat(Routine::createFormat(pool, metadata->outputParameters, false));

prc->setExternal(FB_NEW(getPool()) Procedure(tdbb, this, attInfo->engine,
metadata.release(), externalProcedure, prc));
Expand Down
83 changes: 45 additions & 38 deletions src/jrd/Function.epp
Expand Up @@ -374,58 +374,55 @@ Function* Function::loadMetadata(thread_db* tdbb, USHORT id, bool noscan, USHORT
function->fun_external = NULL;
function->setStatement(NULL);

if (!X.RDB$ENGINE_NAME.NULL || !X.RDB$FUNCTION_BLR.NULL)
if (!X.RDB$ENGINE_NAME.NULL)
{
if (!X.RDB$ENGINE_NAME.NULL)
HalfStaticArray<UCHAR, 512> body;

if (!X.RDB$FUNCTION_SOURCE.NULL)
{
HalfStaticArray<UCHAR, 512> body;
blb* const blob = blb::open(tdbb, sysTransaction, &X.RDB$FUNCTION_SOURCE);
const ULONG len = blob->BLB_get_data(tdbb,
body.getBuffer(blob->blb_length + 1), blob->blb_length + 1);
body[MIN(blob->blb_length, len)] = 0;
}
else
body.getBuffer(1)[0] = 0;

if (!X.RDB$FUNCTION_SOURCE.NULL)
{
blb* const blob = blb::open(tdbb, sysTransaction, &X.RDB$FUNCTION_SOURCE);
const ULONG len = blob->BLB_get_data(tdbb,
body.getBuffer(blob->blb_length + 1), blob->blb_length + 1);
body[MIN(blob->blb_length, len)] = 0;
}
else
body.getBuffer(1)[0] = 0;
dbb->dbb_extManager.makeFunction(tdbb, function, X.RDB$ENGINE_NAME,
(X.RDB$ENTRYPOINT.NULL ? "" : X.RDB$ENTRYPOINT), (char*) body.begin());

dbb->dbb_extManager.makeFunction(tdbb, function, X.RDB$ENGINE_NAME,
(X.RDB$ENTRYPOINT.NULL ? "" : X.RDB$ENTRYPOINT), (char*) body.begin());
if (!function->fun_external)
function->setDefined(false);
}
else if (!X.RDB$FUNCTION_BLR.NULL)
{
MemoryPool* const csb_pool = attachment->createPool();
Jrd::ContextPoolHolder context(tdbb, csb_pool);

if (!function->fun_external)
function->setDefined(false);
}
else
try
{
MemoryPool* const csb_pool = attachment->createPool();
Jrd::ContextPoolHolder context(tdbb, csb_pool);
AutoPtr<CompilerScratch> csb(CompilerScratch::newCsb(*csb_pool, 5));

if (!X.RDB$DEBUG_INFO.NULL)
DBG_parse_debug_info(tdbb, &X.RDB$DEBUG_INFO, *csb->csb_dbg_info);

try
{
AutoPtr<CompilerScratch> csb(CompilerScratch::newCsb(*csb_pool, 5));

if (!X.RDB$DEBUG_INFO.NULL)
DBG_parse_debug_info(tdbb, &X.RDB$DEBUG_INFO, *csb->csb_dbg_info);

try
{
MET_parse_routine_blr(tdbb, function, &X.RDB$FUNCTION_BLR, csb);
}
catch (const Exception&)
{
const string name = function->getName().toString();
status_exception::raise(Arg::Gds(isc_bad_fun_BLR) << Arg::Str(name));
}
MET_parse_routine_blr(tdbb, function, &X.RDB$FUNCTION_BLR, csb);
}
catch (const Exception&)
{
attachment->deletePool(csb_pool);
throw;
const string name = function->getName().toString();
status_exception::raise(Arg::Gds(isc_bad_fun_BLR) << Arg::Str(name));
}

function->getStatement()->function = function;
}
catch (const Exception&)
{
attachment->deletePool(csb_pool);
throw;
}

function->getStatement()->function = function;
}
else if (!X.RDB$MODULE_NAME.NULL && !X.RDB$ENTRYPOINT.NULL)
{
Expand All @@ -444,7 +441,17 @@ Function* Function::loadMetadata(thread_db* tdbb, USHORT id, bool noscan, USHORT
function->setDefined(false);
}
else
{
RefPtr<MsgMetadata> inputMetadata(createMetadata(function->getInputFields()));
inputMetadata->release();
function->setInputFormat(createFormat(function->getPool(), inputMetadata, false));

RefPtr<MsgMetadata> outputMetadata(createMetadata(function->getOutputFields()));
outputMetadata->release();
function->setOutputFormat(createFormat(function->getPool(), outputMetadata, true));

function->setImplemented(false);
}

if (X.RDB$VALID_BLR.NULL || X.RDB$VALID_BLR == FALSE)
valid_blr = false;
Expand Down
11 changes: 9 additions & 2 deletions src/jrd/Routine.cpp
Expand Up @@ -48,14 +48,14 @@ MsgMetadata* Routine::createMetadata(const Array<NestConst<Parameter> >& paramet
}

// Create a Format based on an IMessageMetadata.
Format* Routine::createFormat(MemoryPool& pool, IMessageMetadata* params)
Format* Routine::createFormat(MemoryPool& pool, IMessageMetadata* params, bool addEof)
{
LocalStatus status;

unsigned count = params->getCount(&status);
status.check();

Format* format = Format::newFormat(pool, count * 2);
Format* format = Format::newFormat(pool, count * 2 + (addEof ? 1 : 0));
unsigned runOffset = 0;

dsc* desc = format->fmt_desc.begin();
Expand Down Expand Up @@ -85,6 +85,13 @@ Format* Routine::createFormat(MemoryPool& pool, IMessageMetadata* params)
++desc;
}

if (addEof)
{
// Next item is aligned on USHORT, so as the previous one.
desc->makeShort(0, (SSHORT*)(IPTR) runOffset);
runOffset += sizeof(USHORT);
}

format->fmt_length = runOffset;

return format;
Expand Down
2 changes: 1 addition & 1 deletion src/jrd/Routine.h
Expand Up @@ -62,7 +62,7 @@ namespace Jrd
public:
static Firebird::MsgMetadata* createMetadata(
const Firebird::Array<NestConst<Parameter> >& parameters);
static Format* createFormat(MemoryPool& pool, Firebird::IMessageMetadata* params);
static Format* createFormat(MemoryPool& pool, Firebird::IMessageMetadata* params, bool addEof);

public:
USHORT getId() const
Expand Down
79 changes: 49 additions & 30 deletions src/jrd/met.epp
Expand Up @@ -3062,45 +3062,64 @@ jrd_prc* MET_procedure(thread_db* tdbb, int id, bool noscan, USHORT flags)

if (!external)
{
MemoryPool* csb_pool = attachment->createPool();
if (!P.RDB$PROCEDURE_BLR.NULL)
{
MemoryPool* csb_pool = attachment->createPool();

Jrd::ContextPoolHolder context(tdbb, csb_pool);
CompilerScratch* csb = CompilerScratch::newCsb(*tdbb->getDefaultPool(), 5);
Jrd::ContextPoolHolder context(tdbb, csb_pool);
CompilerScratch* csb = CompilerScratch::newCsb(*tdbb->getDefaultPool(), 5);

if (!P.RDB$DEBUG_INFO.NULL)
DBG_parse_debug_info(tdbb, &P.RDB$DEBUG_INFO, *csb->csb_dbg_info);
if (!P.RDB$DEBUG_INFO.NULL)
DBG_parse_debug_info(tdbb, &P.RDB$DEBUG_INFO, *csb->csb_dbg_info);

try
{
MET_parse_routine_blr(tdbb, procedure,
(P.RDB$PROCEDURE_BLR.NULL ? NULL : &P.RDB$PROCEDURE_BLR), csb);
}
catch (const Exception&)
{
delete csb;

if (procedure->getStatement())
procedure->releaseStatement(tdbb);
else
attachment->deletePool(csb_pool);
try
{
MET_parse_routine_blr(tdbb, procedure,
(P.RDB$PROCEDURE_BLR.NULL ? NULL : &P.RDB$PROCEDURE_BLR), csb);
}
catch (const Exception&)
{
delete csb;

ERR_post(Arg::Gds(isc_bad_proc_BLR) << Arg::Str(procedure->getName().toString()));
}
if (procedure->getStatement())
procedure->releaseStatement(tdbb);
else
attachment->deletePool(csb_pool);

procedure->getStatement()->procedure = procedure;
for (size_t i = 0; i < csb->csb_rpt.getCount(); i++)
{
MessageNode* node = csb->csb_rpt[i].csb_message;
ERR_post(Arg::Gds(isc_bad_proc_BLR) << Arg::Str(procedure->getName().toString()));
}

/***
if (node)
procedure->getStatement()->procedure = procedure;
for (size_t i = 0; i < csb->csb_rpt.getCount(); i++)
{
if (node->messageNumber == 1)
procedure->prc_output_msg = node;
MessageNode* node = csb->csb_rpt[i].csb_message;

/***
if (node)
{
if (node->messageNumber == 1)
procedure->prc_output_msg = node;
}
***/
}
***/
delete csb;
}
else
{
RefPtr<MsgMetadata> inputMetadata(
Routine::createMetadata(procedure->getInputFields()));
inputMetadata->release();
procedure->setInputFormat(
Routine::createFormat(procedure->getPool(), inputMetadata, false));

RefPtr<MsgMetadata> outputMetadata(
Routine::createMetadata(procedure->getOutputFields()));
outputMetadata->release();
procedure->setOutputFormat(
Routine::createFormat(procedure->getPool(), outputMetadata, true));

procedure->setImplemented(false);
}
delete csb;
}

if (P.RDB$VALID_BLR.NULL || P.RDB$VALID_BLR == FALSE)
Expand Down

0 comments on commit 850e529

Please sign in to comment.