Esempio n. 1
0
    /**
Copies an array from the specified source array, beginning at the specified position,
to the specified position of the destination array. A subsequence of array components
are copied from the source array referenced by src to the destination array referenced
by dest. The number of components copied is equal to the length argument. T
he components at positions srcPos through srcPos+length-1 in the source array are
copied into positions destPos through destPos+length-1, respectively, of the
destination array.

If the src and dest arguments refer to the same array object, then the copying is performed as if the components at positions srcPos through srcPos+length-1 were first copied to a temporary array with length components and then the contents of the temporary array were copied into positions destPos through destPos+length-1 of the destination array. 

If dest is null, then a NullPointerException is thrown. 

If src is null, then a NullPointerException is thrown and the destination array is not modified. 

Otherwise, if any of the following is true, an ArrayStoreException is thrown and the destination is not modified: 

The src argument refers to an object that is not an array. 
The dest argument refers to an object that is not an array. 
The src argument and dest argument refer to arrays whose component types are different primitive types. 
The src argument refers to an array with a primitive component type and the dest argument refers to an array with a reference component type. 
The src argument refers to an array with a reference component type and the dest argument refers to an array with a primitive component type. 
Otherwise, if any of the following is true, an IndexOutOfBoundsException is thrown and the destination is not modified: 

The srcPos argument is negative. 
The destPos argument is negative. 
The length argument is negative. 
srcPos+length is greater than src.length, the length of the source array. 
destPos+length is greater than dest.length, the length of the destination array. 
Otherwise, if any actual component of the source array from position srcPos through srcPos+length-1 cannot be converted to the component type of the destination array by assignment conversion, an ArrayStoreException is thrown. In this case, let k be the smallest nonnegative integer less than length such that src[srcPos+k] cannot be converted to the component type of the destination array; when the exception is thrown, source array components from positions srcPos through srcPos+k-1 will already have been copied to destination array positions destPos through destPos+k-1 and no other positions of the destination array will have been modified. (Because of the restrictions already itemized, this paragraph effectively applies only to the situation where both arrays have component types that are reference types.)

Parameters:
src the source array.
srcPos starting position in the source array.
dest the destination array.
destPos starting position in the destination data.
length the number of array elements to be copied.
Throws:
HaikuWRONG: IndexOutOfBoundsException - if copying would cause access of data outside array bounds.
Experiment (see ArrayIndexTest) shows that Sun'S JVM throws: ArrayIndexOutOfBoundsException
ArrayStoreException - if an element in the src array could not be stored into the dest array because of a type mismatch.
NullPointerException - if either src or dest is null.
     */
void native_java_lang_System_arraycopy_Ljava_lang_Object_ILjava_lang_Object_IIV() {
	int      length=  top.s1.i;
	int      destPos= ipop();
    array_t* dest=    (array_t*) apop();
	int      srcPos=  ipop();
	array_t* src=     (array_t*) apop();
	int size;
	popTop();

#if	HAIKU_InternalExceptionEnable & NullPointerException
	if (src==NULL || dest==NULL) {
		throwException(NullPointerException, 0);
		return;
	}
#endif
#if	HAIKU_InternalExceptionEnable & ArrayIndexOutOfBoundsException
	if ( srcPos<0 ||destPos<0 ||length <0 || srcPos+length > src->length || destPos+length >dest->length) throwException(ArrayIndexOutOfBoundsException, srcPos);
#endif

	if (length==0) return;

	size=getSize(dest); // Hierhin wg. möglicher integer div by 0 (if dest->length==0)

#if	HAIKU_InternalExceptionEnable & ArrayStoreException
	if (size!=getSize(src)) throwException(ArrayStoreException, size);
#endif

	if (!isExceptionThrown(NULL))
		memcpy(dest->array+destPos*size, src->array+srcPos*size, length*size);
}
Esempio n. 2
0
void native_haiku_vm_MemoryAccess_setMemory16_IIV() {
	uint16_t      value=  top.s1.i;
	uint8_t *    mem_addr= &mem[ipop()];
	setMemory16(mem_addr, value);
	popTop();
}
Esempio n. 3
0
void native_haiku_vm_MemoryAccess_setMemory16_IIV() {
	uint16_t      value=  top.s1.i;
	uint16_t *    mem_addr=  (uint16_t *)ipop();
	*mem_addr=value;
	popTop();
}
Esempio n. 4
0
void
parse(char *f, int fd, int varoverride)
{
    int hline;
    char *body;
    Word *head, *tail;
    int attr, set, pid;
    char *prog, *p;
    int newfd;
    Biobuf in;
    Bufblock *buf;

    if(fd < 0) {
        perror(f);
        Exit();
    }
    ipush();
    infile = strdup(f);
    mkinline = 1;
    Binit(&in, fd, OREAD);
    buf = newbuf();
    while(assline(&in, buf)) {
        hline = mkinline;
        switch(rhead(buf->start, &head, &tail, &attr, &prog))
        {
        case '<':
            p = wtos(tail, ' ');
            if(*p == 0) {
                SYNERR(-1);
                fprint(2, "missing include file name\n");
                Exit();
            }
            newfd = open(p, OREAD);
            if(newfd < 0) {
                fprint(2, "warning: skipping missing include file: ");
                perror(p);
            } else
                parse(p, newfd, 0);
            break;
        case '|':
            p = wtos(tail, ' ');
            if(*p == 0) {
                SYNERR(-1);
                fprint(2, "missing include program name\n");
                Exit();
            }
            execinit();
            pid=pipecmd(p, envy, &newfd);
            if(newfd < 0) {
                fprint(2, "warning: skipping missing program file: ");
                perror(p);
            } else
                parse(p, newfd, 0);
            while(waitup(-3, &pid) >= 0)
                ;
            if(pid != 0) {
                fprint(2, "bad include program status\n");
                Exit();
            }
            break;
        case ':':
            body = rbody(&in);
            addrules(head, tail, body, attr, hline, prog);
            break;
        case '=':
            if(head->next) {
                SYNERR(-1);
                fprint(2, "multiple vars on left side of assignment\n");
                Exit();
            }
            if(symlook(head->s, S_OVERRIDE, 0)) {
                set = varoverride;
            } else {
                set = 1;
                if(varoverride)
                    symlook(head->s, S_OVERRIDE, (void *)"");
            }
            if(set) {
                /*
                char *cp;
                dumpw("tail", tail);
                cp = wtos(tail, ' '); print("assign %s to %s\n", head->s, cp); free(cp);
                */
                setvar(head->s, (void *) tail);
                symlook(head->s, S_WESET, (void *)"");
            }
            if(attr)
                symlook(head->s, S_NOEXPORT, (void *)"");
            break;
        default:
            SYNERR(hline);
            fprint(2, "expected one of :<=\n");
            Exit();
            break;
        }
    }
    close(fd);
    freebuf(buf);
    ipop();
}