Qt::HANDLE QtLockedFile::getMutexHandle(int idx, bool doCreate)
{
    if (mutexname.isEmpty()) {
        QFileInfo fi(*this);
        mutexname = QString::fromLatin1(MUTEX_PREFIX)
                    + fi.absoluteFilePath().toLower();
    }
    QString mname(mutexname);
    if (idx >= 0)
        mname += QString::number(idx);

    Qt::HANDLE mutex;
    if (doCreate) {
        QT_WA( { mutex = CreateMutexW(NULL, FALSE, (TCHAR*)mname.utf16()); },
               { mutex = CreateMutexA(NULL, FALSE, mname.toLocal8Bit().constData()); } );
	void DebugCLI::print(const char *name)
	{
		if (!name) {
			core->console << "Must specify a name.\n";
			return;
		}

		// todo deal with exceptions
		Multiname mname(
			core->publicNamespace,
			core->constantString(name)
		);

		#if 0
		// rick fixme
		Atom objAtom = env->findproperty(outerScope, scopes, extraScopes, &mname, false);
		Atom valueAtom = env->getproperty(objAtom, &mname);
		core->console << core->string(valueAtom) << '\n';
		#endif
	}
Beispiel #3
0
llvm::Module* Module::genLLVMModule(llvm::LLVMContext& context, Ir* sir)
{
    bool logenabled = Logger::enabled();
    if (llvmForceLogging && !logenabled)
    {
        Logger::enable();
    }

    Logger::println("Generating module: %s", (md ? md->toChars() : toChars()));
    LOG_SCOPE;

    if (global.params.verbose_cg)
        printf("codegen: %s (%s)\n", toPrettyChars(), srcfile->toChars());

    assert(!global.errors);

    // name the module
#if 1
    // Temporary workaround for http://llvm.org/bugs/show_bug.cgi?id=11479 –
    // just use the source file name, as it is unlikely to collide with a
    // symbol name used somewhere in the module.
    llvm::StringRef mname(srcfile->toChars());
#else
    llvm::StringRef mname(toChars());
    if (md != 0)
        mname = md->toChars();
#endif

    // create a new ir state
    // TODO look at making the instance static and moving most functionality into IrModule where it belongs
    IRState ir(new llvm::Module(mname, context));
    gIR = &ir;
    ir.dmodule = this;

    // reset all IR data stored in Dsymbols
    IrDsymbol::resetAll();

    sir->setState(&ir);

    // set target triple
    ir.module->setTargetTriple(global.params.targetTriple.str());

    // set final data layout
    ir.module->setDataLayout(gDataLayout->getStringRepresentation());
    if (Logger::enabled())
        Logger::cout() << "Final data layout: " << ir.module->getDataLayout() << '\n';

    // allocate the target abi
    gABI = TargetABI::getTarget();

    // debug info
    DtoDwarfCompileUnit(this);

    // handle invalid 'objectø module
    if (!ClassDeclaration::object) {
        error("is missing 'class Object'");
        fatal();
    }
    if (!ClassDeclaration::classinfo) {
        error("is missing 'class ClassInfo'");
        fatal();
    }

    LLVM_D_InitRuntime();

    // process module members
    for (unsigned k=0; k < members->dim; k++) {
        Dsymbol* dsym = static_cast<Dsymbol*>(members->data[k]);
        assert(dsym);
        dsym->codegen(sir);
    }

    // emit function bodies
    sir->emitFunctionBodies();

    // for singleobj-compilation, fully emit all seen template instances
    if (global.params.singleObj)
    {
        while (!ir.seenTemplateInstances.empty())
        {
            IRState::TemplateInstanceSet::iterator it, end = ir.seenTemplateInstances.end();
            for (it = ir.seenTemplateInstances.begin(); it != end; ++it)
                (*it)->codegen(sir);
            ir.seenTemplateInstances.clear();

            // emit any newly added function bodies
            sir->emitFunctionBodies();
        }
    }

    // finilize debug info
    DtoDwarfModuleEnd();

    // generate ModuleInfo
    genmoduleinfo();

    // verify the llvm
    verifyModule(*ir.module);

    gIR = NULL;

    if (llvmForceLogging && !logenabled)
    {
        Logger::disable();
    }

    sir->setState(NULL);

    return ir.module;
}
// See if we can find an attribute in the Qt meta-type system.  This is
// primarily to support access to JavaScript (e.g. QDeclarativeItem) so we
// don't support overloads.
PyObject *qpycore_qobject_getattr(QObject *qobj, PyObject *py_qobj,
        const char *name)
{
    const QMetaObject *mo = qobj->metaObject();

    // Try and find a method with the name.
    QMetaMethod method;
    int method_index = -1;

    // Count down to allow overrides (assuming they are possible).
    for (int m = mo->methodCount() - 1; m >= 0; --m)
    {
        method = mo->method(m);

#if QT_VERSION >= 0x040500
        if (method.methodType() == QMetaMethod::Constructor)
            continue;
#endif

        // Get the method name.
#if QT_VERSION >= 0x050000
        QByteArray mname(method.methodSignature());
#else
        QByteArray mname(method.signature());
#endif
        int idx = mname.indexOf('(');

        if (idx >= 0)
            mname.truncate(idx);

        if (mname == name)
        {
            method_index = m;
            break;
        }
    }

    if (method_index < 0)
    {
        // Replicate the standard Python exception.
        PyErr_Format(PyExc_AttributeError, "'%s' object has no attribute '%s'",
                Py_TYPE(py_qobj)->tp_name, name);

        return 0;
    }

    // Get the value to return.  Note that this is recreated each time.  We
    // could put a descriptor in the type dictionary to satisfy the request in
    // future but the typical use case is getting a value from a C++ proxy
    // (e.g. QDeclarativeItem) and we can't assume that what is being proxied
    // is the same each time.
    PyObject *value;

    if (method.methodType() == QMetaMethod::Signal)
    {
        // We need to keep explicit references to the unbound signals (because
        // we don't use the type dictionary to do so) because they own the
        // parsed signature which may be needed by a PyQtProxy at some point.
        typedef QHash<QByteArray, PyObject *> SignalHash;

        static SignalHash *sig_hash = 0;

        // For crappy compilers.
        if (!sig_hash)
            sig_hash = new SignalHash;

        PyObject *sig_obj;
#if QT_VERSION >= 0x050000
        QByteArray sig_str(method.methodSignature());
#else
        QByteArray sig_str(method.signature());
#endif
        SignalHash::const_iterator it = sig_hash->find(sig_str);

        if (it == sig_hash->end())
        {
            sig_obj = (PyObject *)qpycore_pyqtSignal_New(sig_str.constData());

            if (!sig_obj)
                return 0;

            sig_hash->insert(sig_str, sig_obj);
        }
        else
        {
            sig_obj = it.value();
        }

        value = qpycore_pyqtBoundSignal_New((qpycore_pyqtSignal *)sig_obj,
                py_qobj, qobj);
    }
    else
    {
        QByteArray py_name(Py_TYPE(py_qobj)->tp_name);
        py_name.append('.');
        py_name.append(name);

        value = qpycore_pyqtMethodProxy_New(qobj, method_index, py_name);
    }

    return value;
}
Beispiel #5
0
llvm::Module* Module::genLLVMModule(llvm::LLVMContext& context)
{
    bool logenabled = Logger::enabled();
    if (llvmForceLogging && !logenabled)
    {
        Logger::enable();
    }

    IF_LOG Logger::println("Generating module: %s", (md ? md->toChars() : toChars()));
    LOG_SCOPE;

    if (global.params.verbose_cg)
        printf("codegen: %s (%s)\n", toPrettyChars(), srcfile->toChars());

    if (global.errors)
    {
        Logger::println("Aborting because of errors");
        fatal();
    }

    // name the module
#if 1
    // Temporary workaround for http://llvm.org/bugs/show_bug.cgi?id=11479 –
    // just use the source file name, as it is unlikely to collide with a
    // symbol name used somewhere in the module.
    llvm::StringRef mname(srcfile->toChars());
#else
    llvm::StringRef mname(toChars());
    if (md != 0)
        mname = md->toChars();
#endif

    // create a new ir state
    // TODO look at making the instance static and moving most functionality into IrModule where it belongs
    IRState ir(new llvm::Module(mname, context));
    gIR = &ir;
    ir.dmodule = this;

    // reset all IR data stored in Dsymbols
    IrDsymbol::resetAll();

    // set target triple
    ir.module->setTargetTriple(global.params.targetTriple.str());

    // set final data layout
    ir.module->setDataLayout(gDataLayout->getStringRepresentation());
    IF_LOG Logger::cout() << "Final data layout: " << ir.module->getDataLayout() << '\n';

    // allocate the target abi
    gABI = TargetABI::getTarget();

    // handle invalid 'objectø module
    if (!ClassDeclaration::object) {
        error("is missing 'class Object'");
        fatal();
    }

    LLVM_D_InitRuntime();

    codegenModule(this); 

    gIR = NULL;

    if (llvmForceLogging && !logenabled)
    {
        Logger::disable();
    }

    return ir.module;
}
Beispiel #6
0
bool MatchingImplementation::module_matching_with_star_and_valueconstraints(
										  const ParamModule& module, 
									      const PatternModule& pattern, 
									      ArgList& l)
{ 
  if (pattern.isStar()){
	size_t patternsize = pattern.argSize();
	if (patternsize == 0) return true;
	if (patternsize == 1) {
	    size_t modulesize = module.argSize();
	    const LsysVar& v = pattern.getAt(0);
	    if(v.isArgs()) { 
			ArgList largs;
			if(v.isNamed() || v.hasCondition()){ // if necessary we retrieve the args
				ArgsCollector::append_arg(largs,bp::object(module.name()));
				ArgsCollector::append_modargs(largs,module.getParameterList()); 
			}
            // we check the condition
			if(!v.isCompatible(toPyList(largs))) return false;
            // we add the params to the result list
			if(v.isNamed()) ArgsCollector::append_as_arg(l,largs); 
			return true; 
	    }
        else if(v.isKwds()) { 
            if( module.getNamedParameterNb() != module.size()) {
              return false;
            }
            boost::python::dict lkwds;
            if(v.isNamed() || v.hasCondition()){ // if necessary we retrieve the args
                lkwds[boost::python::object("name")] = boost::python::object(module.name());
                module.getNamedParameters(lkwds);
            }
            // we check the condition
            if(!v.isCompatible(lkwds))return false;
            // we add the params to the result list
            if(v.isNamed())  ArgsCollector::append_arg(l,lkwds);
            return true; 
        }
      	else {
		  if(modulesize == 0){ 
             // we get the name
			 boost::python::object largs(module.name()); 
             // we check the condition
			 if (!v.isCompatible(largs)) return false;
             // we add the params to the result list
			 if (v.isNamed()) ArgsCollector::append_arg(l,largs); 
			 return true; 
		  }
		  else return false;
	    }
	}
	else { // patternsize > 2
	  size_t modulesize = module.argSize();
      if (modulesize + 3 < patternsize) return false; // name,args,kwd can be extra args

      const LsysVar& vlast = pattern.getAt(patternsize-1);
      const LsysVar& vbeforelast = pattern.getAt(patternsize-2);

      bool vlastisArgs = vlast.isArgs();
      bool vbeforelastisArgs = vbeforelast.isArgs();
      bool vlastisKwds = vlast.isKwds();

      if(!vlastisArgs && !vlastisKwds){
        if (modulesize != patternsize-1) return false;
      }


      if (patternsize == 2 && vlastisKwds && vbeforelastisArgs){ // (**kwds,*args)
          size_t nbNamedParameter = module.getNamedParameterNb();
          if(nbNamedParameter > modulesize)  return false;
          boost::python::list largs;
          if (vbeforelast.isNamed() || vbeforelast.hasCondition()) {
            largs = module.getSlice(0,modulesize-nbNamedParameter);
          }
          if (!vbeforelast.isCompatible(largs))return false;
          if (vbeforelast.isNamed()) ArgsCollector::append_arg(l,largs);

          boost::python::dict lkwd;
          if (vlast.isNamed() || vlast.hasCondition()) {
              lkwd[boost::python::object("name")] = boost::python::object(module.name());
              module.getNamedParameters(lkwd);
          }
          if (!vlast.isCompatible(lkwd)) return false;
          if (vlast.isNamed()) ArgsCollector::append_arg(l,lkwd);
          return true;
      }

      size_t normalparam = patternsize - 1;
      if (vlastisArgs || vlastisKwds) --normalparam;
      if (vbeforelastisArgs) --normalparam;

      // check if normal number of parameter to retrieve is compatible
      if( normalparam > modulesize) return false;



      // processing module name
	  const LsysVar& v1 = pattern.getAt(0);
      if (v1.isNamed() || v1.hasCondition()) {
        boost::python::object mname(module.name());
        if (!v1.isCompatible(mname))return false;
        if (v1.isNamed()) ArgsCollector::append_arg(l,mname);
      }


      // retrieve normal parameters
      for(int i = 0; i < normalparam; i++) {
        const LsysVar& v = pattern.getAt(i+1);
        if(!v.isCompatible(module.getAt(i))) return false; 
        if(v.isNamed())ArgsCollector::append_arg_ref(l,module.getAt(i));
      }

      // retrieve *args
      if (vbeforelastisArgs || vlastisArgs){
          const LsysVar& varg = (vlastisArgs?vlast:vbeforelast);
          boost::python::list argvalue;
          if (varg.isNamed() || varg.hasCondition()) {
              if ( normalparam == 0 && !vlastisKwds) // (name,*args)
                  argvalue = module.getPyArgs();          
              else if (normalparam == modulesize) // (name,x,*args) on A(1)
                  argvalue = boost::python::list();
              else {
                  int lastarrayarg = modulesize;
                  if (vlastisKwds) {
                        lastarrayarg = std::max(normalparam, modulesize-module.getNamedParameterNb()) ;
                  }
                  if (lastarrayarg <= normalparam) 
                      argvalue = boost::python::list();
                  else 
                      argvalue = module.getSlice(normalparam,lastarrayarg);
              }
          }
          if(!varg.isCompatible(argvalue)) return false; 
          if (varg.isNamed())ArgsCollector::append_arg(l,argvalue);

      }

      // retrieve **kwds
      if (vlastisKwds){
          if (! vbeforelastisArgs && (module.getNamedParameterNb()+normalparam < modulesize) ) return false;

          boost::python::dict kwdvalue;
          if (vlast.isNamed() || vlast.hasCondition()) {
            int startkwd = std::max<int>(0,normalparam - std::max<int>(0, modulesize-module.getNamedParameterNb()));
            module.getNamedParameters(kwdvalue, startkwd);
          }
          if(!vlast.isCompatible(kwdvalue)) return false; 
          if (vlast.isNamed())ArgsCollector::append_arg(l,kwdvalue);
      }


      return true;


/*
	  bool lastarg = false;
	  boost::python::object lastargval;
	  const LsysVar& v = pattern.getAt(patternsize-1);
	  if(!v.isNamed()){
		  if (modulesize != (patternsize-1+beg)) return false;
		  if (!v.isCompatible(module.getAt(patternsize-2+beg)))return false;
	  }
	  else {
		lastarg = true;
		if(beg == 1){
		  if(!v.isArgs()){
			if (modulesize != patternsize) return false;
			lastargval = module.getAt(patternsize-1);
		  }
		  else {
			if (modulesize < patternsize-1) return false;
			else if (modulesize == patternsize-1) lastargval = boost::python::list();
			lastargval = module.getSlice(patternsize-1,modulesize);
		  }
		}
		else {
		  if(!v.isArgs()){
			if (modulesize != patternsize-1) return false;
			lastargval = module.getAt(patternsize-2);
		  }
		  else {
			if (modulesize < patternsize-2) return false;
			else {
			  if(patternsize == 2){
				  lastargval = module.getPyArgs();
				  if(!v.isCompatible(lastargval))return false;
				  ArgsCollector::append_arg(l,lastargval); 
                  return true; 
			  }
			  else if (modulesize == patternsize-2) lastargval = boost::python::list();
			  else lastargval = module.getSlice(patternsize-2,modulesize);
			}
		  }
		}
		if(!v.isCompatible(lastargval))return false;
	  }
	  for(size_t i = 1; i < patternsize-1; i++){
	    const LsysVar& v = pattern.getAt(i);
	    if(!v.isCompatible(module.getAt(i-1+beg))) return false; 
		if(v.isNamed())ArgsCollector::append_arg_ref(l,module.getAt(i-1+beg));
	  }
	  if(lastarg)ArgsCollector::append_arg(l,lastargval);
	  return true;
	*/}
  }
  else { // pattern is not star

    if (!compatibleName(module,pattern)) return false;
    size_t patternsize = pattern.argSize();
    size_t modulesize = module.argSize();
    if (modulesize + 2 < patternsize) return false;

    if( patternsize == 0) return modulesize == 0;
    else if(patternsize == 1) {
      LsysVar v = pattern.getAt(0);
      if(v.isArgs()) { 
            ArgList largs;
            if(v.isNamed() || v.hasCondition()){ // if necessary we retrieve the args
                ArgsCollector::append_modargs(largs,module.getParameterList()); 
            }
            // we check the condition
            if(!v.isCompatible(toPyList(largs))) return false;
            // we add the params to the result list
            if(v.isNamed()) ArgsCollector::append_as_arg(l,largs); 
            return true; 
      }
      else if(v.isKwds()) { 
            if( module.getNamedParameterNb() != module.size()) return false;
            boost::python::dict lkwds;
            if(v.isNamed() || v.hasCondition()){ // if necessary we retrieve the args
                module.getNamedParameters(lkwds);
            }
            // we check the condition
            if(!v.isCompatible(lkwds))return false;
            // we add the params to the result list
            if(v.isNamed())  ArgsCollector::append_arg(l,lkwds);
            return true; 
      }
      else {
          if(modulesize != 1) return false;
          // we check the condition
          if (!v.isCompatible(module.getAt(0))) return false;
          // we add the params to the result list
          if (v.isNamed()) ArgsCollector::append_arg_ref(l,module.getAt(0));
          return true;
      }
    }
    else { // args >= 2

      LsysVar vlast = pattern.getAt(patternsize-1);
      LsysVar vbeforelast = pattern.getAt(patternsize-2);

      bool vlastisArgs = vlast.isArgs();
      bool vbeforelastisArgs = vbeforelast.isArgs();
      bool vlastisKwds = vlast.isKwds();

      if(!vlastisArgs && !vlastisKwds){
        if (modulesize != patternsize) return false;
      }

      if (patternsize == 2 && vbeforelastisArgs && vlastisKwds){ // (*args,**kwds)
          size_t nbNamedParameter = module.getNamedParameterNb();
          if(nbNamedParameter > modulesize)  return false;
          boost::python::list largs;
          if (vbeforelast.isNamed() || vbeforelast.hasCondition()) {
            largs = module.getSlice(0,modulesize-nbNamedParameter);
          }
          if (!vbeforelast.isCompatible(largs))return false;
          if (vbeforelast.isNamed()) ArgsCollector::append_arg(l,largs);

          boost::python::dict lkwd;
          if (vlast.isNamed() || vlast.hasCondition()) {
              module.getNamedParameters(lkwd);
          }
          if (!vlast.isCompatible(lkwd)) return false;
          if (vlast.isNamed()) ArgsCollector::append_arg(l,lkwd);
          return true;
      }


      size_t normalparam = patternsize ;
      if (vbeforelastisArgs) --normalparam;
      if (vlastisArgs || vlastisKwds) --normalparam;

      if( normalparam > modulesize)  return false;

      // retrieve normal parameters
      for(int i = 0; i < normalparam; i++) {
        const LsysVar& v = pattern.getAt(i);
        if(!v.isCompatible(module.getAt(i))) return false; 
        if(v.isNamed())ArgsCollector::append_arg_ref(l,module.getAt(i));
      }

      // retrieve *args
      if (vbeforelastisArgs || vlastisArgs){
          const LsysVar& varg = (vlastisArgs?vlast:vbeforelast);
          boost::python::list argvalue;
          if (varg.isNamed() || varg.hasCondition()) {
              if ( normalparam == 0 && !vlastisKwds) // (name,*args)
                  argvalue = module.getPyArgs();          
              else if (normalparam == modulesize) // (name,x,*args) on A(1)
                  argvalue = boost::python::list();
              else {
                  int lastarrayarg = modulesize;
                  if (vlastisKwds) {
                        lastarrayarg = std::max(normalparam, modulesize-module.getNamedParameterNb()) ;
                  }
                  if (lastarrayarg <= normalparam) 
                      argvalue = boost::python::list();
                  else 
                      argvalue = module.getSlice(normalparam,lastarrayarg);
              }
          }
          if(!varg.isCompatible(argvalue)) return false; 
          if (varg.isNamed())ArgsCollector::append_arg(l,argvalue);
      }

      if (vlastisKwds){
          if (! vbeforelastisArgs && (module.getNamedParameterNb()+normalparam < modulesize) ) {
                return false;
          }          
          boost::python::dict kwdvalue;
          if (vlast.isNamed() || vlast.hasCondition()) {
            int startkwd = std::max<int>(0,normalparam - std::max<int>(0, modulesize-module.getNamedParameterNb()));
            module.getNamedParameters(kwdvalue, startkwd);
          }
          if(!vlast.isCompatible(kwdvalue)) return false; 
          if (vlast.isNamed())ArgsCollector::append_arg(l,kwdvalue);
      }
      return true;

    }
	/*if (!compatibleName(module,pattern)) return false;
	int s = pattern.argSize();
    int s2 = module.argSize();
	if( s == 0) return s2 == 0;
	else {
	  bool lastarg = false;
	  boost::python::object lastargval;
	  const LsysVar& v = pattern.getAt(s-1);
	  if(!v.isNamed()){
		if (s2 != s) return false;
		if (!v.isCompatible(module.getAt(s-1)))return false;
	  }
	  else {
		lastarg = true;
		if(!v.isArgs()){
		  if (s2 != s) return false; 
		  else lastargval = module.getAt(s-1);
		}
		else {
		  if (s2 < s - 1) return false;
		  if(s == 1){ 
			  lastargval =  module.getPyArgs();
			  if(!v.isCompatible(lastargval))return false; 
			  ArgsCollector::append_arg(l,lastargval); return true; 
		  }
		  else if (s2 == s - 1) lastargval = boost::python::list();
		  else lastargval = module.getSlice(s-1,s2);
		}
		if(!v.isCompatible(lastargval)) return false; 
	  }
	  for(size_t i = 0; i < s-1; i++){
		const LsysVar& v = pattern.getAt(i);
		if(!v.isCompatible(module.getAt(i))) return false; 
		if(v.isNamed())ArgsCollector::append_arg_ref(l,module.getAt(i));
	  }
	  if(lastarg)ArgsCollector::append_arg(l,lastargval);
	}
	return true;*/
  }
}
Beispiel #7
0
void
gdk_pixbuf_load_module (GdkPixbufModule *image_module)
{
	image_module->module = (void *) 1;
	
	if (strcmp (image_module->module_name, "png") == 0){
		image_module->load           = mname (png,load);
		image_module->begin_load     = mname (png,begin_load);
		image_module->load_increment = mname (png,load_increment);
		image_module->stop_load      = mname (png,stop_load);
		return;
	}

	if (strcmp (image_module->module_name, "bmp") == 0){
		image_module->load           = mname (bmp,load);
		image_module->begin_load     = mname (bmp,begin_load);
		image_module->load_increment = mname (bmp,load_increment);
		image_module->stop_load      = mname (bmp,stop_load);
		return;
	}

	if (strcmp (image_module->module_name, "gif") == 0){
		image_module->load           = mname (gif,load);
		image_module->begin_load     = mname (gif,begin_load);
		image_module->load_increment = mname (gif,load_increment);
		image_module->stop_load      = mname (gif,stop_load);
		image_module->load_animation = mname (gif,load_animation);
		return;
	}

	if (strcmp (image_module->module_name, "ico") == 0){
		image_module->load           = mname (ico,load);
		image_module->begin_load     = mname (ico,begin_load);
		image_module->load_increment = mname (ico,load_increment);
		image_module->stop_load      = mname (ico,stop_load);
		return;
	}

	if (strcmp (image_module->module_name, "jpeg") == 0){
		image_module->load           = mname (jpeg,load);
		image_module->begin_load     = mname (jpeg,begin_load);
		image_module->load_increment = mname (jpeg,load_increment);
		image_module->stop_load      = mname (jpeg,stop_load);
		return;
	}
	if (strcmp (image_module->module_name, "pnm") == 0){
		image_module->load           = mname (pnm,load);
		image_module->begin_load     = mname (pnm,begin_load);
		image_module->load_increment = mname (pnm,load_increment);
		image_module->stop_load      = mname (pnm,stop_load);
		return;
	}
	if (strcmp (image_module->module_name, "ras") == 0){
		image_module->load           = mname (ras,load);
		image_module->begin_load     = mname (ras,begin_load);
		image_module->load_increment = mname (ras,load_increment);
		image_module->stop_load      = mname (ras,stop_load);
		return;
	}
	if (strcmp (image_module->module_name, "tiff") == 0){
		image_module->load           = mname (tiff,load);
		image_module->begin_load     = mname (tiff,begin_load);
		image_module->load_increment = mname (tiff,load_increment);
		image_module->stop_load      = mname (tiff,stop_load);
		return;
	}
	if (strcmp (image_module->module_name, "xpm") == 0){
		image_module->load           = mname (xpm,load);
		image_module->load_xpm_data  = mname (xpm,load_xpm_data);
		return;
	}
	if (strcmp (image_module->module_name, "xbm") == 0){
		image_module->load           = mname (xbm,load);
		image_module->begin_load     = mname (xbm,begin_load);
		image_module->load_increment = mname (xbm,load_increment);
		image_module->stop_load      = mname (xbm,stop_load);
		return;
	}
}
// The type call slot.
static PyObject *pyqtMethodProxy_call(PyObject *self, PyObject *args,
        PyObject *kw_args)
{
    qpycore_pyqtMethodProxy *mp = (qpycore_pyqtMethodProxy *)self;

    const char *py_name = mp->py_name->constData();

    // Check for keyword arguments.
    if (kw_args)
    {
        PyErr_Format(PyExc_TypeError,
                "%s() does not support keyword arguments", py_name);
        return 0;
    }

    QMetaMethod method = mp->qobject->metaObject()->method(mp->method_index);
    QList<QByteArray> arg_types = method.parameterTypes();

    if (PyTuple_Size(args) != arg_types.size())
    {
        PyErr_Format(PyExc_TypeError,
#if PY_VERSION_HEX >= 0x02050000
                "%s() called with %zd arguments but %d expected",
#else
                "%s() called with %d arguments but %d expected",
#endif
                py_name, PyTuple_Size(args), arg_types.size());
        return 0;
    }

    // Parse the return type and the arguments.
    QGenericReturnArgument ret;
    QGenericArgument a0, a1, a2, a3, a4, a5, a6, a7, a8, a9;
    Chimera::Storage *return_storage, *storage[10];
    QByteArray return_type(method.typeName());
    bool failed = false;

    return_storage = 0;

    if (!return_type.isEmpty())
    {
        const Chimera *ct = Chimera::parse(return_type);

        if (!ct)
        {
            PyErr_Format(PyExc_TypeError,
                    "unable to convert return value of %s from '%s' to a Python object",
                    py_name, return_type.constData());
            return 0;
        }

        return_storage = ct->storageFactory();

        ret = QGenericReturnArgument(return_type.constData(),
                return_storage->address());
    }

    parse_arg(args, 0, arg_types, a0, storage, failed, py_name);
    parse_arg(args, 1, arg_types, a1, storage, failed, py_name);
    parse_arg(args, 2, arg_types, a2, storage, failed, py_name);
    parse_arg(args, 3, arg_types, a3, storage, failed, py_name);
    parse_arg(args, 4, arg_types, a4, storage, failed, py_name);
    parse_arg(args, 5, arg_types, a5, storage, failed, py_name);
    parse_arg(args, 6, arg_types, a6, storage, failed, py_name);
    parse_arg(args, 7, arg_types, a7, storage, failed, py_name);
    parse_arg(args, 8, arg_types, a8, storage, failed, py_name);
    parse_arg(args, 9, arg_types, a9, storage, failed, py_name);

    // Invoke the method.
    PyObject *result = 0;

    if (!failed)
    {
#if QT_VERSION >= 0x040500
        failed = !method.invoke(mp->qobject, ret, a0, a1, a2, a3, a4, a5, a6,
                a7, a8, a9);
#else
        // Get the method name.
        QByteArray mname(method.signature());
        mname.truncate(mname.indexOf('('));

        failed = !QMetaObject::invokeMethod(mp->qobject, mname.constData(),
                ret, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9);
#endif

        if (failed)
        {
            PyErr_Format(PyExc_TypeError, "invocation of %s() failed", py_name);
        }
        else if (return_storage)
        {
            result = return_storage->toPyObject();
        }
        else
        {
            result = Py_None;
            Py_INCREF(result);
        }
    }

    // Release any storage.
    if (return_storage)
    {
        delete return_storage->type();
        delete return_storage;
    }

    for (int i = 0; i < 10; ++i)
    {
        Chimera::Storage *st = storage[i];

        if (st)
        {
            delete st->type();
            delete st;
        }
    }

    return result;
}
Beispiel #9
0
/// Generate a new sbiad index by passing through the data twice.
/// - (1) scan the data to generate a list of distinct values and their count.
/// - (2) scan the data a second time to produce the bit vectors.
void ibis::sbiad::construct2(const char* f, const uint32_t nbase) {
    { // a block to limit the scope of hst
	histogram hst;
	mapValues(f, hst); // scan the data to produce the histogram
	if (hst.empty())   // no data, of course no index
	    return;

	// convert histogram into two arrays
	const uint32_t nhst = hst.size();
	vals.resize(nhst);
	cnts.resize(nhst);
	histogram::const_iterator it = hst.begin();
	for (uint32_t i = 0; i < nhst; ++i) {
	    vals[i] = (*it).first;
	    cnts[i] = (*it).second;
	    ++ it;
	}
    }

    // determine the base sizes
    setBases(bases, vals.size(), nbase);
    const uint32_t nb = bases.size();
    int ierr;

    // allocate the correct number of bitvectors
    uint32_t nobs = 0;
    for (uint32_t ii = 0; ii < nb; ++ii)
	nobs += bases[ii];
    bits.resize(nobs);
    for (uint32_t ii = 0; ii < nobs; ++ii)
	bits[ii] = new ibis::bitvector;

    std::string fnm; // name of the data file
    dataFileName(fnm, f);

    nrows = col->partition()->nRows();
    ibis::bitvector mask;
    {   // name of mask file associated with the data file
	array_t<ibis::bitvector::word_t> arr;
	std::string mname(fnm);
	mname += ".msk";
	if (ibis::fileManager::instance().getFile(mname.c_str(), arr) == 0)
	    mask.copy(ibis::bitvector(arr)); // convert arr to a bitvector
	else
	    mask.set(1, nrows); // default mask
    }

    // need to do different things for different columns
    switch (col->type()) {
    case ibis::TEXT:
    case ibis::UINT: {// unsigned int
	array_t<uint32_t> val;
	if (! fnm.empty())
	    ierr = ibis::fileManager::instance().getFile(fnm.c_str(), val);
	else
	    ierr = col->getValuesArray(&val);
	if (ierr < 0 || val.empty()) {
	    LOGGER(ibis::gVerbose > 0)
		<< "Warning -- sbiad::construct2 failed to retrieve any value";
	    break;
	}

	if (val.size() > mask.size()) {
	    col->logWarning("sbiad::construct", "the data file \"%s\" "
			    "contains more elements (%lu) then expected "
			    "(%lu)", fnm.c_str(),
			    static_cast<long unsigned>(val.size()),
			    static_cast<long unsigned>(mask.size()));
	    mask.adjustSize(nrows, nrows);
	}
	ibis::bitvector::indexSet iset = mask.firstIndexSet();
	uint32_t nind = iset.nIndices();
	const ibis::bitvector::word_t *iix = iset.indices();
	while (nind) {
	    if (iset.isRange()) { // a range
		uint32_t k = (iix[1] < nrows ? iix[1] : nrows);
		for (uint32_t i = *iix; i < k; ++i)
		    setBit(i, val[i]);
	    }
	    else if (*iix+ibis::bitvector::bitsPerLiteral() < nrows) {
		// a list of indices
		for (uint32_t i = 0; i < nind; ++i) {
		    uint32_t k = iix[i];
		    setBit(k, val[k]);
		}
	    }
	    else {
		for (uint32_t i = 0; i < nind; ++i) {
		    uint32_t k = iix[i];
		    if (k < nrows)
			setBit(k, val[k]);
		}
	    }
	    ++iset;
	    nind = iset.nIndices();
	    if (*iix >= nrows)
		nind = 0;
	} // while (nind)
	break;}
    case ibis::INT: {// signed int
	array_t<int32_t> val;
	if (! fnm.empty())
	    ierr = ibis::fileManager::instance().getFile(fnm.c_str(), val);
	else
	    ierr = col->getValuesArray(&val);
	if (ierr < 0 || val.empty()) {
	    LOGGER(ibis::gVerbose > 0)
		<< "Warning -- sbiad::construct2 failed to retrieve any value";
	    break;
	}

	if (val.size() > mask.size()) {
	    col->logWarning("sbiad::construct", "the data file \"%s\" "
			    "contains more elements (%lu) then expected "
			    "(%lu)", fnm.c_str(),
			    static_cast<long unsigned>(val.size()),
			    static_cast<long unsigned>(mask.size()));
	    mask.adjustSize(nrows, nrows);
	}
	ibis::bitvector::indexSet iset = mask.firstIndexSet();
	uint32_t nind = iset.nIndices();
	const ibis::bitvector::word_t *iix = iset.indices();
	while (nind) {
	    if (iset.isRange()) { // a range
		uint32_t k = (iix[1] < nrows ? iix[1] : nrows);
		for (uint32_t i = *iix; i < k; ++i)
		    setBit(i, val[i]);
	    }
	    else if (*iix+ibis::bitvector::bitsPerLiteral() < nrows) {
		// a list of indices
		for (uint32_t i = 0; i < nind; ++i) {
		    uint32_t k = iix[i];
		    setBit(k, val[k]);
		}
	    }
	    else {
		for (uint32_t i = 0; i < nind; ++i) {
		    uint32_t k = iix[i];
		    if (k < nrows)
			setBit(k, val[k]);
		}
	    }
	    ++iset;
	    nind = iset.nIndices();
	    if (*iix >= nrows)
		nind = 0;
	} // while (nind)
	break;}
    case ibis::ULONG: {// unsigned long int
	array_t<uint64_t> val;
	if (! fnm.empty())
	    ierr = ibis::fileManager::instance().getFile(fnm.c_str(), val);
	else
	    ierr = col->getValuesArray(&val);
	if (ierr < 0 || val.empty()) {
	    LOGGER(ibis::gVerbose > 0)
		<< "Warning -- sbiad::construct2 failed to retrieve any value";
	    break;
	}

	if (val.size() > mask.size()) {
	    col->logWarning("sbiad::construct", "the data file \"%s\" "
			    "contains more elements (%lu) then expected "
			    "(%lu)", fnm.c_str(),
			    static_cast<long unsigned>(val.size()),
			    static_cast<long unsigned>(mask.size()));
	    mask.adjustSize(nrows, nrows);
	}
	ibis::bitvector::indexSet iset = mask.firstIndexSet();
	uint32_t nind = iset.nIndices();
	const ibis::bitvector::word_t *iix = iset.indices();
	while (nind) {
	    if (iset.isRange()) { // a range
		uint32_t k = (iix[1] < nrows ? iix[1] : nrows);
		for (uint32_t i = *iix; i < k; ++i)
		    setBit(i, val[i]);
	    }
	    else if (*iix+ibis::bitvector::bitsPerLiteral() < nrows) {
		// a list of indices
		for (uint32_t i = 0; i < nind; ++i) {
		    uint32_t k = iix[i];
		    setBit(k, val[k]);
		}
	    }
	    else {
		for (uint32_t i = 0; i < nind; ++i) {
		    uint32_t k = iix[i];
		    if (k < nrows)
			setBit(k, val[k]);
		}
	    }
	    ++iset;
	    nind = iset.nIndices();
	    if (*iix >= nrows)
		nind = 0;
	} // while (nind)
	break;}
    case ibis::LONG: {// signed long int
	array_t<int64_t> val;
	if (! fnm.empty())
	    ierr = ibis::fileManager::instance().getFile(fnm.c_str(), val);
	else
	    ierr = col->getValuesArray(&val);
	if (ierr < 0 || val.empty()) {
	    LOGGER(ibis::gVerbose > 0)
		<< "Warning -- sbiad::construct2 failed to retrieve any value";
	    break;
	}

	if (val.size() > mask.size()) {
	    col->logWarning("sbiad::construct", "the data file \"%s\" "
			    "contains more elements (%lu) then expected "
			    "(%lu)", fnm.c_str(),
			    static_cast<long unsigned>(val.size()),
			    static_cast<long unsigned>(mask.size()));
	    mask.adjustSize(nrows, nrows);
	}
	ibis::bitvector::indexSet iset = mask.firstIndexSet();
	uint32_t nind = iset.nIndices();
	const ibis::bitvector::word_t *iix = iset.indices();
	while (nind) {
	    if (iset.isRange()) { // a range
		uint32_t k = (iix[1] < nrows ? iix[1] : nrows);
		for (uint32_t i = *iix; i < k; ++i)
		    setBit(i, val[i]);
	    }
	    else if (*iix+ibis::bitvector::bitsPerLiteral() < nrows) {
		// a list of indices
		for (uint32_t i = 0; i < nind; ++i) {
		    uint32_t k = iix[i];
		    setBit(k, val[k]);
		}
	    }
	    else {
		for (uint32_t i = 0; i < nind; ++i) {
		    uint32_t k = iix[i];
		    if (k < nrows)
			setBit(k, val[k]);
		}
	    }
	    ++iset;
	    nind = iset.nIndices();
	    if (*iix >= nrows)
		nind = 0;
	} // while (nind)
	break;}
    case ibis::USHORT: {// unsigned short int
	array_t<uint16_t> val;
	if (! fnm.empty())
	    ierr = ibis::fileManager::instance().getFile(fnm.c_str(), val);
	else
	    ierr = col->getValuesArray(&val);
	if (ierr < 0 || val.empty()) {
	    LOGGER(ibis::gVerbose > 0)
		<< "Warning -- sbiad::construct2 failed to retrieve any value";
	    break;
	}

	if (val.size() > mask.size()) {
	    col->logWarning("sbiad::construct", "the data file \"%s\" "
			    "contains more elements (%lu) then expected "
			    "(%lu)", fnm.c_str(),
			    static_cast<long unsigned>(val.size()),
			    static_cast<long unsigned>(mask.size()));
	    mask.adjustSize(nrows, nrows);
	}
	ibis::bitvector::indexSet iset = mask.firstIndexSet();
	uint32_t nind = iset.nIndices();
	const ibis::bitvector::word_t *iix = iset.indices();
	while (nind) {
	    if (iset.isRange()) { // a range
		uint32_t k = (iix[1] < nrows ? iix[1] : nrows);
		for (uint32_t i = *iix; i < k; ++i)
		    setBit(i, val[i]);
	    }
	    else if (*iix+ibis::bitvector::bitsPerLiteral() < nrows) {
		// a list of indices
		for (uint32_t i = 0; i < nind; ++i) {
		    uint32_t k = iix[i];
		    setBit(k, val[k]);
		}
	    }
	    else {
		for (uint32_t i = 0; i < nind; ++i) {
		    uint32_t k = iix[i];
		    if (k < nrows)
			setBit(k, val[k]);
		}
	    }
	    ++iset;
	    nind = iset.nIndices();
	    if (*iix >= nrows)
		nind = 0;
	} // while (nind)
	break;}
    case ibis::SHORT: {// signed short int
	array_t<int16_t> val;
	if (! fnm.empty())
	    ierr = ibis::fileManager::instance().getFile(fnm.c_str(), val);
	else
	    ierr = col->getValuesArray(&val);
	if (ierr < 0 || val.empty()) {
	    LOGGER(ibis::gVerbose > 0)
		<< "Warning -- sbiad::construct2 failed to retrieve any value";
	    break;
	}

	if (val.size() > mask.size()) {
	    col->logWarning("sbiad::construct", "the data file \"%s\" "
			    "contains more elements (%lu) then expected "
			    "(%lu)", fnm.c_str(),
			    static_cast<long unsigned>(val.size()),
			    static_cast<long unsigned>(mask.size()));
	    mask.adjustSize(nrows, nrows);
	}
	ibis::bitvector::indexSet iset = mask.firstIndexSet();
	uint32_t nind = iset.nIndices();
	const ibis::bitvector::word_t *iix = iset.indices();
	while (nind) {
	    if (iset.isRange()) { // a range
		uint32_t k = (iix[1] < nrows ? iix[1] : nrows);
		for (uint32_t i = *iix; i < k; ++i)
		    setBit(i, val[i]);
	    }
	    else if (*iix+ibis::bitvector::bitsPerLiteral() < nrows) {
		// a list of indices
		for (uint32_t i = 0; i < nind; ++i) {
		    uint32_t k = iix[i];
		    setBit(k, val[k]);
		}
	    }
	    else {
		for (uint32_t i = 0; i < nind; ++i) {
		    uint32_t k = iix[i];
		    if (k < nrows)
			setBit(k, val[k]);
		}
	    }
	    ++iset;
	    nind = iset.nIndices();
	    if (*iix >= nrows)
		nind = 0;
	} // while (nind)
	break;}
    case ibis::UBYTE: {// unsigned char
	array_t<unsigned char> val;
	if (! fnm.empty())
	    ierr = ibis::fileManager::instance().getFile(fnm.c_str(), val);
	else
	    ierr = col->getValuesArray(&val);
	if (ierr < 0 || val.empty()) {
	    LOGGER(ibis::gVerbose > 0)
		<< "Warning -- sbiad::construct2 failed to retrieve any value";
	    break;
	}

	if (val.size() > mask.size()) {
	    col->logWarning("sbiad::construct", "the data file \"%s\" "
			    "contains more elements (%lu) then expected "
			    "(%lu)", fnm.c_str(),
			    static_cast<long unsigned>(val.size()),
			    static_cast<long unsigned>(mask.size()));
	    mask.adjustSize(nrows, nrows);
	}
	ibis::bitvector::indexSet iset = mask.firstIndexSet();
	uint32_t nind = iset.nIndices();
	const ibis::bitvector::word_t *iix = iset.indices();
	while (nind) {
	    if (iset.isRange()) { // a range
		uint32_t k = (iix[1] < nrows ? iix[1] : nrows);
		for (uint32_t i = *iix; i < k; ++i)
		    setBit(i, val[i]);
	    }
	    else if (*iix+ibis::bitvector::bitsPerLiteral() < nrows) {
		// a list of indices
		for (uint32_t i = 0; i < nind; ++i) {
		    uint32_t k = iix[i];
		    setBit(k, val[k]);
		}
	    }
	    else {
		for (uint32_t i = 0; i < nind; ++i) {
		    uint32_t k = iix[i];
		    if (k < nrows)
			setBit(k, val[k]);
		}
	    }
	    ++iset;
	    nind = iset.nIndices();
	    if (*iix >= nrows)
		nind = 0;
	} // while (nind)
	break;}
    case ibis::BYTE: {// signed char
	array_t<signed char> val;
	if (! fnm.empty())
	    ierr = ibis::fileManager::instance().getFile(fnm.c_str(), val);
	else
	    ierr = col->getValuesArray(&val);
	if (ierr < 0 || val.empty()) {
	    LOGGER(ibis::gVerbose > 0)
		<< "Warning -- sbiad::construct2 failed to retrieve any value";
	    break;
	}

	if (val.size() > mask.size()) {
	    col->logWarning("sbiad::construct", "the data file \"%s\" "
			    "contains more elements (%lu) then expected "
			    "(%lu)", fnm.c_str(),
			    static_cast<long unsigned>(val.size()),
			    static_cast<long unsigned>(mask.size()));
	    mask.adjustSize(nrows, nrows);
	}
	ibis::bitvector::indexSet iset = mask.firstIndexSet();
	uint32_t nind = iset.nIndices();
	const ibis::bitvector::word_t *iix = iset.indices();
	while (nind) {
	    if (iset.isRange()) { // a range
		uint32_t k = (iix[1] < nrows ? iix[1] : nrows);
		for (uint32_t i = *iix; i < k; ++i)
		    setBit(i, val[i]);
	    }
	    else if (*iix+ibis::bitvector::bitsPerLiteral() < nrows) {
		// a list of indices
		for (uint32_t i = 0; i < nind; ++i) {
		    uint32_t k = iix[i];
		    setBit(k, val[k]);
		}
	    }
	    else {
		for (uint32_t i = 0; i < nind; ++i) {
		    uint32_t k = iix[i];
		    if (k < nrows)
			setBit(k, val[k]);
		}
	    }
	    ++iset;
	    nind = iset.nIndices();
	    if (*iix >= nrows)
		nind = 0;
	} // while (nind)
	break;}
    case ibis::FLOAT: {// (4-byte) floating-point values
	array_t<float> val;
	if (! fnm.empty())
	    ierr = ibis::fileManager::instance().getFile(fnm.c_str(), val);
	else
	    ierr = col->getValuesArray(&val);
	if (ierr < 0 || val.empty()) {
	    LOGGER(ibis::gVerbose > 0)
		<< "Warning -- sbiad::construct2 failed to retrieve any value";
	    break;
	}

	if (val.size() > mask.size()) {
	    col->logWarning("sbiad::construct", "the data file \"%s\" "
			    "contains more elements (%lu) then expected "
			    "(%lu)", fnm.c_str(),
			    static_cast<long unsigned>(val.size()),
			    static_cast<long unsigned>(mask.size()));
	    mask.adjustSize(nrows, nrows);
	}
	ibis::bitvector::indexSet iset = mask.firstIndexSet();
	uint32_t nind = iset.nIndices();
	const ibis::bitvector::word_t *iix = iset.indices();
	while (nind) {
	    if (iset.isRange()) { // a range
		uint32_t k = (iix[1] < nrows ? iix[1] : nrows);
		for (uint32_t i = *iix; i < k; ++i)
		    setBit(i, val[i]);
	    }
	    else if (*iix+ibis::bitvector::bitsPerLiteral() < nrows) {
		// a list of indices
		for (uint32_t i = 0; i < nind; ++i) {
		    uint32_t k = iix[i];
		    setBit(k, val[k]);
		}
	    }
	    else {
		for (uint32_t i = 0; i < nind; ++i) {
		    uint32_t k = iix[i];
		    if (k < nrows)
			setBit(k, val[k]);
		}
	    }
	    ++iset;
	    nind = iset.nIndices();
	    if (*iix >= nrows)
		nind = 0;
	} // while (nind)
	break;}
    case ibis::DOUBLE: {// (8-byte) floating-point values
	array_t<double> val;
	if (! fnm.empty())
	    ierr = ibis::fileManager::instance().getFile(fnm.c_str(), val);
	else
	    ierr = col->getValuesArray(&val);
	if (ierr < 0 || val.empty()) {
	    LOGGER(ibis::gVerbose > 0)
		<< "Warning -- sbiad::construct2 failed to retrieve any value";
	    break;
	}

	if (val.size() > mask.size()) {
	    col->logWarning("sbiad::construct", "the data file \"%s\" "
			    "contains more elements (%lu) then expected "
			    "(%lu)", fnm.c_str(),
			    static_cast<long unsigned>(val.size()),
			    static_cast<long unsigned>(mask.size()));
	    mask.adjustSize(nrows, nrows);
	}
	ibis::bitvector::indexSet iset = mask.firstIndexSet();
	uint32_t nind = iset.nIndices();
	const ibis::bitvector::word_t *iix = iset.indices();
	while (nind) {
	    if (iset.isRange()) { // a range
		uint32_t k = (iix[1] < nrows ? iix[1] : nrows);
		for (uint32_t i = *iix; i < k; ++i)
		    setBit(i, val[i]);
	    }
	    else if (*iix+ibis::bitvector::bitsPerLiteral() < nrows) {
		// a list of indices
		for (uint32_t i = 0; i < nind; ++i) {
		    uint32_t k = iix[i];
		    setBit(k, val[k]);
		}
	    }
	    else {
		for (uint32_t i = 0; i < nind; ++i) {
		    uint32_t k = iix[i];
		    if (k < nrows)
			setBit(k, val[k]);
		}
	    }
	    ++iset;
	    nind = iset.nIndices();
	    if (*iix >= nrows)
		nind = 0;
	} // while (nind)
	break;}
    case ibis::CATEGORY: // no need for a separate index
	col->logWarning("sbiad::ctor", "no need for another index");
	return;
    default:
	col->logWarning("sbiad::ctor", "unable to create bit sbiad index "
			"for column type %s",
			ibis::TYPESTRING[(int)col->type()]);
	return;
    }

    // make sure all bit vectors are the same size
    for (uint32_t i = 0; i < nobs; ++i) {
	bits[i]->adjustSize(0, nrows);
    }
    // sum up the bitvectors according to interval-encoding
    array_t<bitvector*> beq;
    beq.swap(bits);
    try {    
	uint32_t ke = 0;
	bits.clear();
	for (uint32_t i = 0; i < nb; ++i) {
	    if (bases[i] > 2) {
		nobs = (bases[i] - 1) / 2;
		bits.push_back(new ibis::bitvector);
		bits.back()->copy(*(beq[ke]));
		if (nobs > 64)
		    bits.back()->decompress();
		for (uint32_t j = ke+1; j <= ke+nobs; ++j)
		    *(bits.back()) |= *(beq[j]);
		bits.back()->compress();
		for (uint32_t j = 1; j < bases[i]-nobs; ++j) {
		    bits.push_back(*(bits.back()) - *(beq[ke+j-1]));
		    *(bits.back()) |= *(beq[ke+j+nobs]);
		    bits.back()->compress();
		}
		for (uint32_t j = ke; j < ke+bases[i]; ++j) {
		    delete beq[j];
		    beq[j] = 0;
		}
	    }
	    else {
		bits.push_back(beq[ke]);
		if (bases[i] > 1) {
		    delete beq[ke+1];
		    beq[ke+1] = 0;
		}
	    }
	    ke += bases[i];
	}
    }
    catch (...) {
	LOGGER(ibis::gVerbose > 1)
	    << "Warning -- column::[" << col->name()
	    << "]::construct2 encountered an exception while converting "
	    "to inverval encoding, cleaning up ...";
	for (uint32_t i = 0; i < beq.size(); ++ i)
	    delete beq[i];
	throw;
    }
    beq.clear();
    optionalUnpack(bits, col->indexSpec());

    // write out the current content
    if (ibis::gVerbose > 8) {
 	ibis::util::logger lg;
 	print(lg());
    }
} // ibis::sbiad::construct2
Beispiel #10
0
void loadModuleInterfaces(const char *dll, void **rmodule) // loads the interface from a dll and populates it's internal list
{
#if defined(WIN32)
  UINT errorMode = 0;
  if ( gSuppressLoadError ) errorMode = SEM_FAILCRITICALERRORS;
  UINT oldErrorMode = SetErrorMode(errorMode);
  HMODULE module = LoadLibraryA(dll);
  SetErrorMode(oldErrorMode);
#else
  std::string mname(dll);
  mname.assign(mname.substr(0, mname.rfind(DLL_IN_EXT)));
  mname.insert(0,"lib");
  mname.append(".so");
  HMODULE module = (HMODULE)dlopen(mname.c_str(), RTLD_LAZY);
#endif

  bool found_exports = (module != 0);

  if ( module )
  {    
    #if defined(WIN32)
    void *proc = GetProcAddress(module,"getInterfaceList");
    #else
    void *proc = dlsym(module, "getInterfaceList");
    #endif
    if ( proc )
    {
      const INTERFACE_EXPORT *interfaces;
      NxI32 num = ((PLUGIN_INTERFACE_LIST_FUNC)proc)(&interfaces);
      for (NxI32 i = 0; i < num; i++)
      {
        getHash()[interfaces[i].name] = interfaces[i].func;
        found_exports = true;
      }
    }
    //LEGACY SUPPORT
    else // DO it the old way
    {
      #if defined(WIN32)
      void *proc = GetProcAddress(module,"getInterface");
      #else
      void *proc = dlsym(module, "getInterface");
      #endif
      if ( proc )
      {
        // store the name of the dll sans extension as the classname lookup
        std::string cname(dll);
        getHash()[cname.substr(0, cname.rfind(DLL_IN_EXT))] = (PLUGIN_INTERFACE_FUNC)proc;
        found_exports = true;
      }
    }
    //END LEGACY
  }

  if (found_exports)
  {
    if (rmodule)
      *rmodule = module;
  }
  else
  {
    unloadModule(module);
    if (rmodule)
      *rmodule = 0;
  }
}
Beispiel #11
0
llvm::Module* Module::genLLVMModule(llvm::LLVMContext& context)
{
    bool logenabled = Logger::enabled();
    if (llvmForceLogging && !logenabled)
    {
        Logger::enable();
    }

    IF_LOG Logger::println("Generating module: %s", (md ? md->toChars() : toChars()));
    LOG_SCOPE;

    if (global.params.verbose_cg)
        printf("codegen: %s (%s)\n", toPrettyChars(), srcfile->toChars());

    if (global.errors)
    {
        Logger::println("Aborting because of errors");
        fatal();
    }

    // name the module
#if 1
    // Temporary workaround for http://llvm.org/bugs/show_bug.cgi?id=11479 –
    // just use the source file name, as it is unlikely to collide with a
    // symbol name used somewhere in the module.
    llvm::StringRef mname(srcfile->toChars());
#else
    llvm::StringRef mname(toChars());
    if (md != 0)
        mname = md->toChars();
#endif

    // create a new ir state
    // TODO look at making the instance static and moving most functionality into IrModule where it belongs
    IRState ir(new llvm::Module(mname, context));
    gIR = &ir;
    ir.dmodule = this;

    // reset all IR data stored in Dsymbols
    IrDsymbol::resetAll();

    // set target triple
    ir.module->setTargetTriple(global.params.targetTriple.str());

    // set final data layout
    ir.module->setDataLayout(gDataLayout->getStringRepresentation());
    IF_LOG Logger::cout() << "Final data layout: " << ir.module->getDataLayout() << '\n';

    // allocate the target abi
    gABI = TargetABI::getTarget();

    // debug info
    gIR->DBuilder.EmitCompileUnit(this);

    // handle invalid 'objectø module
    if (!ClassDeclaration::object) {
        error("is missing 'class Object'");
        fatal();
    }

    LLVM_D_InitRuntime();

    // process module members
    for (unsigned k=0; k < members->dim; k++) {
        Dsymbol* dsym = static_cast<Dsymbol*>(members->data[k]);
        assert(dsym);
        Declaration_codegen(dsym);
    }

    // finalize debug info
    gIR->DBuilder.EmitModuleEnd();

    // generate ModuleInfo
    genmoduleinfo();

    build_llvm_used_array(&ir);

#if LDC_LLVM_VER >= 303
    // Add the linker options metadata flag.
    ir.module->addModuleFlag(llvm::Module::AppendUnique, "Linker Options",
                             llvm::MDNode::get(ir.context(), ir.LinkerMetadataArgs));
#endif

#if LDC_LLVM_VER >= 304
    // Emit ldc version as llvm.ident metadata.
    llvm::NamedMDNode *IdentMetadata = ir.module->getOrInsertNamedMetadata("llvm.ident");
    std::string Version("ldc version ");
    Version.append(global.ldc_version);
    llvm::Value *IdentNode[] = {
        llvm::MDString::get(ir.context(), Version)
    };
    IdentMetadata->addOperand(llvm::MDNode::get(ir.context(), IdentNode));
#endif

    // verify the llvm
    verifyModule(*ir.module);

    gIR = NULL;

    if (llvmForceLogging && !logenabled)
    {
        Logger::disable();
    }

    return ir.module;
}