예제 #1
0
static void
modify_event_perl(plcb_IOPROCS *async, plcb_EVENT *cevent, short flags)
{
    SV **tmpsv;
    tmpsv = av_fetch(cevent->pl_event, PLCB_EVIDX_FD, 1);

    if (SvIOK(*tmpsv)) {
        SvIVX(*tmpsv) = cevent->fd;
    } else {
        sv_setiv(*tmpsv, cevent->fd);
    }

    SvIVX(async->flags_sv) = flags;
    /* Figure out the proper masks */

    SvIVX(async->sched_r_sv) = flags & LCB_READ_EVENT && (cevent->flags & LCB_READ_EVENT) == 0;
    SvIVX(async->sched_w_sv) = flags & LCB_WRITE_EVENT && (cevent->flags & LCB_WRITE_EVENT) == 0;
    SvIVX(async->stop_r_sv) = (flags & LCB_READ_EVENT) == 0  && cevent->flags & LCB_READ_EVENT;
    SvIVX(async->stop_w_sv) = (flags & LCB_WRITE_EVENT) == 0 && cevent->flags & LCB_WRITE_EVENT;


    cb_args_noret(async->cv_evmod, 0, 7,
        async->userdata, cevent->rv_event, async->flags_sv,
        async->sched_r_sv, async->sched_w_sv,
        async->stop_r_sv, async->stop_w_sv);

    cevent->flags = flags;
    tmpsv = av_fetch(cevent->pl_event, PLCB_EVIDX_WATCHFLAGS, 1);
    SvIVX(*tmpsv) = cevent->flags;
}
예제 #2
0
void
Point::from_SV(SV* point_sv)
{
    AV* point_av = (AV*)SvRV(point_sv);
    this->x = (long)SvIV(*av_fetch(point_av, 0, 0));
    this->y = (long)SvIV(*av_fetch(point_av, 1, 0));
}
static void modify_event_perl(PLCBA_t *async,
                              PLCBA_c_event *cevent,
                              PLCBA_evaction_t action,
                              short flags)
{
    SV **tmpsv;

    tmpsv = av_fetch(cevent->pl_event, PLCBA_EVIDX_FD, 1);
    if (SvIOK(*tmpsv)) {
        if (SvIV(*tmpsv) != cevent->fd) {
            /*file descriptor mismatch!*/
            av_delete(cevent->pl_event, PLCBA_EVIDX_DUPFH, G_DISCARD);
        }

    } else {
        sv_setiv(*tmpsv, cevent->fd);
    }
    
    plcb_call_sv_with_args_noret(async->cv_evmod,
                                 1,
                                 3,
                                 newRV_inc( (SV*)(cevent->pl_event)),
                                 newSViv(action),
                                 newSViv(flags));
    
    /*set the current flags*/
    if (action != PLCBA_EVACTION_SUSPEND && action != PLCBA_EVACTION_RESUME) {
        sv_setiv( *(av_fetch(cevent->pl_event, PLCBA_EVIDX_WATCHFLAGS, 1)),
                 flags);
    }
    
    /*set the current state*/
    sv_setiv( *(av_fetch(cevent->pl_event, PLCBA_EVIDX_STATEFLAGS, 1)),
             cevent->state);
}
예제 #4
0
static CORBA_boolean
put_any (GIOPSendBuffer *buf, CORBA_TypeCode tc, SV *sv)
{
    AV *av;
    SV **tc_sv;
    CORBA_TypeCode output_tc;
    
    if (sv == &PL_sv_undef) {
	if (PL_dowarn & G_WARN_ON)
	    warn ("Uninitialized CORBA::Any");
	output_tc = porbit_find_typecode ("IDL:omg.org/CORBA/Null:1.0");
	ORBit_encode_CORBA_TypeCode (output_tc, buf);
	return CORBA_TRUE;
    }

    if (!SvROK(sv) || 
	(SvTYPE(SvRV(sv)) != SVt_PVAV) ||
	(av_len((AV *)SvRV(sv)) != 1)) {
	warn ("CORBA::Any must be array reference of length 2");
	return CORBA_FALSE;
    }

    av = (AV *)SvRV(sv);
    tc_sv = av_fetch(av, 0, 0); 

    if (!tc_sv || !sv_isa(*tc_sv, "CORBA::TypeCode")) {
	warn ("First member of any isn't a CORBA::TypeCode");
	return CORBA_FALSE;
    }

    output_tc = (CORBA_TypeCode)SvIV(SvRV(*tc_sv));
    ORBit_encode_CORBA_TypeCode (output_tc, buf);
    
    return porbit_put_sv (buf, output_tc, *av_fetch (av, 1, 0));
}
예제 #5
0
void
ffi_pl_perl_to_complex_float(SV *sv, float *ptr)
{
  if(sv_isobject(sv) && sv_derived_from(sv, "Math::Complex"))
  {
    ptr[0] = decompose(sv, 0);
    ptr[1] = decompose(sv, 1);
  }
  else if(SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVAV)
  {
    AV *av = (AV*) SvRV(sv);
    SV **real_sv, **imag_sv;
    real_sv = av_fetch(av, 0, 0);
    imag_sv = av_fetch(av, 1, 0);
    ptr[0] = real_sv != NULL ? SvNV(*real_sv) : 0.0;
    ptr[1]= imag_sv != NULL ? SvNV(*imag_sv) : 0.0;
  }
  else if(SvOK(sv))
  {
    ptr[0] = SvNV(sv);
    ptr[1] = 0.0;
  }
  else
  {
    ptr[0] = 0.0;
    ptr[1] = 0.0;
  }
}
예제 #6
0
static void ctor_extract_methpairs(AV *options,
                                   int idx, SV **outmeth, SV **inmeth)
{
    SV **tmpsv;
    AV *methav;
    int ii;
    
    SV **assgn_array[] = { outmeth, inmeth };
    
    *outmeth = *inmeth = NULL;
    if ( (tmpsv = av_fetch(options, idx, 0)) == NULL ) {
        return;
    }
    
    if (SvROK(*tmpsv) == 0 ||
        ((methav = (AV*)SvRV(*tmpsv)) && SvTYPE(methav) != SVt_PVAV) ||
        av_len(methav) != 1) {
        die("Expected an array reference with two elements");
    }
    
    for (ii = 0; ii < 2; ii++) {
        tmpsv = av_fetch(methav, ii, 0);
        if(SvROK(*tmpsv) == 0 || SvTYPE(SvRV(*tmpsv)) != SVt_PVCV) {
            die("Expected code reference.");
        }
        *(assgn_array[ii]) = newRV_inc(SvRV(*tmpsv));
    }
}
예제 #7
0
void plcb_ctor_init_common(PLCB_t *object, libcouchbase_t instance,
                           AV *options)
{
    NV timeout_value;
    SV **tmpsv;
    
    object->instance = instance;
    object->errors = newAV();
    if(! (object->ret_stash = gv_stashpv(PLCB_RET_CLASSNAME, 0)) ) {
        die("Could not load '%s'", PLCB_RET_CLASSNAME);
    }
    
    /*gather instance-related options from the constructor*/
    if( (tmpsv = av_fetch(options, PLCB_CTORIDX_TIMEOUT, 0))  && 
            (SvIOK(*tmpsv) || SvNOK(*tmpsv))) {
        timeout_value = SvNV(*tmpsv);
        if(!timeout_value) {
            warn("Cannot use 0 for timeout");
        } else {
            libcouchbase_set_timeout(instance,
                timeout_value * (1000*1000));
        }
    }
    
    if((tmpsv = av_fetch(options, PLCB_CTORIDX_NO_CONNECT, 0)) &&
       SvTRUE(*tmpsv)) {
        object->my_flags |= PLCBf_NO_CONNECT;
    }
    /*maybe more stuff here?*/
}
예제 #8
0
파일: Line.cpp 프로젝트: lineuve/x2swn
void
Line::from_SV(SV* line_sv)
{
    AV* line_av = (AV*)SvRV(line_sv);
    this->a.from_SV_check(*av_fetch(line_av, 0, 0));
    this->b.from_SV_check(*av_fetch(line_av, 1, 0));
}
예제 #9
0
void 
Drawable_set( Handle self, HV * profile)
{
   dPROFILE;
   if ( pexist( font))
   {
      SvHV_Font( pget_sv( font), &Font_buffer, "Drawable::set");
      my-> set_font( self, Font_buffer);
      pdelete( font);
   }
   if ( pexist( translate))
   {
      AV * av = ( AV *) SvRV( pget_sv( translate));
      Point tr = {0,0};
      SV ** holder = av_fetch( av, 0, 0);
      if ( holder) tr.x = SvIV( *holder); else warn("RTC0059: Array panic on 'translate'");
      holder = av_fetch( av, 1, 0);
      if ( holder) tr.y = SvIV( *holder); else warn("RTC0059: Array panic on 'translate'");
      my-> set_translate( self, tr);
      pdelete( translate);
   }
   if ( pexist( width) && pexist( height)) {
      Point size;
      size. x = pget_i( width);
      size. y = pget_i( height);
      my-> set_size( self, size);
      pdelete( width);
      pdelete( height);
   }
   inherited set( self, profile);
}
예제 #10
0
파일: reservation.c 프로젝트: A1ve5/slurm
/*
 * convert perl HV to reserve_info_t
 */
int
hv_to_reserve_info(HV *hv, reserve_info_t *resv_info)
{
	SV **svp;
	AV *av;
	int i, n;

	memset(resv_info, 0, sizeof(reserve_info_t));

	FETCH_FIELD(hv, resv_info, accounts, charp, FALSE);
	FETCH_FIELD(hv, resv_info, end_time, time_t, TRUE);
	FETCH_FIELD(hv, resv_info, features, charp, FALSE);
	FETCH_FIELD(hv, resv_info, flags, uint16_t, TRUE);
	FETCH_FIELD(hv, resv_info, licenses, charp, FALSE);
	FETCH_FIELD(hv, resv_info, name, charp, TRUE);
	FETCH_FIELD(hv, resv_info, node_cnt, uint32_t, TRUE);
	svp = hv_fetch(hv, "node_inx", 8, FALSE);
	if (svp && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVAV) {
		av = (AV*)SvRV(*svp);
		n = av_len(av) + 2; /* for trailing -1 */
		resv_info->node_inx = xmalloc(n * sizeof(int));
		for (i = 0 ; i < n-1; i += 2) {
			resv_info->node_inx[i] = (int)SvIV(*(av_fetch(av, i ,FALSE)));
			resv_info->node_inx[i+1] = (int)SvIV(*(av_fetch(av, i+1 ,FALSE)));
		}
		resv_info->node_inx[n-1] = -1;
	} else {
		/* nothing to do */
	}
	FETCH_FIELD(hv, resv_info, node_list, charp, FALSE);
	FETCH_FIELD(hv, resv_info, partition, charp, FALSE);
	FETCH_FIELD(hv, resv_info, start_time, time_t, TRUE);
	FETCH_FIELD(hv, resv_info, users, charp, FALSE);
	return 0;
}
예제 #11
0
파일: Point.cpp 프로젝트: brentdbell/Slic3r
void
Pointf::from_SV(SV* point_sv)
{
    AV* point_av = (AV*)SvRV(point_sv);
    this->x = SvNV(*av_fetch(point_av, 0, 0));
    this->y = SvNV(*av_fetch(point_av, 1, 0));
}
예제 #12
0
파일: util.c 프로젝트: dse/geo-modules
void av_to_arrays (AV* points,
                   double** xp,
                   double** yp,
                   int* npointsp) {
    int prev_exists;
    int i;
    int j;
    double prev_x;
    double prev_y;
    double x;
    double y;

    *npointsp = 0;
    *xp = (double *)malloc(sizeof(double) * (av_len(points) + 1));
    *yp = (double *)malloc(sizeof(double) * (av_len(points) + 1));

    for (i = 0, j = 0; i <= av_len(points); i += 1) {
        SV** pointp = av_fetch(points, i, 0);
        if (!pointp || !*pointp) continue;
        SV* point = *pointp;
        if (!IS_ARRAY_REF(point)) continue;
        AV* xy = (AV*)SvRV(point);
        if (av_len(xy) < 1) continue;
        x = SvNV(*(av_fetch(xy, 0, 0)));
        y = SvNV(*(av_fetch(xy, 1, 0)));
        if (prev_exists && x == prev_x && y == prev_y) continue;
        (*xp)[j] = x;
        (*yp)[j] = y;
        j += 1;
        prev_x = x;
        prev_y = y;
        prev_exists = 1;
    }
    *npointsp = j;
}
예제 #13
0
파일: Game.cpp 프로젝트: KAMI911/openmortal
/** In debug mode, this method is used to draw the frame of the fighters.

\param a_pcName The name of the polygon (in the perl namespace)
\param a_iColor The game color to draw the polygon with.
*/
void CGame::DrawPoly( const char* a_pcName, int a_iColor )
{
	AV *poList;
	int n;

	poList = get_av( a_pcName, FALSE );
	if ( poList == NULL )
	{
		return;
	}

	n = av_len( poList ) + 1;

	if ( n< 2 )
	{
		return;
	}

	for ( int i=0; i<n; i += 2 )
	{
		int j = (i+2) % n;

		int x1 = SvIV( *av_fetch( poList, i, false) );
		int y1 = SvIV( *av_fetch( poList, i+1, false) );
		int x2 = SvIV( *av_fetch( poList, j, false) );
		int y2 = SvIV( *av_fetch( poList, j+1, false) );

		sge_Line( gamescreen, x1, y1 + m_iYOffset, x2, y2 + m_iYOffset, a_iColor ) ;
	}
}
예제 #14
0
파일: Point.cpp 프로젝트: dually8/Slic3r
void
Point::from_SV(SV* point_sv)
{
    AV* point_av = (AV*)SvRV(point_sv);
    // get a double from Perl and round it, otherwise
    // it would get truncated
    this->x = lrint(SvNV(*av_fetch(point_av, 0, 0)));
    this->y = lrint(SvNV(*av_fetch(point_av, 1, 0)));
}
예제 #15
0
void plcb_ctor_conversion_opts(PLCB_t *object, AV *options)
{
    SV **tmpsv;
    AV *methav;
    int dummy;
    
#define meth_assert_getpairs(flag, optidx) \
    ((object->my_flags & flag) \
    ? \
        (((tmpsv = av_fetch(options, optidx, 0)) && SvROK(*tmpsv) && \
            (methav = (AV*)SvRV(*tmpsv))) \
            ? (void*)1 \
            :  die("Flag %s specified but no methods provided", #flag)) \
    : NULL)
    
#define meth_assert_assign(target_field, source_idx, diemsg) \
    if((tmpsv = av_fetch(methav, source_idx, 0)) == NULL) { \
        die("Nothing in IDX=%d (%s)", source_idx, diemsg); \
    } \
    if(! ((SvROK(*tmpsv) && SvTYPE(SvRV(*tmpsv)) == SVt_PVCV) ) ) { \
        die("Expected CODE reference at IDX=%d: %s",source_idx, diemsg); \
    } \
    object->target_field = newRV_inc(SvRV(*tmpsv));
    
    if( (tmpsv = av_fetch(options, PLCB_CTORIDX_MYFLAGS, 0))
       && SvIOK(*tmpsv)) {
        object->my_flags = SvUV(*tmpsv);
    }
    
    ctor_extract_methpairs(options, PLCB_CTORIDX_COMP_METHODS,
                           &object->cv_compress, &object->cv_decompress);
    
    if ((object->my_flags & PLCBf_USE_COMPRESSION) &&
        object->cv_compress == NULL) {
        
        die("Compression requested but no methods provided");
    }
    
    
    ctor_extract_methpairs(options, PLCB_CTORIDX_SERIALIZE_METHODS,
                           &object->cv_serialize, &object->cv_deserialize);
    
    if ((object->my_flags & PLCBf_USE_STORABLE) &&
        object->cv_serialize == NULL) {
        
        die("Serialization requested but no methods provided");
    }
        
    if ((tmpsv = av_fetch(options, PLCB_CTORIDX_COMP_THRESHOLD, 0))
       && SvIOK(*tmpsv)) {
        object->compress_threshold = SvIV(*tmpsv);
    } else {
        object->compress_threshold = 0;
    }
}
예제 #16
0
파일: Point.cpp 프로젝트: dually8/Slic3r
bool
Pointf::from_SV(SV* point_sv)
{
    AV* point_av = (AV*)SvRV(point_sv);
    SV* sv_x = *av_fetch(point_av, 0, 0);
    SV* sv_y = *av_fetch(point_av, 1, 0);
    if (!looks_like_number(sv_x) || !looks_like_number(sv_y)) return false;
    
    this->x = SvNV(sv_x);
    this->y = SvNV(sv_y);
    return true;
}
예제 #17
0
static void
Scalarize(pTHX_ SV *sv, AV *av)
{
 int n    = av_len(av)+1;
 if (n == 0)
  sv_setpvn(sv,"",0);
 else
  {
   SV **svp;
   if (n == 1 && (svp = av_fetch(av, 0, 0)))
    {
     STRLEN len = 0;
     char *s  = SvPV(*svp,len);
#ifdef SvUTF8
     int utf8 = SvUTF8(*svp);
     sv_setpvn(sv,s,len);
     if (utf8)
      SvUTF8_on(sv);
#else
     sv_setpvn(sv,s,len);
#endif
    }
   else
    {
     Tcl_DString ds;
     int i;
     Tcl_DStringInit(&ds);
     for (i=0; i < n; i++)
      {
       if ((svp = av_fetch(av, i, 0)))
        {
         SV *el = *svp;
         int temp = 0;
         if (SvROK(el) && !SvOBJECT(SvRV(el)) && SvTYPE(SvRV(el)) == SVt_PVAV)
          {
           el = newSVpv("",0);
           temp = 1;
           if ((AV *) SvRV(*svp) == av)
            abort();
           Scalarize(aTHX_ el,(AV *) SvRV(*svp));
          }
         Tcl_DStringAppendElement(&ds,Tcl_GetString(el));
         if (temp)
          SvREFCNT_dec(el);
        }
      }
     sv_setpvn(sv,Tcl_DStringValue(&ds), Tcl_DStringLength(&ds));
     sv_maybe_utf8(sv);
     Tcl_DStringFree(&ds);
    }
  }
}
예제 #18
0
파일: partition.c 프로젝트: diorsman/slurm
/*
 * convert perl HV to partition_info_t
 */
int
hv_to_partition_info(HV *hv, partition_info_t *part_info)
{
    SV **svp;
    AV *av;
    int i, n;

    memset(part_info, 0, sizeof(partition_info_t));

    FETCH_FIELD(hv, part_info, allow_alloc_nodes, charp, FALSE);
    FETCH_FIELD(hv, part_info, allow_accounts, charp, FALSE);
    FETCH_FIELD(hv, part_info, allow_groups, charp, FALSE);
    FETCH_FIELD(hv, part_info, allow_qos, charp, FALSE);
    FETCH_FIELD(hv, part_info, alternate, charp, FALSE);
    FETCH_FIELD(hv, part_info, cr_type, uint16_t, FALSE);
    FETCH_FIELD(hv, part_info, def_mem_per_cpu, uint32_t, FALSE);
    FETCH_FIELD(hv, part_info, default_time, uint32_t, TRUE);
    FETCH_FIELD(hv, part_info, deny_accounts, charp, FALSE);
    FETCH_FIELD(hv, part_info, deny_qos, charp, FALSE);
    FETCH_FIELD(hv, part_info, flags, uint16_t, TRUE);
    FETCH_FIELD(hv, part_info, grace_time, uint32_t, FALSE);
    FETCH_FIELD(hv, part_info, max_cpus_per_node, uint32_t, FALSE);
    FETCH_FIELD(hv, part_info, max_mem_per_cpu, uint32_t, FALSE);
    FETCH_FIELD(hv, part_info, max_nodes, uint32_t, TRUE);
    FETCH_FIELD(hv, part_info, max_share, uint16_t, TRUE);
    FETCH_FIELD(hv, part_info, max_time, uint32_t, TRUE);
    FETCH_FIELD(hv, part_info, min_nodes, uint32_t, TRUE);
    FETCH_FIELD(hv, part_info, name, charp, TRUE);
    svp = hv_fetch(hv, "node_inx", 8, FALSE);
    if (svp && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVAV) {
        av = (AV*)SvRV(*svp);
        n = av_len(av) + 2; /* for trailing -1 */
        part_info->node_inx = xmalloc(n * sizeof(int));
        for (i = 0 ; i < n-1; i += 2) {
            part_info->node_inx[i] = (int)SvIV(*(av_fetch(av, i, FALSE)));
            part_info->node_inx[i+1] = (int)SvIV(*(av_fetch(av, i+1 ,FALSE)));
        }
        part_info->node_inx[n-1] = -1;
    } else {
        /* nothing to do */
    }
    FETCH_FIELD(hv, part_info, nodes, charp, FALSE);
    FETCH_FIELD(hv, part_info, preempt_mode, uint16_t, TRUE);
    FETCH_FIELD(hv, part_info, priority, uint16_t, TRUE);
    FETCH_FIELD(hv, part_info, qos_char, charp, TRUE);
    FETCH_FIELD(hv, part_info, state_up, uint16_t, TRUE);
    FETCH_FIELD(hv, part_info, total_cpus, uint32_t, TRUE);
    FETCH_FIELD(hv, part_info, total_nodes, uint32_t, TRUE);
    return 0;
}
예제 #19
0
파일: mod_psgi.c 프로젝트: mattn/mod_psgi
static int output_response(request_rec *r, SV *res)
{
    dTHX;
    AV *res_av;
    SV **status;
    SV **headers;
    AV *headers_av;
    SV **body;
    int rc;

    if (!SvROK(res) || SvTYPE(SvRV(res)) != SVt_PVAV) {
        server_error(r, "response must be an array reference");
        return HTTP_INTERNAL_SERVER_ERROR;
    }
    res_av = (AV *) SvRV(res);
    if (av_len(res_av) != 2) {
        server_error(r, "response must have 3 elements");
        return HTTP_INTERNAL_SERVER_ERROR;
    }

    status = av_fetch(res_av, 0, 0);
    if (!SvOK(*status)) {
        server_error(r, "response status must be a scalar value");
        return HTTP_INTERNAL_SERVER_ERROR;
    }
    rc = output_status(r, *status);
    if (rc != OK) return rc;

    headers = av_fetch(res_av, 1, 0);
    if (!SvROK(*headers) || SvTYPE(SvRV(*headers)) != SVt_PVAV) {
        server_error(r, "response headers must be an array reference");
        return HTTP_INTERNAL_SERVER_ERROR;
    }
    headers_av = (AV *) SvRV(*headers);
    if ((av_len(headers_av) + 1) % 2 != 0) {
        server_error(r, "num of response headers must be even");
        return HTTP_INTERNAL_SERVER_ERROR;
    }
    rc = output_headers(r, headers_av);
    if (rc != OK) return rc;

    body = av_fetch(res_av, 2, 0);
    if (!SvROK(*body)) {
        server_error(r, "response body must be a reference");
        return HTTP_INTERNAL_SERVER_ERROR;
    }
    rc = output_body(r, *body);

    return rc;
}
예제 #20
0
파일: ExPolygon.cpp 프로젝트: 4ZM/Slic3r
void
ExPolygon::from_SV(SV* expoly_sv)
{
    AV* expoly_av = (AV*)SvRV(expoly_sv);
    const unsigned int num_polygons = av_len(expoly_av)+1;
    this->holes.resize(num_polygons-1);
    
    SV** polygon_sv = av_fetch(expoly_av, 0, 0);
    this->contour.from_SV(*polygon_sv);
    for (unsigned int i = 0; i < num_polygons-1; i++) {
        polygon_sv = av_fetch(expoly_av, i+1, 0);
        this->holes[i].from_SV(*polygon_sv);
    }
}
예제 #21
0
static CORBA_boolean
put_union (GIOPSendBuffer *buf, CORBA_TypeCode tc, SV *sv)
{
    SV **discriminator;
    SV **value;
    AV *av;
    CORBA_long arm;
    
    if (sv == &PL_sv_undef) {
	if (PL_dowarn & G_WARN_ON)
	    warn ("Uninitialized union");
	if (!porbit_put_sv (buf, tc->discriminator, &PL_sv_undef))
	    return CORBA_FALSE;
	arm = porbit_union_find_arm (tc, &PL_sv_undef);
	if (arm < 0) {
	    warn("union discriminator branch does not match any arm, and no default arm");
	    return CORBA_FALSE;
	}
	return porbit_put_sv (buf, tc->subtypes[arm], &PL_sv_undef);
    }

    if (!SvROK(sv) || 
	(SvTYPE(SvRV(sv)) != SVt_PVAV)) {
	warn("Union must be array reference");
	return CORBA_FALSE;
    }

    av = (AV *)SvRV(sv);
    discriminator = av_fetch(av, 0, 0);

    if (!discriminator && (PL_dowarn & G_WARN_ON))
	warn ("Uninitialized union discriminator");

    if (!porbit_put_sv (buf, tc->discriminator,
	discriminator ? *discriminator : &PL_sv_undef))
	return CORBA_FALSE;
    
    arm = porbit_union_find_arm (tc,
	discriminator ? *discriminator : &PL_sv_undef);
    if (arm < 0) {
	warn("union discriminator branch does not match any arm, and no default arm");
	return CORBA_FALSE;
    }

    value = av_fetch(av, 1, 0);

    return porbit_put_sv (buf, tc->subtypes[arm],
	value ? *value : &PL_sv_undef);
}
예제 #22
0
void
srl_merger_append_all(pTHX_ srl_merger_t *mrg, AV *src)
{
    SSize_t i;
    SV **svptr;
    STRLEN size = 0;
    SSize_t tidx = av_len(src);

    if (mrg->obuf_last_successfull_offset) {
        /* If obuf_last_successfull_offset is true then last merge
         * operation has failed. It means that some cleanup operation needs to
         * be done. */

        SRL_MERGER_TRACE("last merge operation has failed, need to do some cleanup (offset %"UVuf")",
                          mrg->obuf_last_successfull_offset);

        mrg->obuf.pos = mrg->obuf.body_pos + mrg->obuf_last_successfull_offset;
        srl_cleanup_dedup_tlbs(aTHX_ mrg, mrg->obuf_last_successfull_offset);
        DEBUG_ASSERT_BUF_SANE(&mrg->obuf);
    }

    for (i = 0; i <= tidx; ++i) {
        svptr = av_fetch(src, i, 0);
        if (expect_false(svptr == NULL))
            croak("av_fetch returned NULL");

        size += SvLEN(*svptr);
    }

    /* preallocate space in obuf in one go,
     * of course this's is very rough estimation */
    GROW_BUF(&mrg->obuf, size);

    for (i = 0; i <= tidx; ++i) {
        srl_set_input_buffer(aTHX_ mrg, *av_fetch(src, i, 0));
        srl_build_track_table(aTHX_ mrg);

        /* save current offset as last successfull */
        mrg->obuf_last_successfull_offset = BODY_POS_OFS(&mrg->obuf);

        mrg->recursion_depth = 0;
        mrg->ibuf.pos = mrg->ibuf.body_pos + 1;
        srl_merge_single_value(aTHX_ mrg);

        mrg->cnt_of_merged_elements++;
        mrg->obuf_last_successfull_offset = 0;
    }
}
예제 #23
0
파일: PJS_PerlArray.c 프로젝트: gitpan/JSP
static JSBool
perlarray_get(
    JSContext *cx,
    JSObject *obj,
    jsval id,
    jsval *vp
) {
    dTHX;
    SV *ref = (SV *)JS_GetPrivate(cx, obj);
    AV *av = (AV *)SvRV(ref);
    JSBool ok = JS_TRUE;

    PJS_ARRAY_CHECK

    if(JSVAL_IS_INT(id)) {
        I32 ix = JSVAL_TO_INT(id);
        SV **v;
	ENTER; SAVETMPS;
        v = av_fetch(av, ix, 0);
        if(v) {
	    if(SvGMAGICAL(*v)) mg_get(*v);
            ok = PJS_ReflectPerl2JS(aTHX_ cx, obj, sv_mortalcopy(*v), vp);
        }
        else {
            JS_ReportError(cx, "Failed to retrieve element at index: %d", ix);
            ok = JS_FALSE;
        }
	FREETMPS; LEAVE;
    }
    
    return ok;
}
예제 #24
0
파일: args.c 프로젝트: gitpan/Couchbase
static void
load_doc_options(PLCB_t *parent, AV *ret, plcb_OPTION *values)
{
    plcb_OPTION *cur = values;

    for (cur = values; cur->value; cur++) {
        SV **tmpsv;
        int ix;

        if (cur->type == PLCB_ARG_T_PAD) {
            continue;
        }

        if (!strcmp(cur->key, PLCB_ARG_K_CAS)) {
            ix = PLCB_RETIDX_CAS;
        } else if (!strcmp(cur->key,PLCB_ARG_K_EXPIRY)) {
            ix = PLCB_RETIDX_EXP;
        } else if (!strcmp(cur->key,PLCB_ARG_K_VALUE)) {
            ix = PLCB_RETIDX_VALUE;
        } else if (!strcmp(cur->key,PLCB_ARG_K_FMT)) {
            ix = PLCB_RETIDX_FMTSPEC;
        } else {
            continue;
        }
        tmpsv = av_fetch(ret, ix, 0);
        if (!tmpsv) {
            continue;
        }

        if (convert_valspec(cur, *tmpsv) == -1) {
            die("Couldn't convert %s", cur->key);
        }
        cur->sv = *tmpsv;
    }
}
예제 #25
0
파일: PJS_PerlArray.c 프로젝트: gitpan/JSP
static JSBool
perlarray_resolve(
    JSContext *cx,
    JSObject *obj,
    jsval id,
    uintN flags,
    JSObject **objp
) {
    dTHX;
    SV *ref = (SV *)JS_GetPrivate(cx, obj);
    AV *av = (AV *)SvRV(ref);
    SV **v;
    int index;

    PJS_ARRAY_CHECK

    if(JSVAL_IS_STRING(id))
	return JS_TRUE;

    if(JSVAL_IS_INT(id)) {
	index = JSVAL_TO_INT(id);
	v = av_fetch(av, index, 0);
	if(v) {
	    JSString *str = JS_ValueToString(cx,id);
	    if(!JS_DefineProperty(cx, obj, JS_GetStringBytes(str),
	                          JSVAL_VOID, NULL, NULL, 0))
		return JS_FALSE;
	    *objp = obj;
	}
    }
    return JS_TRUE;
}
    /* Run a query and return a list of ranked results.
     * Call this from Perl like `$index->fetch(['water', 'jar'])`. The result
     * will be an arrayref, with each entry of it being an arrayref of the form
     * [id, rank]. They will be sorted by their rank in descending order, so the
     * most relevant document will be at the top. */
    SV* fetch(SV* tokens) const
    {
        AV* av = reinterpret_cast<AV*>(SvRV(tokens));
        std::unordered_map<std::string, int> query;
        for (int i = 0; i <= av_top_index(av); ++i)
        {
            std::string token = string_from_sv(*av_fetch(av, i, 0));
            ++query[token];
        }

        AV* results = newAV();
        for (const auto& id2rank : search(query))
        {
            AV*    entry  = newAV();
            double length = lengths.find(id2rank.first)->second;

            av_push(entry, newSViv(id2rank.first));
            av_push(entry, newSVnv(id2rank.second / length));

            av_push(results, newRV_noinc(reinterpret_cast<SV*>(entry)));
        }

        sortsv(AvARRAY(results), av_top_index(results) + 1, sort_ratings);
        return newRV_noinc(reinterpret_cast<SV*>(results));
    }
예제 #27
0
/* Handles the row, adding it into the internal structure */
static void
invoke_row(AV *req, SV *reqrv, SV *rowsrv)
{
    SV *meth;

    dSP;
    ENTER;
    SAVETMPS;
    PUSHMARK(SP);

    /* First arg */
    XPUSHs(reqrv);

    meth = *av_fetch(req, PLCB_VHIDX_PRIVCB, 0);
    if (rowsrv) {
        XPUSHs(rowsrv);
    }

    PUTBACK;
    call_sv(meth, G_DISCARD|G_EVAL);
    SPAGAIN;

    if (SvTRUE(ERRSV)) {
        warn("Got error in %s", SvPV_nolen(ERRSV));
    }

    if (rowsrv) {
        av_clear((AV *)SvRV(rowsrv));
    }

    FREETMPS;
    LEAVE;
}
예제 #28
0
파일: srl_path.c 프로젝트: ab5tract/Sereal
SRL_STATIC_INLINE void
srl_parse_array(pTHX_ srl_path_t *path, int expr_idx, SV *route)
{
    int range[3];
    const char *loc_str;
    STRLEN loc_len;
    SV *loc;

    assert(route != NULL);
    assert(expr_idx >= 0);
    assert(expr_idx <= av_len(path->expr));
    assert(srl_iterator_stack(aTHX_ path->iter) != NULL);

    loc = *av_fetch(path->expr, expr_idx, 0);
    loc_str = SvPV(loc, loc_len);

    if (is_all(loc_str, loc_len)) {                                                     // *
        srl_parse_array_all(aTHX_ path, expr_idx, route);
    } else if (is_number(loc_str, loc_len)) {                                           // [10]
        srl_parse_array_item(aTHX_ path, expr_idx, route, atoi(loc_str));
    } else if (is_list(loc_str, loc_len)) {                                             // [0,1,2]
        srl_parse_array_list(aTHX_ path, expr_idx, route, loc_str, loc_len);
    } else if (is_range(loc_str, loc_len, (int*) &range)) {                             // [start:stop:step]
        srl_parse_array_range(aTHX_ path, expr_idx, route, (int*) &range);
    }
}
예제 #29
0
/*
 *     Gets the content from hashes
 */
static int get_hv_content(TALLOC_CTX *ctx, REQUEST *request, HV *my_hv, VALUE_PAIR **vps,
			  const char *hash_name, const char *list_name)
{
	SV		*res_sv, **av_sv;
	AV		*av;
	char		*key;
	I32		key_len, len, i, j;
	int		ret = 0;

	*vps = NULL;
	for (i = hv_iterinit(my_hv); i > 0; i--) {
		res_sv = hv_iternextsv(my_hv,&key,&key_len);
		if (SvROK(res_sv) && (SvTYPE(SvRV(res_sv)) == SVt_PVAV)) {
			av = (AV*)SvRV(res_sv);
			len = av_len(av);
			for (j = 0; j <= len; j++) {
				av_sv = av_fetch(av, j, 0);
				ret = pairadd_sv(ctx, request, vps, key, *av_sv, T_OP_ADD, hash_name, list_name) + ret;
			}
		} else ret = pairadd_sv(ctx, request, vps, key, res_sv, T_OP_EQ, hash_name, list_name) + ret;
	}

	if (*vps) LIST_VERIFY(*vps);

	return ret;
}
예제 #30
0
파일: job.c 프로젝트: IFCA/slurm
/* 
 * convert perl HV to job_info_msg_t
 */
int
hv_to_job_info_msg(HV *hv, job_info_msg_t *job_info_msg)
{
	SV **svp;
	AV *av;
	int i, n;

	memset(job_info_msg, 0, sizeof(job_info_msg_t));

	FETCH_FIELD(hv, job_info_msg, last_update, time_t, TRUE);
	svp = hv_fetch(hv, "job_array", 9, FALSE);
	if (! (svp && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVAV)) {
		Perl_warn (aTHX_ "job_array is not an arrary reference in HV for job_info_msg_t");
		return -1;
	}
	av = (AV*)SvRV(*svp);
	n = av_len(av) + 1;
	job_info_msg->record_count = n;

	job_info_msg->job_array = xmalloc(n * sizeof(job_info_t));
	for(i = 0; i < n; i ++) {
		svp = av_fetch(av, i, FALSE);
		if (! (svp && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV)) {
			Perl_warn (aTHX_ "element %d in job_array is not valid", i);
			return -1;
		}
		if (hv_to_job_info((HV*)SvRV(*svp), &job_info_msg->job_array[i]) < 0) {
			Perl_warn(aTHX_ "failed to convert element %d in job_array", i);
			return -1;
		}
	}
	return 0;
}