def test_dlopenflags(self):
     self.assertTrue(hasattr(sys, "getdlopenflags"))
     self.assertRaises(TypeError, sys.getdlopenflags, 42)
     oldflags = sys.getdlopenflags()
     self.assertRaises(TypeError, sys.setdlopenflags)
     sys.setdlopenflags(oldflags+1)
     self.assertEqual(sys.getdlopenflags(), oldflags+1)
     sys.setdlopenflags(oldflags)
Exemplo n.º 2
0
 def test_dlopenflags(self):
     import sys
     raises(TypeError, sys.getdlopenflags, 42)
     oldflags = sys.getdlopenflags()
     raises(TypeError, sys.setdlopenflags)
     sys.setdlopenflags(oldflags+1)
     assert sys.getdlopenflags() == oldflags+1
     sys.setdlopenflags(oldflags)
Exemplo n.º 3
0
 def test_dlopenflags(self):
     if hasattr(sys, "setdlopenflags"):
         assert hasattr(sys, "getdlopenflags")
         raises(TypeError, sys.getdlopenflags, 42)
         oldflags = sys.getdlopenflags()
         raises(TypeError, sys.setdlopenflags)
         sys.setdlopenflags(oldflags + 1)
         assert sys.getdlopenflags() == oldflags + 1
         sys.setdlopenflags(oldflags)
Exemplo n.º 4
0
def __import_extension__(name, package, locals):
  """Import a module.

  The 'package' argument is required when performing a relative import. It
  specifies the package to use as the anchor point from which to resolve the
  relative import to an absolute import.

  """

  # This is a fix to the problem of using templates/static/exceptions/dynamic
  # casts with boost.python. It makes all symbols loaded by python from this
  # point onwards global
  default_flags = sys.getdlopenflags()
  sys.setdlopenflags(default_flags|ctypes.RTLD_GLOBAL)

  if name.startswith('.'):
    if not package:
      raise TypeError("relative imports require the 'package' argument")
    level = 0
    for character in name:
      if character != '.':
        break
      level += 1
    name = __resolve_name__(name[level:], package, level)
  __import__(name, locals=locals)
  sys.setdlopenflags(default_flags)

  return sys.modules[name]
Exemplo n.º 5
0
def setdlopenflags():
    oldflags = sys.getdlopenflags()
    try:
        from DLFCN import RTLD_GLOBAL, RTLD_LAZY
    except ImportError:
        RTLD_GLOBAL = -1
        RTLD_LAZY = -1
        import os

        osname = os.uname()[0]
        if osname == "Linux" or osname == "SunOS" or osname == "FreeBSD":
            RTLD_GLOBAL = 0x100
            RTLD_LAZY = 0x1
        elif osname == "Darwin":
            RTLD_GLOBAL = 0x8
            RTLD_LAZY = 0x1
        del os
    except:
        RTLD_GLOBAL = -1
        RTLD_LAZY = -1

    if RTLD_GLOBAL != -1 and RTLD_LAZY != -1:
        sys.setdlopenflags(RTLD_LAZY | RTLD_GLOBAL)

    return oldflags
Exemplo n.º 6
0
def enableHouModule():
    '''Set up the environment so that "import hou" works.'''
    #import sys, os

    # Importing hou will load in Houdini's libraries and initialize Houdini.
    # In turn, Houdini will load any HDK extensions written in C++.  These
    # extensions need to link against Houdini's libraries, so we need to
    # make sure that the symbols from Houdini's libraries are visible to
    # other libraries that Houdini loads.  So, we adjust Python's dlopen
    # flags before importing hou.
    HFS = "/opt/hfs.current"
    if hasattr(sys, "setdlopenflags"):
        old_dlopen_flags = sys.getdlopenflags()
        import DLFCN
        sys.setdlopenflags(old_dlopen_flags | DLFCN.RTLD_GLOBAL)

    try:
        import hou
    except ImportError:
        # Add $HFS/houdini/python2.6libs to sys.path so Python can find the
        # hou module.
        sys.path.append(HFS + "/houdini/python%d.%dlibs" % sys.version_info[:2])
        #sys.path.append(os.environ['HFS'] + "/houdini/python2.6libs")
        import hou
    finally:
        if hasattr(sys, "setdlopenflags"):
            sys.setdlopenflags(old_dlopen_flags)
Exemplo n.º 7
0
def loadGenius():
    if sys.platform=='win32':
        modulePath = '/lib/genius.pyd'
    else:
        modulePath = '/lib/genius.so'

    searchPath = [ os.path.abspath(os.path.dirname(os.path.abspath(__file__)) + '/..'),
                  '.', '..']
    if os.environ.has_key('GENIUS_DIR'):
        searchPath.insert(0, os.environ['GENIUS_DIR'])
        
    GeniusDir = None
    for path in searchPath:
        if os.path.exists(path+modulePath):
            GeniusDir = os.path.abspath(path)
            break
    
    if GeniusDir==None:
        raise GeniusError('Genius library binaries are not found.')
            
    sys.path.insert(0, GeniusDir+'/lib')
    
    global genius
    try:
        flagsave = sys.getdlopenflags()
        if sys.platform=='linux2':
            import DLFCN
            sys.setdlopenflags(DLFCN.RTLD_NOW|DLFCN.RTLD_GLOBAL)
        import genius
        sys.setdlopenflags(flagsave)
    except ImportError:
        raise GeniusError('Failed loading Genius binaries.')

    genius.Genius.set_genius_dir(GeniusDir)
    genius.baseDir = GeniusDir
Exemplo n.º 8
0
def setup_dlopen():
    """Set the flags for a call to import a shared library
    such that all symbols are imported.
    
    On Linux this sets the flags for dlopen so that 
    all symbols from the library are imported in to
    the global symbol table.
    
    Without this each shared library gets its own
    copy of any singleton, which is not the correct
    behaviour
    
    Returns the original flags
    """
    if platform.system() != "Linux": return None
    old_flags = sys.getdlopenflags()
    try:
        import DLFCN as dynload
    except:
        # Try older module
        try:
            import dl as dynload
        except:
            # If neither is available then this platform is unsupported
            print "Both the DLFCN and dl modules are unavailable."
            print "Cannot run Mantid from stand-alone Python on this platform."
            sys.exit(1)
    
    sys.setdlopenflags(dynload.RTLD_NOW | dynload.RTLD_GLOBAL)
    return old_flags
Exemplo n.º 9
0
def setDLFlags():
    # brought over from ITK Wrapping/CSwig/Python

    # Python "help(sys.setdlopenflags)" states:
    #
    # setdlopenflags(...)
    #     setdlopenflags(n) -> None
    #     
    #     Set the flags that will be used for dlopen() calls. Among other
    #     things, this will enable a lazy resolving of symbols when
    #     importing a module, if called as sys.setdlopenflags(0) To share
    #     symbols across extension modules, call as
    #
    #     sys.setdlopenflags(dl.RTLD_NOW|dl.RTLD_GLOBAL)
    #
    # GCC 3.x depends on proper merging of symbols for RTTI:
    #   http://gcc.gnu.org/faq.html#dso
    #
    try:
        import dl
        newflags = dl.RTLD_NOW|dl.RTLD_GLOBAL
    except:
        newflags = 0x102  # No dl module, so guess (see above).
        
    try:
        oldflags = sys.getdlopenflags()
        sys.setdlopenflags(newflags)
    except:
        oldflags = None

    return oldflags
Exemplo n.º 10
0
def modified_dlopenflags(dlopenflags):
    try:
        old_dlopenflags = sys.getdlopenflags()
        sys.setdlopenflags(dlopenflags)
        yield
    finally:
        sys.setdlopenflags(old_dlopenflags)
Exemplo n.º 11
0
def _load_libzmq():
    """load bundled libzmq if there is one"""
    import sys, ctypes, platform, os
    dlopen = hasattr(sys, 'getdlopenflags') # unix-only
    # RTLD flags are added to os in Python 3
    # get values from os because ctypes values are WRONG on pypy
    PYPY = platform.python_implementation().lower() == 'pypy'
    
    if dlopen:
        dlflags = sys.getdlopenflags()
        # set RTLD_GLOBAL, unset RTLD_LOCAL
        flags = ctypes.RTLD_GLOBAL | dlflags
        # ctypes.RTLD_LOCAL is 0 on pypy, which is *wrong*
        flags &= ~ getattr(os, 'RTLD_LOCAL', 4)
        # pypy on darwin needs RTLD_LAZY for some reason
        if PYPY and sys.platform == 'darwin':
            flags |= getattr(os, 'RTLD_LAZY', 1)
            flags &= ~ getattr(os, 'RTLD_NOW', 2)
        sys.setdlopenflags(flags)
    try:
        from . import libzmq
    except ImportError:
        pass
    else:
        # store libzmq as zmq._libzmq for backward-compat
        globals()['_libzmq'] = libzmq
        if PYPY:
            # some versions of pypy (5.3 < ? < 5.8) needs explicit CDLL load for some reason,
            # otherwise symbols won't be globally available
            # do this unconditionally because it should be harmless (?)
            ctypes.CDLL(libzmq.__file__, ctypes.RTLD_GLOBAL)
    finally:
        if dlopen:
            sys.setdlopenflags(dlflags)
Exemplo n.º 12
0
 def imp_load_module(name, *args):
     pathParts = args[1].split(os.path.sep)
     extension = os.path.splitext(pathParts[-1])[-1]
     # Find all swigged LSST libs.  Load _lsstcppimport.so by
     # adding it to the EXCEPTIONLIST since it may not have lsst in
     # the path (it's in $BASE_DIR/python, not
     # $BASE_DIR/python/lsst).  Also, look for paths that look like
     # python/lsst as that is how to know if you are in an LSST
     # package.
     lsstIdx = [i for i, el in enumerate(pathParts) if el == 'python']
     if pathParts[-1] in LIB_EXCEPTION_LIST or (extension in SHARED_LIB_EXTENSION_LIST and
                                                pathParts[-1].startswith('_') and
                                                'lsst' in [pathParts[i + 1] for i in lsstIdx]):
         # Get currently set flags
         originalDLFlags = sys.getdlopenflags()
         # Set flags
         sys.setdlopenflags(DLFLAGS)
         try:
             module = orig_imp_load_module(name, *args)
         finally:
             # Set original flags
             sys.setdlopenflags(originalDLFlags)
     else:
         module = orig_imp_load_module(name, *args)
     return module
Exemplo n.º 13
0
def DlopenGuard():
    if _set_global_flags:
        old_flags = sys.getdlopenflags()
        sys.setdlopenflags(old_flags | ctypes.RTLD_GLOBAL)
    yield
    if _set_global_flags:
        sys.setdlopenflags(old_flags)
Exemplo n.º 14
0
def enableHouModule():
    """Set up the environment so that "import hou" works."""

    # Handle dlopen flags so dsos can be loaded correctly.
    if hasattr(sys, "setdlopenflags"):
        import DLFCN

        old_dlopen_flags = sys.getdlopenflags()
        sys.setdlopenflags(old_dlopen_flags | DLFCN.RTLD_GLOBAL)

    # Try to import hou.
    try:
        import hou
    # If it can't find it, make sure it is in the path.
    except ImportError:
        # Python needs to know where the hou module is.
        path = os.path.join(
            os.getenv("HH"),
            "python{}.{}".format(sys.version_info[0], sys.version_info[1])
        )

        # Append the path.
        sys.path.append(path)

        # Try again.
        import hou

    finally:
        # Restore old flags.
        if hasattr(sys, "setdlopenflags"):
            sys.setdlopenflags(old_dlopen_flags)
Exemplo n.º 15
0
def DlopenGuard():
    # In python 2.7 required constants are not defined.
    # Thus they are listed explicitly
    flags = sys.getdlopenflags()
    sys.setdlopenflags(DLFCN.RTLD_GLOBAL | DLFCN.RTLD_NOW)
    yield
    sys.setdlopenflags(flags)
Exemplo n.º 16
0
def load_prepare(mod_path, depends_on, has_dependent):
        root_name = mod_path[0]
        mod_name = os.path.basename(root_name)

        env_var_name = 'LIMA_%s_VERSION' % mod_name.upper()
        if env_var_name in os.environ:
                version = os.environ[env_var_name]
        else:
                version = 'LAST'

        if version.upper() == 'LAST':
                version_filter = []
        elif version_re.match(version):
                version_filter = version_code(version)
        else:
                raise ImportError('Invalid %s: %s' % (env_var_name, version))

        def good_dir(v, r=root_name, f=version_filter):
                return good_version_dir(v, r, f)

        version_dirs = [x for x in os.listdir(root_name) if good_dir(x)]
        if not version_dirs:
                raise ImportError('Invalid %s: %s' % (env_var_name, version))

        version_dirs.sort(key=version_code)
        version = version_dirs[-1]
        mod_dir = os.path.join(root_name, version)
        ld_open_flags = sys.getdlopenflags()

        cleanup_data = mod_path, mod_dir, ld_open_flags, has_dependent

        if not depends_on:
                return load_ld_prepare(cleanup_data)

        cap_dep = depends_on.upper()
        dep_version_fname = os.path.join(mod_dir, '%s_VERSION' % cap_dep)
        dep_version_file = open(dep_version_fname, 'rt')
        dep_version = dep_version_file.readline().strip()

        link_strict_version = os.environ['LIMA_LINK_STRICT_VERSION']
        if link_strict_version == 'MINOR':
                dep_version = VSEP.join(dep_version.split(VSEP)[:2])
        elif link_strict_version != 'FULL':
                raise ImportError('Invalid LIMA_LINK_STRICT_VERSION var: %s' %
                                  link_strict_version)
        
        env_var_name = 'LIMA_%s_VERSION' % cap_dep
        if env_var_name in os.environ:
                prev_version = os.environ[env_var_name]
                if prev_version != dep_version:
                        msg = 'Forcing %s to %s, which was previously set to '\
                              '%s' % (env_var_name, dep_version, prev_version)
                        raise ImportError('%s: %s' % (mod_name, msg))
        else:
                os.environ[env_var_name] = dep_version

        return cleanup_data
Exemplo n.º 17
0
 def load_library(self, flags=None):
     # XXX review all usages of 'self' here!
     # import it as a new extension module
     imp.acquire_lock()
     try:
         if hasattr(sys, "getdlopenflags"):
             previous_flags = sys.getdlopenflags()
         try:
             if hasattr(sys, "setdlopenflags") and flags is not None:
                 sys.setdlopenflags(flags)
             module = imp.load_dynamic(self.verifier.get_module_name(),
                                       self.verifier.modulefilename)
         except ImportError as e:
             error = "importing %r: %s" % (self.verifier.modulefilename, e)
             raise ffiplatform.VerificationError(error)
         finally:
             if hasattr(sys, "setdlopenflags"):
                 sys.setdlopenflags(previous_flags)
     finally:
         imp.release_lock()
     #
     # call loading_cpy_struct() to get the struct layout inferred by
     # the C compiler
     self._load(module, 'loading')
     #
     # the C code will need the <ctype> objects.  Collect them in
     # order in a list.
     revmapping = dict([(value, key)
                        for (key, value) in self._typesdict.items()])
     lst = [revmapping[i] for i in range(len(revmapping))]
     lst = list(map(self.ffi._get_cached_btype, lst))
     #
     # build the FFILibrary class and instance and call _cffi_setup().
     # this will set up some fields like '_cffi_types', and only then
     # it will invoke the chained list of functions that will really
     # build (notably) the constant objects, as <cdata> if they are
     # pointers, and store them as attributes on the 'library' object.
     class FFILibrary(object):
         _cffi_python_module = module
         _cffi_ffi = self.ffi
         _cffi_dir = []
         def __dir__(self):
             return FFILibrary._cffi_dir + list(self.__dict__)
     library = FFILibrary()
     if module._cffi_setup(lst, ffiplatform.VerificationError, library):
         import warnings
         warnings.warn("reimporting %r might overwrite older definitions"
                       % (self.verifier.get_module_name()))
     #
     # finally, call the loaded_cpy_xxx() functions.  This will perform
     # the final adjustments, like copying the Python->C wrapper
     # functions from the module to the 'library' object, and setting
     # up the FFILibrary class with properties for the global C variables.
     self._load(module, 'loaded', library=library)
     module._cffi_original_ffi = self.ffi
     module._cffi_types_of_builtin_funcs = self._types_of_builtin_functions
     return library
Exemplo n.º 18
0
def preserve_dlopenflags(flags):
    """A context manager that temporarily sets the dlopen flags and then
    returns them to previous values.
    """
    outer_flags = sys.getdlopenflags()
    try:
        sys.setdlopenflags(flags)
        yield
    finally:
        sys.setdlopenflags(outer_flags)
Exemplo n.º 19
0
 def setup(self):
   self.old_cwd = os.getcwd()
   os.chdir(itkConfig.swig_lib)
   self.old_path = sys.path
   sys.path = [itkConfig.swig_lib, itkConfig.swig_py] + sys.path
   try:
     self.old_dlopenflags = sys.getdlopenflags()
     sys.setdlopenflags(self.dlopenflags)
   except:
     self.old_dlopenflags = None
Exemplo n.º 20
0
def import_pyfftw():
    if os.name == 'nt':
        import pyfftw
    else:
        # Import pyfftw as soon as possible with RTLD_NOW|RTLD_DEEPBIND
        # to minimize chance of MKL overriding fftw functions
        import ctypes
        import sys
        curFlags = sys.getdlopenflags()
        sys.setdlopenflags(curFlags | ctypes.RTLD_GLOBAL)
        import pyfftw
        sys.setdlopenflags(curFlags)
        del curFlags
    fft_impl = 'pyfftw'
Exemplo n.º 21
0
 def setup(self):
   self.old_cwd = os.getcwd()
   try:
     os.chdir(itkConfig.swig_lib)
   except OSError:
     # silently pass to avoid the case where the dir is not there
     pass
   self.old_path = sys.path
   sys.path = [itkConfig.swig_lib, itkConfig.swig_py] + sys.path
   try:
     self.old_dlopenflags = sys.getdlopenflags()
     sys.setdlopenflags(self.dlopenflags)
   except:
     self.old_dlopenflags = None
Exemplo n.º 22
0
def _try_import_with_global_library_symbols():
    try:
        import DLFCN
        dlopen_flags = DLFCN.RTLD_NOW | DLFCN.RTLD_GLOBAL
    except ImportError:
        import ctypes
        dlopen_flags = ctypes.RTLD_GLOBAL

    import sys
    old_flags = sys.getdlopenflags()
    try:
        sys.setdlopenflags(dlopen_flags)
        import lupa._lupa
    finally:
        sys.setdlopenflags(old_flags)
Exemplo n.º 23
0
def dl_import(import_expr):
    """Import module according to import_expr, but with RTLD_GLOBAL enabled."""
    # we need to get the locals and globals of the _calling_ function. Thus, we
    # need to go deeper into the call stack
    call_frame = sys._getframe(1)
    local_dict = call_frame.f_locals
    global_dict = call_frame.f_globals

    # RTLD_GLOBAL needs to be set in dlopen() if we want typeinfo and friends to
    # work properly across DSO boundaries. See http://gcc.gnu.org/faq.html#dso

    orig_dlopen_flags = sys.getdlopenflags()
    sys.setdlopenflags(RTLD_LAZY | RTLD_GLOBAL)

    exec import_expr in local_dict, global_dict

    sys.setdlopenflags(orig_dlopen_flags)  # reset it to normal case to avoid
Exemplo n.º 24
0
    def os_details():
        """
        Returns a dictionary containing details about the operating system
        """
        # Compute architecture and linkage
        bits, linkage = platform.architecture()
        results = {
            # Machine details
            'platform.arch.bits': bits,
            'platform.arch.linkage': linkage,
            'platform.machine': platform.machine(),
            'platform.process': platform.processor(),
            'sys.byteorder': sys.byteorder,

            # OS details
            'os.name': os.name,
            'host.name': socket.gethostname(),
            'sys.platform': sys.platform,
            'platform.system': platform.system(),
            'platform.release': platform.release(),
            'platform.version': platform.version(),
            'encoding.filesystem': sys.getfilesystemencoding(),
        }

        # Paths and line separators
        for name in ('sep', 'altsep', 'pathsep', 'linesep'):
            results['os.{0}'.format(name)] = getattr(os, name, None)

        try:
            # Available since Python 3.4
            results['os.cpu_count'] = os.cpu_count()
        except AttributeError:
            results['os.cpu_count'] = None

        try:
            # Only for Unix
            # pylint: disable=E1101
            results['sys.dlopenflags'] = sys.getdlopenflags()
        except AttributeError:
            results['sys.dlopenflags'] = None

        return results
Exemplo n.º 25
0
def import_ext(name, optional=False):
    components = name.split(".")
    if len(components) > 1:
        __import__(".".join(components[:-1]))
    previous_dlopenflags = None
    if sys.platform.startswith("linux"):
        previous_dlopenflags = sys.getdlopenflags()
        sys.setdlopenflags(0x100 | 0x2)
    try:
        mod = __import__(name)
    except ImportError, e:
        if optional:
            return None
        error_msg = str(e)
        m = symbol_not_found_pat.search(error_msg)
        if m:
            error_msg = error_msg[: m.start(1)] + cpp_function_name.demangle(m.group(1)) + error_msg[m.end(1) :]
        raise ImportError(
            "\n  ".join(['__import__("%s"): %s' % (name, error_msg), "sys.path:"] + ["  " + p for p in sys.path])
        )
Exemplo n.º 26
0
    def os_details():
        """
        Returns a dictionary containing details about the operating system
        """
        # Compute architecture and linkage
        bits, linkage = platform.architecture()
        results = {
            # Machine details
            "platform.arch.bits": bits,
            "platform.arch.linkage": linkage,
            "platform.machine": platform.machine(),
            "platform.process": platform.processor(),
            "sys.byteorder": sys.byteorder,
            # OS details
            "os.name": os.name,
            "host.name": socket.gethostname(),
            "sys.platform": sys.platform,
            "platform.system": platform.system(),
            "platform.release": platform.release(),
            "platform.version": platform.version(),
            "encoding.filesystem": sys.getfilesystemencoding(),
        }

        # Paths and line separators
        for name in "sep", "altsep", "pathsep", "linesep":
            results["os.{0}".format(name)] = getattr(os, name, None)

        try:
            # Available since Python 3.4
            results["os.cpu_count"] = os.cpu_count()
        except AttributeError:
            results["os.cpu_count"] = None

        try:
            # Only for Unix
            # pylint: disable=E1101
            results["sys.dlopenflags"] = sys.getdlopenflags()
        except AttributeError:
            results["sys.dlopenflags"] = None

        return results
Exemplo n.º 27
0
def _load_libzmq():
    """load bundled libzmq if there is one"""
    import sys, ctypes, platform
    dlopen = hasattr(sys, 'getdlopenflags') # unix-only
    if dlopen:
        dlflags = sys.getdlopenflags()
        sys.setdlopenflags(ctypes.RTLD_GLOBAL | dlflags)
    try:
        from . import libzmq
    except ImportError:
        pass
    else:
        # store libzmq as zmq._libzmq for backward-compat
        globals()['_libzmq'] = libzmq
        if platform.python_implementation().lower() == 'pypy':
            # pypy needs explicit CDLL load for some reason,
            # otherwise symbols won't be globally available
            ctypes.CDLL(libzmq.__file__, ctypes.RTLD_GLOBAL)
    finally:
        if dlopen:
            sys.setdlopenflags(dlflags)
def openmpi_workaround():

  # find the flag to be set to open all shared libraries at once

  try:
    import dl
    globalFlag = dl.RTLD_GLOBAL
  except:
    try:
      import ctypes
      globalFlag = ctypes.RTLD_GLOBAL
    except:
      print 'ATTENTION: could not find flag RTLD_GLOBAL for dlopen'
      # take a good value for Linux (but is platform-dependent)
      globalFlag = 256

  # now set this flag so that dlopen will use it

  import sys
  flags = sys.getdlopenflags()
  sys.setdlopenflags(flags | globalFlag)
Exemplo n.º 29
0
    def _loadGenius(self):
        if sys.platform == "win32":
            modulePath = "/lib/genius.pyd"
        else:
            modulePath = "/lib/genius.so"
        searchPath = [os.path.abspath(os.path.dirname(os.path.abspath(__file__)) + "/.."), ".", ".."]
        if os.environ.has_key("GENIUS_DIR"):
            searchPath.insert(0, os.environ["GENIUS_DIR"])

        GeniusDir = None
        for path in searchPath:
            if os.path.exists(path + modulePath):
                GeniusDir = os.path.abspath(path)
                break

        if GeniusDir == None:
            raise GeniusError("Genius library binaries are not found.")

        sys.path.insert(0, GeniusDir + "/lib")

        try:
            if sys.platform == "win32":
                import genius
            else:
                flagsave = sys.getdlopenflags()
                if sys.platform == "linux2":
                    import DLFCN

                    if hasattr(DLFCN, "RTLD_DEEPBIND"):
                        sys.setdlopenflags(DLFCN.RTLD_NOW | DLFCN.RTLD_GLOBAL | DLFCN.RTLD_DEEPBIND)
                    else:
                        sys.setdlopenflags(DLFCN.RTLD_NOW | DLFCN.RTLD_GLOBAL | 0x00008)
                import genius

                sys.setdlopenflags(flagsave)
        except ImportError, e:
            raise GeniusError("Failed loading Genius binaries. %s" % str(e))
Exemplo n.º 30
0
def _shared_cextension():
    """Our extensions need to shared symbols amongst them due to:
      - the static boost python type registry
      - static singleton instances marked as weak symbols by clang
    gcc uses an extension to mark these attributes as globally unique
    but clang marks them as weak and without RTLD_GLOBAL each shared
    library has its own copy of each singleton.

    See https://docs.python.org/3/library/sys.html#sys.setdlopenflags
    """
    import sys
    if not sys.platform.startswith('linux'):
        yield
        return

    import six
    if six.PY2:
        import DLFCN as dl
    else:
        import os as dl
    flags_orig = sys.getdlopenflags()
    sys.setdlopenflags(dl.RTLD_NOW | dl.RTLD_GLOBAL)
    yield
    sys.setdlopenflags(flags_orig)
Exemplo n.º 31
0
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

#
# Init file for osg package.
#

# Hack to bring in all symbols OpenSG is linked against and loads from plugins
# Search for : setdlopenflags and RTLD_GLOBAL on google to see why

from ..OSGBase import AttachmentContainer

original_dlopen_flags = None

try:
    import dl, sys
    original_dlopen_flags = sys.getdlopenflags()
    sys.setdlopenflags(original_dlopen_flags | dl.RTLD_GLOBAL)
except:
    pass

# Import everything from the opensg module
from OSGWindowGLUTPy import *

if original_dlopen_flags:
    sys.setdlopenflags(original_dlopen_flags)


def _fc_cmp(self, other):
    """ Comparison operator for field containers. """
    id_self = None
    id_other = None
Exemplo n.º 32
0
'''
Internal functions and classes of the clingo module.
'''

from os import _exit
from traceback import print_exception
import os
import sys
try:
    _FLAGS = None
    # In the pip module the library also exports the clingo symbols, which
    # should be globally available for other libraries depending on clingo.
    if hasattr(sys, 'setdlopenflags'):
        _FLAGS = sys.getdlopenflags()
        sys.setdlopenflags(os.RTLD_LAZY|os.RTLD_GLOBAL)
    try:
        # Note: imported first to correctly handle the embedded case
        from _clingo import ffi as _ffi, lib as _lib # type: ignore # pylint: disable=no-name-in-module
    except ImportError:
        from ._clingo import ffi as _ffi, lib as _lib # type: ignore # pylint: disable=no-name-in-module
finally:
    if _FLAGS is not None:
        sys.setdlopenflags(_FLAGS)

def _str(f_size, f_str, *args, handler=None):
    p_size = _ffi.new('size_t*')
    _handle_error(f_size(*args, p_size), handler)
    p_str = _ffi.new('char[]', p_size[0])
    _handle_error(f_str(*args, p_str, p_size[0]), handler)
    return _ffi.string(p_str).decode()
Exemplo n.º 33
0
import ctypes
import sys

# this file is simply a facade for the (underscored) native module which ensures the module
# is loaded in a specific way...

# set RTLD_GLOBAL for tracehook import so that afl-instrumented native libs are able to find
# our __afl_area_ptr and __afl_prev_loc globals
_prev_dlopenflags = sys.getdlopenflags()
sys.setdlopenflags(_prev_dlopenflags | ctypes.RTLD_GLOBAL)
from cpytraceafl._tracehook import *
sys.setdlopenflags(_prev_dlopenflags)
            return Fraction(self.num * other.denom, self.denom * other.num)
        elif isinstance(other, int):
            return Fraction(self.num, self.denom * other)
        return TypeError

    def __rdiv__(self, other):
        if isinstance(other, int):
            return Fraction(self.denom * other, self.num)
        return TypeError

    def __float__(self):
        return float(self.num) / float(self.denom)


try:
    dlsave = sys.getdlopenflags()
    from DLFCN import RTLD_GLOBAL, RTLD_LAZY
except AttributeError:
    # windows doesn't have sys.getdlopenflags()
    RTLD_GLOBAL = -1
    RTLD_LAZY = -1
except ImportError:
    RTLD_GLOBAL = -1
    RTLD_LAZY = -1
    import os
    osname = os.uname()[0]
    if osname == 'Linux' or osname == 'SunOS' or osname == 'FreeBSD' or osname == 'GNU/kFreeBSD' or osname == 'GNU':
        machinename = os.uname()[4]
        if machinename == 'mips' or machinename == 'mips64':
            RTLD_GLOBAL = 0x4
            RTLD_LAZY = 0x1
Exemplo n.º 35
0
def setup():
    import atexit, os
    __path__.append(os.path.join(__path__[0], os.environ['CMTCONFIG']))

    # make sure that 3rd party libraries can see Hephaestus symbols by letting
    # python load the memory tracker in "broadcast" mode
    import DLFCN, sys
    dlflags = sys.getdlopenflags()
    sys.setdlopenflags(DLFCN.RTLD_GLOBAL | DLFCN.RTLD_NOW)
    import MemoryTracker
    sys.setdlopenflags(dlflags)

    # switch off profiling; do filter STL internal allocations
    MemoryTracker.configure(MemoryTracker.LEAK_CHECK | MemoryTracker.QUICK
                            | MemoryTracker.FILTER_STL)

    # ignore muon common blocks in report
    MemoryTracker.ignore('__m_mb_')

    # ignore CINT dictionary builtup in report
    MemoryTracker.ignore('G__')
    MemoryTracker.ignore('TCint::')

    # ignore Reflex dictionary builtup in report
    MemoryTracker.ignore('Reflex::')

    # ignore streamers and collections from ROOT I/O in report
    MemoryTracker.ignore('TStreamerInfo')
    MemoryTracker.ignore('TGenCollectionProxy')
    MemoryTracker.ignore('TCollectionProxy')
    MemoryTracker.ignore('TStorage')

    # like STL, the following only leaks if the full object is leaked, so it's a dupe
    MemoryTracker.ignore('TStringRef::GetRep')
    MemoryTracker.ignore('TString::Init')
    MemoryTracker.ignore('TString::Replace')
    MemoryTracker.ignore('TList::NewLink')

    # this was a known issue, no longer relevant, but leave ignore in
    MemoryTracker.ignore('StoreGateSvc::setupProxy')

    # ignore unknowns, as they've never proven useful; they typically arise from file
    # static functions (that for that reason have no linker symbol associated with
    # them), which are usually in system libraries rather than in ATLAS code ...
    MemoryTracker.ignore('<unknown>')

    MemoryTracker.ignore('THashTable::THashTable')
    MemoryTracker.ignore('InitCallFunc_')
    MemoryTracker.ignore('_PyObject_GenericSetAttrWithDict')
    MemoryTracker.ignore('_PyObject_GC_NewVar')
    MemoryTracker.ignore('PyType_GenericAlloc')
    MemoryTracker.ignore('PyDict_MergeFromSeq2')
    MemoryTracker.ignore('PyEval_EvalFrameEx')
    MemoryTracker.ignore('Cintex::CINTClassBuilder')
    MemoryTracker.ignore('Cintex::CintTag')
    MemoryTracker.ignore('PyROOT::')
    MemoryTracker.ignore('ROOT::TSchemaRule::ProcessVersion')
    MemoryTracker.ignore('CLHEP::HepMatrix::invert')
    MemoryTracker.ignore('IncidentSvc::addListener')
    MemoryTracker.ignore('TClass::Init')
    MemoryTracker.ignore('_PyObject_GC_New')
    MemoryTracker.ignore('_PyObject_GC_Malloc')
    MemoryTracker.ignore('_PyObject_GC_Resize')
    MemoryTracker.ignore('TString::Clobber')
    MemoryTracker.ignore('PyString_FromStringAndSize')
    MemoryTracker.ignore('clang::')
    MemoryTracker.ignore('cling::')
    MemoryTracker.ignore('llvm::')
    MemoryTracker.ignore('TExMap::Expand')
    MemoryTracker.ignore('TExMap::TExMap')
    MemoryTracker.ignore('TCling::')
    MemoryTracker.ignore('TClingDataMemberInfo::TClingDataMemberInfo')
    MemoryTracker.ignore('TClingBaseClassInfo::TClingBaseClassInfo')
    MemoryTracker.ignore('TClingCallFunc::SetFuncProto')
    MemoryTracker.ignore('TClassTable::AddAlternate')
    MemoryTracker.ignore('ROOT::TMetaUtils::GetFileName')

    atexit.register(MemoryTracker.atexit)
Exemplo n.º 36
0
#!/usr/bin/python

import ctypes
import sys
saved_flags = sys.getdlopenflags()
sys.setdlopenflags(saved_flags | ctypes.RTLD_GLOBAL)
# import dpdk with RTLD_GLOBAL, so it would export its symbols to other PMDs
from dpdk import *
sys.setdlopenflags(saved_flags)

import time
import binascii
import dpkt

params = ["pytest", "-c", "6", "-n", "2", "--no-huge"]
params += ["--vdev", "eth_pcap0,iface=eth0"]
print "eal init:", rte_eal_init(params)  #, "--no-pci"])

enabled_cores = [i for i in xrange(RTE_MAX_LCORE) if rte_lcore_is_enabled(i)]
print "enabled_lcores:", enabled_cores

print "lcore_id", rte_lcore_id()

print "core 2 is on socket %d" % rte_lcore_to_socket_id(2)

pool = PacketPool("pktpool", 1024, 2048, 128, 0, 0)

print "pool count:", pool.count()
print "allocated packet:", pool.alloc()
print "pool count:", pool.count()
Exemplo n.º 37
0
import ctypes

import IECore

moduleSearchPath = IECore.SearchPath( os.environ["PYTHONPATH"] )
if moduleSearchPath.find( "IECoreUSD" ) :

	# Import the USD Python module _without_ RTLD_GLOBAL, otherwise
	# we get errors like the following spewed to the shell when we first
	# open a USD file :
	#
	# ```
	# Coding Error: in DefinePythonClass at line 932 of /disk1/john/dev/gafferDependencies/USD/working/USD-18.09/pxr/base/lib/tf/type.cpp
	# -- TfType 'TfNotice' already has a defined Python type; cannot redefine
	# ```
	#
	# > Note : RTLD_GLOBAL is turned on in the first place by IECore/__init__.py.
	# > Ideally we'd stop doing that and wouldn't need this workaround. See
	# > https://github.com/ImageEngine/cortex/pull/810.

	try :
		originalDLOpenFlags = sys.getdlopenflags()
		sys.setdlopenflags( originalDLOpenFlags & ~ctypes.RTLD_GLOBAL )
		from pxr import Usd
	finally :
		sys.setdlopenflags( originalDLOpenFlags )

	# Import IECoreUSD so that we get the USD SceneInterface registered,
	# providing USD functionality to both the SceneReader and SceneWriter.
	import IECoreUSD
Exemplo n.º 38
0
def main():
    import sys
    import hou

    import soho
    import sohoglue
    import SOHOcommon

    import sys
    import ctypes
    if hasattr(sys, 'setdlopenflags'):
        sys.setdlopenflags(sys.getdlopenflags() | ctypes.RTLD_GLOBAL)

    import _vfh_ipr

    from soho import SohoParm

    LogLevel = type('Enum', (), {
        'Info': 0,
        'Progress': 1,
        'Warning': 2,
        'Error': 3,
        'Debug': 4,
    })

    def logMessage(level, fmt, *args):
        _vfh_ipr.logMessage(level, fmt % args)

    def printDebug(fmt, *args):
        logMessage(LogLevel.Debug, fmt, *args)

    def dumpObjects(listName):
        printDebug("Checking \"%s\"" % listName)
        for obj in soho.objectList(listName):
            printDebug("   %s", obj.getName())

    def exportObjects(listName):
        for obj in soho.objectList(listName):
            _vfh_ipr.exportOpNode(opNode=obj.getName())

    def deleteObjects(listName):
        for obj in soho.objectList(listName):
            _vfh_ipr.deleteOpNode(opNode=obj.getName())

    def getViewParams(camera, sohoCam, t):
        camParms = {
            'space:world': SohoParm('space:world', 'real', [], False),
            'focal': SohoParm('focal', 'real', [0.050], False),
            'aperture': SohoParm('aperture', 'real', [0.0414214], False),
            'orthowidth': SohoParm('orthowidth', 'real', [2], False),
            'near': SohoParm('near', 'real', [0.001], False),
            'far': SohoParm('far', 'real', [1000], False),
            'res': SohoParm('res', 'int', [640, 480], False),
            'projection': SohoParm('projection', 'string', ["perspective"],
                                   False),
            'cropl': SohoParm('cropl', 'real', [-1], False),
            'cropr': SohoParm('cropr', 'real', [-1], False),
            'cropb': SohoParm('cropb', 'real', [-1], False),
            'cropt': SohoParm('cropt', 'real', [-1], False),
            'camera': SohoParm('camera', 'string', ['/obj/cam1'], False),
        }

        camParmsEval = sohoCam.evaluate(camParms, t)
        if not camParmsEval:
            return {}

        viewParams = {}
        for key in camParmsEval:
            viewParams[key] = camParmsEval[key].Value[0]

        viewParams['transform'] = camParmsEval['space:world'].Value
        viewParams['ortho'] = 1 if camParmsEval['projection'].Value[0] in {
            'ortho'
        } else 0
        viewParams['res'] = camParmsEval['res'].Value

        cropX = viewParams['res'][0] * viewParams['cropl']
        cropY = viewParams['res'][1] * (1.0 - viewParams['cropt'])
        cropW = viewParams['res'][0] * (viewParams['cropr'] -
                                        viewParams['cropl'])
        cropH = viewParams['res'][1] * (viewParams['cropt'] -
                                        viewParams['cropb'])

        printDebug("  Res: %s" % viewParams['res'])
        printDebug("  Crop: %i-%i %i x %i" % (cropX, cropY, cropW, cropH))
        printDebug("  Camera: %s" % camera)

        return viewParams

    def exportView(rop, camera, sohoCam, t):
        printDebug("exportView()")

        _vfh_ipr.exportView(viewParams=getViewParams(camera, sohoCam, t))

    mode = soho.getDefaultedString('state:previewmode', ['default'])[0]

    # Evaluate an intrinsic parameter (see HDK_SOHO_API::evaluate())
    # The 'state:time' parameter evaluates the time from the ROP.
    now = soho.getDefaultedFloat('state:time', [0.0])[0]

    # Evaluate the 'camera' parameter as a string.
    # If the 'camera' parameter doesn't exist, use ['/obj/cam1'].
    # SOHO always returns lists of values.
    camera = soho.getDefaultedString('camera', ['/obj/cam1'])[0]

    # MPlay / Render View port.
    host = soho.getDefaultedString("vm_image_mplay_sockethost", [0])[0]
    port = soho.getDefaultedInt("vm_image_mplay_socketport", [0])[0]

    # ROP node.
    ropPath = soho.getOutputDriver().getName()
    ropNode = hou.node(ropPath)

    printDebug("Initialize SOHO...")

    # Initialize SOHO with the camera.
    # XXX: This doesn't work for me, but it should according to the documentation...
    #   soho.initialize(now, camera)
    if not sohoglue.initialize(now, camera, None):
        soho.error("Unable to initialize rendering module with given camera")

    # Now, add objects to our scene
    soho.addObjects(now, "*", "*", "*", True)

    # Before we can evaluate the scene from SOHO, we need to lock the object lists.
    soho.lockObjects(now)

    for sohoCam in soho.objectList('objlist:camera'):
        break
    else:
        soho.error("Unable to find viewing camera for render")

    sohoOverride = soho.getDefaultedString('soho_overridefile', ['Unknown'])[0]

    printDebug("Processing Mode: \"%s\"" % mode)

    if mode in {"generate"}:
        # generate: Generation phase of IPR rendering
        # In generate mode, SOHO will keep the pipe (soho_pipecmd)
        # command open between invocations of the soho_program.
        #   objlist:all
        #   objlist:camera
        #   objlist:light
        #   objlist:instance
        #   objlist:fog
        #   objlist:space
        #   objlist:mat
        #
        printDebug("IPR Host: %s:%s" % (host, port))
        printDebug("Driver: %s" % ropPath)
        printDebug("Camera: %s" % camera)
        printDebug("Now: %.3f" % now)

        for obj in soho.objectList('objlist:instance'):
            # Register SOP as IPR dependency.
            obj.getDefaultedString('object:soppath', now, [''])

            # Register SHOP as IPR dependency.
            # TODO: Investigave this. Use OP_Node::addOpInterest() for now.
            # shader = []
            # shader_type   = []
            # shader_handle = []
            # obj.evalShaderAndType("shop_materialpath", now, shader, shader_type, shader_handle)

        _vfh_ipr.init(rop=ropPath,
                      port=port,
                      now=now,
                      viewParams=getViewParams(camera, sohoCam, now))

    elif mode in {"update"}:
        # update: Send updated changes from previous generation
        #
        # In this rendering mode, the special object list parameters:
        #   objlist:dirtyinstance
        #   objlist:dirtylight
        #   objlist:dirtyspace
        #   objlist:dirtyfog
        # will contain the list of all objects modified since the last render
        # (whether a generate or update).
        #
        # As well, the parameters:
        #   objlist:deletedinstance
        #   objlist:deletedlight
        #   objlist:deletedspace
        #   objlist:deletedfog
        # will list all objects which have been deleted from the scene.
        #
        if not _vfh_ipr.isRopValid():
            _vfh_ipr.init(rop=ropPath,
                          port=port,
                          now=now,
                          viewParams=getViewParams(camera, sohoCam, now))
        else:
            # Have to handle "time" event manually here.
            _vfh_ipr.setTime(now)

            for obj in soho.objectList('objlist:dirtyinstance'):
                obj.getDefaultedString('object:soppath', now, [''])

            exportObjects("objlist:dirtyinstance")
            exportObjects("objlist:dirtylight")

            exportView(ropPath, camera, sohoCam, now)
Exemplo n.º 39
0
explicit.
"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import ctypes
import sys

# On UNIX-based platforms, pywrap_tensorflow is a SWIG-generated python library
# that dynamically loads _pywrap_tensorflow.so. The default mode for loading
# keeps all the symbol private and not visible to other libraries that may be
# loaded. Setting the mode to RTLD_GLOBAL to make the symbols visible, so that
# custom op libraries imported using `tf.load_op_library()` can access symbols
# defined in _pywrap_tensorflow.so.
_use_rtld_global = (hasattr(sys, 'getdlopenflags')
                    and hasattr(sys, 'setdlopenflags'))
if _use_rtld_global:
    _default_dlopen_flags = sys.getdlopenflags()


def set_dlopen_flags():
    if _use_rtld_global:
        sys.setdlopenflags(_default_dlopen_flags | ctypes.RTLD_GLOBAL)


def reset_dlopen_flags():
    if _use_rtld_global:
        sys.setdlopenflags(_default_dlopen_flags)
Exemplo n.º 40
0
def setup():
    import atexit, os
    __path__.append(os.path.join(__path__[0], os.environ['CMTCONFIG']))

    # make sure that 3rd party libraries can see Hephaestus symbols by letting
    # python load the memory tracker in "broadcast" mode
    import DLFCN, sys
    dlflags = sys.getdlopenflags()
    sys.setdlopenflags(DLFCN.RTLD_GLOBAL | DLFCN.RTLD_NOW)
    import MemoryTracker
    sys.setdlopenflags(dlflags)

    # switch off profiling; do filter STL internal allocations
    MemoryTracker.configure(MemoryTracker.LEAK_CHECK | MemoryTracker.QUICK
                            | MemoryTracker.FILTER_STL)

    # ignore muon common blocks in report
    MemoryTracker.ignore('__m_mb_')

    # ignore streamers and collections from ROOT I/O in report
    MemoryTracker.ignore('TStreamerInfo')
    MemoryTracker.ignore('TGenCollectionProxy')
    MemoryTracker.ignore('TCollectionProxy')
    MemoryTracker.ignore('TStorage')

    # like STL, the following only leaks if the full object is leaked, so it's a dupe
    MemoryTracker.ignore('TStringRef::GetRep')
    MemoryTracker.ignore('TString::Init')
    MemoryTracker.ignore('TString::Replace')
    MemoryTracker.ignore('TList::NewLink')

    # this was a known issue, no longer relevant, but leave ignore in
    MemoryTracker.ignore('StoreGateSvc::setupProxy')

    # ignore unknowns, as they've never proven useful; they typically arise from file
    # static functions (that for that reason have no linker symbol associated with
    # them), which are usually in system libraries rather than in ATLAS code ...
    MemoryTracker.ignore('<unknown>')

    MemoryTracker.ignore('THashTable::THashTable')
    MemoryTracker.ignore('InitCallFunc_')
    MemoryTracker.ignore('_PyObject_GenericSetAttrWithDict')
    MemoryTracker.ignore('_PyObject_GC_NewVar')
    MemoryTracker.ignore('PyType_GenericAlloc')
    MemoryTracker.ignore('PyDict_MergeFromSeq2')
    MemoryTracker.ignore('PyEval_EvalFrameEx')
    MemoryTracker.ignore('PyROOT::')
    MemoryTracker.ignore('ROOT::TSchemaRule::ProcessVersion')
    MemoryTracker.ignore('CLHEP::HepMatrix::invert')
    MemoryTracker.ignore('IncidentSvc::addListener')
    MemoryTracker.ignore('TClass::Init')
    MemoryTracker.ignore('_PyObject_GC_New')
    MemoryTracker.ignore('_PyObject_GC_Malloc')
    MemoryTracker.ignore('_PyObject_GC_Resize')
    MemoryTracker.ignore('TString::Clobber')
    MemoryTracker.ignore('PyString_FromStringAndSize')
    MemoryTracker.ignore('clang::')
    MemoryTracker.ignore('cling::')
    MemoryTracker.ignore('llvm::')
    MemoryTracker.ignore('TExMap::Expand')
    MemoryTracker.ignore('TExMap::TExMap')
    MemoryTracker.ignore('TCling::')
    MemoryTracker.ignore('TClingDataMemberInfo::TClingDataMemberInfo')
    MemoryTracker.ignore('TClingBaseClassInfo::TClingBaseClassInfo')
    MemoryTracker.ignore('TClingCallFunc::SetFuncProto')
    MemoryTracker.ignore('TClassTable::AddAlternate')
    MemoryTracker.ignore('ROOT::TMetaUtils::GetFileName')

    MemoryTracker.ignore('SvcFactory<SegMemSvc>::create')
    MemoryTracker.ignore('SvcFactory<JobIDSvc>::create')
    MemoryTracker.ignore('SvcFactory<MuonTGC_CablingSvc>::create')
    MemoryTracker.ignore('Service::Service')
    MemoryTracker.ignore('AthService::AthService')
    MemoryTracker.ignore('emplace_back_aux<Property')
    MemoryTracker.ignore('PluginService::Factory2')
    MemoryTracker.ignore('PropertyMgr::declareProperty')
    MemoryTracker.ignore('SCT_ByteStreamErrorsSvc')
    MemoryTracker.ignore('TClassTable::SortTable')
    MemoryTracker.ignore('TWebPalette::TWebPalette')
    MemoryTracker.ignore('Gaudi::PluginService::Factory')

    # ???
    MemoryTracker.ignoreCall('TClass::GetClass')
    MemoryTracker.ignoreCall('TClass::TClass')
    MemoryTracker.ignoreCall('TClass::GetStreamerInfo')
    MemoryTracker.ignoreCall('uuid_generate')
    MemoryTracker.ignoreCall('TPluginManager::FindHandler')
    MemoryTracker.ignoreCall('TROOT::RegisterModule')
    MemoryTracker.ignoreCall('TStreamerInfo::TStreamerInfo')
    MemoryTracker.ignoreCall('TStreamerInfo::Build')
    MemoryTracker.ignoreCall('TClass::Property')
    MemoryTracker.ignoreCall('register_xAOD_')
    MemoryTracker.ignoreCall('xAOD::TDVCollectionProxy::TDVCollectionProxy')
    MemoryTracker.ignoreCall('Property* PropertyMgr::declareProperty')

    # Come back to
    MemoryTracker.ignore('ServiceManager::service')
    MemoryTracker.ignore('TDVCollectionProxy')
    MemoryTracker.ignore('allocator<IOVRange>')
    MemoryTracker.ignore('ArenaCachingHandle')
    MemoryTracker.ignore('ArenaHandle')
    MemoryTracker.ignore('vector<SG::ArenaBase')
    MemoryTracker.ignore('TConverterRegistry::AddConverter')
    MemoryTracker.ignore('TEmulatedCollectionProxy::InitializeEx')
    MemoryTracker.ignore('FileMgr::open')
    MemoryTracker.ignore('FileMgr::close')
    MemoryTracker.ignore('TMVA::DataSetFactory::Build')
    MemoryTracker.ignore('SimpleProperty')
    MemoryTracker.ignore('TDVCollectionFuncs::create_env')  ###
    MemoryTracker.ignore('PoolSvc::setObjPtr')
    MemoryTracker.ignore('LWPool')
    MemoryTracker.ignore('std::vector<LWPoolArea')

    atexit.register(MemoryTracker.atexit)
Exemplo n.º 41
0
sys.path.pop()


class tlpgui(_tulipgui.tlpgui):
    pass


def tulipguiExitFunc():
    import tulipgui
    tulipgui.tlpgui.runQtMainLoop()


# fix loading of Tulip plugins when the tulipgui module has been installed
# with the pip tool
if platform.system() == 'Linux' and os.path.exists(_tulipGuiNativePluginsPath):
    dlOpenFlagsBackup = sys.getdlopenflags()
    if sys.version_info < (3, 6):
        import DLFCN
        dlOpenFlags = DLFCN.RTLD_NOW | DLFCN.RTLD_GLOBAL
    else:
        dlOpenFlags = os.RTLD_NOW | os.RTLD_GLOBAL
    sys.setdlopenflags(dlOpenFlags)

tlp.loadTulipPluginsFromDir(_tulipGuiPluginsPath)

if (platform.system() == 'Linux'
        and os.path.exists(_tulipGuiNativePluginsPath)):
    sys.setdlopenflags(dlOpenFlagsBackup)

# Check if we are in script execution mode
# (sys.ps1 is not defined in that case)
Exemplo n.º 42
0
    import dl
except ImportError:
    # do not give up too early:
    # are we on AMD64 ?
    try:
      import DLFCN as dl
    except ImportError:
      dl = None
except SystemError:
    dl = None

# set the dlopen flags so that VTK does not run into problems with
# shared symbols.
try:
    # only Python >= 2.2 has this functionality
    orig_dlopen_flags = sys.getdlopenflags()
except AttributeError:
    orig_dlopen_flags = None

if dl and (os.name == 'posix'):
    sys.setdlopenflags(dl.RTLD_NOW|dl.RTLD_GLOBAL)

# --------------------------------------
from vtkCommonCore import *
from vtkCommonMath import *
from vtkCommonMisc import *
from vtkCommonSystem import *
from vtkCommonTransforms import *
from vtkCommonDataModel import *
from vtkCommonExecutionModel import *
from vtkCommonComputationalGeometry import *
Exemplo n.º 43
0
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Tests for head.py."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import math
import sys

# TODO: #6568 Remove this hack that makes dlopen() not crash.
if hasattr(sys, "getdlopenflags") and hasattr(sys, "setdlopenflags"):
    import ctypes
    sys.setdlopenflags(sys.getdlopenflags() | ctypes.RTLD_GLOBAL)

import numpy as np
import six

from tensorflow.contrib.learn.python.learn.estimators import constants
from tensorflow.contrib.learn.python.learn.estimators import head as head_lib
from tensorflow.contrib.learn.python.learn.estimators import model_fn
from tensorflow.contrib.learn.python.learn.estimators import prediction_key
from tensorflow.core.framework import summary_pb2
from tensorflow.python.client import session
from tensorflow.python.framework import constant_op
from tensorflow.python.framework import dtypes
from tensorflow.python.framework import ops
from tensorflow.python.framework import sparse_tensor
from tensorflow.python.ops import control_flow_ops
Exemplo n.º 44
0
def listPythonSystem():
    """!
    Function to list information about the installed Python system.

    @return: Dictionary of {attributes: values}.
    """
    try: dllhandle = sys.dllhandle
    except AttributeError: dllhandle = "Not Defined"
    try: androidapilevel = sys.getandroidapilevel()
    except AttributeError: androidapilevel = "Not Defined"
    try: dlopenflags = sys.getdlopenflags()
    except AttributeError: dlopenflags = "Not Defined"
    try: windowsversion_major = sys.getwindowsversion().major 
    except AttributeError: windowsversion_major = "Not Defined"
    try: windowsversion_minor = sys.getwindowsversion().minor 
    except AttributeError: windowsversion_minor = "Not Defined"
    try: windowsversion_build = sys.getwindowsversion().build 
    except AttributeError: windowsversion_build = "Not Defined"
    try: windowsversion_platform = sys.getwindowsversion().platform
    except AttributeError: windowsversion_platform = "Not Defined"
    try: 
        service_pack = sys.getwindowsversion().service_pack
        if service_pack == '': 
            service_pack = 'Not Specified'
    except AttributeError: service_pack = "Not Defined"
    try: winver = sys.winver
    except AttributeError: winver = "Not Defined"
    if sys.thread_info.lock == None:
        thread_info_lock = "Not Defined"
    else:
        thread_info_lock = sys.thread_info.lock
    if sys.thread_info.version == None:
        thread_info_version = "Not Defined"
    else:
        thread_info_version = sys.thread_info.version
    results = {"allocatedblocks": str(sys.getallocatedblocks()),
               "androidapilevel": str(androidapilevel),
               "api_version": str(sys.api_version),
               "base_exec_prefix": str(sys.base_exec_prefix),
               "base_prefix": str(sys.base_prefix),
               "byteorder": str(sys.byteorder),
               "builtin_module_names": ' | '.join(sys.builtin_module_names),
               "defaultencoding": str(sys.getdefaultencoding()),
               "dllhandle": str(dllhandle),
               "dlopenflags": str(dlopenflags),
               "exec_prefix": str(sys.exec_prefix),
               "executable": str(sys.executable),
               "filesystemencoding": str(sys.getfilesystemencoding()),
               "filesystemencodeerrors": str(sys.getfilesystemencodeerrors()),
               "flag_debug": str(sys.flags.debug),
               "flag_inspect": str(sys.flags.inspect), 
               "flag_interactive": str(sys.flags.interactive), 
               "flag_optimize": str(sys.flags.optimize), 
               "flag_dont_write_bytecode": str(sys.flags.dont_write_bytecode), 
               "flag_no_user_site": str(sys.flags.no_user_site), 
               "flag_no_site": str(sys.flags.no_site), 
               "flag_ignore_environment": str(sys.flags.ignore_environment), 
               "flag_verbose": str(sys.flags.verbose), 
               "flag_bytes_warning": str(sys.flags.bytes_warning), 
               "flag_quiet": str(sys.flags.quiet), 
               "flag_has_randomization": str(sys.flags.hash_randomization), 
               "flag_isolated": str(sys.flags.isolated), 
               "flag_dev_mode": str(sys.flags.dev_mode), 
               "flag_utf8_mode": str(sys.flags.utf8_mode),
               "float_info_max": str(sys.float_info.max), 
               "float_info_max_exp": str(sys.float_info.max_exp), 
               "float_info_max_10_exp": str(sys.float_info.max_10_exp), 
               "float_info_min": str(sys.float_info.min), 
               "float_info_min_exp": str(sys.float_info.min_exp), 
               "float_info_min_10_exp": str(sys.float_info.min_10_exp), 
               "float_info_dig": str(sys.float_info.dig), 
               "float_info_mant_dig": str(sys.float_info.mant_dig), 
               "float_info_epsilon": str(sys.float_info.epsilon), 
               "float_info_radix": str(sys.float_info.radix), 
               "float_info_rounds": str(sys.float_info.rounds),
               "float_repr_style": str(sys.float_repr_style),
               "hash_info_width": str(sys.hash_info.width), 
               "hash_info_modulus": str(sys.hash_info.modulus), 
               "hash_info_inf": str(sys.hash_info.inf), 
               "hash_info_nan": str(sys.hash_info.nan), 
               "hash_info_imag": str(sys.hash_info.imag), 
               "hash_info_algorithm": str(sys.hash_info.algorithm), 
               "hash_info_hash_bits": str(sys.hash_info.hash_bits), 
               "hash_info_seed_bits": str(sys.hash_info.seed_bits), 
               "hash_info_cutoff": str(sys.hash_info.cutoff),
               "hexversion": str(sys.hexversion),
               "implementation_name": str(sys.implementation.name),
               "implementation_cache_tag": str(sys.implementation.cache_tag),
               "int_info_bits_per_digit": str(sys.int_info.bits_per_digit), 
               "int_info_sizeof_digit": str(sys.int_info.sizeof_digit),
               "maxsize": str(sys.maxsize),
               "maxunicode": str(sys.maxunicode),
               "platform": str(sys.platform),
               "prefix": str(sys.prefix),
               "recursionlimit": str(sys.getrecursionlimit()),
               "switchinterval": str(sys.getswitchinterval()),
               "thread_info_name": str(sys.thread_info.name),
               "thread_info_lock": str(thread_info_lock),
               "thread_info_version": str(thread_info_version),
               "version_info_major": str(sys.version_info.major), 
               "version_info_minor:": str(sys.version_info.minor), 
               "version_info_micro": str(sys.version_info.micro), 
               "version_info_releaselevel": str(sys.version_info.releaselevel), 
               "version_info_serial": str(sys.version_info.serial),
               "windowsversion_major": str(windowsversion_major),
               "windowsversion_minor": str(windowsversion_minor),
               "windowsversion_build": str(windowsversion_build), 
               "windowsversion_platform": str(windowsversion_platform),
               "windowsversion_service_pack": str(service_pack),               
               "winver": str(sys.winver)}
    return results
Exemplo n.º 45
0
the source code).

Copies vs. in-place operation
-----------------------------
Most of the functions in `numpy` return a copy of the array argument
(e.g., `np.sort`).  In-place versions of these functions are often
available as array methods, i.e. ``x = np.array([1,2,3]); x.sort()``.
Exceptions to this rule are documented.

"""
from __future__ import division, absolute_import, print_function

import sys

import ctypes
_old_rtld = sys.getdlopenflags()
sys.setdlopenflags(_old_rtld | ctypes.RTLD_GLOBAL)


class ModuleDeprecationWarning(DeprecationWarning):
    """Module deprecation warning.

    The nose tester turns ordinary Deprecation warnings into test failures.
    That makes it hard to deprecate whole modules, because they get
    imported by default. So this is a special Deprecation warning that the
    nose tester will let pass without making tests fail.

    """
    pass

Exemplo n.º 46
0
                        __title__, __url__, __version__)

import os
import sys
if sys.platform.startswith("linux"):
    # When the _pybinding C++ extension is compiled with MKL, it requires specific
    # dlopen flags on Linux: RTLD_GLOBAL. This will not play nice with some scipy
    # modules, i.e. it will produce segfaults. As a workaround, specific modules
    # are imported first with default dlopenflags.
    # After that, RTLD_GLOBAL must be set for MKL to load properly. It's not possible
    # to set RTLD_GLOBAL, import _pybinding and then reset to default flags. This is
    # fundamentally an MKL issue which makes it difficult to resolve. This workaround
    # is the best solution at the moment.
    import scipy.sparse.linalg
    import scipy.spatial
    sys.setdlopenflags(sys.getdlopenflags() | os.RTLD_GLOBAL)

import _pybinding as _cpp

from .model import *
from .lattice import *
from .shape import *
from .modifier import *
from .results import *

from .support.pickle import save, load
from .parallel import parallel_for, parallelize

from . import (chebyshev, constants, greens, parallel, pltutils, results, solver, system, utils)

Exemplo n.º 47
0
####################################

# fBIRN_lib.py
# Script for performing fMRI quality control (fBIRN QA tools)
#
# TO DO:
# - ...

#__version__ = 20151026

# IMPORT FUNCTIONS
#import os
import tempfile
import sys
import ctypes #provides C compatible data types, allows calling functions from DLLs or shared libraries
flags = sys.getdlopenflags()  #?? (ctypes stuff)
sys.setdlopenflags(flags|ctypes.RTLD_GLOBAL) #?? (ctypes stuff)
#import argparse
#import traceback
#import numpy
import nibabel
#from compute_fd import *
from statsmodels.tsa.tsatools import detrend
#import statsmodels.api
#import matplotlib
# by default matplotlib ships configured to work with a graphical user interface which may require an X11 connection (errors running on background!)
#     +info:: http://matplotlib.org/faq/howto_faq.html#matplotlib-in-a-web-application-server
#matplotlib.use('Agg') # should be specified right after matplotlib is imported
#import matplotlib.pyplot as plt
import sklearn.cross_validation
from Plugin_development.MRI.MRI_fBIRN.utils.mk_slice_mosaic import *
Exemplo n.º 48
0
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
#
#
#

from sys import getdlopenflags,setdlopenflags
from dl import RTLD_NOW,RTLD_GLOBAL
flags = getdlopenflags()
setdlopenflags(RTLD_NOW | RTLD_GLOBAL)

from _mapnik import *
from paths import inputpluginspath

# The base Boost.Python class
BoostPythonMetaclass = coord.__class__

class _injector(object):
    class __metaclass__(BoostPythonMetaclass):
        def __init__(self, name, bases, dict):
            for b in bases:
                if type(b) not in (self, type):
                    for k,v in dict.items():
                        setattr(b,k,v)
Exemplo n.º 49
0
__author__ = "Oleksandr Pavlyk"
__copyright__ = "Copyright (c) 2016, UChicago Argonne, LLC."
__docformat__ = 'restructuredtext en'
__all__ = ['fft_impl']

try:
    import mkl_fft
    fft_impl = 'mkl_fft'
    logger.debug('FFT implementation is mkl_fft')
except ImportError:
    import os
    try:
        if os.name == 'nt':
            import pyfftw
        else:
            # Import pyfftw as soon as possible with RTLD_NOW|RTLD_DEEPBIND
            # to minimize chance of MKL overriding fftw functions
            import ctypes, sys

            curFlags = sys.getdlopenflags()
            sys.setdlopenflags(curFlags | ctypes.RTLD_GLOBAL)
            import pyfftw
            sys.setdlopenflags(curFlags)
            del curFlags
        fft_impl = 'pyfftw'
        logger.debug('FFT implementation is pyfftw')
    except ImportError:
        import numpy.fft
        fft_impl = 'numpy.fft'
        logger.debug('FFT implementation is numpy.fft')
Exemplo n.º 50
0
import collections
import ctypes
import inspect
import math
import sys

_oldFlags = sys.getdlopenflags()
sys.setdlopenflags(_oldFlags | ctypes.RTLD_GLOBAL)
from .libpymod import *
sys.setdlopenflags(_oldFlags)

# from http://mail.python.org/pipermail/tutor/2003-November/026645.html
class Unbuffered(object):
	def __init__(self, stream):
		self.stream = stream
	def write(self, data):
		self.stream.write(data)
		self.stream.flush()
	def __getattr__(self, attr):
		return getattr(self.stream, attr)
sys.stdout = Unbuffered(sys.stdout)

def _NoNew__setattr__(self, name, value):
	if hasattr(self, "_frozen") and self._frozen:
		msg = "Can not modify object '%s' of type '%s'. It has been frozen." % (self, type(self))
		raise AttributeError(msg)
	if hasattr(self, name):
		object.__setattr__(self, name, value)
	else:
		msg = "Can not create new attribute '%s' on object '%s' of type '%s'." % (name, self, type(self))
Exemplo n.º 51
0
#
# Unless required by applicable law or agreed to in writing, software distributed under
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific language
# governing permissions and limitations under the License.
"""Module provides ``OmnisciServer`` class."""

import uuid
import sys
import os

import pyarrow as pa
import numpy as np

if sys.platform == "linux":
    prev = sys.getdlopenflags()
    sys.setdlopenflags(1 | 256)  # RTLD_LAZY+RTLD_GLOBAL

try:
    from omniscidbe import PyDbEngine
except ModuleNotFoundError:  # fallback for older omniscidbe4py package naming
    from dbe import PyDbEngine

if sys.platform == "linux":
    sys.setdlopenflags(prev)

from modin.config import OmnisciFragmentSize, OmnisciLaunchParameters


class OmnisciServer:
    """Wrapper class for OmniSci backend."""
Exemplo n.º 52
0
# Copyright (C) AB Strakt
# See LICENSE for details.
"""
pyOpenSSL - A simple wrapper around the OpenSSL library
"""

import sys

try:
    orig = sys.getdlopenflags()
except AttributeError:
    from OpenSSL import crypto
else:
    try:
        import DLFCN
    except ImportError:
        try:
            import dl
        except ImportError:
            try:
                import ctypes
            except ImportError:
                flags = 2 | 256
            else:
                flags = 2 | ctypes.RTLD_GLOBAL
                del ctypes
        else:
            flags = dl.RTLD_NOW | dl.RTLD_GLOBAL
            del dl
    else:
        flags = DLFCN.RTLD_NOW | DLFCN.RTLD_GLOBAL
Exemplo n.º 53
0
import os
import platform
import sys
import time

if platform.system() == 'Linux':
    sys.setdlopenflags(sys.getdlopenflags() | 8)  # RTLD_GLOBAL = 0x08
import cisstMultiTaskPython as mts

name = 'My Tracker'
period = 0.01
configuration = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                             'configNDITracker.xml')

manager = mts.mtsManagerLocal.GetInstance()
manager.CreateAllAndWait(5.0)
manager.StartAllAndWait(5.0)

proxy = mts.mtsComponentWithManagement('{}Proxy'.format(name))
manager.AddComponent(proxy)
proxy.CreateAndWait(5.0)
time.sleep(0.5)

services = proxy.GetManagerComponentServices()
result = services.Load('sawNDITracker')
assert result, 'Failed to load {} using component services'.format(
    'sawNDITracker')

args = mts.mtsTaskPeriodicConstructorArg(name, period)
result = services.ComponentCreate('mtsNDISerial', args)
assert result, 'Failed to create {} of type {}'.format(name, 'mtsNDISerial')
Exemplo n.º 54
0
    dll_paths = [th_dll_path, py_dll_path, get_nvToolsExt_path(), _dl_flags.environ['PATH']]

    # then add the path to env
    _dl_flags.environ['PATH'] = ';'.join(dll_paths)

else:
    # first check if the os package has the required flags
    if not hasattr(_dl_flags, 'RTLD_GLOBAL') or not hasattr(_dl_flags, 'RTLD_LAZY'):
        try:
            # next try if DLFCN exists
            import DLFCN as _dl_flags
        except ImportError:
            # as a last attempt, use compile-time constants
            import torch._dl as _dl_flags

    old_flags = sys.getdlopenflags()
    sys.setdlopenflags(_dl_flags.RTLD_GLOBAL | _dl_flags.RTLD_LAZY)

del _dl_flags

from torch._C import *

__all__ += [name for name in dir(_C)
            if name[0] != '_' and
            not name.endswith('Base')]

if platform.system() != 'Windows':
    sys.setdlopenflags(old_flags)
    del old_flags

################################################################################
Exemplo n.º 55
0
import multiprocessing, os, sys, types
dlflags = sys.getdlopenflags()
sys.setdlopenflags(0x100 | 0x2)  # RTLD_GLOBAL | RTLD_NOW
import _athenamp as amp
sys.setdlopenflags(dlflags)

__all__ = ['cpu_count']

# cpu_count is pure python (but does call sysconf for Linux)
cpu_count = multiprocessing.cpu_count

# the following sets are replacements, which are accessed on C++ through the
# _athenamp extesion module for now

# current_process is used for identification purposes in multiprocessing; it
# serves no real purpose in AthenaMP (it's only used for printing a message)
# since there is a single relation of a mother process with multiple children


def current_process():
    '''
    Return process object representing the current process
    '''
    return amp.Process(os.getpid())


# active_children does not match exactly, but since AthenaMP only starts
# readers/workers/writers from the mother, an aggregate of all groups will
# do; note also that b/c of the AthenaMP model, no cleanup is needed (as is
# in multiprocessing: Pools could close and re-open there)
Exemplo n.º 56
0
def inline(code, arg_names=[], local_dict=None,
           global_dict=None, force=0, compiler="gcc", verbose=0,
           auto_downcast=1, support_code="", libraries=[],
           library_dirs=[], extra_compile_args=[],
           runtime_library_dirs=[], extra_objects=[],
           extra_link_args=[], mask_ret=[], debug=False):
    """Compile (if necessary) and run the C++ action specified by 'code',
    using weave."""

    # each term on the expansion will properly unwrap a tuple pointer value
    # to a reference with the appropriate name and type
    exp_term = """typename boost::remove_pointer<typename tr1::tuple_element<%d,Args>::type>::type& %s =
                          *tr1::get<%d>(_args);"""
    arg_expansion = "\n".join([ exp_term % (i,arg_names[i],i) for i in \
                                xrange(0, len(arg_names))])

    # we need to get the locals and globals of the _calling_ function. Thus, we
    # need to go deeper into the call stack
    call_frame = sys._getframe(1)
    if local_dict is None:
        local_dict = call_frame.f_locals
    if global_dict is None:
        global_dict = call_frame.f_globals

    # convert variables to boost::python::object, except some known convertible
    # types
    arg_def = props
    arg_conv = ""
    arg_alias = []
    alias_dict = {}
    for arg in arg_names:
        if arg not in local_dict.keys() and arg not in global_dict.keys():
            raise ValueError("undefined variable: "+ arg)
        if arg in local_dict.keys():
            arg_val = local_dict[arg]
        else:
            arg_val = global_dict[arg]
        if issubclass(type(arg_val), core.Graph):
            alias = "__gt__" + arg
            gi = "__gt__" + arg + "__gi"
            graph_type = get_graph_type(arg_val)
            gi_val = arg_val._Graph__graph
            arg_def += "typedef GraphWrap<%s > %s_graph_t;\n" % (graph_type, arg);
            arg_def += "GraphInterface& %s = python::extract<GraphInterface&>(%s);\n" %\
                        (gi, alias)
            arg_def += "%s_graph_t %s = graph_wrap(*boost::any_cast<%s*>(%s.GetGraphView()), %s);\n" % \
                        (arg, arg, graph_type, gi, gi)
            arg_alias.append(alias)
            alias_dict[alias] = gi_val
        elif type(arg_val) == core.PropertyMap:
            alias = "__gt__" + arg
            if arg_val == arg_val.get_graph().vertex_index:
                prop_name = "GraphInterface::vertex_index_map_t"
            elif arg_val == arg_val.get_graph().edge_index:
                prop_name = "GraphInterface::edge_index_map_t"
            else:
                prop_name = "%sprop_%s_t" % \
                            (arg_val.key_type(),
                             clean_prop_type(arg_val.value_type()))
            arg_def  += "%s %s;\n" % (prop_name, arg)
            arg_conv += "%s = get_prop<%s>(%s);\n" % \
                        (arg, prop_name, alias)
            arg_alias.append(alias)
            alias_dict[alias] = arg_val
        elif type(arg_val) not in [int, bool, float, string, numpy.ndarray]:
            alias = "__gt__" + arg
            obj_type = "python::object"
            if type(arg_val) == list:
                obj_type = "python::list"
            elif type(arg_val) == dict:
                obj_type = "python::dict"
            elif type(arg_val) == tuple:
                obj_type = "python::tuple"
            arg_def += "%s %s;\n" % (obj_type, arg)
            arg_conv += "%s = %s(python::object(python::handle<>" % (arg, obj_type) + \
                        "(python::borrowed((PyObject*)(%s)))));\n" % alias
            arg_alias.append(alias)
            alias_dict[alias] = arg_val
        elif type(arg_val) == bool:
            #weave is dumb with bools
            alias = "__gt__" + arg
            arg_def += "bool %s;\n" % arg;
            arg_conv += "%s = python::extract<bool>(python::object(python::handle<>" % arg + \
                        "(python::borrowed((PyObject*)(%s)))));\n" % alias
            arg_alias.append(alias)
            alias_dict[alias] = arg_val
        else:
            arg_alias.append(arg)
            if arg in local_dict.keys():
                alias_dict[arg] = local_dict[arg]
            else:
                alias_dict[arg] = global_dict[arg]

    # handle returned values
    return_vals = ""
    for arg in arg_names:
        if arg in local_dict.keys():
            arg_val = local_dict[arg]
        else:
            arg_val = global_dict[arg]
        if arg not in mask_ret and \
               type(arg_val) not in [numpy.ndarray, core.PropertyMap] and \
               not issubclass(type(arg_val), core.Graph):
            return_vals += 'return_vals["%s"] = %s;\n' % (arg, arg)

    support_code += globals()["support_template"]

    # set debug flag and disable optimization in debug mode
    compile_args = [cxxflags] + extra_compile_args
    if debug:
        compile_args = [re.sub("-O[^ ]*", "", x) for x in compile_args] + ["-g"]

    # insert a hash value into the code below, to force recompilation when
    # support_code (and module version) changes
    support_hash = hashlib.md5(support_code + code + \
                               " ".join(libraries + library_dirs +
                                        [cxxflags] + \
                                        extra_compile_args +\
                                        extra_objects + \
                                        extra_link_args) + \
                               headers_hash + core.__version__).hexdigest()
    code += "\n// support code hash: " + support_hash
    inline_code = string.Template(globals()["code_template"]).\
                  substitute(var_defs=arg_def, var_extract=arg_conv,
                             code=code, return_vals=return_vals)

    # RTLD_GLOBAL needs to be set in dlopen() if we want typeinfo and
    # friends to work properly across DSO boundaries. See
    # http://gcc.gnu.org/faq.html#dso
    orig_dlopen_flags = sys.getdlopenflags()
    sys.setdlopenflags(core.RTLD_NOW|core.RTLD_GLOBAL)

    # call weave and pass all the updated kw arguments
    ret_vals = \
             scipy.weave.inline(inline_code, arg_alias, force=force,
                                local_dict=alias_dict, global_dict=global_dict,
                                compiler=compiler, verbose=verbose,
                                auto_downcast=auto_downcast,
                                support_code=support_code,
                                libraries=libraries,
                                library_dirs=sys.path + library_dirs,
                                extra_compile_args=compile_args,
                                runtime_library_dirs=runtime_library_dirs,
                                extra_objects=extra_objects,
                                extra_link_args=["-Wl,-E "] + extra_link_args)
    # check if exception was thrown
    if ret_vals["__exception_thrown"]:
        libgraph_tool_core.raise_error(ret_vals["__exception_error"])
    else:
        del ret_vals["__exception_thrown"]
        del ret_vals["__exception_error"]
    sys.setdlopenflags(orig_dlopen_flags) # reset dlopen to normal case to
                                          # avoid unnecessary symbol collision
    # set return vals
    for arg in arg_names:
        if ret_vals.has_key(arg):
            if local_dict.has_key(arg):
                local_dict[arg] = ret_vals[arg]
            else:
                global_dict[arg] = ret_vals[arg]
    return ret_vals
Exemplo n.º 57
0
import mfem

if mfem.mfem_mode is None:
    mfem.mfem_mode = 'parallel'
if mfem.mfem_mode == 'serial':
    raise ImportError("MFEM serial mode is already loaded")

from mpi4py import MPI

## libmfem.a is linked only with _array.so
## this make sure that symbols are resovled
import sys, ctypes
rtld_now = sys.getdlopenflags()
sys.setdlopenflags(ctypes.RTLD_GLOBAL | sys.getdlopenflags())

from array import *
from socketstream import *
from operators import *
from blockoperator import *
from blockvector import *
from blockmatrix import *
from coefficient import *
from lininteg import *
from handle import *
from mesh import *
from fe_coll import *
from vector import *
from fespace import *
from linearform import *
from bilininteg import *
from gridfunc import *
Exemplo n.º 58
0
# System imports
import sys

# Import NumPy so it will not be screwed by imports after RTLD_GLOBAL is set
# Work around for lp:1085986
import numpy

# Work around lp:956939 and lp:961946
import io

# Store dl open flags to restore them after import
stored_dlopen_flags = None

if "linux" in sys.platform:
    stored_dlopen_flags = sys.getdlopenflags()

# A try to get rid of problems with dynamic_cast of types defined in different
# SWIG modules. The problem rises from the dynamic loader not making all types
# available for all shared modules. The key is the RTLD_GLOBAL. RTLD_NOW is set
# by default. This seems to be similar to the dynamicloadmpi problem above.
# See: for references: http://gcc.gnu.org/faq.html#dso
if "linux" in sys.platform:
    # FIXME: What with other platforms?
    try:
        from ctypes import RTLD_NOW, RTLD_GLOBAL
    except ImportError:
        RTLD_NOW = 2
        RTLD_GLOBAL = 256
    sys.setdlopenflags(RTLD_NOW | RTLD_GLOBAL)
Exemplo n.º 59
0
def import_scope(flags):
    prev = sys.getdlopenflags()
    sys.setdlopenflags(flags)
    yield
    sys.setdlopenflags(prev)
Exemplo n.º 60
0
Underworld is an open-source project. 
"""

# first import h5py. this is due to the dlopen changes which follow.
# by importing h5py, we ensure it uses the libHDF5 it was built against
# as opposed to version PETSc is possibly built against.
import h5py as _h5py
# ok, now need to change default python dlopen flags to global
# this is because when python imports the module, the shared libraries are loaded as RTLD_LOCAL
# and then when MPI_Init is called, OpenMPI tries to dlopen its plugin, they are unable to
# link to the openmpi libraries as they are private
import sys as _sys
import ctypes as _ctypes

_oldflags = _sys.getdlopenflags()
_sys.setdlopenflags(_oldflags | _ctypes.RTLD_GLOBAL)

__version__ = "2.8.1b"

# squelch h5py/numpy future warnings
import warnings as _warnings

_warnings.simplefilter(action='ignore', category=FutureWarning)
# also these warnings as they are very noisey and not necessary
# https://stackoverflow.com/questions/40845304/runtimewarning-numpy-dtype-size-changed-may-indicate-binary-incompatibility
_warnings.filterwarnings("ignore", message="numpy.dtype size changed")
_warnings.filterwarnings("ignore", message="numpy.ufunc size changed")

# DEPRECATE
# let's check PYTHONPATH includes path to lib directory, as this will probably