Esempio n. 1
0
/* 
 * ===  FUNCTION  ======================================================================
 *         Name:  download_eng_init
 *  Description:  Initilize the downloader engine.
 * =====================================================================================
 */
extern DownloadEngine_t *
download_eng_init(  Scheduler_t * sc)
{
	const Opts_t *opts = sc->sc_opts;

	DownloadEngine_t *de = (DownloadEngine_t *) malloc( sizeof(DownloadEngine_t) );
	if( ! de ) {
		dl_error(sc, "could not inilize downloader engine");
		return NULL;
	}


	/* create regular expression pattern holder */
	if( (de->de_urire = URIRegexInit()) == NULL) {
		dl_error(sc, "regular expresion error for downloader engine");
		free( de );
		return NULL;
	}

	/* create internet socket */
	if( (de->de_dl = InitDownloadHTML( opts )) == NULL ) {
		dl_error(sc, "could not initilize DownloadHTML");
		URIRegexCleanUp( de->de_urire );
		free( de );
		return NULL;
	} 

	/* set de_sc if all has gone well */
	de->de_sc = sc;

	return de;
}
Esempio n. 2
0
static VALUE
library_dlerror(VALUE self)
{
    char errmsg[1024];
    dl_error(errmsg, sizeof(errmsg));
    return rb_tainted_str_new2(errmsg);
}
Esempio n. 3
0
/*
 * call-seq: initialize(libname, libflags)
 * @param [String] libname name of library to open
 * @param [Fixnum] libflags flags for library to open
 * @return [FFI::DynamicLibrary]
 * @raise {LoadError} if +libname+ cannot be opened
 * A new DynamicLibrary instance.
 */
static VALUE
library_initialize(VALUE self, VALUE libname, VALUE libflags)
{
    Library* library;
    int flags;

    Check_Type(libflags, T_FIXNUM);

    Data_Get_Struct(self, Library, library);
    flags = libflags != Qnil ? NUM2UINT(libflags) : 0;
    
    library->handle = dl_open(libname != Qnil ? StringValueCStr(libname) : NULL, flags);
    if (library->handle == NULL) {
        char errmsg[1024];
        dl_error(errmsg, sizeof(errmsg));
        rb_raise(rb_eLoadError, "Could not open library '%s': %s",
                libname != Qnil ? StringValueCStr(libname) : "[current process]",
                errmsg);
    }
#ifdef __CYGWIN__
    // On Cygwin 1.7.17 "dlsym(dlopen(0,0), 'getpid')" fails. (dlerror: "No such process")
    // As a workaround we can use "dlsym(RTLD_DEFAULT, 'getpid')" instead.
    // Since 0 == RTLD_DEFAULT we won't call dl_close later.
    if (libname == Qnil) {
        dl_close(library->handle);
        library->handle = RTLD_DEFAULT;
    }
#endif
    rb_iv_set(self, "@name", libname != Qnil ? libname : rb_str_new2("[current process]"));
    return self;
}
Esempio n. 4
0
/*
 * Class:     com_kenai_jffi_Foreign
 * Method:    dlerror
 * Signature: ()Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL
Java_com_kenai_jffi_Foreign_dlerror(JNIEnv* env, jobject self)
{
    char errbuf[1024] = { 0 };
    dl_error(errbuf, sizeof(errbuf) - 1);
    return (*env)->NewStringUTF(env, errbuf);
}
Esempio n. 5
0
void DynaLoader::loadLibrary ( const QString& fileName ) 
    /*throw (DynaLoader::LibraryLoadException)*/
{
    freeLibrary();    
    QFileInfo dlInfo( fileName );
    QString dlFileName = dlInfo.fileName();

    QString convertedFileName = fileName;
//TODO: should load MAC frameworks with out .dyld postfix specified
#ifndef _MAC_
    QRegExp regExp( "^" + libPrefix() + ".+\\." + libExtension() + "$" );
    if ( -1 == regExp.indexIn( dlFileName ) ) {
        dlFileName = libPrefix() + dlFileName + "." + libExtension();
        convertedFileName = dlInfo.absolutePath() + QDir::separator() +
                            dlFileName;
    }
#endif
    convertedFileName = QDir::convertSeparators( convertedFileName );
#if defined UNICODE && (defined _WIN32 || defined WIN32)
    handle = dl_open(convertedFileName.toStdWString().data());
#else
    handle = dl_open(QFile::encodeName(convertedFileName));
#endif
    if ( handle == 0 )
        throw LibraryLoadException( dl_error() );
}
Esempio n. 6
0
ProcAddress DynaLoader::getProcAddress ( const QString& funcName ) const
    /*throw (DynaLoader::AddressException)*/
{
    ProcAddress address = dl_sym(handle, funcName.toAscii().data());
    if ( address == 0 )
        throw AddressException( dl_error() );
    return address;
}
Esempio n. 7
0
/* 
 * ===  FUNCTION  ======================================================================
 *         Name:  de_sth_init
 *  Description:  initilise the database and statement handle for the downloader engine,
 *                this must be done inside the downloader thread
 * =====================================================================================
 */
/*  static */DownloadEngine_t *
de_sth_init( DownloadEngine_t *de, Scheduler_t *sc )
{
	de->de_db = DBSQLHandleInit(  sc->sc_opts );
	/* create connection to the database */
	if( de->de_db == NULL) {
		dl_error(sc,"download engine no db");
		return NULL;
	}	

	/*  Initlize the statement handle. */
	de->de_dbsth = dbInitSth( de->de_db );
	if( de->de_dbsth == NULL ) {
		dl_error(sc, "could not create STH");
		return NULL;
	} 
	return de;
}
vtx_t par_eseprefine(
    ctrl_t * const ctrl,
    graph_t * const graph,
    esinfo_t * const esinfo)
{
  vtx_t nmoves;
  wgt_t maxpwgt[2];

  wgt_t * const pwgts = graph->pwgts;

  DL_ASSERT(check_esinfo(esinfo,graph,(pid_t const **)graph->where), \
      "Bad esinfo before refinement");
  DL_ASSERT(check_esbnd(esinfo->bnd,graph),"Bad boundary before refinement");

  maxpwgt[0] = graph->tvwgt * ctrl->tpwgts[0] * ctrl->ubfactor;
  maxpwgt[1] = graph->tvwgt * ctrl->tpwgts[1] * ctrl->ubfactor;

  if (graph->nedges < SERIAL_FM_FACTOR*sqrt(graph->dist.nthreads)) {
    nmoves = __eseprefine_FM1S(ctrl,graph,ctrl->nrefpass,esinfo,maxpwgt);
  } else {
    switch (ctrl->rtype) {
      case MTMETIS_RTYPE_FM:
        nmoves = __eseprefine_FM1S(ctrl,graph,ctrl->nrefpass,esinfo,maxpwgt);
        break;
      case MTMETIS_RTYPE_GREEDY:
        nmoves = __par_eseprefine_GREEDY(ctrl,graph,ctrl->nrefpass,esinfo, \
            maxpwgt);
        break;
      default:
        dl_error("Unknown refinement type for edge separators '%d'\n", \
            ctrl->rtype);
    }
  }

  DL_ASSERT_EQUALS(graph->mincut,par_graph_cut(graph, \
        (pid_t const **)graph->where),"%"PF_WGT_T);
  DL_ASSERT_EQUALS(wgt_lsum(graph->pwgts,2),graph->tvwgt,"%"PF_TWGT_T);
  DL_ASSERT(check_esbnd(esinfo->bnd,graph),"Bad boundary before refinement");

  par_vprintf(ctrl->verbosity,MTMETIS_VERBOSITY_HIGH,"%zu) [%"PF_VTX_T" %" \
      PF_ADJ_T"] {%"PF_WGT_T":%"PF_WGT_T" %"PF_WGT_T" # %"PF_WGT_T":%" \
      PF_WGT_T" %"PF_VTX_T"}\n",graph->level,graph->nvtxs,graph->nedges, \
      pwgts[0],pwgts[1],graph->mincut,maxpwgt[0],maxpwgt[1],nmoves);

  return nmoves;
}
vtx_t par_refine_graph(
    ctrl_t * const ctrl,
    graph_t * const graph)
{
  vtx_t nmoves; 

  tid_t const myid = dlthread_get_id(ctrl->comm);

  nmoves = 0;

  if (myid == 0) {
    dl_start_timer(&(ctrl->timers.refinement));
  }

  switch (ctrl->ptype) {
    case MTMETIS_PTYPE_ND:
    case MTMETIS_PTYPE_VSEP:
      if (graph->vsinfo == NULL) {
        __partparams_vsep(ctrl,graph);
      }
      nmoves = par_vseprefine(ctrl,graph,graph->vsinfo+myid);
      break;
    case MTMETIS_PTYPE_RB:
    case MTMETIS_PTYPE_ESEP:
      if (graph->esinfo == NULL) {
        __partparams_esep(ctrl,graph);
      }
      nmoves = par_eseprefine(ctrl,graph,graph->esinfo+myid);
      break;
    case MTMETIS_PTYPE_KWAY:
      if (graph->kwinfo == NULL) {
        __partparams_kway(ctrl,graph);
      }
      nmoves = par_kwayrefine(ctrl,graph,graph->kwinfo+myid);
      break;
    default:
      dl_error("Unknown partition type '%d'\n",ctrl->ptype);
  }

  if (myid == 0) {
    dl_stop_timer(&(ctrl->timers.refinement));
  }

  return nmoves;
}
Esempio n. 10
0
File: Library.c Progetto: jnr/jffi
/*
 * Class:     com_kenai_jffi_Foreign
 * Method:    dlopen
 * Signature: (Ljava/lang/String;I)J
 */
JNIEXPORT jlong JNICALL
Java_com_kenai_jffi_Foreign_dlopen(JNIEnv* env, jobject self, jstring jPath, jint jFlags)
{
#ifdef _WIN32
    if (jPath == NULL) {
        return p2j(GetModuleHandle(NULL));
    } else {
        wchar_t path[PATH_MAX];
        DWORD dwFlags;
        getWideString(env, path, jPath, sizeof(path) / sizeof(path[0]));
        dwFlags = PathIsRelativeW(path) ? 0 : LOAD_WITH_ALTERED_SEARCH_PATH;
        return p2j(LoadLibraryExW(path, NULL, dwFlags));
    }
#else
    char path_[PATH_MAX];
    const char* path = NULL; // Handle dlopen(NULL, flags);
    void* handle = NULL;
    int flags = 0;
#define F(x) (jFlags & com_kenai_jffi_Foreign_RTLD_##x) != 0 ? RTLD_##x : 0;
    flags |= F(LAZY);
    flags |= F(GLOBAL);
    flags |= F(LOCAL);
    flags |= F(NOW);
#undef F

#ifdef _AIX
    flags |= RTLD_MEMBER; //  Needed for AIX
#endif
    
    if (jPath != NULL) {
        path = path_;
        getMultibyteString(env, path_, jPath, sizeof(path_));
    }

    handle = dl_open(path, flags);
    if (handle == NULL) {
        char errbuf[1024] = { 0 };
        dl_error(errbuf, sizeof(errbuf) - 1);
        throwException(env, UnsatisfiedLink, "%s", errbuf);
    }
    
    return p2j(handle);
#endif
}
Esempio n. 11
0
File: Library.c Progetto: jnr/jffi
JNIEXPORT jlong JNICALL
Java_com_kenai_jffi_Foreign_dlsym(JNIEnv* env, jclass cls, jlong handle, jstring jstr)
{
    char sym[1024];
    void* addr;

    getMultibyteString(env, sym, jstr, sizeof(sym));
#ifndef _WIN32
    dlerror(); // clear any errors
#endif
    addr = dl_sym(j2p(handle), sym);
    if (addr == NULL) {
        char errbuf[1024] = { 0 };
        dl_error(errbuf, sizeof(errbuf) - 1);
        throwException(env, UnsatisfiedLink, "%s", errbuf);
    }

    return p2j(addr);
}
Esempio n. 12
0
static VALUE
library_initialize(VALUE self, VALUE libname, VALUE libflags)
{
    Library* library;
    int flags;

    Check_Type(libflags, T_FIXNUM);

    Data_Get_Struct(self, Library, library);
    flags = libflags != Qnil ? NUM2UINT(libflags) : 0;
    
    library->handle = dl_open(libname != Qnil ? StringValueCStr(libname) : NULL, flags);
    if (library->handle == NULL) {
        char errmsg[1024];
        dl_error(errmsg, sizeof(errmsg));
        rb_raise(rb_eLoadError, "Could not open library '%s': %s",
                libname != Qnil ? StringValueCStr(libname) : "[current process]",
                errmsg);
    }
    rb_iv_set(self, "@name", libname != Qnil ? libname : rb_str_new2("[current process]"));
    return self;
}
vtx_t par_kwayrefine(
    ctrl_t * const ctrl,
    graph_t * const graph,
    kwinfo_t * const kwinfo)
{
  vtx_t nmoves; 

  nmoves = 0;

  switch (ctrl->rtype) {
    case MTMETIS_RTYPE_GREEDY:
      nmoves = __par_kwayrefine_GREEDY(ctrl,graph,ctrl->nrefpass,kwinfo);
      break;
    default:
      dl_error("Unsupported refinement type '%d' for K-Way partitions.", \
          ctrl->rtype);
  }

  par_vprintf(ctrl->verbosity,MTMETIS_VERBOSITY_HIGH,"%zu) [%"PF_VTX_T" %" \
      PF_ADJ_T"] {%"PF_WGT_T" %"PF_VTX_T"}\n",graph->level,graph->nvtxs, \
      graph->nedges,graph->mincut,nmoves);

  return nmoves;
}