コード例 #1
0
ファイル: Script.cpp プロジェクト: Zylann/SnowfeetEngine
//------------------------------------------------------------------------------
bool Script::compileString(
    const std::string & sourceCode, 
    const std::string & scriptName)
{
    releaseObject();

    if(SQ_FAILED(sq_compilebuffer(m_vm, 
        sourceCode.c_str(), 
        static_cast<SQInteger>(sourceCode.size()),
        scriptName.c_str(), 
        true // raise error
        )))
    {
        return false;
    }

    sq_getstackobj(m_vm, -1, &m_object);
    sq_addref(m_vm, &m_object);
    sq_pop(m_vm, 1);

    return true;
}
コード例 #2
0
ファイル: socketSSL.c プロジェクト: eXtremal-ik7/libp2p
static void finishSSLOp(SSLOp *Op, AsyncOpStatus status)
{
  SSLOp *current = Op->next;
  if (Op->type != sslOpWrite)
    Op->info.socket->current = current;
 
  Op->info.status = status;
  if (Op->info.callback)
    Op->info.callback(&Op->info);
  releaseObject(Op->info.socket->base, Op, sslPoolId);
  if (current && Op->type != sslOpWrite) {
    SSLSocket *S = current->info.socket;
    switch (current->type) {
      case sslOpConnect :
        asyncConnect(S->object, &current->address, current->usTimeout, connectProc, current);
        break;
      case sslOpRead :
        asyncRead(S->object, S->sslReadBuffer, S->sslReadBufferSize, afNone, current->usTimeout, readProc, current);
        break;
    }
  }
}
コード例 #3
0
ファイル: callJNI.c プロジェクト: cran/rJava
/* loader: if NULL does NOT use any custom loader but uses system FindClass,
   otherwise Class.forName(..., true, loader) if user first and system only as fall-back */
HIDE jclass findClass(JNIEnv *env, const char *cName, jobject loader) {
  if (loader) {
    char cn[128], *c=cn;
    jobject cns;
    jclass cl;

    strcpy(cn, cName);
    while (*c) { if (*c=='/') *c='.'; c++; };
    cns = newString(env, cn);
    if (!cns) error("unable to create Java string from '%s'", cn);
#ifdef DEBUG_CL
    printf("findClass(\"%s\") [with %s loader]\n", cn, (loader && loader == oClassLoader) ? "rJava" : "custom");
#endif
    cl = (jclass) (*env)->CallStaticObjectMethod(env, javaClassClass, mid_forName, cns, (jboolean) 1, loader);
#if RJAVA_LEGACY
    clx(env);
#endif
    _mp(MEM_PROF_OUT("  %08x LNEW class\n", (int) cl))
    releaseObject(env, cns);
#ifdef DEBUG_CL
    printf(" - got %x\n", (unsigned int) cl);
#endif
#if RJAVA_LEGACY
    if (cl)
#endif
	return cl;
  }
#ifdef DEBUG_CL
  printf("findClass(\"%s\") (no loader)\n", cName);
#endif
  { 
    jclass cl = (*env)->FindClass(env, cName);
    _mp(MEM_PROF_OUT("  %08x LNEW class\n", (int) cl))
#ifdef DEBUG_CL
    printf(" - got %x\n", (unsigned int) cl); 
#endif
    return cl;
  }
}
コード例 #4
0
ファイル: config.cpp プロジェクト: hypronet/Equalizer
void Config::releaseData()
{
    releaseObject( &_initData );
}
コード例 #5
0
ファイル: dns.c プロジェクト: fukusaka/polipo
static int
really_do_dns(AtomPtr name, ObjectPtr object)
{
    int rc;
    DnsQueryPtr query;
    AtomPtr message = NULL;
    int id;
    AtomPtr a = NULL;

    if(a == NULL) {
        if(name == atomLocalhost || name == atomLocalhostDot) {
            char s[1 + sizeof(HostAddressRec)];
            memset(s, 0, sizeof(s));
            s[0] = DNS_A;
            s[1] = 4;
            s[2] = 127;
            s[3] = 0;
            s[4] = 0;
            s[5] = 1;
            a = internAtomN(s, 1 + sizeof(HostAddressRec));
            if(a == NULL) {
                abortObject(object, 501,
                            internAtom("Couldn't allocate address"));
                notifyObject(object);
                errno = ENOMEM;
                return -1;
            }
        }
    }

    if(a == NULL) {
        struct in_addr ina;
        rc = inet_aton(name->string, &ina);
        if(rc == 1) {
            char s[1 + sizeof(HostAddressRec)];
            memset(s, 0, sizeof(s));
            s[0] = DNS_A;
            s[1] = 4;
            memcpy(s + 2, &ina, 4);
            a = internAtomN(s, 1 + sizeof(HostAddressRec));
            if(a == NULL) {
                abortObject(object, 501,
                            internAtom("Couldn't allocate address"));
                notifyObject(object);
                errno = ENOMEM;
                return -1;
            }
        }
    }
#ifdef HAVE_IPv6
    if(a == NULL)
        a = rfc2732(name);
#endif

    if(a) {
        object->headers = a;
        object->age = current_time.tv_sec;
        object->expires = current_time.tv_sec + 240;
        object->flags &= ~(OBJECT_INITIAL | OBJECT_INPROGRESS);
        notifyObject(object);
        return 0;
    }

    rc = establishDnsSocket();
    if(rc < 0) {
        do_log_error(L_ERROR, -rc, "Couldn't establish DNS socket.\n");
        message = internAtomError(-rc, "Couldn't establish DNS socket");
        goto fallback;
    }

    /* The id is used to speed up detecting replies to queries that
       are no longer current -- see dnsReplyHandler. */
    id = (idSeed++) & 0xFFFF;

    query = malloc(sizeof(DnsQueryRec));
    if(query == NULL) {
        do_log(L_ERROR, "Couldn't allocate DNS query.\n");
        message = internAtom("Couldn't allocate DNS query");
        goto fallback;
    }
    query->id = id;
    query->inet4 = NULL;
    query->inet6 = NULL;
    query->name = name;
    query->time = current_time.tv_sec;
    query->object = retainObject(object);
    query->timeout = 4;
    query->timeout_handler = NULL;
    query->next = NULL;

    query->timeout_handler = 
        scheduleTimeEvent(query->timeout, dnsTimeoutHandler,
                          sizeof(query), &query);
    if(query->timeout_handler == NULL) {
        do_log(L_ERROR, "Couldn't schedule DNS timeout handler.\n");
        message = internAtom("Couldn't schedule DNS timeout handler");
        goto free_fallback;
    }
    insertQuery(query);

    object->flags |= OBJECT_INPROGRESS;
    rc = sendQuery(query);
    if(rc < 0) {
        if(rc != -EWOULDBLOCK && rc != -EAGAIN && rc != -ENOBUFS) {
            object->flags &= ~OBJECT_INPROGRESS;
            message = internAtomError(-rc, "Couldn't send DNS query");
            goto remove_fallback;
        }
        /* else let it timeout */
    }
    releaseAtom(message);
    return 1;

 remove_fallback:
    removeQuery(query);
 free_fallback:
    releaseObject(query->object);
    cancelTimeEvent(query->timeout_handler);
    free(query);
 fallback:
    if(dnsUseGethostbyname >= 1) {
        releaseAtom(message);
        do_log(L_WARN, "Falling back on gethostbyname.\n");
        return really_do_gethostbyname(name, object);
    } else {
        abortObject(object, 501, message);
        notifyObject(object);
        return 1;
    }
}
コード例 #6
0
ファイル: dns.c プロジェクト: fukusaka/polipo
int
do_gethostbyname(char *origname,
                 int count,
                 int (*handler)(int, GethostbynameRequestPtr),
                 void *data)
{
    ObjectPtr object;
    int n = strlen(origname);
    AtomPtr name;
    GethostbynameRequestRec request;
    int done, rc;

    memset(&request, 0, sizeof(request));
    request.name = NULL;
    request.addr = NULL;
    request.error_message = NULL;
    request.count = count;
    request.handler = handler;
    request.data = data;

    if(n <= 0 || n > 131) {
        if(n <= 0) {
            request.error_message = internAtom("empty name");
            do_log(L_ERROR, "Empty DNS name.\n");
            done = handler(-EINVAL, &request);
        } else {
            request.error_message = internAtom("name too long");
            do_log(L_ERROR, "DNS name too long.\n");
            done = handler(-ENAMETOOLONG, &request);
        }
        assert(done);
        releaseAtom(request.error_message);
        return 1;
    }

    if(origname[n - 1] == '.')
        n--;

    name = internAtomLowerN(origname, n);

    if(name == NULL) {
        request.error_message = internAtom("couldn't allocate name");
        do_log(L_ERROR, "Couldn't allocate DNS name.\n");
        done = handler(-ENOMEM, &request);
        assert(done);
        releaseAtom(request.error_message);
        return 1;
    }

    request.name = name;
    request.addr = NULL;
    request.error_message = NULL;
    request.count = count;
    request.object = NULL;
    request.handler = handler;
    request.data = data;

    object = findObject(OBJECT_DNS, name->string, name->length);
    if(object == NULL || objectMustRevalidate(object, NULL)) {
        if(object) {
            privatiseObject(object, 0);
            releaseObject(object);
        }
        object = makeObject(OBJECT_DNS, name->string, name->length, 1, 0,
                            NULL, NULL);
        if(object == NULL) {
            request.error_message = internAtom("Couldn't allocate object");
            do_log(L_ERROR, "Couldn't allocate DNS object.\n");
            done = handler(-ENOMEM, &request);
            assert(done);
            releaseAtom(name);
            releaseAtom(request.error_message);
            return 1;
        }
    }

    if((object->flags & (OBJECT_INITIAL | OBJECT_INPROGRESS)) ==
       OBJECT_INITIAL) {
        if(dnsUseGethostbyname >= 3)
            rc = really_do_gethostbyname(name, object);
        else
            rc = really_do_dns(name, object);
        if(rc < 0) {
            assert(!(object->flags & (OBJECT_INITIAL | OBJECT_INPROGRESS)));
            goto fail;
        }
    }

    if(dnsUseGethostbyname >= 3)
        assert(!(object->flags & OBJECT_INITIAL));

#ifndef NO_FANCY_RESOLVER    
    if(object->flags & OBJECT_INITIAL) {
        ConditionHandlerPtr chandler;
        assert(object->flags & OBJECT_INPROGRESS);
        request.object = object;
        chandler = conditionWait(&object->condition, dnsHandler,
                                 sizeof(request), &request);
        if(chandler == NULL)
            goto fail;
        return 1;
    }
#endif

    if(object->headers && object->headers->length > 0) {
        if(object->headers->string[0] == DNS_A)
            assert(((object->headers->length - 1) % 
                    sizeof(HostAddressRec)) == 0);
        else
            assert(object->headers->string[0] == DNS_CNAME);
        request.addr = retainAtom(object->headers);
    } else if(object->message) {
        request.error_message = retainAtom(object->message);
    }

    releaseObject(object);

    if(request.addr && request.addr->length > 0)
        done = handler(1, &request);
    else
        done = handler(-EDNS_HOST_NOT_FOUND, &request);
    assert(done);

    releaseAtom(request.addr); request.addr = NULL;
    releaseAtom(request.name); request.name = NULL;
    releaseAtom(request.error_message); request.error_message = NULL;
    return 1;

 fail:
    releaseNotifyObject(object);
    done = handler(-errno, &request);
    assert(done);
    releaseAtom(name);
    return 1;
}
コード例 #7
0
ファイル: dns.c プロジェクト: fukusaka/polipo
static int
dnsGethostbynameFallback(int id, AtomPtr message)
{
    DnsQueryPtr query, previous;
    ObjectPtr object;

    if(inFlightDnsQueries == NULL) {
        releaseAtom(message);
        return 1;
    }

    query = NULL;
    if(id < 0 || inFlightDnsQueries->id == id) {
        previous = NULL;
        query = inFlightDnsQueries;
    } else {
        previous = inFlightDnsQueries;
        while(previous->next) {
            if(previous->next->id == id) {
                query = previous->next;
                break;
            }
            previous = previous->next;
        }
        if(!query) {
            previous = NULL;
            query = inFlightDnsQueries;
        }
    }

    if(previous == NULL) {
        inFlightDnsQueries = query->next;
        if(inFlightDnsQueries == NULL)
            inFlightDnsQueriesLast = NULL;
    } else {
        previous->next = query->next;
        if(query->next == NULL)
            inFlightDnsQueriesLast = NULL;
    }

    object = makeObject(OBJECT_DNS, query->name->string, query->name->length,
                        1, 0, NULL, NULL);
    if(!object) {
        do_log(L_ERROR, "Couldn't make DNS object.\n");
        releaseAtom(query->name);
        releaseAtom(message);
        releaseObject(query->object);
        cancelTimeEvent(query->timeout_handler);
        free(query);
        return -1;
    }
    if(dnsUseGethostbyname >= 1) {
        releaseAtom(message);
        do_log(L_WARN, "Falling back to using system resolver.\n");
        really_do_gethostbyname(retainAtom(query->name), object);
    } else {
        releaseAtom(object->message);
        object->message = message;
        object->flags &= ~OBJECT_INPROGRESS;
        releaseNotifyObject(object);
    }
    cancelTimeEvent(query->timeout_handler);
    releaseAtom(query->name);
    if(query->inet4) releaseAtom(query->inet4);
    if(query->inet6) releaseAtom(query->inet6);
    releaseObject(query->object);
    free(query);
    return 1;
}
コード例 #8
0
ファイル: fields.c プロジェクト: carrot-garden/rp_rJava
/** get value of a field of an object or class
    object (int), return signature (string), field name (string)
    arrays and objects are returned as IDs (hence not evaluated)
    class name can be in either form / or .
*/
REPC SEXP RgetField(SEXP obj, SEXP sig, SEXP name, SEXP trueclass) {
  jobject o = 0;
  SEXP e;
  const char *retsig, *fnam;
  char *clnam = 0, *detsig = 0;
  jfieldID fid;
  jclass cls;
  int tc = asInteger(trueclass);
  JNIEnv *env=getJNIEnv();

  if (obj == R_NilValue) return R_NilValue;
  if ( IS_JOBJREF(obj) )
    obj = GET_SLOT(obj, install("jobj"));
  if (TYPEOF(obj)==EXTPTRSXP) {
    jverify(obj);
    o=(jobject)EXTPTR_PTR(obj);
  } else if (TYPEOF(obj)==STRSXP && LENGTH(obj)==1)
    clnam = strdup(CHAR(STRING_ELT(obj, 0)));
  else
    error("invalid object parameter");
  if (!o && !clnam)
    error("cannot access a field of a NULL object");
#ifdef RJ_DEBUG
  if (o) {
    rjprintf("RgetField.object: "); printObject(env, o);
  } else {
    rjprintf("RgetField.class: %s\n", clnam);
  }
#endif
  if (o)
    cls = objectClass(env, o);
  else {
    char *c = clnam;
    while(*c) { if (*c=='/') *c='.'; c++; }
    cls = findClass(env, clnam);
    free(clnam);
    if (!cls) {
      error("cannot find class %s", CHAR(STRING_ELT(obj, 0)));
    }
  }
  if (!cls)
    error("cannot determine object class");
#ifdef RJ_DEBUG
  rjprintf("RgetField.class: "); printObject(env, cls);
#endif
  if (TYPEOF(name)!=STRSXP || LENGTH(name)!=1) {
    releaseObject(env, cls);
    error("invalid field name");
  }
  fnam = CHAR(STRING_ELT(name,0));
  if (sig == R_NilValue) {
    retsig = detsig = findFieldSignature(env, cls, fnam);
    if (!retsig) {
      releaseObject(env, cls);
      error("unable to detect signature for field '%s'", fnam);
    }
  } else {
    if (TYPEOF(sig)!=STRSXP || LENGTH(sig)!=1) {
      releaseObject(env, cls);
      error("invalid signature parameter");
    }
    retsig = CHAR(STRING_ELT(sig,0));
  }
  _dbg(rjprintf("field %s signature is %s\n",fnam,retsig));
  
  if (o) { /* first try non-static fields */
    fid = (*env)->GetFieldID(env, cls, fnam, retsig);
    checkExceptionsX(env, 1);
    if (!fid) { /* if that fails, try static ones */
      o = 0;
      fid = (*env)->GetStaticFieldID(env, cls, fnam, retsig);
    }
  } else /* no choice if the object was a string */
    fid = (*env)->GetStaticFieldID(env, cls, fnam, retsig);

  if (!fid) {
    checkExceptionsX(env, 1);
    releaseObject(env, cls);
    if (detsig) free(detsig);
    error("RgetField: field %s not found", fnam);
  }
  switch (*retsig) {
  case 'I': {
    int r=o?
      (*env)->GetIntField(env, o, fid):
      (*env)->GetStaticIntField(env, cls, fid);
    e = allocVector(INTSXP, 1);
    INTEGER(e)[0] = r;
    releaseObject(env, cls);
    if (detsig) free(detsig);
    return e;
  }
  case 'S': {
    jshort r=o?
      (*env)->GetShortField(env, o, fid):
      (*env)->GetStaticShortField(env, cls, fid);
    e = allocVector(INTSXP, 1);
    INTEGER(e)[0] = r;
    releaseObject(env, cls);
    if (detsig) free(detsig);
    return e;
  }
  case 'C': {
    int r=(int) (o?
		 (*env)->GetCharField(env, o, fid):
		 (*env)->GetStaticCharField(env, cls, fid));
    e = allocVector(INTSXP, 1);
    INTEGER(e)[0] = r;
    releaseObject(env, cls);
    if (detsig) free(detsig);
    return e;
  }
  case 'B': {
    int r=(int) (o?
		 (*env)->GetByteField(env, o, fid):
		 (*env)->GetStaticByteField(env, cls, fid));
    e = allocVector(INTSXP, 1);
    INTEGER(e)[0] = r;
    releaseObject(env, cls);
    if (detsig) free(detsig);
    return e;
  }
  case 'J': {
    jlong r=o?
      (*env)->GetLongField(env, o, fid):
      (*env)->GetStaticLongField(env, cls, fid);
    e = allocVector(REALSXP, 1);
    REAL(e)[0] = (double)r;
    releaseObject(env, cls);
    if (detsig) free(detsig);
    return e;
  }
  case 'Z': {
    jboolean r=o?
      (*env)->GetBooleanField(env, o, fid):
      (*env)->GetStaticBooleanField(env, cls, fid);
    e = allocVector(LGLSXP, 1);
    LOGICAL(e)[0] = r?1:0;
    releaseObject(env, cls);
    if (detsig) free(detsig);
    return e;
  }
  case 'D': {
    double r=o?
      (*env)->GetDoubleField(env, o, fid):
      (*env)->GetStaticDoubleField(env, cls, fid);
    e = allocVector(REALSXP, 1);
    REAL(e)[0] = r;
    releaseObject(env, cls);
    if (detsig) free(detsig);
    return e;
  }
  case 'F': {
    double r = (double) (o?
      (*env)->GetFloatField(env, o, fid):
      (*env)->GetStaticFloatField(env, cls, fid));
    e = allocVector(REALSXP, 1);
    REAL(e)[0] = r;
    releaseObject(env, cls);
    if (detsig) free(detsig);
    return e;
  }
  case 'L':
  case '[': {
    SEXP rv;
    jobject r = o?
      (*env)->GetObjectField(env, o, fid):
      (*env)->GetStaticObjectField(env, cls, fid);
    _mp(MEM_PROF_OUT("  %08x LNEW field value\n", (int) r))
    releaseObject(env, cls);
    if (tc) {
      if (detsig) free(detsig);
      return new_jobjRef(env, r, 0);
    }
    if (*retsig=='L') { /* need to fix the class name */      
      char *d = strdup(retsig), *c = d;
      while (*c) { if (*c==';') { *c=0; break; }; c++; }
      rv = new_jobjRef(env, r, d+1);
      free(d);
    } else
      rv = new_jobjRef(env, r, retsig);
    if (detsig) free(detsig);
    return rv;
  }
  } /* switch */
  releaseObject(env, cls);
  if (detsig) {
    free(detsig);
    error("unknown field signature");
  }
  error("unknown field signature '%s'", retsig);
  return R_NilValue;
}
コード例 #9
0
ファイル: fields.c プロジェクト: carrot-garden/rp_rJava
REPC SEXP RsetField(SEXP ref, SEXP name, SEXP value) {
  jobject o = 0, otr;
  SEXP obj = ref;
  const char *fnam;
  sig_buffer_t sig;
  char *clnam = 0;
  jfieldID fid;
  jclass cls;
  jvalue jval;
  JNIEnv *env=getJNIEnv();

  if (TYPEOF(name)!=STRSXP && LENGTH(name)!=1)
    error("invalid field name");
  fnam = CHAR(STRING_ELT(name, 0));
  if (obj == R_NilValue) error("cannot set a field of a NULL object");
  if (IS_JOBJREF(obj))
    obj = GET_SLOT(obj, install("jobj"));
  if (TYPEOF(obj)==EXTPTRSXP) {
    jverify(obj);
    o=(jobject)EXTPTR_PTR(obj);
  } else if (TYPEOF(obj)==STRSXP && LENGTH(obj)==1)
    clnam = strdup(CHAR(STRING_ELT(obj, 0)));
  else
    error("invalid object parameter");
  if (!o && !clnam)
    error("cannot set a field of a NULL object");
#ifdef RJ_DEBUG
  if (o) {
    rjprintf("RsetField.object: "); printObject(env, o);
  } else {
    rjprintf("RsetField.class: %s\n", clnam);
  }
#endif
  if (o)
    cls = objectClass(env, o);
  else {
    char *c = clnam;
    while(*c) { if (*c=='/') *c='.'; c++; }
    cls = findClass(env, clnam);
    if (!cls) {
      error("cannot find class %s", CHAR(STRING_ELT(obj, 0)));
    }
  }
  if (!cls)
    error("cannot determine object class");
#ifdef RJ_DEBUG
  rjprintf("RsetField.class: "); printObject(env, cls);
#endif
  init_sigbuf(&sig);
  jval = R1par2jvalue(env, value, &sig, &otr);
  
  if (o) {
    fid = (*env)->GetFieldID(env, cls, fnam, sig.sig);
    if (!fid) {
      checkExceptionsX(env, 1);
      o = 0;
      fid = (*env)->GetStaticFieldID(env, cls, fnam, sig.sig);
    }
  } else
    fid = (*env)->GetStaticFieldID(env, cls, fnam, sig.sig);
  if (!fid) {
    checkExceptionsX(env, 1);
    releaseObject(env, cls);
    if (otr) releaseObject(env, otr);
    done_sigbuf(&sig);
    error("cannot find field %s with signature %s", fnam, sig.sigbuf);
  }
  switch(sig.sig[0]) {
  case 'Z':
    o?(*env)->SetBooleanField(env, o, fid, jval.z):
      (*env)->SetStaticBooleanField(env, cls, fid, jval.z);
    break;
  case 'C':
    o?(*env)->SetCharField(env, o, fid, jval.c):
      (*env)->SetStaticCharField(env, cls, fid, jval.c);
    break;
  case 'B':
    o?(*env)->SetByteField(env, o, fid, jval.b):
      (*env)->SetStaticByteField(env, cls, fid, jval.b);
    break;
  case 'I':
    o?(*env)->SetIntField(env, o, fid, jval.i):
      (*env)->SetStaticIntField(env, cls, fid, jval.i);
    break;
  case 'D':
    o?(*env)->SetDoubleField(env, o, fid, jval.d):
      (*env)->SetStaticDoubleField(env, cls, fid, jval.d);
    break;
  case 'F':
    o?(*env)->SetFloatField(env, o, fid, jval.f):
      (*env)->SetStaticFloatField(env, cls, fid, jval.f);
    break;
  case 'J':
    o?(*env)->SetLongField(env, o, fid, jval.j):
      (*env)->SetStaticLongField(env, cls, fid, jval.j);
    break;
  case 'S':
    o?(*env)->SetShortField(env, o, fid, jval.s):
      (*env)->SetStaticShortField(env, cls, fid, jval.s);
    break;
  case '[':
  case 'L':
    o?(*env)->SetObjectField(env, o, fid, jval.l):
      (*env)->SetStaticObjectField(env, cls, fid, jval.l);
    break;
  default:
    releaseObject(env, cls);
    if (otr) releaseObject(env, otr);
    done_sigbuf(&sig);
    error("unknown field sighanture %s", sig.sigbuf);
  }
  done_sigbuf(&sig);
  releaseObject(env, cls);
  if (otr) releaseObject(env, otr);
  return ref;
}