예제 #1
0
Obj MPIrecv( Obj self, Obj args )
{ volatile Obj buf, source, tag; /* volatile to satisfy gcc compiler */
  MPIARGCHK( 1, 3, MPI_Recv( <string buf>, <opt int source = MPI_ANY_SOURCE>[, <opt int tag = MPI_ANY_TAG> ] ) );
  buf = ELM_LIST( args, 1 );
  source = ( LEN_LIST(args) > 1 ? ELM_LIST( args, 2 ) :
	     INTOBJ_INT(MPI_ANY_SOURCE) );
  tag = ( LEN_LIST(args) > 2 ? ELM_LIST( args, 3 ) :
	  INTOBJ_INT(MPI_ANY_TAG) );
  if ( ! IS_STRING( buf ) )
      ErrorQuit("MPI_Recv():  received a buffer that is not a string", 0L, 0L);
  ConvString( buf );
  /* Note GET_LEN_STRING() returns GAP string length
	 and strlen(CSTR_STRING()) returns C string length (up to '\0') */
  if ( ! MPI_READ_ERROR() )
    MPI_Recv( CSTR_STRING(buf), GET_LEN_STRING(buf),
	     last_datatype=MPIdatatype_infer(buf),
             INT_INTOBJ(source), INT_INTOBJ(tag), MPI_COMM_WORLD, &last_status);
  MPI_READ_DONE();
  if ( ! IS_STRING( buf ) )
  { /* CLEAN THIS UP LATER */
    ErrorQuit("ParGAP: panic: MPI_Recv():  result buffer is not a string", 0L, 0L);
    exit(1);
  }
  /* if (last_datatype != MPI_CHAR) {
       MPI_Get_count(&last_status, last_datatype, &count); etc. } */
  return buf;
}
예제 #2
0
파일: c_rt_lib.c 프로젝트: nianiolang/nl
int nl_compare_internal(ImmT left, ImmT right) {
	if (_global_const_begin_ != NULL && left >= _global_const_begin_ && left < _global_const_end_ 
			&& right >= _global_const_begin_ && right < _global_const_end_) {
		return left == right;
	}
	if (((NlData *)left)->type != ((NlData *)right)->type) {
		if(IS_INT(left) && IS_STRING(right))
			return eq_int_string((NlInt *)left, (NlString *)right);
		if(IS_INT(right) && IS_STRING(left))
			return eq_int_string((NlInt *)right, (NlString *)left);
			
		if(IS_INT(right) && IS_FLOAT(left))
			return ((NlInt *)right)->i == ((NlFloat *)left)->f;
		if(IS_INT(left) && IS_FLOAT(right))
			return ((NlInt *)left)->i == ((NlFloat *)right)->f;
			
		if(IS_FLOAT(left) && IS_STRING(right))
			return eq_float_string((NlFloat *)left, (NlString *)right);
		if(IS_FLOAT(right) && IS_STRING(left))
			return eq_float_string((NlFloat *)right, (NlString *)left);
		return 0;
	}
	if (((NlData *)left)->type == ___TYPE_STRING) {
		return compare_strings((NlString *)left, (NlString *)right) == 0;
	} else if (((NlData *)left)->type == ___TYPE_INT) {
		return (((NlInt *)left)->i == ((NlInt *)right)->i);
	} else if (((NlData *)left)->type == ___TYPE_FLOAT) {
		return (((NlFloat *)left)->f == ((NlFloat *)right)->f);
	} else {
		return left == right;
	}
}
예제 #3
0
파일: pnstdio.c 프로젝트: jongyeol/peanut
static pn_object *PnStdio_PrintLine(pn_world *world, pn_object *object, pn_object *params[], int length)
{
    PN_ASSERT(world != NULL);
    PN_ASSERT(object != NULL);
    PN_ASSERT(length == 1);

    pn_object *a_param = NULL;

    if (IS_STRING(params[0]))
        a_param = params[0];
    else
        a_param = PnFunction_ExecuteByObject("to_str", world, params[0], NULL, 0);

    PN_ASSERT(IS_STRING(a_param));

    __print(a_param->val.str_val);
    __print("\n");

    size_t len = strlen(a_param->val.str_val);
    char *s = (char *)malloc(sizeof(char) * (len + 2));
    strcpy(s, a_param->val.str_val);
    s[len] = '\n';
    s[len+1] = 0;

    pn_object *ret = PnString_Create(world, s);
    PN_ASSERT(ret != NULL);
    PN_ASSERT(IS_STRING(ret));

    free(s);

    return ret;
}
예제 #4
0
파일: disque_job.cpp 프로젝트: AALEKH/acl
bool disque_job::init(const redis_result& rr)
{
	size_t n;
	const redis_result** children = rr.get_children(&n);
	if (n == 0)
		return false;
	if (n % 2 != 0)
		return false;

	string name;
	for (size_t i = 0; i < n;)
	{
		const redis_result* r1 = children[i];
		i++;
		const redis_result* r2 = children[i];
		i++;
		if (r1->get_type() != REDIS_RESULT_STRING)
			continue;
		name.clear();
		r1->argv_to_string(name);
		if (name.empty())
			continue;

		redis_result_t type = r2->get_type();

#define EQ(x, y) !strcasecmp((x).c_str(), (y))
#define IS_NUMBER(x) (x) == REDIS_RESULT_INTEGER
#define IS_STRING(x) (x) == REDIS_RESULT_STRING
#define IS_ARRAY(x)  (x) == REDIS_RESULT_ARRAY

		if (EQ(name, "id") && IS_STRING(type))
			r2->argv_to_string(id_);
		else if (EQ(name, "queue") && IS_STRING(type))
			r2->argv_to_string(queue_);
		else if (EQ(name, "state") && IS_STRING(type))
			r2->argv_to_string(state_);
		else if (EQ(name, "repl") && IS_NUMBER(type))
			repl_ = r2->get_integer();
		else if (EQ(name, "ttl") && IS_NUMBER(type))
			ttl_ = r2->get_integer();
		else if (EQ(name, "ctime") && IS_NUMBER(type))
			ctime_ = r2->get_integer64();
		else if (EQ(name, "delay") && IS_NUMBER(type))
			delay_ = r2->get_integer();
		else if (EQ(name, "retry") && IS_NUMBER(type))
			retry_ = r2->get_integer();
		else if (EQ(name, "nodes-delivered") && IS_ARRAY(type))
			set_nodes_delivered(*r2);
		else if (EQ(name, "nodes-confirmed") && IS_ARRAY(type))
			set_nodes_confirmed(*r2);
		else if (EQ(name, "next-requeue-within") && IS_NUMBER(type))
			next_requeue_within_ = r2->get_integer();
		else if (EQ(name, "next-awake-within") && IS_NUMBER(type))
			next_awake_within_ = r2->get_integer();
		else if (EQ(name, "body") && IS_STRING(type))
			r2->argv_to_string(body_);
	}

	return true;
}
예제 #5
0
파일: ngs.c 프로젝트: Wingie/ngs
void print_exception(VM *vm, VALUE result) {
	// TODO: fprintf to stderr and teach dump_titled to optionally fprintf to stderr too
	printf("====== Exception of type '%s' ======\n", obj_to_cstring(NGS_TYPE_NAME(NORMAL_TYPE_INSTANCE_TYPE(result))));
	// TODO: maybe macro to iterate attributes
	VALUE fields = NGS_TYPE_FIELDS(NORMAL_TYPE_INSTANCE_TYPE(result));
	HASH_OBJECT_ENTRY *e;
	for(e=HASH_HEAD(fields); e; e=e->insertion_order_next) {
		if(obj_is_of_type(ARRAY_ITEMS(NORMAL_TYPE_INSTANCE_FIELDS(result))[GET_INT(e->val)], vm->Backtrace)) {
			printf("=== [ backtrace ] ===\n");
			// Backtrace.frames = [{"closure": ..., "ip": ...}, ...]
			VALUE backtrace = ARRAY_ITEMS(NORMAL_TYPE_INSTANCE_FIELDS(result))[GET_INT(e->val)];
			VALUE frames;
			assert(get_normal_type_instace_attribute(backtrace, make_string("frames"), &frames) == METHOD_OK);
			unsigned int i;
			for(i = 0; i < OBJ_LEN(frames); i++) {
				VALUE frame, resolved_ip, ip;
				frame = ARRAY_ITEMS(frames)[i];
				H(ip, frame, "ip");
				resolved_ip = resolve_ip(vm, (IP)(GET_INT(ip) - 1));
				if(IS_HASH(resolved_ip)) {
					VALUE file, first_line, first_column, last_line, last_column;
					HASH_OBJECT_ENTRY *closure_entry;
					char *closure_name = "<anonymous>";
					H(file, resolved_ip, "file");
					H(first_line, resolved_ip, "first_line");
					H(first_column, resolved_ip, "first_column");
					H(last_line, resolved_ip, "last_line");
					H(last_column, resolved_ip, "last_column");
					closure_entry = get_hash_key(frame, make_string("closure"));
					if(closure_entry && IS_CLOSURE(closure_entry->val) && (IS_HASH(CLOSURE_OBJ_ATTRS(closure_entry->val)))) {
						HASH_OBJECT_ENTRY *name_entry;
						name_entry = get_hash_key(CLOSURE_OBJ_ATTRS(closure_entry->val), make_string("name"));
						if(name_entry) {
							closure_name = obj_to_cstring(name_entry->val);
						}
					}
					// TODO: fix types
					printf("[Frame #%u] %s:%d:%d - %d:%d [in %s]\n", i, obj_to_cstring(file), (int) GET_INT(first_line), (int) GET_INT(first_column), (int) GET_INT(last_line), (int) GET_INT(last_column), closure_name);
				} else {
					printf("[Frame #%u] (no source location)\n", i);
				}
			}
			continue;
		}
		if(obj_is_of_type(ARRAY_ITEMS(NORMAL_TYPE_INSTANCE_FIELDS(result))[GET_INT(e->val)], vm->Exception)) {
			assert(IS_STRING(e->key));
			printf("---8<--- %s - start ---8<---\n", obj_to_cstring(e->key));
			print_exception(vm, ARRAY_ITEMS(NORMAL_TYPE_INSTANCE_FIELDS(result))[GET_INT(e->val)]);
			printf("---8<--- %s - end ---8<---\n", obj_to_cstring(e->key));
			continue;
		}
		if(IS_STRING(e->key)) {
			dump_titled(obj_to_cstring(e->key), ARRAY_ITEMS(NORMAL_TYPE_INSTANCE_FIELDS(result))[GET_INT(e->val)]);
		} else {
			// Should not happen
			dump_titled("attribute key", e->key);
			dump_titled("attribute value", ARRAY_ITEMS(NORMAL_TYPE_INSTANCE_FIELDS(result))[GET_INT(e->val)]);
		}
	}
}
예제 #6
0
파일: strings.c 프로젝트: szastupov/lgears
static int string_eq(vm_thread_t *thread, obj_t *a, obj_t *b)
{
	SAFE_ASSERT(IS_STRING(*a));
	SAFE_ASSERT(IS_STRING(*b));
	string_t *sa = PTR(*a);
	string_t *sb = PTR(*b);

	RETURN_BOOL(strcmp(sa->str, sb->str) == 0);
}
예제 #7
0
파일: cli.c 프로젝트: godzivan/arcadehid
static int f_uconf(int uart, int speed) {
  if (_argc != 2) {
    return -1;
  }
  if (IS_STRING(uart) || IS_STRING(speed) || uart < 0 || uart >= CONFIG_UART_CNT) {
    return -1;
  }
  UART_config(_UART(uart), speed,
      UART_DATABITS_8, UART_STOPBITS_1, UART_PARITY_NONE, UART_FLOWCONTROL_NONE, TRUE);

  return 0;
}
예제 #8
0
파일: VM.cpp 프로젝트: preda/pepper
static bool lessThanNonNum(Value a, Value b) {
    if (IS_STRING(a) && IS_STRING(b)) {
        char *p1 = GET_CSTR(a);
        char *p2 = GET_CSTR(b);
        unsigned len1 = len(a);
        unsigned len2 = len(b);
        int cmp = strncmp(p1, p2, min(len1, len2));
        return cmp < 0 || (cmp == 0 && len1 < len2);
    }
    if (IS_ARRAY(a) && IS_ARRAY(b)) {
        return ARRAY(a)->lessThan(ARRAY(b));
    }
    return false;
}
예제 #9
0
bool validateString(WrenVM* vm, Value* args, int index, const char* argName)
{
  if (IS_STRING(args[index])) return true;

  args[0] = wrenStringFormat(vm, "$ must be a string.", argName);
  return false;
}
예제 #10
0
void _stdcall ReplaceDebugAlloc(void* pOrig, void* pNew, int nSize)
{
	LPDBGALLOCINFO pDbg = gpDbgInfo;
	VALUE(vProgInfo);
	char* pProgInfo = 0;

	if (!pNew || !gbTrackAlloc)
		return;
    
	while (pDbg && pDbg->pPointer != pOrig)
		pDbg = pDbg->next;

    if (pDbg)
	{
		EVALUATE(vProgInfo,"ALLTRIM(STR(LINENO())) + ':' + PROGRAM() + CHR(0)");
		if (IS_STRING(vProgInfo))
		{
			pProgInfo = strdup(HANDTOPTR(vProgInfo));
			FREEHAND(vProgInfo);
		}

		if (pDbg->pProgInfo)
			free(pDbg->pProgInfo);

		pDbg->pPointer = pNew;
		pDbg->pProgInfo = pProgInfo;
		pDbg->nSize = nSize;
	}
}
예제 #11
0
void _stdcall AddDebugAlloc(void* pPointer, int nSize)
{
	VALUE(vProgInfo);
	LPDBGALLOCINFO pDbg;	
	char *pProgInfo = 0;

	if (pPointer && gbTrackAlloc)
	{
		pDbg = malloc(sizeof(DBGALLOCINFO));
		if (!pDbg)
			return;

		EVALUATE(vProgInfo,"ALLTRIM(STR(LINENO())) + ':' + PROGRAM() + CHR(0)");
		if (IS_STRING(vProgInfo))
		{
			pProgInfo = strdup(HANDTOPTR(vProgInfo));
			FREEHAND(vProgInfo);
		}

		pDbg->pPointer = pPointer;
		pDbg->pProgInfo = pProgInfo;
		pDbg->nSize = nSize;
		pDbg->next = gpDbgInfo;
		gpDbgInfo = pDbg;
	}
}
예제 #12
0
파일: strings.c 프로젝트: szastupov/lgears
static int string_length(vm_thread_t *thread, obj_t *ostr)
{
	SAFE_ASSERT(IS_STRING(*ostr));
	string_t *str = PTR(*ostr);

	RETURN_FIXNUM(str->size-1);
}
예제 #13
0
파일: wren_debug.c 프로젝트: hbarve1/wren
void wrenDebugPrintStackTrace(ObjFiber* fiber)
{
  if (IS_STRING(fiber->error))
  {
    fprintf(stderr, "%s\n", AS_CSTRING(fiber->error));
  }
  else
  {
    // TODO: Print something a little useful here. Maybe the name of the error's
    // class?
    fprintf(stderr, "[error object]\n");
  }

  for (int i = fiber->numFrames - 1; i >= 0; i--)
  {
    CallFrame* frame = &fiber->frames[i];
    ObjFn* fn = wrenGetFrameFunction(frame);

    // Built-in libraries and method call stubs have no source path and are
    // explicitly omitted from stack traces since we don't want to highlight to
    // a user the implementation detail of what part of a core library is
    // implemented in C and what is in Wren.
    if (fn->debug->sourcePath == NULL ||
        fn->debug->sourcePath->length == 0)
    {
      continue;
    }

    // -1 because IP has advanced past the instruction that it just executed.
    int line = fn->debug->sourceLines[frame->ip - fn->bytecode - 1];
    fprintf(stderr, "[%s line %d] in %s\n",
            fn->debug->sourcePath->value, line, fn->debug->name);
  }
}
예제 #14
0
파일: p-file.c 프로젝트: mbk/ren-c
*/	static void Write_File_Port(REBREQ *file, REBVAL *data, REBCNT len, REBCNT args)
/*
***********************************************************************/
{
	REBSER *ser;

	if (IS_BLOCK(data)) {
		// Form the values of the block
		// !! Could be made more efficient if we broke the FORM
		// into 32K chunks for writing.
		REB_MOLD mo;
		CLEARS(&mo);
		Reset_Mold(&mo);
		if (args & AM_WRITE_LINES) {
			mo.opts = 1 << MOPT_LINES;
		}
		Mold_Value(&mo, data, 0);
		Set_String(data, mo.series); // fall into next section
		len = SERIES_TAIL(mo.series);
	}

	// Auto convert string to UTF-8
	if (IS_STRING(data)) {
		ser = Encode_UTF8_Value(data, len, ENCF_OS_CRLF);
		file->common.data = ser? BIN_HEAD(ser) : VAL_BIN_DATA(data); // No encoding may be needed
		len = SERIES_TAIL(ser);
	}
	else {
		file->common.data = VAL_BIN_DATA(data);
	}
	file->length = len;
	OS_DO_DEVICE(file, RDC_WRITE);
}
예제 #15
0
const char *typeStr(Value v) {
    const char *s = "?";
    if (IS_NIL(v)) {
        s = "nil";
    } else if (IS_NUM(v)) {
        s = "number";
    } else if (IS_STRING(v)) {
        s = "string";
    } else if (IS_ARRAY(v)) {
        s = "array";
    } else if (IS_MAP(v)) {
        s = "map";
    } else if (IS_FUNC(v)) {
        s = "func";
    } else if (IS_CFUNC(v)) {
        s = "cfunc";
    } else if (IS_CF(v)) {
        s = "cf";
    } else if (IS_CP(v)) {
        s = "cp";
    } else if (IS_PROTO(v)) {
        s = "proto";
    } else if (IS_REG(v)) {
        s = "reg";
    }
    return s;
}
예제 #16
0
bool validateString(WrenVM* vm, Value arg, const char* argName)
{
  if (IS_STRING(arg)) return true;

  vm->fiber->error = wrenStringFormat(vm, "$ must be a string.", argName);
  return false;
}
예제 #17
0
파일: io.c 프로젝트: jaz303/lispy
void pretty_print(env_t *env, VALUE v, int i) {
    if (VALUE_IS_ERROR(v)) {
        printf("<error>\n");
    } else if (IS_LIST(v)) {
        printf("(\n");
		int j;
		for (j = 0; j < list_len(v); j++) {
            indent(i + 1); pretty_print(env, list_get(v, j), i + 1);
		}
		indent(i); printf(")\n");
    } else {
        if (VALUE_IS_INT(v)) {
    		printf("%lld\n", INTVAL(v));
    	} else if (VALUE_IS_BOOL(v)) {
    		printf("#%c\n", BOOLVAL(v) ? 't' : 'f');
        } else if (VALUE_IS_NIL(v)) {
            printf("#nil\n");
        } else if (VALUE_IS_IDENT(v)) {
            printf("%s\n", intern_table_get_str(&env->intern, IDENT(v)));
        } else if (VALUE_IS_ATOM(v)) {
            printf(":%s\n", intern_table_get_str(&env->intern, ATOM(v)));
        } else if (IS_STRING(v)) {
    		printf("\"%s\"\n", string_chars(v));
		} else {
            printf("<unknown %p>\n", v);
    	}
    }
}
예제 #18
0
파일: cli.c 프로젝트: godzivan/arcadehid
static int f_help(char *s) {
  if (IS_STRING(s)) {
    int i = 0;
    while (c_tbl[i].name != NULL ) {
      if (strcmp(s, c_tbl[i].name) == 0) {
        print("%s\t%s", c_tbl[i].name, c_tbl[i].help);
        return 0;
      }
      i++;
    }
    print("%s\tno such command\n", s);
  } else {
    print ("  ");
    cli_print_app_name();
    print("\n");
    int i = 0;
    while (c_tbl[i].name != NULL ) {
      if ((c_tbl[i].dbg && __dbg_level < 1) || (!c_tbl[i].dbg)) {
        int len = strpbrk(c_tbl[i].help, "\n") - c_tbl[i].help;
        char tmp[64];
        strncpy(tmp, c_tbl[i].help, len + 1);
        tmp[len + 1] = 0;
        char fill[24];
        int fill_len = sizeof(fill) - strlen(c_tbl[i].name);
        memset(fill, ' ', sizeof(fill));
        fill[fill_len] = 0;
        print("  %s%s%s", c_tbl[i].name, fill, tmp);
      }
      i++;
    }
  }
  return 0;
}
예제 #19
0
void _fastcall WritePCString(ParamBlk *parm)
{
	char *pNewAddress = 0;
	char **pOldAddress = (char**)p1.ev_long;

	if (IS_STRING(p2) && pOldAddress)
	{
		__try
		{
			if ((*pOldAddress))
			{
				pNewAddress = HeapReAlloc(ghHeap,HEAP_E_FLAG,(*pOldAddress),p2.ev_length+1);
				REPLACEDEBUGALLOC(*pOldAddress,pNewAddress,p2.ev_length);
			}
			else
			{
				pNewAddress = HeapAlloc(ghHeap,HEAP_E_FLAG,p2.ev_length+1);
				ADDDEBUGALLOC(pNewAddress,p2.ev_length);
			}
		}
		__except(SAVEHEAPEXCEPTION()) { }

		if (pNewAddress)
		{
			*pOldAddress = pNewAddress;
			LOCKHAND(p2);
			memcpy(pNewAddress,HANDTOPTR(p2),p2.ev_length);
			pNewAddress[p2.ev_length] = '\0';		
			UNLOCKHAND(p2);
			RET_POINTER(pNewAddress);
			return;
		}
		else
			RAISEERROREX(0);
	}
예제 #20
0
int genTypeName(const DCL_NOM_STR* dcl, char* buf)
{
	char buf2[80];
	char *addr = NULL;
	int i;

	switch(dcl->type->type) {
		case CHAR:
			sprintf(buf2, "c_char");
			break;
		case INT:
			if (dcl->type->flags & SHORT_INT) {
				if (dcl->type->flags & UNSIGNED_TYPE) 
					sprintf(buf2, "c_ushort");
				else 
					sprintf(buf2, "c_short");
			} else if (dcl->type->flags & LONG_INT) {
				if (dcl->type->flags & UNSIGNED_TYPE) 
					sprintf(buf2, "c_ulong");
				else 
					sprintf(buf2, "c_long");
			} else if (dcl->type->flags & LONG_LONG_INT) {
				if (dcl->type->flags & UNSIGNED_TYPE) 
					sprintf(buf2, "c_ulonglong");
				else 
					sprintf(buf2, "c_longlong");
			} else {
				if (dcl->type->flags & UNSIGNED_TYPE) 
					sprintf(buf2, "c_uint");
				else 
					sprintf(buf2, "c_int");
			}
			break;
		case FLOAT:
			sprintf(buf2, "c_float");
			break;
		case DOUBLE:
			sprintf(buf2, "c_double");
			break;
		case ENUM:
			sprintf(buf2, "c_uint");
			break;

		default:
			sprintf(buf2, "%s", dcl->type->name);
	}

	if (IS_ARRAY(dcl) || IS_STRING(dcl)) {
		for (i = 0; i < dcl->ndimensions; i++) {
			bufcat(&addr, " * %d", dcl->dimensions[i]);
		}
		sprintf(buf, "%s %s", buf2, addr);
		free(addr);
	} else {
		sprintf(buf, "%s", buf2);
	}

	return 0;
}
예제 #21
0
MPI_Datatype MPIdatatype_infer(Obj object)
{ if ( IS_STRING(object) ) return MPI_CHAR;
  /* Maybe any other kind of GAP list should assume a list of int's coming */
  if ( IS_HOMOG_LIST(object) && IS_INTOBJ(ELM_LIST(object, 1) ) ) return MPI_INT;
  ErrorQuit("bad vector passed for message handling; must be string or gen. vec.",
	0L,0L);
  return 0;
}
예제 #22
0
파일: wren_core.c 프로젝트: 1100110/wren
// Validates that the given argument in [args] is a String. Returns true if it
// is. If not, reports an error and returns false.
static bool validateString(WrenVM* vm, Value* args, int index,
                           const char* argName)
{
  if (IS_STRING(args[index])) return true;

  args[0] = OBJ_VAL(wrenStringConcat(vm, argName, " must be a string."));
  return false;
}
예제 #23
0
파일: strings.c 프로젝트: szastupov/lgears
static int string_copy_to(vm_thread_t *thread, obj_t *odest, obj_t *opos, obj_t *osrc)
{
	SAFE_ASSERT(IS_STRING(*odest));
	SAFE_ASSERT(IS_HEAP_PTR(*odest));
	SAFE_ASSERT(IS_STRING(*osrc));
	SAFE_ASSERT(IS_FIXNUM(*opos));

	string_t *src = PTR(*osrc);
	string_t *dst = PTR(*odest);
	SAFE_ASSERT(dst->allocated);
	int pos = FIXNUM(*opos);

	SAFE_ASSERT((pos >= 0)
				&& (pos+src->size <= dst->size));
	memcpy(&dst->str[pos], src->str, src->size-1);

	RETURN_OBJ(cvoid);
}
예제 #24
0
파일: strings.c 프로젝트: szastupov/lgears
static int string_ref(vm_thread_t *thread, obj_t *ostr, obj_t *opos)
{
	SAFE_ASSERT(IS_STRING(*ostr));
	SAFE_ASSERT(IS_FIXNUM(*opos));
	string_t *str = PTR(*ostr);
	int pos = FIXNUM(*opos);
	SAFE_ASSERT(pos < str->size-1);

	RETURN_CHAR(str->str[pos]);
}
예제 #25
0
static int
wrap_setattro(PyObject *self, PyObject *name, PyObject *value)
{
    PyObject *wrapped;
    PyObject *descriptor;
    const char *name_as_string;
    int res = -1;

#if PY_MAJOR_VERSION < 3 && defined(Py_USING_UNICODE)
    /* The Unicode to string conversion is done here because the
       existing tp_setattro slots expect a string object as name
       (except under Python 3) and we wouldn't want to break those. */

    if (PyUnicode_Check(name)) {
        name = PyUnicode_AsEncodedString(name, NULL, NULL);
        if (name == NULL)
            return -1;
    }
    else
#endif

    if (!IS_STRING(name)){
        PyErr_SetString(PyExc_TypeError, "attribute name must be string");
        return -1;
    }
    else
        Py_INCREF(name);

    descriptor = WrapperType_Lookup(self->ob_type, name);

    if (descriptor != NULL
#if PY_MAJOR_VERSION < 3 // This is always true in Python 3 (I think)
        && PyType_HasFeature(descriptor->ob_type, Py_TPFLAGS_HAVE_CLASS)
#endif
        && descriptor->ob_type->tp_descr_set != NULL)
      {
        res = descriptor->ob_type->tp_descr_set(descriptor, self, value);
        goto finally;
      }

    name_as_string = MAKE_STRING(name);

    wrapped = Proxy_GET_OBJECT(self);
    if (wrapped == NULL) {
        PyErr_Format(PyExc_RuntimeError,
            "object is NULL; requested to set attribute '%s'",
            name_as_string);
        goto finally;
    }
    res = PyObject_SetAttr(wrapped, name, value);

finally:
    Py_DECREF(name);
    return res;
}
예제 #26
0
bool validateKey(WrenVM* vm, Value arg)
{
  if (IS_BOOL(arg) || IS_CLASS(arg) || IS_FIBER(arg) || IS_NULL(arg) ||
      IS_NUM(arg) || IS_RANGE(arg) || IS_STRING(arg))
  {
    return true;
  }

  vm->fiber->error = CONST_STRING(vm, "Key must be a value type or fiber.");
  return false;
}
예제 #27
0
파일: strings.c 프로젝트: szastupov/lgears
static int string_concat(vm_thread_t *thread, obj_t *oa, obj_t *ob)
{
	SAFE_ASSERT(IS_STRING(*oa));
	SAFE_ASSERT(IS_STRING(*ob));

	//FIXME: it's not gc safe
	string_t *a = PTR(*oa);
	string_t *b = PTR(*ob);

	size_t new_size = a->size + b->size - 1;
	void *mem = heap_alloc(&thread->heap, new_size+sizeof(string_t), t_string);
	string_t *new_str = mem;
	new_str->str = mem + sizeof(string_t);
	new_str->size = new_size;

	int sep = a->size-1;
	memcpy(new_str->str, a->str, sep);
	memcpy(new_str->str+sep, b->str, b->size);

	RETURN_OBJ(MAKE_HEAP_PTR(new_str));
}
예제 #28
0
bool validateKey(WrenVM* vm, Value* args, int index)
{
  Value arg = args[index];
  if (IS_BOOL(arg) || IS_CLASS(arg) || IS_NULL(arg) ||
      IS_NUM(arg) || IS_RANGE(arg) || IS_STRING(arg))
  {
    return true;
  }

  args[0] = CONST_STRING(vm, "Key must be a value type.");
  return false;
}
예제 #29
0
static int
tclArgNumberGen(DCL_NOM_STR *nom)
{
   int n = -1;

   switch (nom->type->type) {

      case CHAR:
      case SHORT:
      case INT:
      case FLOAT:
      case DOUBLE:
      case ENUM:
	 n = 1;
	 break;

      case STRUCT:
      case UNION:
      {
	 int p;
	 DCL_NOM_LIST *m;

	 n = 0;
	 for (m = nom->type->members; m != NULL; m = m->next) {
	    p = tclArgNumberGen(m->dcl_nom);
	    if (p < 0) {
	       fprintf(stderr,
		       "Error: struct member %s was problematic.\n",
		       m->dcl_nom->name);
	       n = -1;
	       break;
	    } else
	       n += p;
	 }
	 break;
      }

      case TYPEDEF:
	 fprintf(stderr, "Warning: encountered a typedef for %s.\n",
		 nom->name);
	 break;
   }

   if (IS_ARRAY(nom)) {
      int i;

      for(i=0; i<nom->ndimensions-(IS_STRING(nom)?1:0); i++)
	 n *= nom->dimensions[i];
   }

   return n;
}
예제 #30
0
파일: cli.c 프로젝트: godzivan/arcadehid
static int f_uwrite(int uart, char* data) {
  if (_argc != 2 || !IS_STRING(data)) {
    return -1;
  }
  if (uart < 0 || uart >= CONFIG_UART_CNT) {
    return -1;
  }
  char c;
  while ((c = *data++) != 0) {
    UART_put_char(_UART(uart), c);
  }
  return 0;
}