Skip to content

Commit

Permalink
Implement unregister of system functions
Browse files Browse the repository at this point in the history
It is needed as due to Y2Namespace documentation after createFunction caller
can immediatelly destroy Y2Function, but Y2SystemNamespace try to switch it even
if it is destroyed. Such action lead to segfault.
  • Loading branch information
jreidinger committed May 23, 2013
1 parent 3a7abe1 commit ccd2a6d
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 12 deletions.
6 changes: 3 additions & 3 deletions wfm/src/Y2SystemFunction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@

#include "ycp/SymbolTable.h"

Y2SystemFunction::Y2SystemFunction (Y2Function* local_call, constFunctionTypePtr type) :
Y2SystemFunction::Y2SystemFunction (Y2Function* local_call, constFunctionTypePtr type, Y2SystemNamespace *name_space) :
m_local (local_call)
, m_remote (0)
, m_use_remote (false)
, m_type (type)
, m_namespace(name_space)
{
#ifdef DEBUG
y2debug ("The local function: %s", m_local->name ().c_str ());
Expand All @@ -48,8 +49,7 @@ Y2SystemFunction::Y2SystemFunction (Y2Function* local_call, constFunctionTypePtr
Y2SystemFunction::~Y2SystemFunction ()
{
// FIXME deletes

// FIXME unregister in Y2Namespace
m_namespace->unregisterFunction(this);
}

bool
Expand Down
4 changes: 3 additions & 1 deletion wfm/src/Y2SystemFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ class Y2SystemFunction : public Y2Function {
bool m_use_remote;

constFunctionTypePtr m_type;

Y2SystemNamespace *m_namespace;

public:
Y2SystemFunction (Y2Function* local_call, constFunctionTypePtr type);
Y2SystemFunction (Y2Function* local_call, constFunctionTypePtr type, Y2SystemNamespace* system_namespace);

virtual ~Y2SystemFunction ();

Expand Down
17 changes: 15 additions & 2 deletions wfm/src/Y2SystemNamespace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Y2SystemNamespace::createFunctionCall (const string name, constFunctionTypePtr t

y2debug ("allocating new Y2SystemFunction %s::%s", m_name.c_str (), name.c_str ());

Y2SystemFunction* fnc = new Y2SystemFunction (local_func, type);
Y2SystemFunction* fnc = new Y2SystemFunction (local_func, type, this);
m_functions.push_back (fnc);

// currently we use remote communication
Expand Down Expand Up @@ -138,7 +138,7 @@ Y2SystemNamespace::useRemote (Y2ProgramComponent* sender)
void
Y2SystemNamespace::useLocal ()
{
y2milestone ("redirecting to local %u modules", m_functions.size());
y2milestone ("redirecting to local %u functions", m_functions.size());
for ( vector<Y2SystemFunction*>::iterator it = m_functions.begin ();
it != m_functions.end () ; ++it )
{
Expand All @@ -149,3 +149,16 @@ Y2SystemNamespace::useLocal ()

m_use_remote = false;
}

void Y2SystemNamespace::unregisterFunction(Y2SystemFunction *f)
{
long to_remove =-1;
for( unsigned i = 0; i < m_functions.size(); i++)
{
// get our function
if (f == m_functions.at(i))
to_remove = i;
}
if (to_remove >= 0)
m_functions.erase(m_functions.begin()+to_remove);
}
6 changes: 4 additions & 2 deletions wfm/src/Y2SystemNamespace.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ class Y2SystemNamespace : public Y2Namespace {
bool m_use_remote;

vector<Y2SystemFunction*> m_functions;

string m_name;


void unregisterFunction(Y2SystemFunction *f);

friend class Y2SystemFunction;

public:
Expand Down
13 changes: 9 additions & 4 deletions wfm/src/Y2WFMComponent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -754,14 +754,18 @@ Y2WFMComponent::import (const char* name_space)
// System:: namespace access
if (strstr (name_space, "System::") == name_space)
{
y2milestone("import System namespace %s", name_space);
// check if namespace is not already imported

for ( SystemNamespaces::iterator ns = system_namespaces.begin ();
ns != system_namespaces.end (); ns ++ )
{
if ((*ns)->name() == name_space)
return 0;
}
{
y2milestone("Namespace %s already imported", name_space);
return *ns;
}
}

char* subsys = const_cast<char*>(name_space) + 8; // skip the prefix
Y2Component* local_comp = Y2ComponentBroker::getNamespaceComponent (subsys);
Expand All @@ -777,8 +781,9 @@ Y2WFMComponent::import (const char* name_space)

Y2SystemNamespace* ns = new Y2SystemNamespace (local_ns);

system_namespaces.push_back (ns);

system_namespaces.push_back (ns);

y2milestone("Namespace %s properly imported", ns->name().c_str());
return ns;
}
return 0;
Expand Down

0 comments on commit ccd2a6d

Please sign in to comment.