Esempio n. 1
0
static PyObject*
condition_notify(ConditionObject *self, int num)
{
    PyObject *res, *waiters;
    PyObject *iter, *item;
    
    DEBUG("self:%p", self);
    res = call_method((PyObject*)self, "_is_owned");
    if (res == NULL) {
        return NULL;
    }
    
    if (PyObject_Not(res)) {
        Py_DECREF(res);
        PyErr_SetString(PyExc_RuntimeError, "cannot release un-acquired lock");
        return NULL;
    }
    Py_DECREF(res);
    waiters = PyList_GetSlice(self->waiters, 0, num);
    if (waiters == NULL) {
        return NULL;
    }
    if (PyObject_Not(waiters)) {
        Py_RETURN_NONE;
    }

    iter = PyObject_GetIter(waiters);
    if (PyErr_Occurred()) {
        return NULL;
    }

    while ((item =  PyIter_Next(iter))) {
        res = semaphore_release((SemaphoreObject*)item);
        Py_XDECREF(res);
        if (res == NULL) {
            Py_DECREF(item);
            goto err;
        }
        if (remove_from_list((PyListObject*)self->waiters, item) == -1) {
            Py_DECREF(item);
            goto err;
        }
        Py_DECREF(item);
        /* DEBUG("self->waiters len:%d", PyList_Size(self->waiters)); */
    }
    Py_DECREF(waiters);
    Py_DECREF(iter);
    Py_RETURN_NONE;
err:
    Py_DECREF(waiters);
    Py_DECREF(iter);
    return NULL;

}
Esempio n. 2
0
int
perl_back_compare(
	Operation	*op,
	SlapReply	*rs )
{
	int count, avalen;
	char *avastr;

	PerlBackend *perl_back = (PerlBackend *)op->o_bd->be_private;

	avalen = op->orc_ava->aa_desc->ad_cname.bv_len + 1 +
		op->orc_ava->aa_value.bv_len;
	avastr = ch_malloc( avalen + 1 );

	lutil_strcopy( lutil_strcopy( lutil_strcopy( avastr,
		op->orc_ava->aa_desc->ad_cname.bv_val ), "=" ),
		op->orc_ava->aa_value.bv_val );

	PERL_SET_CONTEXT( PERL_INTERPRETER );
	ldap_pvt_thread_mutex_lock( &perl_interpreter_mutex );	

	{
		dSP; ENTER; SAVETMPS;

		PUSHMARK(sp);
		XPUSHs( perl_back->pb_obj_ref );
		XPUSHs(sv_2mortal(newSVpv( op->o_req_dn.bv_val , op->o_req_dn.bv_len)));
		XPUSHs(sv_2mortal(newSVpv( avastr , avalen)));
		PUTBACK;

		count = call_method("compare", G_SCALAR);

		SPAGAIN;

		if (count != 1) {
			croak("Big trouble in back_compare\n");
		}

		rs->sr_err = POPi;

		PUTBACK; FREETMPS; LEAVE;
	}

	ldap_pvt_thread_mutex_unlock( &perl_interpreter_mutex );	

	ch_free( avastr );

	send_ldap_result( op, rs );

	Debug( LDAP_DEBUG_ANY, "Perl COMPARE\n", 0, 0, 0 );

	return (0);
}
Esempio n. 3
0
/* if necessary, call self._p_connection.note_access(self) */
static int
pb_note_access(PersistentBaseObject *self)
{
	ConnectionBaseObject *connection;
	connection = (ConnectionBaseObject *)self->p_connection;
	if (self->p_connection != Py_None &&
	    self->p_serial != connection->transaction_serial) {
		return call_method(
			(PyObject *)connection, "note_access", (PyObject *)self);
	} else 
		return 1;
}
Esempio n. 4
0
int
perl_back_add(
	Backend	*be,
	Connection	*conn,
	Operation	*op,
	Entry	*e
)
{
	int len;
	int count;
	int return_code;

	PerlBackend *perl_back = (PerlBackend *) be->be_private;

	ldap_pvt_thread_mutex_lock( &perl_interpreter_mutex );
	ldap_pvt_thread_mutex_lock( &entry2str_mutex );

	{
		dSP; ENTER; SAVETMPS;

		PUSHMARK(sp);
		XPUSHs( perl_back->pb_obj_ref );
		XPUSHs(sv_2mortal(newSVpv( entry2str( e, &len ), 0 )));

		PUTBACK;

#ifdef PERL_IS_5_6
		count = call_method("add", G_SCALAR);
#else
		count = perl_call_method("add", G_SCALAR);
#endif

		SPAGAIN;

		if (count != 1) {
			croak("Big trouble in back_add\n");
		}
							 
		return_code = POPi;

		PUTBACK; FREETMPS; LEAVE;
	}

	ldap_pvt_thread_mutex_unlock( &entry2str_mutex );
	ldap_pvt_thread_mutex_unlock( &perl_interpreter_mutex );	

	send_ldap_result( conn, op, return_code,
		NULL, NULL, NULL, NULL );

	Debug( LDAP_DEBUG_ANY, "Perl ADD\n", 0, 0, 0 );
	return( 0 );
}
Esempio n. 5
0
//// Callbacks ////
static void init_cgi_obj(struct req_state *state){
	dSP;
	ENTER;
	SAVETMPS;
	PUSHMARK(SP);
	XPUSHs( state->req_obj );
	PUTBACK;
	
	call_method ("new", G_DISCARD);
	
	FREETMPS;
	LEAVE;
};
Esempio n. 6
0
static void
call_load(Class cls)
{
    if (cls->info & OBJC_CLASS_INFO_LOADED)
        return;

    if (cls->superclass != Nil)
        call_load(cls->superclass);

    call_method(cls, "load");

    cls->info |= OBJC_CLASS_INFO_LOADED;
}
Esempio n. 7
0
int
perl_back_modrdn(
	Operation	*op,
	SlapReply	*rs )
{
	PerlBackend *perl_back = (PerlBackend *) op->o_bd->be_private;
	int count;

#if defined(HAVE_WIN32_ASPERL) || defined(USE_ITHREADS)
	PERL_SET_CONTEXT( PERL_INTERPRETER );
#endif

	ldap_pvt_thread_mutex_lock( &perl_interpreter_mutex );	

	{
		dSP; ENTER; SAVETMPS;
		
		PUSHMARK(sp) ;
		XPUSHs( perl_back->pb_obj_ref );
		XPUSHs(sv_2mortal(newSVpv( op->o_req_dn.bv_val , 0 )));
		XPUSHs(sv_2mortal(newSVpv( op->orr_newrdn.bv_val , 0 )));
		XPUSHs(sv_2mortal(newSViv( op->orr_deleteoldrdn )));
		if ( op->orr_newSup != NULL ) {
			XPUSHs(sv_2mortal(newSVpv( op->orr_newSup->bv_val , 0 )));
		}
		PUTBACK ;

#ifdef PERL_IS_5_6
		count = call_method("modrdn", G_SCALAR);
#else
		count = perl_call_method("modrdn", G_SCALAR);
#endif

		SPAGAIN ;

		if (count != 1) {
			croak("Big trouble in back_modrdn\n") ;
		}
							 
		rs->sr_err = POPi;

		PUTBACK; FREETMPS; LEAVE ;
	}

	ldap_pvt_thread_mutex_unlock( &perl_interpreter_mutex );
	
	send_ldap_result( op, rs );

	Debug( LDAP_DEBUG_ANY, "Perl MODRDN\n", 0, 0, 0 );
	return( 0 );
}
Esempio n. 8
0
void display_menu()
{
	int val;
	puts("\t\t\t----------------------------BST------------------------------------------");
	puts("1:Insert a Node\n2:Traverse BST\n3:Sucessor of a Node\n4:Predecessor of a Node\n5:Search a Node\n6:Delete a Node\n7:Exit\n8:Sum of all children\n\nEnter your choice:");
	scanf("%d",&val);
	{
		char dummy;
		scanf("%c",&dummy);
	}
	call_method(val);

	
}
Esempio n. 9
0
int
perl_back_add(
	Operation	*op,
	SlapReply	*rs )
{
	PerlBackend *perl_back = (PerlBackend *) op->o_bd->be_private;
	int len;
	int count;

#if defined(HAVE_WIN32_ASPERL) || defined(USE_ITHREADS)
	PERL_SET_CONTEXT( PERL_INTERPRETER );
#endif
	ldap_pvt_thread_mutex_lock( &perl_interpreter_mutex );
	ldap_pvt_thread_mutex_lock( &entry2str_mutex );

	{
		dSP; ENTER; SAVETMPS;

		PUSHMARK(sp);
		XPUSHs( perl_back->pb_obj_ref );
		XPUSHs(sv_2mortal(newSVpv( entry2str( op->ora_e, &len ), 0 )));

		PUTBACK;

#ifdef PERL_IS_5_6
		count = call_method("add", G_SCALAR);
#else
		count = perl_call_method("add", G_SCALAR);
#endif

		SPAGAIN;

		if (count != 1) {
			croak("Big trouble in back_add\n");
		}
							 
		rs->sr_err = POPi;

		PUTBACK; FREETMPS; LEAVE;
	}

	ldap_pvt_thread_mutex_unlock( &entry2str_mutex );
	ldap_pvt_thread_mutex_unlock( &perl_interpreter_mutex );	

	send_ldap_result( op, rs );

	Debug( LDAP_DEBUG_ANY, "Perl ADD\n", 0, 0, 0 );
	return( 0 );
}
Esempio n. 10
0
/*
 * mono.new(class, "ctor_sig", ...)
 * class 为MonoClass指针(userdata)
 * "ctor_sig" : 带有函数签名的.ctor 比如 : .ctor(int, int), 
 *              若使用默认构造函数(无参数), 该参数为空字符串
 * ... : 为构造函数所需实参
 * 返回 : MonoObject*(userdata)
 */
static int l_newobj (lua_State *L) {
    MonoClass *clazz = (MonoClass*)lua_touserdata (L, 1);
    luaL_argcheck (L, clazz != 0, 1, "class is null.");
    char const *ctor_sig = luaL_checkstring (L, 2);
    MonoMethod *ctor = get_class_method (clazz, ctor_sig);
    if (!ctor)
        luaL_error (L, "class %s can not find the %s.", mono_class_get_name (clazz), ctor_sig);
    MonoObject *obj = mono_object_new (mono_domain_get (), clazz);
    MonoObject *ex = 0;
    call_method (L, 3, obj, ctor, &ex);
    if (ex)
        luaL_error (L, "init the obj cause an exception!");
    lua_pushlightuserdata (L, obj);
    return 1;
}
Esempio n. 11
0
/* Calls a method on a perl object representing a message.
   If the return value is non-null, the caller must free it.
 */
CALLER_OWN char *owl_perlconfig_message_call_method(const owl_message *m, const char *method, int argc, const char **argv)
{
  dSP;
  unsigned int count, i;
  SV *msgref, *srv;
  char *out;

  msgref = owl_perlconfig_message2hashref(m);

  ENTER;
  SAVETMPS;

  PUSHMARK(SP);
  XPUSHs(sv_2mortal(msgref));
  for(i=0;i<argc;i++) {
    XPUSHs(sv_2mortal(owl_new_sv(argv[i])));
  }
  PUTBACK;

  count = call_method(method, G_SCALAR|G_EVAL);

  SPAGAIN;

  if(count != 1) {
    fprintf(stderr, "perl returned wrong count %u\n", count);
    abort();
  }

  if (SvTRUE(ERRSV)) {
    owl_function_error("Error: '%s'", SvPV_nolen(ERRSV));
    /* and clear the error */
    sv_setsv (ERRSV, &PL_sv_undef);
  }

  srv = POPs;

  if (srv) {
    out = g_strdup(SvPV_nolen(srv));
  } else {
    out = NULL;
  }

  PUTBACK;
  FREETMPS;
  LEAVE;

  return out;
}
Esempio n. 12
0
STATIC mp_obj_t jmethod_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
    if (n_kw != 0) {
        nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "kwargs not supported"));
    }
    mp_obj_jmethod_t *self = self_in;

    const char *name = qstr_str(self->name);
//    jstring meth_name = JJ(NewStringUTF, name);

    jclass obj_class = self->obj;
    if (!self->is_static) {
        obj_class = JJ(GetObjectClass, self->obj);
    }
    jarray methods = JJ(CallObjectMethod, obj_class, Class_getMethods_mid);

    return call_method(self->obj, name, methods, false, n_args, args);
}
Esempio n. 13
0
void
Perl_av_extend(pTHX_ AV *av, I32 key)
{
    dVAR;
    MAGIC *mg;

    PERL_ARGS_ASSERT_AV_EXTEND;
    assert(SvTYPE(av) == SVt_PVAV);

    mg = SvTIED_mg((const SV *)av, PERL_MAGIC_tied);
    if (mg) {
	dSP;
	ENTER;
	SAVETMPS;
	PUSHSTACKi(PERLSI_MAGIC);
	PUSHMARK(SP);
	EXTEND(SP,2);
	PUSHs(SvTIED_obj(MUTABLE_SV(av), mg));
	mPUSHi(key + 1);
        PUTBACK;
	call_method("EXTEND", G_SCALAR|G_DISCARD);
	POPSTACK;
	FREETMPS;
	LEAVE;
	return;
    }
    if (key > AvMAX(av)) {
	SV** ary;
	I32 tmp;
	I32 newmax;

	if (AvALLOC(av) != AvARRAY(av)) {
	    ary = AvALLOC(av) + AvFILLp(av) + 1;
	    tmp = AvARRAY(av) - AvALLOC(av);
	    Move(AvARRAY(av), AvALLOC(av), AvFILLp(av)+1, SV*);
	    AvMAX(av) += tmp;
	    AvARRAY(av) = AvALLOC(av);
	    if (AvREAL(av)) {
		while (tmp)
		    ary[--tmp] = &PL_sv_undef;
	    }
	    if (key > AvMAX(av) - 10) {
		newmax = key + AvMAX(av);
		goto resize;
	    }
	}
Esempio n. 14
0
static SV*
S_do_callback_sv(void *vobj, char *method, uint32_t num_args, va_list args) 
{
    SV *return_val;
    SI_push_args(vobj, args, num_args);
    {
        int num_returned = call_method(method, G_SCALAR);
        dSP;
        if (num_returned != 1) {
            CFISH_THROW(KINO_ERR, "Bad number of return vals from %s: %i32", method,
                (int32_t)num_returned);
        }
        return_val = POPs;
        PUTBACK;
    }
    return return_val;
}
Esempio n. 15
0
const std::string sv_to_msg(SV* msg) {
    dSP;
    ENTER;
    SAVETMPS;
    PUSHMARK(SP);
    XPUSHs(msg);
    PUTBACK;
    int rc = call_method("encode", G_SCALAR);
    SPAGAIN;

    std::string retval(sv_to_string(POPs));

    FREETMPS;
    LEAVE;

    return retval; 
}
Esempio n. 16
0
static object_t *oostruct_dispose(object_t *obj)
{
   /* oostruct gets called only once */
   assert(!ZOMBIEP(obj->backptr));

   obj->next_unreachable = NULL;

   int oldready = error_doc.ready_to_an_error;
   error_doc.ready_to_an_error = true;
   struct lush_context mycontext;
   context_push(&mycontext);
   
   int errflag = sigsetjmp(context->error_jump,1);
   if (errflag==0) {
      /* call all destructors for interpreted part */
      /* destructors for compiled part are called  */
      /* by finalizer for compiled part            */
      at *f = NIL;
      class_t *cl = Class(obj->backptr);
      while (cl) {
         struct hashelem *hx = _getmethod(cl, at_destroy);
         cl = cl->super;
         if (! hx)
            break;
         else if (hx->function == f)
            continue;
         else if (classof(hx->function) == dh_class)
            break;
         call_method(obj->backptr, hx, NIL);
         f = hx->function;
      }
   }
   
   context_pop();
   error_doc.ready_to_an_error = oldready;
   if (obj->cptr)
      obj->cptr->__lptr = NULL;
   zombify(obj->backptr);
   
   if (errflag)
      siglongjmp(context->error_jump, -1L);

   return obj;
}
Esempio n. 17
0
void
kino_Host_callback(void *vobj, char *method, uint32_t num_args, ...) 
{
    va_list args;
    
    va_start(args, num_args);
    SI_push_args(vobj, args, num_args);
    va_end(args);
    
    {
        int count = call_method(method, G_VOID|G_DISCARD);
        if (count != 0) {
            CFISH_THROW(KINO_ERR, "callback '%s' returned too many values: %i32", 
                method, (int32_t)count);
        }
        FREETMPS;
        LEAVE;
    }
}
Esempio n. 18
0
static SV*
do_callback_sv(kino_Obj *obj, char *method, chy_u32_t num_args, va_list args) 
{
    dSP;
    int num_returned;
    SV *return_val;
    SV *invoker;
    chy_u32_t i;
    
    if (KINO_OBJ_IS_A(obj, KINO_VTABLE)) {
        kino_VTable *vtable = (kino_VTable*)obj;
        invoker = XSBind_cb_to_sv(vtable->name);
    }
    else {
        invoker = (SV*)Kino_Obj_To_Host(obj);
    }

    ENTER;
    SAVETMPS;
    PUSHMARK(SP);
    XPUSHs( sv_2mortal(invoker) );

    for (i = 0; i < num_args; i++) {
        PUSH_ARG(args, num_args);
    }

    PUTBACK;

    num_returned = call_method(method, G_SCALAR);

    SPAGAIN;

    if (num_returned != 1) {
        KINO_THROW("Bad number of return vals from %s: %i32", method,
            (chy_i32_t)num_returned);
    }

    return_val = POPs;

    PUTBACK;

    return return_val;
}
Esempio n. 19
0
static int
pb_setattro(PersistentBaseObject *self, PyObject *name, PyObject *value)
{
	char *sname;
    sname = NULL;
	if (AttributeName_Check(name)) {
	    sname = AttributeName_AsString(name);
	} else {
		PyErr_SetString(PyExc_TypeError, "attribute name must be a string");
        return -1;
	}
	if (load_triggering_name(sname)) {
		if (self->p_status != UNSAVED) {
			if (!call_method((PyObject *)self, "_p_note_change", NULL))
				return -1;
		}
	}
	return PyObject_GenericSetAttr((PyObject *)self, name, value);
}
Esempio n. 20
0
static void coroae_condvar_call(SV *cv, const char *method) {
	dSP;

        ENTER;
        SAVETMPS;
        PUSHMARK(SP);
        XPUSHs(cv);
        PUTBACK;

        call_method(method, G_DISCARD|G_EVAL);

        SPAGAIN;
        if(SvTRUE(ERRSV)) {
                uwsgi_log("[uwsgi-perl error] %s", SvPV_nolen(ERRSV));
        }
        PUTBACK;
        FREETMPS;
        LEAVE;
}
Esempio n. 21
0
void
kino_Host_callback(void *vobj, char *method, chy_u32_t num_args, ...) 
{
    kino_Obj *obj = (kino_Obj*)vobj;
    dSP;
    va_list args;
    int count;
    chy_u32_t i;
    SV *invoker;
    kino_VTable *vtable;
    
    if (KINO_OBJ_IS_A(obj, KINO_VTABLE)) {
        vtable  = (kino_VTable*)obj;
        invoker = XSBind_cb_to_sv(vtable->name);
    }
    else {
        vtable  = obj->vtable;
        invoker = (SV*)Kino_Obj_To_Host(obj);
    }

    ENTER;
    SAVETMPS;
    PUSHMARK(SP);
    XPUSHs( sv_2mortal(invoker) );

    va_start(args, num_args);
    for (i = 0; i < num_args; i++) {
        PUSH_ARG(args, num_args);
    }
    va_end(args);

    PUTBACK;

    count = call_method(method, G_VOID|G_DISCARD);
    if (count != 0) {
        KINO_THROW("callback '%s' in '%o' returned too many values: %i32", 
            method, Kino_VTable_Get_Name(vtable), (chy_i32_t)count);
    }

    PUTBACK;
    FREETMPS;
    LEAVE;
}
Esempio n. 22
0
SV *p5_wrap_p6_hash(
    PerlInterpreter *my_perl,
    IV i
) {
    PERL_SET_CONTEXT(my_perl);
    {
        int flags = G_SCALAR;
        dSP;

        SV * inst;
        SV * inst_ptr;
        inst_ptr = newSViv(0); // will be upgraded to an RV
        inst = newSVrv(inst_ptr, "Perl6::Object");
        _perl6_hash_magic priv;

        /* set up magic */
        priv.key = PERL6_HASH_MAGIC_KEY;
        priv.index = i;
        sv_magicext(inst, inst, PERL_MAGIC_ext, &p5_inline_hash_mg_vtbl, (char *) &priv, sizeof(priv));

        ENTER;
        SAVETMPS;

        PUSHMARK(SP);

        XPUSHs(newSVpv("Perl6::Hash", 0));
        XPUSHs(inst_ptr);

        PUTBACK;

        call_method("new", flags);
        SPAGAIN;

        SV *tied_handle = POPs;
        SvREFCNT_inc(tied_handle);

        PUTBACK;
        FREETMPS;
        LEAVE;

        return tied_handle;
    }
}
Esempio n. 23
0
File: coroae.c Progetto: JuanS/uwsgi
static void coroae_wait_condvar(SV *cv) {
	dSP;

        ENTER;
        SAVETMPS;
        PUSHMARK(SP);
        XPUSHs(cv);
        PUTBACK;

        call_method( "recv", G_DISCARD);

        SPAGAIN;
        if(SvTRUE(ERRSV)) {
                uwsgi_log("[uwsgi-perl error] %s", SvPV_nolen(ERRSV));
        }
        PUTBACK;
        FREETMPS;
        LEAVE;
}
Esempio n. 24
0
	bool	as_loadvars::load(const char * c_url)
	{
		lfl_string host, uri;
		request_data request;

		if( parse_url(c_url, host, uri) )
		{
			request.m_iface = new net_interface_tcp();
			request.m_ns = request.m_iface->connect(host, 80);
		}

		bool is_connected = request.m_ns ? true : false;

		if( !is_connected )
		{
			as_value function;
			if (get_member("onLoad", &function))
			{
				as_environment env(get_player());
				env.push(false);
				call_method(function, &env, this, 1, env.get_top_index());
			}

			delete request.m_iface;

			return false;
		}

		request.m_target = this;
		get_root()->add_listener(this);

		m_headers.set("Host", host);

		lfl_string request_string = create_request( "GET", uri, true );

		printf( request_string.c_str() );
		request.m_ns->write_string(request_string, 1);
		request.m_state = PARSE_REQUEST;

		m_requests.push_back( request );

		return true;
	}
Esempio n. 25
0
int
perl_back_db_open(
    BackendDB	*be,
    ConfigReply	*cr
)
{
    int count;
    int return_code;

    PerlBackend *perl_back = (PerlBackend *) be->be_private;

    ldap_pvt_thread_mutex_lock( &perl_interpreter_mutex );

    {
        dSP;
        ENTER;
        SAVETMPS;

        PUSHMARK(sp);
        XPUSHs( perl_back->pb_obj_ref );

        PUTBACK;

        count = call_method("init", G_SCALAR);

        SPAGAIN;

        if (count != 1) {
            croak("Big trouble in perl_back_db_open\n");
        }

        return_code = POPi;

        PUTBACK;
        FREETMPS;
        LEAVE;
    }

    ldap_pvt_thread_mutex_unlock( &perl_interpreter_mutex );

    return return_code;
}
Esempio n. 26
0
static int respond_to(SV *obj, const char *method)
{
    dTHX;
    int res;
    dSP;
    ENTER;
    SAVETMPS;
    PUSHMARK(SP);
    XPUSHs(obj);
    XPUSHs(sv_2mortal(newSVpv(method, 0)));
    PUTBACK;

    call_method("can", G_SCALAR);
    SPAGAIN;
    res = SvROK(POPs);
    PUTBACK;
    FREETMPS;
    LEAVE;
    return res;
}
Esempio n. 27
0
int test_me () {


    // short if 1
    if (a && b || c) ;
    else do_something ();

    // short if 2
    if (a && b || c) ;

    // short if 3
    if (a && b || c) do_something ();
    else ;

    // short while
    while (call_method ()) ;

    // very short (infinite) for
    for (;;);
}
Esempio n. 28
0
File: av.c Progetto: gitpan/ponie
void
Perl_av_extend(pTHX_ AV *av, I32 key)
{
    MAGIC *mg;
    if ((mg = SvTIED_mg((SV*)av, PERL_MAGIC_tied))) {
	dSP;
	ENTER;
	SAVETMPS;
	PUSHSTACKi(PERLSI_MAGIC);
	PUSHMARK(SP);
	EXTEND(SP,2);
	PUSHs(SvTIED_obj((SV*)av, mg));
	PUSHs(sv_2mortal(newSViv(key+1)));
        PUTBACK;
	call_method("EXTEND", G_SCALAR|G_DISCARD);
	POPSTACK;
	FREETMPS;
	LEAVE;
	return;
    }
    if (key > AvMAX(av)) {
	SV** ary;
	I32 tmp;
	I32 newmax;

	if (AvALLOC(av) != AvARRAY(av)) {
	    ary = AvALLOC(av) + AvFILLp(av) + 1;
	    tmp = AvARRAY(av) - AvALLOC(av);
	    Move(AvARRAY(av), AvALLOC(av), AvFILLp(av)+1, SV*);
	    AvMAX(av) += tmp;
	    SvPVX(av) = (char*)AvALLOC(av);
	    if (AvREAL(av)) {
		while (tmp)
		    ary[--tmp] = &PL_sv_undef;
	    }
	    
	    if (key > AvMAX(av) - 10) {
		newmax = key + AvMAX(av);
		goto resize;
	    }
	}
Esempio n. 29
0
AV *p5_call_package_method(PerlInterpreter *my_perl, char *package, char *name, int len, SV *args[]) {
    dSP;
    int i;
    I32 count;
    AV * const retval = newAV();
    int flags = G_ARRAY | G_EVAL;

    PERL_SET_CONTEXT(my_perl);

    ENTER;
    SAVETMPS;

    PUSHMARK(SP);

    XPUSHs(newSVpv(package, 0));
    for (i = 0; i < len; i++) {
        XPUSHs(sv_2mortal(args[i]));
    }

    PUTBACK;

    count = call_method(name, flags);
    SPAGAIN;

    if (count > 0)
        av_extend(retval, count - 1);

    for (i = count - 1; i >= 0; i--) {
        SV * const next = POPs;
        SvREFCNT_inc(next);

        if (av_store(retval, i, next) == NULL)
            SvREFCNT_dec(next); /* see perlguts Working with AVs */
    }

    PUTBACK;
    FREETMPS;
    LEAVE;

    return retval;
}
Esempio n. 30
0
	bool as_xmlsock::connect(const char* host, int port)
	{
		m_ns = m_iface->connect(host, port);
		bool is_connected = m_ns ? true : false;

		as_value function;
		if (get_member("onConnect", &function))
		{
			as_environment env(get_player());
			env.push(is_connected);
			call_method(function, &env, as_value(), 1, env.get_top_index());
		}

		// add to net listener
		if (is_connected && get_root())
		{
			get_root()->add_listener(this);
		}

		return is_connected;
	}