Revision: 21569
Author: gervandiepen
Date: Wed Feb 18 14:42:54 2015 UTC
Log: Slightly changed way of dynamic library loading
https://code.google.com/p/casacore/source/detail?r=21569
Modified:
/branches/nov14/python/CMakeLists.txt
/branches/nov14/tables/TaQL/TaQLStyle.cc
/branches/nov14/tables/TaQL/UDFBase.cc
/branches/nov14/tables/TaQL/UDFBase.h
=======================================
--- /branches/nov14/python/CMakeLists.txt Tue Jun 10 07:48:08 2014 UTC
+++ /branches/nov14/python/CMakeLists.txt Wed Feb 18 14:42:54 2015 UTC
@@ -8,6 +8,7 @@
Converters/PycArrayNP.cc
Converters/PycBasicData.cc
Converters/PycExcp.cc
+Converters/PycImport.cc
Converters/PycRecord.cc
Converters/PycValueHolder.cc
)
=======================================
--- /branches/nov14/tables/TaQL/TaQLStyle.cc Wed Dec 10 08:06:42 2014 UTC
+++ /branches/nov14/tables/TaQL/TaQLStyle.cc Wed Feb 18 14:42:54 2015 UTC
@@ -41,6 +41,7 @@
{
// Define mscal as a synonym for derivedmscal.
defineSynonym ("mscal", "derivedmscal");
+ defineSynonym ("py", "pytaql");
}
void TaQLStyle::set (const String& value)
=======================================
--- /branches/nov14/tables/TaQL/UDFBase.cc Wed Dec 10 08:06:42 2014 UTC
+++ /branches/nov14/tables/TaQL/UDFBase.cc Wed Feb 18 14:42:54 2015 UTC
@@ -179,14 +179,9 @@
libname = style.findSynonym (libname);
fname = libname + fname.substr(j);
ScopedMutexLock lock(theirMutex);
- map<String,MakeUDFObject*>::iterator iter = theirRegistry.find
(fname);
- if (iter != theirRegistry.end()) {
- return iter->second (fname);
- }
- // Not found. See if library is already loaded.
- // If so, it is an unknown function in the UDF library.
- map<String,MakeUDFObject*>::iterator sit = theirRegistry.find
(libname);
- if (sit == theirRegistry.end()) {
+ // See if the library is already loaded.
+ map<String,MakeUDFObject*>::iterator iter = theirRegistry.find
(libname);
+ if (iter == theirRegistry.end()) {
// Try to load the dynamic library.
DynLib dl(libname, string("libcasa_"), "register_"+libname, False);
if (dl.getHandle()) {
@@ -194,13 +189,18 @@
// Note that a libname is different from a function name because
// it does not contain dots.
theirRegistry[libname] = 0;
- // See if function is registered now.
- map<String,MakeUDFObject*>::iterator iter = theirRegistry.find
(fname);
- if (iter != theirRegistry.end()) {
- return iter->second (fname);
- }
}
}
+ // Try to find the function.
+ iter = theirRegistry.find (fname);
+ if (iter != theirRegistry.end()) {
+ return iter->second (fname);
+ }
+ // Look up 'libname.*' to see if the UDF supports any function.
+ iter = theirRegistry.find (libname + ".*");
+ if (iter != theirRegistry.end()) {
+ return iter->second (fname);
+ }
}
throw TableInvExpr ("TaQL function " + name + " (=" + fname +
") is unknown");
=======================================
--- /branches/nov14/tables/TaQL/UDFBase.h Wed Feb 18 09:15:05 2015 UTC
+++ /branches/nov14/tables/TaQL/UDFBase.h Wed Feb 18 14:42:54 2015 UTC
@@ -309,7 +309,7 @@
void setAggregate (Bool isAggregate);
public:
- // Register a the name and construction function of a UDF
(thread-safe).
+ // Register the name and construction function of a UDF (thread-safe).
// An exception is thrown if this name already exists with a different
// construction function.
static void registerUDF (const String& name, MakeUDFObject* func);
@@ -340,6 +340,8 @@
{ return itsIsAggregate; }
// Create a UDF object (thread-safe).
+ // It looks in the map with fixed function names. If unknown,
+ // it looks if a wildcarded function name is supported (for PyTaQL).
static UDFBase* createUDF (const String& name, const TaQLStyle& style);
private:
@@ -351,6 +353,11 @@
String itsUnit;
Bool itsIsConstant;
Bool itsIsAggregate;
+ //# The registry is used for two purposes:
+ //# 1. It is a map of known function names (lib.func) to funcptr.
+ //# Function name * means that the library can contain any function,
+ //# which is intended for python functions (through PyTaQL).
+ //# 2. The loaded libraries are kept in the map (with 0 funcptr).
static map<String, MakeUDFObject*> theirRegistry;
static Mutex theirMutex;
};