Beispiel #1
0
const char* test_object_stack() {
  gc_object_stack stack;

  os_pointer pa = (os_pointer)0xABCDABCDABCDABCD;
  os_pointer pb = (os_pointer)0x1337133713371337;

  initialize_object_stack(&stack, 10);

  push_object(pa, &stack);
  if(stack.stack_low[0] != pa) return "push 1 failed";

  push_object(pb, &stack);
  if(stack.stack_low[1] != pb) return "push 2 failed";

  if(pop_object(&stack) != pb) return "pop 1 failed";

  if(is_object_stack_empty(&stack)) return "is empty 1 failed";

  if(pop_object(&stack) != pa) return "pop 2 failed";

  if(!is_object_stack_empty(&stack)) return "is empty 2 failed";

  finalize_object_stack(&stack);

  return "passed";
}
Beispiel #2
0
static void image_ttf_face_make(INT32 args)
{
   pop_n_elems(args);

   ref_push_object(THISOBJ);
   push_object(clone_object(image_ttf_faceinstance_program,1));
}
Beispiel #3
0
static void pextsElementDecl(void *ctx, const xmlChar *name, int type, xmlElementContentPtr content)
{
  struct mapping  *cmap;
  
  DBG_FUNC_ENTER();
  if (CB_ABSENT(elementDeclSAX)) {
    DBG_FUNC_LEAVE();
    return;
  }

  THIS->ctxt = (xmlParserCtxtPtr)ctx;
  
  push_object(this_object());
  safe_push_text(name);
  push_int(type);
  cmap = tree2mapping(content);
  if (cmap)
    push_mapping(cmap);
  else
    push_int(0);
  push_svalue(&THIS->user_data);
  
  CB_CALL(elementDeclSAX, 5);
  pop_stack();
  
  DBG_FUNC_LEAVE();
}
/**
 * Creates magical stairs after finishing a quest monster.
 */
static void build_quest_stairs(int y, int x)
{
	int ny, nx;

	/* Stagger around */
	while (!square_changeable(cave, y, x) && !square_iswall(cave, y, x) &&
		   !square_isdoor(cave, y, x)) {
		/* Pick a location */
		scatter(cave, &ny, &nx, y, x, 1, FALSE);

		/* Stagger */
		y = ny; x = nx;
	}

	/* Push any objects */
	push_object(y, x);

	/* Explain the staircase */
	msg("A magical staircase appears...");

	/* Create stairs down */
	square_set_feat(cave, y, x, FEAT_MORE);

	/* Update the visuals */
	player->upkeep->update |= (PU_UPDATE_VIEW | PU_MONSTERS);

	/* Fully update the flow */
	player->upkeep->update |= (PU_FORGET_FLOW | PU_UPDATE_FLOW);
}
/* Snapshot the memory for an indirect buffer */
static int snapshot_ib(struct kgsl_device *device, void *snapshot,
	int remain, void *priv)
{
	struct kgsl_snapshot_ib *header = snapshot;
	struct kgsl_snapshot_obj *obj = priv;
	unsigned int *src = obj->ptr;
	unsigned int *dst = snapshot + sizeof(*header);
	int i;

	if (remain < (obj->dwords << 2) + sizeof(*header)) {
		KGSL_DRV_ERR(device,
			"snapshot: Not enough memory for the ib section");
		return 0;
	}

	/* Write the sub-header for the section */
	header->gpuaddr = obj->gpuaddr;
	header->ptbase = obj->ptbase;
	header->size = obj->dwords;

	/* Write the contents of the ib */
	for (i = 0; i < obj->dwords; i++) {
		*dst = *src;
		/* If another IB is discovered, then push it on the list too */

		if (adreno_cmd_is_ib(*src))
			push_object(device, SNAPSHOT_OBJ_TYPE_IB, obj->ptbase,
				*(src + 1), *(src + 2));

		src++;
		dst++;
	}

	return (obj->dwords << 2) + sizeof(*header);
}
Beispiel #6
0
/* Make doors */
static void project_feature_handler_MAKE_DOOR(project_feature_handler_context_t *context)
{
	const int x = context->x;
	const int y = context->y;

	/* Require a grid without monsters */
	if (square_monster(cave, y, x)) return;

	/* Require a floor grid */
	if (!square_isfloor(cave, y, x)) return;

	/* Push objects off the grid */
	if (square_object(cave, y, x))
		push_object(y,x);

	/* Create closed door */
	square_add_door(cave, y, x, true);

	/* Observe */
	if (square_isknown(cave, y, x))
		context->obvious = true;

	/* Update the visuals */
	player->upkeep->update |= (PU_UPDATE_VIEW | PU_MONSTERS);
}
Beispiel #7
0
/*
**! method: Mhash.hash feed(string data)
**!    alt: Mhash.hash update(string data)
**!  Update the current hash context with data.
**!  update() is here for compatibility reasons with Crypto.md5.
**! arg: string data
**!  The data to update the context with.
**! returns:
**!  The current hash object.
**! name: feed - Update the current hash context.
*/
void f_hash_feed(INT32 args) 
{
  if(THIS->hash == NULL) {
    if(THIS->type != -1) {
      free_hash();
      THIS->hash = mhash_init(THIS->type);
      if(THIS->hash == MHASH_FAILED) {
	THIS->hash = NULL;
	Pike_error("Failed to initialize hash.\n");
      }
    } else
      Pike_error("Hash is uninitialized. Use Mhash.Hash()->set_type() to select hash type.\n");
  }
  if(args == 1) {
    if(Pike_sp[-args].type != T_STRING) {
      Pike_error("Invalid argument 1. Expected string.\n");
    }
    mhash(THIS->hash, Pike_sp[-args].u.string->str,
	  Pike_sp[-args].u.string->len << Pike_sp[-args].u.string->size_shift);
  } else {
    Pike_error("Invalid number of arguments to Mhash.Hash->feed(), expected 1.\n");
  }
  pop_n_elems(args);
  push_object(this_object());
}
Beispiel #8
0
static void pextsFatalError(void *ctx, const char *msg, ...)
{
  char    *vmsg;
  va_list  ap;
  
  DBG_FUNC_ENTER();
  if (CB_ABSENT(fatalErrorSAX)) {
    DBG_FUNC_LEAVE();
    return;
  }

  THIS->ctxt = (xmlParserCtxtPtr)ctx;
  
  push_object(this_object());
  /* I'm being lazy here :> */
  vmsg = NULL;
  va_start(ap, msg);
  if (vasprintf(&vmsg, msg, ap) < -1)
    push_int(0);
  else {
    push_text(vmsg);
    free(vmsg);
  }
  push_svalue(&THIS->user_data);
  CB_CALL(fatalErrorSAX, 3);
  pop_stack();
  
  DBG_FUNC_LEAVE();
}
Beispiel #9
0
static void push_log_entry(struct log_entry *le)
{
  struct object *o = clone_object( aap_log_object_program, 0 );
  struct log_object *lo = (struct log_object*)o->storage;
  lo->time = le->t;
  lo->sent_bytes = le->sent_bytes;
  lo->reply = le->reply;
  lo->received_bytes = le->received_bytes;
  lo->raw = make_shared_binary_string(le->raw.str, le->raw.len);
  lo->url = make_shared_binary_string(le->url.str, le->url.len);
  lo->method = make_shared_binary_string(le->method.str, le->method.len);
  lo->protocol = le->protocol;
  le->protocol->refs++;
#ifdef HAVE_INET_NTOP
  {
    char buffer[64];
    lo->from = make_shared_string( inet_ntop(SOCKADDR_FAMILY(le->from),
					     SOCKADDR_IN_ADDR(le->from),
					     buffer, sizeof(buffer)) );
  }
#else
  lo->from = make_shared_string( inet_ntoa(*SOCKADDR_IN_ADDR(le->from)) );
#endif
  push_object( o );
}
Beispiel #10
0
/*
**! method object decode(string data)
**! 	Decodes a XBM image. 
**!
**! note
**!	Throws upon error in data.
*/
static void image_xbm_decode( INT32 args )
{
  struct pike_string *data;
  struct object *o;
  get_all_args( "Image.XBM.decode", args, "%S", &data );
  o = load_xbm( data );
  pop_n_elems(args);
  push_object( o );
}
Beispiel #11
0
/*
 * Check that a path to a file is valid for read or write.
 * This is done by functions in the master object.
 * The path is always treated as an absolute path, and is returned without
 * a leading '/'.
 * If the path was '/', then '.' is returned.
 * Otherwise, the returned path is temporarily allocated by apply(), which
 * means it will be deallocated at next apply().
 */
const char *check_valid_path (const char * path, object_t * call_object, const char * const  call_fun, int writeflg)
{
    svalue_t *v;

    if(!master_ob && !call_object){
    	//early startup, ignore security
    	extern svalue_t apply_ret_value;
        free_svalue(&apply_ret_value, "check_valid_path");
        apply_ret_value.type = T_STRING;
        apply_ret_value.subtype = STRING_MALLOC;
        path = apply_ret_value.u.string = string_copy(path, "check_valid_path");
    	return path;
    }

    if (call_object == 0 || call_object->flags & O_DESTRUCTED)
        return 0;

#ifdef WIN32
    {
        char *p;
        
        for(p=path; *p; p++) if (*p == '\\') *p='/';
    }
#endif

    copy_and_push_string(path);
    push_object(call_object);
    push_constant_string(call_fun);
    if (writeflg)
        v = apply_master_ob(APPLY_VALID_WRITE, 3);
    else
        v = apply_master_ob(APPLY_VALID_READ, 3);

    if (v == (svalue_t *)-1)
        v = 0;
    
    if (v && v->type == T_NUMBER && v->u.number == 0) return 0;
    if (v && v->type == T_STRING) {
        path = v->u.string;
    } else {
        extern svalue_t apply_ret_value;
        
        free_svalue(&apply_ret_value, "check_valid_path");
        apply_ret_value.type = T_STRING;
        apply_ret_value.subtype = STRING_MALLOC;
        path = apply_ret_value.u.string = string_copy(path, "check_valid_path");
    }
    
    if (path[0] == '/')
        path++;
    if (path[0] == '\0')
        path = ".";
    if (legal_path(path))
        return path;

    return 0;
}
Beispiel #12
0
static CLObject create_range_object_for_new(CLObject type_object, sVMInfo* info)
{
    CLObject self;
    CLObject head_object;
    CLObject tail_object;

    head_object = create_int_object(0);
    push_object(head_object, info);

    tail_object = create_int_object(0);
    push_object(tail_object, info);

    self = create_range_object(type_object, head_object, tail_object);
    CLOBJECT_HEADER(self)->mType = type_object;

    pop_object(info);
    pop_object(info);

    return self;
}
void get_near_objects(object_list **out, object_list *in, double x, double y, double distance) {
    object *o;
    
    
    for (; in; in = in->next) {
        o = in->data;
        if (get_distance(x, y, o->x, o->y) < distance + o->a) {
            push_object(out, o);
        }
    }
    
}
INLINE int
valid_hide P1(struct object *, obj)
{
    struct svalue *ret;

    if (!obj) {
	return 0;
    }
    push_object(obj);
    ret = apply_master_ob(APPLY_VALID_HIDE, 1);
    return (!IS_ZERO(ret));
}
Beispiel #15
0
static CLObject create_bool_object_for_new(CLObject type_object, sVMInfo* info)
{
    CLObject self;

    self = create_bool_object(0);
    push_object(self, info);

    CLOBJECT_HEADER(self)->mType = type_object;

    pop_object(info);

    return self;
}
Beispiel #16
0
/*! @decl PathIterator _get_iterator()
 *!
 *! Get an iterator for a given path. The iterator is implicitly used in the
 *! @tt{foreach(;;)@} statement.
 *!
 *! @example
 *!
 *! Cairo.Context ctx = ...;
 *! Cairo.Path p = ctx->copy_path();
 *! foreach(p; int i; Cairo.PathElement e)
 *!   {
 *!     ... examine e here ...
 *!   }
 *!
 */
static void f_path_get_iterator(INT32 args)
{
  struct object* iterator_object;
  struct cairo_mod_path_iterator* iterator;

  iterator_object = clone_object(cairo_mod_path_iterator_program, 0);
  iterator = (struct cairo_mod_path_iterator*)get_storage(iterator_object,
                                                          cairo_mod_path_iterator_program);
  assert(iterator);
  iterator->path_obj = Pike_fp->current_object;
  add_ref(Pike_fp->current_object);
  push_object(iterator_object);
}
Beispiel #17
0
void f_msg_getfd(INT32 args) {
	MESSAGE *message;
	struct object *obj;
	
	message=THISMSG->msg;
	
	pop_n_elems(args);
	if( message->fp ) {
		obj=file_make_object_from_fd(fileno(message->fp), 0x1000,0);
		push_object(obj);
	} else 
		push_int(-1);
}
Beispiel #18
0
static void _image_orient(struct image *source,
			  struct object *o[5],
			  struct image *img[5])
{
   int i;
   struct { int x,y; } or[4]={ {1,0}, {1,1}, {0,1}, {-1,1} };
   int x,y;

   for (i=0; i<5; i++)
   {
      push_int(source->xsize);
      push_int(source->ysize);
      o[i]=clone_object(image_program,2);
      img[i]=get_storage(o[i],image_program);
      push_object(o[i]);
   }

THREADS_ALLOW();
CHRONO("start");
   for (i=0; i<4; i++) /* four directions */
   {
      rgb_group *d=img[i]->img;
      rgb_group *s=source->img;
      int xz=source->xsize;
      int yz=source->ysize;
      int xd=or[i].x;
      int yd=or[i].y;

      for(x=1; x<xz-1; x++)
	 for(y=1; y<yz-1; y++)
	 {
#define FOOBAR(CO) \
  d[x+y*xz].CO \
     = \
  (COLORTYPE) \
     my_abs( s[(x+xd)+(y+yd)*xz].CO - s[(x-xd)+(y-yd)*xz].CO )

	    FOOBAR(r);
	    FOOBAR(g);
	    FOOBAR(b);

#undef FOOBAR
	 }
   }
CHRONO("end");
THREADS_DISALLOW();
}
Beispiel #19
0
static void finished_p(struct callback *foo, void *b, void *c)
{
    extern void f_low_aap_reqo__init( struct c_request_object * );

    aap_clean_cache();

    while(request)
    {
        struct args *arg;
        struct object *o;
        struct c_request_object *obj;

        mt_lock(&queue_mutex);
        arg = request;
        request = arg->next;
        mt_unlock(&queue_mutex);

        o = clone_object( request_program, 0 ); /* see requestobject.c */
        obj = (struct c_request_object *)get_storage(o, c_request_program );
        MEMSET(obj, 0, sizeof(struct c_request_object));
        obj->request = arg;
        obj->done_headers   = allocate_mapping( 20 );
        obj->misc_variables = allocate_mapping( 40 );

        f_low_aap_reqo__init( obj );

        push_object( o );
        assign_svalue_no_free(sp++, &arg->args);

        /*     { */
        /*       JMP_BUF recovery; */

        /*       free_svalue(& throw_value); */
        /*       mark_free_svalue (&throw_value); */

        /*       if(SETJMP(recovery)) */
        /*       { */
        /*       } */
        /*       else */
        /*       { */
        apply_svalue(&arg->cb, 2);
        /*       } */
        /*     } */
        pop_stack();
    }
}
Beispiel #20
0
static void pextsEndDocument(void *ctx)
{
  DBG_FUNC_ENTER();
  if (CB_ABSENT(endDocumentSAX)) {
    DBG_FUNC_LEAVE();
    return;
  }

  THIS->ctxt = (xmlParserCtxtPtr)ctx;
  
  push_object(this_object());
  push_svalue(&THIS->user_data);
  CB_CALL(endDocumentSAX, 2);
  pop_stack();
  
  DBG_FUNC_LEAVE();
}
Beispiel #21
0
static void pextsComment(void *ctx, const xmlChar *value)
{
  DBG_FUNC_ENTER();
  if (CB_ABSENT(commentSAX)) {
    DBG_FUNC_LEAVE();
    return;
  }

  THIS->ctxt = (xmlParserCtxtPtr)ctx;
  
  push_object(this_object());
  safe_push_text(value);
  push_svalue(&THIS->user_data);
  CB_CALL(commentSAX, 3);
  pop_stack();
  
  DBG_FUNC_LEAVE();
}
Beispiel #22
0
static void pextsProcessingInstruction(void *ctx, const xmlChar *target, const xmlChar *data)
{
  DBG_FUNC_ENTER();
  if (CB_ABSENT(processingInstructionSAX)) {
    DBG_FUNC_LEAVE();
    return;
  }

  THIS->ctxt = (xmlParserCtxtPtr)ctx;
  
  push_object(this_object());
  safe_push_text(target);
  safe_push_text(data);
  push_svalue(&THIS->user_data);
  CB_CALL(processingInstructionSAX, 4);
  pop_stack();
  
  DBG_FUNC_LEAVE();
}
Beispiel #23
0
static CLObject alloc_bytes_object(unsigned int len2, CLObject type_object, sVMInfo* info)
{
    CLObject obj;
    CLObject obj2;
    unsigned int size;
    unsigned int chars_size;

    size = object_size();
    obj = alloc_heap_mem(size, type_object);

    push_object(obj, info);

    chars_size = chars_object_size(len2);
    obj2 = alloc_heap_mem(chars_size, 0);
    CLBYTES(obj)->mData = obj2;

    pop_object(info);

    return obj;
}
Beispiel #24
0
static int pextsHasExternalSubset(void *ctx)
{
  struct svalue   sv;
  
  DBG_FUNC_ENTER();
  if (CB_ABSENT(hasExternalSubsetSAX)) {
    DBG_FUNC_LEAVE();
    return 0;
  }

  THIS->ctxt = (xmlParserCtxtPtr)ctx;
  
  push_object(this_object());
  push_svalue(&THIS->user_data);
  CB_CALL(hasExternalSubsetSAX, 2);
  stack_pop_to(&sv);
  
  DBG_FUNC_LEAVE();
  return sv.u.integer;
}
Beispiel #25
0
static void pextsExternalSubset(void *ctx, const xmlChar *name, const xmlChar *externalId, const xmlChar *systemId)
{
  DBG_FUNC_ENTER();
  if (CB_ABSENT(externalSubsetSAX)) {
    DBG_FUNC_LEAVE();
    return;
  }

  THIS->ctxt = (xmlParserCtxtPtr)ctx;
  
  push_object(this_object());
  safe_push_text(name);
  safe_push_text(externalId);
  safe_push_text(systemId);
  push_svalue(&THIS->user_data);
  CB_CALL(externalSubsetSAX, 5);
  pop_stack();
  
  DBG_FUNC_LEAVE();
}
Beispiel #26
0
/* valid_database
 *
 * Calls APPLY_VALID_DATABASE in the master object to provide some
 * security on which objects can tweak your database (we don't want
 * people doing "DELETE * FROM *" or equivalent for us)
 */
svalue_t *valid_database (const char * action, array_t * info)
{
	svalue_t *ret;

	/*
	 * Call valid_database(object ob, string action, mixed *info)
	 *
	 * Return: string - password for access
	 *         int    - 1 for no password, accept, 0 deny
	 */
	push_object(current_object);
	push_constant_string(action);
	push_refed_array(info);

	ret = apply_master_ob(APPLY_VALID_DATABASE, 3);
	if (ret && (ret == (svalue_t *)-1 || (ret->type == T_STRING || (ret->type == T_NUMBER && ret->u.number))))
		return ret;

	error("Database security violation attempted\n");
}
Beispiel #27
0
static int pextsIsStandalone(void *ctx)
{
  struct svalue   sv;
  
  DBG_FUNC_ENTER();
  if (CB_ABSENT(isStandaloneSAX)) {
    DBG_FUNC_LEAVE();
    return 1;
  }

  THIS->ctxt = (xmlParserCtxtPtr)ctx;
  
  push_object(this_object());
  push_svalue(&THIS->user_data);
  CB_CALL(isStandaloneSAX, 2);
  stack_pop_to(&sv);
  
  DBG_FUNC_LEAVE();
  return sv.u.integer;
}
Beispiel #28
0
static void pextsAttributeDecl(void *ctx, const xmlChar *elem, const xmlChar *fullname, int type, int def,
                               const xmlChar *defaultValue, xmlEnumerationPtr tree)
{
  int  nenum;
  
  DBG_FUNC_ENTER();
  if (CB_ABSENT(attributeDeclSAX)) {
    DBG_FUNC_LEAVE();
    return;
  }

  THIS->ctxt = (xmlParserCtxtPtr)ctx;
  
  push_object(this_object());
  safe_push_text(elem);
  safe_push_text(fullname);
  push_int(type);
  push_int(def);
  safe_push_text(defaultValue);
  push_svalue(&THIS->user_data);
  
  if (tree) {
    xmlEnumerationPtr   tmp = tree;
    struct array      *arr;
    
    nenum = 0;
    while (tree) {
      safe_push_text(tmp->name);
      tmp = tmp->next;
      nenum++;
    }
    arr = aggregate_array(nenum);
    push_array(arr);
  } else
    push_int(0);

  CB_CALL(attributeDeclSAX, 8);
  pop_stack();
  
  DBG_FUNC_LEAVE();
}
Beispiel #29
0
static void pextsCdataBlock(void *ctx, const xmlChar *value, int len)
{
  DBG_FUNC_ENTER();
  if (CB_ABSENT(cdataBlockSAX)) {
    DBG_FUNC_LEAVE();
    return;
  }

  THIS->ctxt = (xmlParserCtxtPtr)ctx;
  
  push_object(this_object());
  if (value)
    push_string(make_shared_binary_string((const char*)value, (size_t) len));
  else
    push_int(0);
  push_svalue(&THIS->user_data);
  CB_CALL(cdataBlockSAX, 3);
  pop_stack();
  
  DBG_FUNC_LEAVE();
}
Beispiel #30
0
static void pextsIgnorableWhitespace(void *ctx, const xmlChar *ch, int len)
{
  DBG_FUNC_ENTER();
  if (CB_ABSENT(ignorableWhitespaceSAX)) {
    DBG_FUNC_LEAVE();
    return;
  }

  THIS->ctxt = (xmlParserCtxtPtr)ctx;
  
  push_object(this_object());
  if (ch && len)
    push_string(make_shared_binary_string((const char*)ch, (size_t) len));
  else
    push_int(0);
  push_svalue(&THIS->user_data);
  CB_CALL(ignorableWhitespaceSAX, 3);
  pop_stack();
  
  DBG_FUNC_LEAVE();
}