Object *getAnnotationsAsArray(AnnotationData *annotations) { Object *array; if(annotations == NULL) return NULL; if((array = allocTypeArray(T_BYTE, annotations->len)) == NULL) return NULL; memcpy(ARRAY_DATA(array, void*), annotations->data, annotations->len); return array; }
Object *createStringFromUnicode(unsigned short *unicode, int len) { Object *array = allocTypeArray(T_CHAR, len); Object *ob = allocObject(string_class); if(array != NULL && ob != NULL) { unsigned short *data = (unsigned short *)ARRAY_DATA(array); memcpy(data, unicode, len*sizeof(unsigned short)); INST_DATA(ob)[count_offset] = len; INST_DATA(ob)[value_offset] = (uintptr_t)array; return ob; } return NULL; }
Object *createString(const char* utf8) { int len = utf8Len(utf8); unsigned short *data; Object *array; Object *ob; if((array = allocTypeArray(T_CHAR, len)) == NULL || (ob = allocObject(string_class)) == NULL) return NULL; data = (unsigned short *)ARRAY_DATA(array); convertUtf8(utf8, data); INST_DATA(ob)[count_offset] = len; INST_DATA(ob)[value_offset] = (uintptr_t)array; return ob; }
/* * Create a new array which type is [C. * In interp.c's OPC_LDC. * @qcliu 2015/03/08 * invoked by:creatString(); */ O char2Char(char *s) { C class; int length; O obj; int i; length = strlen(s); obj = (O) allocTypeArray(T_CHAR, length, NULL); for (i = 0; i < length; i++) { *((char *) (unsigned short *) obj->data + i) = s[i]; } return obj; }