Beispiel #1
0
int
runstatement_ts(const char * module, const char * stmt)
{
    PyObject *stmtstr, *modstr, *mod, *dict, *result; 
    char modbuff[120], *p1, *p2;
    /* find module to import */
    if (module != NULL && strlen(module) > 0) {
        modstr = strLenToUtfPy((char *)module, strlen(module));
        strcpy(modbuff, "import ");
        strcat(modbuff, PyString_AS_STRING(modstr));
        PyRun_SimpleString(modbuff);
    } else {
        modstr = NULL;
    }
    mod = PyImport_AddModule("__main__");
    dict = PyModule_GetDict(mod);
    stmtstr = strLenToUtfPy((char *)stmt, strlen(stmt));
    p1 = PyString_AS_STRING(stmtstr);
    /* run the statement */
    p2 = malloc(strlen(p1) + 120);
    strcpy(p2, "x = ");
    if (modstr != NULL) {
        strcat(p2, PyString_AS_STRING(modstr));
        strcat(p2, ".");
    }
    strcat(p2, p1);
    PyRun_SimpleString(p2);
    free(p2);
    Py_XDECREF(stmtstr);
    Py_XDECREF(modstr);
    result = PyDict_GetItemString(dict, "x");
    if (result == NULL)
        return -1;
    return newHandle(result);
}
Beispiel #2
0
int
dictkeys(const int handle)
{
    PyObject *v;
    PyObject *obj = getObjectFromHandle(handle);
    v = PyDict_Keys(obj);
    return newHandle(v);
}
Beispiel #3
0
int
runpython(const char *modname, const char * clsname, const char * funcname, const int paramhandle)
{
    PyObject *modstr, *mod, *clsstr, *cls, *funcstr, *func, *plist, *args, *retval; 
    /* convert module, class and func to utf-8 */
    modstr = strLenToUtfPy((char *)modname, strlen(modname));
    plist = getObjectFromHandle(paramhandle);
    /* parameters */
    if (!PyList_Check(plist))
        return newHandle(PyString_FromString("Error: parameters must be a list."));
    /* import modules */
    mod = PyImport_Import(modstr);
    if (mod == NULL)
    {
        Py_DECREF(modstr);
        return newHandle(PyString_FromString("Error: module not found."));
    }
    if (clsname != NULL)
        clsstr = strLenToUtfPy((char *)clsname, strlen(clsname));
    funcstr = strLenToUtfPy((char *)funcname, strlen(funcname));
    if (clsname != NULL && strlen(clsname) > 0)
    {
        cls = PyObject_GetAttr(mod, clsstr);
        if (cls != NULL)
            func = PyObject_GetAttr(cls, funcstr);
    } else {
        func = PyObject_GetAttr(mod, funcstr);
    }
    if (!func || !PyCallable_Check(func))
    {
        Py_XDECREF(cls);
        Py_XDECREF(mod);
        return newHandle(PyString_FromString("Error: function not found."));
    }
    args = PyList_AsTuple(plist);
    retval = PyObject_CallObject(func, args);
    Py_XDECREF(args);
    Py_XDECREF(func);
    Py_XDECREF(funcstr);
    Py_XDECREF(cls);
    Py_XDECREF(clsstr);
    Py_XDECREF(mod);
    Py_XDECREF(modstr);
    /* keep the return value */
    return newHandle(retval);
}
Beispiel #4
0
LispRef newString(LispRef stream, LispRef eos_error_p, LispRef eos_value)
{
    WITH_DEBUG(fprintf(stderr, "newString\n"));
    LispRef str;
    eul_read_utf(str);
    newHandle(stream, str);
    return str;
}
Beispiel #5
0
std::unique_ptr<CurlHandle> CurlHandle::clone() const {
  CURL* cHandle = curl_easy_duphandle(mCurl);
  runtimeAssert("Error when trying to curl_easy_duphandle() a handle",
                cHandle != NULL);
  unique_ptr<CurlHandle> newHandle(new CurlHandle(cHandle));

  return newHandle;
}
Beispiel #6
0
LispRef newClass(LispRef stream, LispRef eos_error_p, LispRef eos_value)
{
    WITH_DEBUG(fprintf(stderr, "newClass\n"));

    LispRef name = content(stream, eos_error_p, eos_value);
    LispRef supers = content(stream, eos_error_p, eos_value);
    LispRef slot_descs = content(stream, eos_error_p, eos_value);
    LispRef res = eul_serial_make_class(name, supers, slot_descs);
    newHandle(stream, res);

    return res;
}
Beispiel #7
0
LispRef newObject(LispRef stream, LispRef eos_error_p, LispRef eos_value)
{
    WITH_DEBUG(fprintf(stderr, "newObject\n"));

    LispRef cl = content(stream, eos_error_p, eos_value);
    LispRef res = eul_serial_allocate_instance(cl);
    newHandle(stream, res);
    LispRef inits = content(stream, eos_error_p, eos_value);
    eul_serial_initialize_instance(res, inits);

    return res;
}
Beispiel #8
0
int
dictget(const int handle, const char * key)
{
    PyObject *v;
    PyObject *obj = getObjectFromHandle(handle);
    PyObject *k = strLenToUtfPy((char *)key, strlen(key));
    v = PyDict_GetItem(obj, k);
    Py_DECREF(k);
    if (v == NULL)
        return 0;
    Py_INCREF(v);
    return newHandle(v);
}
Beispiel #9
0
LispRef newCons(LispRef stream, LispRef eos_error_p, LispRef eos_value)
{
    WITH_DEBUG(fprintf(stderr, "newCons\n"));

    LispRef res;
    eul_allocate_empty_cons(res);
    newHandle(stream, res);
    LispRef the_car = content(stream, eos_error_p, eos_value);
    LispRef the_cdr = content(stream, eos_error_p, eos_value);
    eul_car(res) = the_car;
    eul_cdr(res) = the_cdr;

    return res;
}
	HResource Resources::_createResourceHandle(const SPtr<Resource>& obj)
	{
		String uuid = UUIDGenerator::generateRandom();
		HResource newHandle(obj, uuid);

		{
			Lock lock(mLoadedResourceMutex);

			LoadedResourceData& resData = mLoadedResources[uuid];
			resData.resource = newHandle.getWeak();
			mHandles[uuid] = newHandle.getWeak();
		}
	
		return newHandle;
	}
PassRefPtr<ResourceHandle> ResourceHandle::create(const ResourceRequest& request, ResourceHandleClient* client,
    Frame* frame, bool defersLoading, bool shouldContentSniff, bool mightDownloadFromHandle)
{
    RefPtr<ResourceHandle> newHandle(new ResourceHandle(request, client, defersLoading, shouldContentSniff, mightDownloadFromHandle));

    if (!portAllowed(request)) {
        newHandle->scheduleBlockedFailure();
        return newHandle.release();
    }
        
    if (newHandle->start(frame))
        return newHandle.release();

    return 0;
}
Beispiel #12
0
/**************************************************************************//**
* \fn      CAENComm_ErrorCode STDCALL CAENComm_OpenDevice(CAENComm_DeviceDescr dd, int *handle);
* \brief   Open the device
*
* \param	[IN] LinkType: the link used by the device(CAENComm_USB|CAENComm_PCI_OpticalLink|CAENComm_PCIE_OpticalLink|CAENComm_PCIE)
* \param	[IN] LinkNum: The link number
* \param	[IN] ConetNode: The board number in the link.
* \param	[IN] VMEBaseAddress: The VME base address of the board
* \param	[OUT] handle: device handler
* \return  0 = Success; negative numbers are error codes
* \note  We ignore the link type -- it's always going to be SBS
* \note  The LinkNum will be the SBS interface board.
* \note  The ConetNode will be ignored,.
* \note  We are always going to open BT_DEV_A32
* \note  SBS errors are converted to a generic error.
*
******************************************************************************/
CAENComm_ErrorCode STDCALL CAENComm_OpenDevice(CAENComm_ConnectionType LinkType,
					       int LinkNum, int ConetNode, 
					       uint32_t VMEBaseAddress, 
					       int *handle)
{
  CAENComm_ErrorCode status =CAENComm_Success;	// optimistic completion code.

  try {
    char deviceName[PATH_MAX+1];
    bt_desc_t*  btHandle = new bt_desc_t;;
    void*      pMap;
    
    // Generate our device name and attempt to open it:
    

    const char*  pName = bt_gen_name(LinkNum, BT_DEV_A32, deviceName, sizeof(deviceName));
    
    if (pName != deviceName) throw CAENComm_GenericError;

    bt_error_t ok = bt_open(btHandle, pName, BT_RDWR);
    if (ok != BT_SUCCESS) throw CAENComm_GenericError;

    // Attempt to map the address space:

    ok = bt_mmap(*btHandle, &pMap, 
		 VMEBaseAddress, gWindowSize, 
		 BT_RDWR, BT_SWAP_NONE);

    if(ok != BT_SUCCESS) throw CAENComm_GenericError;

    // Create the handle, fill it in, validate it and return its index to the caller.

    int iHandle              = newHandle();
    pNSCLHandle pHandle      = &(gHandles[iHandle]);
    pHandle->s_pSbsHandle    = btHandle;
    pHandle->s_nBaseAddress  = VMEBaseAddress;
    pHandle->s_pMappedMemory = pMap;
    pHandle->s_fValid        = true;
    *handle                  = iHandle;

  }
  catch(CAENComm_ErrorCode code) {
    status = code;
  }
  return status;
    

}
HTOOLHANDLE CClientTools::AttachToEntity( EntitySearchResult entityToAttach )
{
	C_BaseEntity *ent = reinterpret_cast< C_BaseEntity * >( entityToAttach );
	if ( !ent )
		return (HTOOLHANDLE)0;

	HTOOLHANDLE curHandle = ent->GetToolHandle();
	if ( curHandle != 0 )
		return curHandle; // Already attaached

	HToolEntry_t newHandle( s_nNextHandle++, ent );

	m_Handles.Insert( newHandle );
	m_ActiveHandles.AddToTail( newHandle.m_Handle );

	return (HTOOLHANDLE)newHandle.m_Handle;
}
Beispiel #14
0
PassRefPtr<ResourceHandle> ResourceHandle::create(NetworkingContext* context, const ResourceRequest& request, ResourceHandleClient* client, bool defersLoading, bool shouldContentSniff)
{
    BuiltinResourceHandleConstructorMap::iterator protocolMapItem = builtinResourceHandleConstructorMap().find(request.url().protocol());

    if (protocolMapItem != builtinResourceHandleConstructorMap().end())
        return protocolMapItem->value(request, client);

    RefPtr<ResourceHandle> newHandle(adoptRef(new ResourceHandle(context, request, client, defersLoading, shouldContentSniff)));

    if (newHandle->d->m_scheduledFailureType != NoFailure)
        return newHandle.release();

    if (newHandle->start())
        return newHandle.release();

    return 0;
}
Beispiel #15
0
LispRef newFunction(LispRef stream, LispRef eos_error_p, LispRef eos_value)
{
    WITH_DEBUG(fprintf(stderr, "newFunction\n"));

    LispRef name = content(stream, eos_error_p, eos_value);
    LispRef domain = content(stream, eos_error_p, eos_value);
    LispRef setter = content(stream, eos_error_p, eos_value);
    LispRef env = content(stream, eos_error_p, eos_value);

    int n;
    read_int(n);

    WITH_DEBUG(fprintf(stderr, "size: %d\n", n));

    char *data = read_bytes(n);
    char *new_data = (char *)gc_malloc(n);
    memcpy(new_data, data, n);

    LispRef code;
    eul_allocate_nstring(code, new_data, n);

    LispRef res;
    eul_allocate_lambda1(res, name, domain, code);
    LAMBDA_SETTER(res) = setter;
    LAMBDA_ENV(res) = env;
    newHandle(stream, res);
    LispRef refs = content(stream, eos_error_p, eos_value);

    WITH_DEBUG(fprintf(stderr, "!!!Refs: "));
    WITH_DEBUG(fprint_ref(stderr, refs));
    WITH_DEBUG(fprintf(stderr, "\n"));

    if (refs != eul_nil)
    {
        if (eul_link_lambda_refs(res, refs) == eul_nil)
        {
            LispRef str;
            eul_allocate_string(str, "cannot serialize foreign function");
            eul_serial_error(stream, str, eul_nil);
            return eul_nil;
        }
    }

    return res;
}
Beispiel #16
0
TInt CCmdUndertaker::DoWork()
	{
	TRequestStatus mainThreadDeadStat;
	iMainThread.Logon(mainThreadDeadStat);
	
	TRequestStatus stat;
	TInt deadThreadHandle;
	TInt err = KErrNone;
	for (;;)
		{
		err = iUndertaker.Logon(stat, deadThreadHandle);
		TRequestStatus* s = &iMainThreadStat;
		if (err)
			{
			iMainThread.RequestComplete(s, err);
			break;
			}
		else
			{
			User::WaitForRequest(stat, mainThreadDeadStat);
			if (mainThreadDeadStat.Int() != KRequestPending)
				{
				// We're dead
				err = mainThreadDeadStat.Int();
				// Have to clean up our process-owned handles here...
				CloseProcessOwnedHandles();
				break;
				}
			// Have to duplicate the thread handle so the main thread can see it. Can't seem to persuade RUndertaker to give us a process-owned handle in the first place
			RThread origHandle;
			origHandle.SetHandle(deadThreadHandle);
			RThread newHandle(origHandle);
			err = newHandle.Duplicate(RThread(), EOwnerProcess);
			origHandle.Close();
			if (!err)
				{
				iLock.Wait();
				err = iHandles.Append(newHandle.Handle());
				iLock.Signal();
				}
			iMainThread.RequestComplete(s, err);
			}
		}
	return err;
	}
Beispiel #17
0
LispRef newVector(LispRef stream, LispRef eos_error_p, LispRef eos_value)
{
    WITH_DEBUG(fprintf(stderr, "newVector\n"));

    int n;
    read_int(n);

    LispRef vec;
    eul_allocate_vector(vec, n, eul_nil);
    newHandle(stream, vec);

    for (int i = 0; i < n; i++)
    {
        slot_ref(vec, i) = content(stream, eos_error_p, eos_value);
    }

    return vec;
}
Beispiel #18
0
void Database::addInitialHandles( uint desired )
{
    Endpoint srv( Configuration::DbAddress, Configuration::DbPort );

    if ( desired == 0 ) {
        uint max = Configuration::scalar( Configuration::DbMaxHandles );
        desired = 3;
        if ( Configuration::toggle( Configuration::Security ) &&
             srv.protocol() == Endpoint::Unix )
            desired = max;
        if ( desired > max )
            desired = max;
    }

    while ( desired ) {
        newHandle();
        desired--;
    }
}
void HbPredictionFactoryPrivate::initialize()
{
    clearEngineData();
    for (int j = 0; j < activePlugins.count(); j++) {
        delete activePlugins[j];
    }
    activePlugins.clear();

    QStringList pathList = HbInputSettingProxy::predictionEnginePaths();

    for (int kk = 0; kk < pathList.count(); kk++) {
        QDir dir(pathList[kk]);

        for (unsigned int i = 0; i < dir.count(); i++) {
            QString fileName = dir[i];

            if (!QLibrary::isLibrary(dir[i])) {
                continue;
            }

            QPluginLoader loader(dir.absoluteFilePath(fileName));
            QObject *engine_base = loader.instance();
            if (engine_base) {
                HbPredictionPlugin *plugin = qobject_cast<HbPredictionPlugin *>(engine_base);
                if (plugin) {
                    HbEngineData data;
                    data.languages = plugin->languages();
                    data.type = plugin->type();
                    data.handle = newHandle();
                    data.filename = fileName;
                    data.vendorId = plugin->vendorId();
                    engines.append(data);
                    delete plugin;
                } else {
                    qDebug("HbPredictionFactory::Initialize qobject_cast failed, probably loading ime plugin.");
                }
            } else {
                qDebug("HbPredictionFactory: Unable to create found plugin instance!");
            }
        }
    }
}
Beispiel #20
0
PassRefPtr<ResourceHandle> ResourceHandle::create(const ResourceRequest& request, ResourceHandleClient* client,
    Frame* frame, bool defersLoading, bool shouldContentSniff)
{
    if (shouldContentSniff)
        shouldContentSniff = shouldContentSniffURL(request.url());

    RefPtr<ResourceHandle> newHandle(adoptRef(new ResourceHandle(request, client, defersLoading, shouldContentSniff)));

    if (!request.url().isValid()) {
        newHandle->scheduleFailure(InvalidURLFailure);
        return newHandle.release();
    }

    if (!portAllowed(request.url())) {
        newHandle->scheduleFailure(BlockedFailure);
        return newHandle.release();
    }
        
    if (newHandle->start(frame))
        return newHandle.release();

    return 0;
}
Beispiel #21
0
int
runpython_ts(const char *modname, const char * clsname, const char * funcname, const int paramhandle)
{
    PyObject *modstr, *mod, *clsstr, *cls, *funcstr, *func, *plist, *args, *retval; 
    /* convert module, class and func to utf-8 */
    modstr = strLenToUtfPy((char *)modname, strlen(modname));
    plist = getObjectFromHandle(paramhandle);
    /* parameters */
    if (PyString_Check(plist)) {
        /* parameter should be a json string */
        plist = from_json(plist); 
        if (plist == NULL) {
            error_msg("Error in json parameter string");
            return -1;
        }
    }
    if (!PyList_Check(plist)) {
        error_msg("Error in runpython: parameters must be a list");
        return -1;
    }
    /* import modules */
    mod = PyImport_Import(modstr);
    if (mod == NULL)
    {
        Py_DECREF(modstr);
        error_msg("Error in runpython: Module not found");
        return -1;
    }
    if (clsname != NULL)
        clsstr = strLenToUtfPy((char *)clsname, strlen(clsname));
    funcstr = strLenToUtfPy((char *)funcname, strlen(funcname));
    if (clsname != NULL && strlen(clsname) > 0)
    {
        cls = PyObject_GetAttr(mod, clsstr);
        if (cls != NULL)
            func = PyObject_GetAttr(cls, funcstr);
    } else {
        func = PyObject_GetAttr(mod, funcstr);
    }
    if (!func || !PyCallable_Check(func))
    {
        Py_XDECREF(cls);
        Py_XDECREF(mod);
        error_msg("Error in runpython: Function not found");
        return -1;
    }
    args = PyList_AsTuple(plist);
    retval = PyObject_CallObject(func, args);
    Py_XDECREF(args);
    Py_XDECREF(func);
    Py_XDECREF(funcstr);
    Py_XDECREF(cls);
    Py_XDECREF(clsstr);
    Py_XDECREF(mod);
    Py_XDECREF(modstr);
    if (!retval) {
        PyErr_Print();
        error_msg("Error in runpython: See QPRINT for details");
        return -1;
    }
    /* keep the return value */
    return newHandle(retval);
}
Beispiel #22
0
int
dictnew(void)
{
    PyObject *v = PyDict_New();
    return newHandle(v);
}
Beispiel #23
0
int
getparams(void)
{
    PyObject *o = PyDict_GetItemString(initdict, "params");
    return newHandle(o);
}
Beispiel #24
0
void Database::runQueue()
{
    int connecting = 0;
    int busy = 0;

    if ( !queryQueueLength )
        queryQueueLength = new GraphableNumber( "query-queue-length" );
    if ( !busyDbConnections )
        busyDbConnections = new GraphableNumber( "active-db-connections" );

    // First, we give each idle handle a Query to process

    Query * first = queries->firstElement();

    List< Database >::Iterator it( handles );
    while ( it ) {
        State st = it->state();

        if ( st != Connecting && // connecting isn't working
             st != Broken && // broken isn't working
             ( !it->usable() || // processing a query is working
               st == InTransaction || // occupied by a transaction is, too
               st == FailedTransaction ) )
            busy++;

        if ( st == Idle && it->usable() ) {
            it->processQueue();
            if ( queries->isEmpty() ) {
                queryQueueLength->setValue( 0 );
                busyDbConnections->setValue( busy );
                return;
            }
        }
        else if ( st == Connecting ) {
            connecting++;
        }

        ++it;
    }

    queryQueueLength->setValue( queries->count() );
    busyDbConnections->setValue( busy );

    // If there's nothing to do, or we did get something done, then we
    // don't even consider opening a new database connection.
    if ( queries->isEmpty() || first != queries->firstElement() )
        return;

    // Even if we want to, we cannot create unix-domain handles when
    // we're running within chroot.
    if ( server().protocol() == Endpoint::Unix &&
         !server().address().startsWith( File::root() ) )
        return;

    // And even if we're asked to, we don't create handles while
    // shutting down.
    if ( EventLoop::global()->inShutdown() )
        return;

    // We create at most one new handle per interval.
    int interval = Configuration::scalar( Configuration::DbHandleInterval );
    if ( time( 0 ) - lastCreated < interval )
        return;

    // If we don't have too many, we can create another handle!
    uint max = Configuration::scalar( Configuration::DbMaxHandles );
    if ( handles->count() < max )
        newHandle();
}
VertexShaderHandle VertexShaderManager::newVertexShader( VertexShader & shader )
{
    VertexShaderHandle vsh = newHandle();
    fromHandle( vsh ) = shader;
    return vsh;
}