Subject: Re:[sv-cc] svPut/GetUserData()
From: Andrzej Litwiniuk (Andrzej.Litwiniuk@synopsys.com)
Date: Tue Mar 18 2003 - 08:43:00 PST
John,
I've got a question concerning svGetUserData(). I'm not sure I understand
how it's supposed to work.
void* svGetUserData();
// Returns user context for current extern'ed function
// of current scope
Note that a function (the current extern context func) is only implicit here.
You can set the scope to a different scope, by calling svPutScope(), but
you cannot set a different function. That way svGetUserData() cannot be
used in call chains that contain more than one context function. (The same
function could be legitimately called both from SV and from C).
Your example didn't help me much.
public:
MyCModel( const char *svModulePath ){
dSvScope = svGetScopeByName( svModulePath );
svPutUserData( dSvScope, "MyExternedCFunc", this );
} // This function is called from SV ...
friend void MyExternedCFunc( args ... ){
MyCModel *me = (MyCModel *)svGetUserData(); // <- No args !!!
me->processArgs( args ... );
}
It's my guesswork only that SV compiler shall instrument a call to a context
function by setting some global variable that would identify the function
being called. Then, svGetUserData() will fetch this global variable and will
calculate the right mapping: (instance x function_name) ---> user_data
Is it how you envisioned it?
I've got a couple of questions. (Please ignore them if I got it wrong!)
- Wouldn't a pointer to a function be a more efficient key than a function
name?
- Why to bear some overhead, even if tiny, for extern context calls which
may not use that functionality?
- If all my extern context functions share the same data per instance,
will it be necessary to 'register' each of them separately, by
calling svPutUserData(dSvScope, func_name, shared_data) for each function?
- A function cannot fetch another function's data, since a function
is available to svGetUserData() only implicitly and cannot be switched to
another one. So, if several functions are to share the same instance specific
data (say, a pointer to C/C++ structure/object),
then svPutUserData(..., shared_data) must be called for all of them
with the same data. If you don't have access to the original data,
you cannot later add another function that would share the same data!
Thanks and regards,
Andrzej
This archive was generated by hypermail 2b28 : Tue Mar 18 2003 - 08:43:36 PST