Exemple #1
0
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;
}
Exemple #2
0
html_valid_status_t
html_valid_tag_attr (AV * av, unsigned int tag_id, unsigned int version)
{
    const char * yes_no[n_attributes];
    int i;
    int j;
    int n_attr;
    TagAttributes (tag_id, version, yes_no, & n_attr);
    if (av_len (av) != -1) {
	fprintf (stderr, "%s:%d: unexpected non-empty array with %d elements",
		 __FILE__, __LINE__, (int) (av_len (av) + 1));
	return html_valid_ok;
    }
    if (n_attr == 0) {
	return html_valid_ok;
    }
    j = 0;
    for (i = 0; i < n_attributes; i++) {
	if (yes_no[i]) {
	    SV * attribute;
	    attribute = newSVpv (yes_no[i], strlen (yes_no[i]));
	    av_push (av, attribute);
//	    fprintf (stderr, "Adding %d, %s\n", j, yes_no[i]);
	    j++;
	}
    }
    if (j != n_attr) {
	fprintf (stderr, "%s:%d: inconsistency between expected number of attributes %d and stored number %d\n",
		 __FILE__, __LINE__, n_attr, j);
    }
    return html_valid_ok;
}
Exemple #3
0
static CORBA_boolean
put_array (GIOPSendBuffer *buf, CORBA_TypeCode tc, SV *sv)
{
    AV *av;
    CORBA_unsigned_long i;
    SV **value;

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

    av = (AV *)SvRV(sv);

    if (av_len(av)+1 != (I32)tc->length) {
	warn("Array argument should be of length %d, is %d", tc->length, av_len(av)+1);
	return CORBA_FALSE;
    }
	
    for (i = 0; i < tc->length; i++) {
	value = av_fetch(av, i, 0);
	if (!porbit_put_sv (buf, tc->subtypes[0],
		value ? *value : &PL_sv_undef))
	    return CORBA_FALSE;
    }

    return CORBA_TRUE;
}
Exemple #4
0
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;
}
Exemple #5
0
static void _MopMmV_wrapper (pTHX_ CV *cv) {
    bool has_events;
    I32  j, count;
    SV** args;
    CV*  body;
    SV*  object  = newRV_noinc((SV*) cv);
    AV*  results = newAV();
    
    dXSARGS;

    has_events = MopOV_has_events(object);
    body       = (CV*) CvXSUBANY(cv).any_uv;

    if (has_events) {
        Newx(args, items, SV*);
        for (j = 0; j < items; j++) {
            args[j] = ST(j);
        }
        MopOV_fire_event(object, newSVpv("before:EXECUTE", 14), args, items-1);
    }

    {
        ENTER;
        PUSHMARK(SP);
        for (j = 0; j < items; j++) {
            PUSHs(args[j]);
        }
        PUTBACK;
        count = call_sv((SV*) body, GIMME_V);
        SPAGAIN;

        while (count-- > 0) {
            av_push(results, POPs);
        }

        LEAVE;
    }

    for (j = 0; j < av_len(results) + 1; j++) {
        ST(j) = *av_fetch(results, av_len(results) - j, 0);
    }

    if (has_events) {
        MopOV_fire_event(object, newSVpv("after:EXECUTE", 13), args, items-1);   
    }

    XSRETURN(av_len(results) + 1);
}
Exemple #6
0
/*
 * convert perl HV to slurm_step_launch_params_t
 */
int
hv_to_slurm_step_launch_params(HV *hv, slurm_step_launch_params_t *params)
{
	int i, num_keys;
	STRLEN vlen;
	I32 klen;
	SV **svp;
	HV *environ_hv, *local_fds_hv, *fd_hv;
	AV *argv_av;
	SV *val;
	char *env_key, *env_val;

	slurm_step_launch_params_t_init(params);

	if((svp = hv_fetch(hv, "argv", 4, FALSE))) {
		if(SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVAV) {
			argv_av = (AV*)SvRV(*svp);
			params->argc = av_len(argv_av) + 1;
			if (params->argc > 0) {
				/* memory of params MUST be free-ed by libslurm-perl */
				Newz(0, params->argv, (int32_t)(params->argc + 1), char*);
				for(i = 0; i < params->argc; i ++) {
					if((svp = av_fetch(argv_av, i, FALSE)))
						*(params->argv + i) = (char*) SvPV_nolen(*svp);
					else {
						Perl_warn(aTHX_ "error fetching `argv' of job descriptor");
						free_slurm_step_launch_params_memory(params);
						return -1;
					}
				}
			}
		} else {
Exemple #7
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));
}
Exemple #8
0
AV* coerce1D ( SV* arg, int n ) {

   /* n is the size of array var[] (n=1 for 1 element, etc.) */
   
   AV* array;
   I32 i,m;
   
   /* In ref to scalar case we can do nothing - we can only hope the
      caller made the scalar the right size in the first place  */

   if (is_scalar_ref(arg)) /* Do nothing */
       return (AV*)NULL;
   
   /* Check what has been passed and create array reference whether it
      exists or not */

  if (SvTYPE(arg)==SVt_PVGV) {
       array = GvAVn((GV*)arg);                             /* glob */
   }else if (SvROK(arg) && SvTYPE(SvRV(arg))==SVt_PVAV) {
       array = (AV *) SvRV(arg);                           /* reference */
   }else{
       array = newAV();                                    /* Create */
       sv_setsv(arg, newRV((SV*) array));                            
   }
   
   m = av_len(array);
   
   for (i=m+1; i<n; i++) {
      av_store( array, i, newSViv( (IV) 0 ) );
   }
   
   return array;
}
Exemple #9
0
USER_OBJECT_ 
fromPerlArray(AV *val, unsigned int depth) 
{
 I32 n;
 USER_OBJECT_ ans;
 int i;
 SV **el;
 dTHX;

 if(val == NULL)
    return(NULL_USER_OBJECT);

 n = av_len(val);
 n++;
#ifdef R_PERL_DEBUG
 fprintf(stderr, "Got an array %d\n", (int) n);
#endif
 PROTECT(ans = NEW_LIST(n));
  for(i = 0; i < n; i++) {
    el = av_fetch(val, i, 0);
    SET_VECTOR_ELT(ans, i, fromPerl(*el, TRUE));
  } 
 UNPROTECT(1);
 return(ans);
}
Exemple #10
0
PJS_EXTERN JSBool
PJS_Call_js_function(
    pTHX_
    JSContext *cx,
    JSObject *gobj,
    jsval func,
    AV *av,
    jsval *rval
) {
    jsval *arg_list;
    SV *val;
    int arg_count, i;
    JSBool res;
    
    arg_count = av_len(av);

    Newz(1, arg_list, arg_count + 1, jsval);
    if(!arg_list) {
	JS_ReportOutOfMemory(cx);
	return JS_FALSE;
    }

    for(i = 0; i <= arg_count; i++) {
        val = *av_fetch(av, i, 0);

        if (!PJS_ReflectPerl2JS(aTHX_ cx, gobj, val, &(arg_list[i]))) {
            Safefree(arg_list);
            croak("Can't convert argument number %d to jsval", i);
        }
    }
    res = JS_CallFunctionValue(cx, gobj, func, i, arg_list, rval);
    Safefree(arg_list);
    return res;
}
Exemple #11
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;
}
Exemple #12
0
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);
    }
}
Exemple #13
0
SRL_STATIC_INLINE void
srl_parse_next(pTHX_ srl_path_t *path, int expr_idx, SV *route)
{
    srl_iterator_t *iter = path->iter;

    assert(route != NULL);
    SRL_PATH_TRACE("expr_idx=%d", expr_idx);

    if (srl_iterator_eof(aTHX_ iter)) return;
    if (expr_idx > av_len(path->expr)) { // scaned entiry expr
        SV *res;
        print_route(route, "to decode");
        res = srl_iterator_decode(aTHX_ iter);
        SvREFCNT_inc(res);
        av_push(path->results, res); // TODO store route if needed
        return;
    }

    switch (srl_iterator_object_info(aTHX_ iter, NULL)) {
    case SRL_ITERATOR_OBJ_IS_HASH:
        srl_iterator_step_in(aTHX_ iter, 1);
        srl_parse_hash(aTHX_ path, expr_idx, route);
        break;

    case SRL_ITERATOR_OBJ_IS_ARRAY:
        srl_iterator_step_in(aTHX_ iter, 1);
        srl_parse_array(aTHX_ path, expr_idx, route);
        break;
    }
}
Exemple #14
0
static int xsDecode(HV* hv, AV* av, SV* src, bool useIO) {
  csv_t csv;
  int result;

  SetupCsv(&csv, hv);
  if ((csv.useIO = useIO)) {
    csv.tmp = NULL;
    csv.size = 0;
  } else {
    STRLEN size;
    csv.tmp = src;
    csv.bptr = SvPV(src, size);
    csv.size = size;
  }
  result = Decode(&csv, src, av);
  if (result  &&  csv.types) {
    I32 i, len = av_len(av);
    SV** svp;
    
    for (i = 0;  i <= len  &&  i <= csv.types_len;  i++) {
      if ((svp = av_fetch(av, i, 0))  &&  *svp  &&  SvOK(*svp)) {
	switch (csv.types[i]) {
	case CSV_XS_TYPE_IV:
	  sv_setiv(*svp, SvIV(*svp));
	  break;
	case CSV_XS_TYPE_NV:
	  sv_setnv(*svp, SvIV(*svp));
	  break;
	}
      }
    }
  }
  return result;
}
Exemple #15
0
/*
 * 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;
}
Exemple #16
0
long SvFlagsHash(SV * name, char * optname, HV * o) 
{
	int i;
	int val=0;
	if (!name || !SvOK(name))
		return 0;
	if (SvRV(name) && (SvTYPE(SvRV(name)) == SVt_PVAV)) {
		AV * r = (AV*)SvRV(name);
		for(i=0;i<=av_len(r);i++)
			val |= SvOptsHash(*av_fetch(r, i, 0), optname, o);
	} else if (SvRV(name) && (SvTYPE(SvRV(name)) == SVt_PVHV)) {
		HV * r = (HV*)SvRV(name);
		HE * h;
		hv_iterinit(r);
		while((h = hv_iternext(r))) {
			I32 len;
			char * key = hv_iterkey(h, &len);
			SV ** f;
			if (*key == '-') {
				key++;
				len--;
			}
			f = hv_fetch(o, key, len, 0);
			if (f)
				val |= SvIV(hv_iterval(o, h));
			else
				CroakOptsHash(optname, key, o);
		}
	} else
		val |= SvOptsHash(name, optname, o);
	return val;
}
Exemple #17
0
long SvDefFlagsHash (GtkType type, SV *name) {
	long val = 0;
	GtkFlagValue * vals;
	int i;
	vals = gtk_type_flags_get_values(type);
	if (!vals) {
		warn("Invalid type for flags: %s", gtk_type_name(type));
		return SvIV(name);
	}
	if (SvROK(name) && (SvTYPE(SvRV(name)) == SVt_PVAV)) {
		AV * r = (AV*)SvRV(name);
		for(i=0;i<=av_len(r);i++)
			val |= SvEFValueLookup(vals, SvPV(*av_fetch(r, i, 0), PL_na), type);
	} else if (SvROK(name) && (SvTYPE(SvRV(name)) == SVt_PVHV)) {
		HV * r = (HV*)SvRV(name);
		HE * he;
		I32 len;

		hv_iterinit(r);
		while ((he=hv_iternext(r))) {
			val |= SvEFValueLookup(vals, hv_iterkey(he, &len), type);
		}
	} else
		val |= SvEFValueLookup(vals, SvPV(name, PL_na), type);
	return val;
}
Exemple #18
0
/** 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 ) ;
	}
}
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));
    }
}
Exemple #20
0
void TriangleMesh::ReadFromPerl(SV* vertices, SV* facets)
{
    stl.stats.type = inmemory;
    
    // count facets and allocate memory
    AV* facets_av = (AV*)SvRV(facets);
    stl.stats.number_of_facets = av_len(facets_av)+1;
    stl.stats.original_num_facets = stl.stats.number_of_facets;
    stl_allocate(&stl);
    
    // read geometry
    AV* vertices_av = (AV*)SvRV(vertices);
    for (unsigned int i = 0; i < stl.stats.number_of_facets; i++) {
        AV* facet_av = (AV*)SvRV(*av_fetch(facets_av, i, 0));
        stl_facet facet;
        facet.normal.x = 0;
        facet.normal.y = 0;
        facet.normal.z = 0;
        for (unsigned int v = 0; v <= 2; v++) {
            AV* vertex_av = (AV*)SvRV(*av_fetch(vertices_av, SvIV(*av_fetch(facet_av, v, 0)), 0));
            facet.vertex[v].x = SvNV(*av_fetch(vertex_av, 0, 0));
            facet.vertex[v].y = SvNV(*av_fetch(vertex_av, 1, 0));
            facet.vertex[v].z = SvNV(*av_fetch(vertex_av, 2, 0));
        }
        facet.extra[0] = 0;
        facet.extra[1] = 0;
        
        stl.facet_start[i] = facet;
    }
    
    stl_get_size(&(this->stl));
}
Exemple #21
0
Fichier : job.c Projet : 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;
}
Exemple #22
0
static int output_headers(request_rec *r, AV *headers)
{
    dTHX;
    SV *key_sv, *val_sv;
    char *key;

    r->content_type = NULL;
    while (av_len(headers) > -1) {
        key_sv = av_shift(headers);
        val_sv = av_shift(headers);
        if (key_sv == NULL || val_sv == NULL) break;
        key = SvPV_nolen(key_sv);
        if (strcmp(key, "Content-Type") == 0) {
            r->content_type = apr_pstrdup(r->pool, SvPV_nolen(val_sv));
        } else if (strcmp(key, "Content-Length") == 0) {
            ap_set_content_length(r, SvIV(val_sv));
        } else if (strcmp(key, "Status") == 0) {
            server_error(r, "headers must not contain a Status");
            return HTTP_INTERNAL_SERVER_ERROR;
        } else {
            apr_table_add(r->headers_out, key, SvPV_nolen(val_sv));
        }
        SvREFCNT_dec(key_sv);
        SvREFCNT_dec(val_sv);
    }
    return OK;
}
Exemple #23
0
static void
marked_section_update(PSTATE* p_state)
{
    dTHX;
    /* we look at p_state->ms_stack to determine p_state->ms */
    AV* ms_stack = p_state->ms_stack;
    p_state->ms = MS_NONE;

    if (ms_stack) {
	int stack_len = av_len(ms_stack);
	int stack_idx;
	for (stack_idx = 0; stack_idx <= stack_len; stack_idx++) {
	    SV** svp = av_fetch(ms_stack, stack_idx, 0);
	    if (svp) {
		AV* tokens = (AV*)SvRV(*svp);
		int tokens_len = av_len(tokens);
		int i;
		assert(SvTYPE(tokens) == SVt_PVAV);
		for (i = 0; i <= tokens_len; i++) {
		    SV** svp = av_fetch(tokens, i, 0);
		    if (svp) {
			STRLEN len;
			char *token_str = SvPV(*svp, len);
			enum marked_section_t token;
			if (strEQ(token_str, "include"))
			    token = MS_INCLUDE;
			else if (strEQ(token_str, "rcdata"))
			    token = MS_RCDATA;
			else if (strEQ(token_str, "cdata"))
			    token = MS_CDATA;
			else if (strEQ(token_str, "ignore"))
			    token = MS_IGNORE;
			else
			    token = MS_NONE;
			if (p_state->ms < token)
			    p_state->ms = token;
		    }
		}
	    }
	}
    }
    /* printf("MS %d\n", p_state->ms); */
    p_state->is_cdata = (p_state->ms == MS_CDATA);
    return;
}
Exemple #24
0
html_valid_status_t
html_valid_all_attributes (AV * av)
{
    const char * yes_no[n_attributes];
    int i;
    TagAllAttributes (yes_no);
    if (av_len (av) != -1) {
	fprintf (stderr, "%s:%d: unexpected non-empty array with %d elements",
		 __FILE__, __LINE__, (int) (av_len (av) + 1));
	return html_valid_ok;
    }
    for (i = 0; i < n_attributes; i++) {
	SV * attribute;
	attribute = newSVpv (yes_no[i], strlen (yes_no[i]));
	av_push (av, attribute);
    }
    return html_valid_ok;
}
Exemple #25
0
static JSBool
perlarray_enumerate(
    JSContext *cx,
    JSObject *obj,
    JSIterateOp enum_op,
    jsval *statep,
    jsid  *idp
) {
    dTHX;
    SV *ref = (SV *)JS_GetPrivate(cx, obj);
    AV *av = (AV *)SvRV(ref);

    PJS_ARRAY_CHECK

    if(enum_op == JSENUMERATE_INIT) {
	SV *cc = newSViv(0);
	*statep = PRIVATE_TO_JSVAL(cc);
	if(idp) {
	    I32 alen = av_len(av);
	    *idp = INT_TO_JSVAL(alen + 1);
	}
	return JS_TRUE;
    }
    if(enum_op == JSENUMERATE_NEXT) {
	SV *cc = (SV *)JSVAL_TO_PRIVATE(*statep);
	I32 alen = av_len(av);
	I32 curr;
	if(!SvIOK(cc)) {
	    JS_ReportError(cx, "Wrong Array iterator");
	    return JS_FALSE;
	}
	curr = (I32)SvIVX(cc);
	if(curr > alen) { // At end
	    *statep = JSVAL_NULL;
	    sv_free(cc);
	} else {
	    jsval key = INT_TO_JSVAL(curr);
	    SvIV_set(cc, (IV)(curr+1));
	    return JS_ValueToId(cx, key, idp);
	}
    }
    return JS_TRUE;
}
Exemple #26
0
// ACCESSORS
VAstType VAstEnt::type() {
    assert(this);
    AV* avp = castAVp();
    if (!avp || SvTYPE(avp) != SVt_PVAV || av_len(avp)<1) return VAstType::AN_ERROR;
    // $type_svpp = $this->[0]
    SV** type_svpp = av_fetch(avp, 0, 0);
    if (!type_svpp) return VAstType::AN_ERROR;
    VAstType type = (VAstType)(SvIV(*type_svpp));
    return type;
}
Exemple #27
0
void unpack1D ( SV* arg, void * var, char packtype, int n ) {

   /* n is the size of array var[] (n=1 for 1 element, etc.) If n=0 take
      var[] as having the same dimension as array referenced by arg */
   
   int* ivar = NULL;
   float* fvar = NULL;
   double* dvar = NULL;
   short* svar = NULL;
   unsigned char* uvar = NULL;
   AV* array;
   I32 i,m;

   /* Note in ref to scalar case data is already changed */
   
   if (is_scalar_ref(arg)) /* Do nothing */
       return;

   if (packtype!='f' && packtype!='i' && packtype!= 'd' &&
       packtype!='u' && packtype!='s')
       Perl_croak(aTHX_ "Programming error: invalid type conversion specified to unpack1D");
   
   m=n;  array = coerce1D( arg, m );   /* Get array ref and coerce */
   
   if (m==0) 
      m = av_len( array )+1;  

   if (packtype=='i')        /* Cast void array var[] to appropriate type */
      ivar = (int *) var;
   if (packtype=='f') 
      fvar = (float *) var;
   if (packtype=='d') 
      dvar = (double *) var;
   if (packtype=='u') 
     uvar = (unsigned char *) var;
   if (packtype=='s') 
     svar = (short *) var;
 
   /* Unpack into the array */
   
   for(i=0; i<m; i++) {
      if (packtype=='i')
         av_store( array, i, newSViv( (IV)ivar[i] ) );
      if (packtype=='f') 
         av_store( array, i, newSVnv( (double)fvar[i] ) );
     if (packtype=='d') 
         av_store( array, i, newSVnv( (double)dvar[i] ) );
      if (packtype=='u') 
         av_store( array, i, newSViv( (IV)uvar[i] ) );
      if (packtype=='s') 
         av_store( array, i, newSViv( (IV)svar[i] ) );
   }
   
   return;
}
Exemple #28
0
static void
tn_encode_array(SV *data, struct tn_buffer *buf)
{
	AV *array = (AV *)data;
	I32 len = av_len(array) + 1;
	I32 i;

	for(i = len - 1; i >= 0; --i) {
		tn_encode(*av_fetch(array, i, 0), buf);
	}
}
Exemple #29
0
void
MultiPoint::from_SV(SV* poly_sv)
{
    AV* poly_av = (AV*)SvRV(poly_sv);
    const unsigned int num_points = av_len(poly_av)+1;
    this->points.resize(num_points);
    
    for (unsigned int i = 0; i < num_points; i++) {
        SV** point_sv = av_fetch(poly_av, i, 0);
        this->points[i].from_SV_check(*point_sv);
    }
}
Exemple #30
0
static
XS (XS_Xchat_send_modes)
{
	AV *p_targets = NULL;
	int modes_per_line = 0;
	char sign;
	char mode;
	int i = 0;
	const char **targets;
	int target_count = 0;
	SV **elem;

	dXSARGS;
	if (items < 3 || items > 4) {
		xchat_print (ph,
			"Usage: Xchat::send_modes( targets, sign, mode, modes_per_line)"
		);
	} else {
		if (SvROK (ST (0))) {
			p_targets = (AV*) SvRV (ST (0));
			target_count = av_len (p_targets) + 1;
			targets = malloc (target_count * sizeof (char *));
			for (i = 0; i < target_count; i++ ) {
				elem = av_fetch (p_targets, i, 0);

				if (elem != NULL) {
					targets[i] = SvPV_nolen (*elem);
				} else {
					targets[i] = "";
				}
			}
		} else{
			targets = malloc (sizeof (char *));
			targets[0] = SvPV_nolen (ST (0));
			target_count = 1;
		}
		
		if (target_count == 0) {
			XSRETURN_EMPTY;
		}

		sign = (SvPV_nolen (ST (1)))[0];
		mode = (SvPV_nolen (ST (2)))[0];

		if (items == 4 ) {
			modes_per_line = (int) SvIV (ST (3)); 
		}

		xchat_send_modes (ph, targets, target_count, modes_per_line, sign, mode);
		free (targets);
	}
}