예제 #1
0
파일: paste.c 프로젝트: taksatou/tmux
/*
 * Add an item onto the tail of the stack, freeing the bottom if at limit. Note
 * that the caller is responsible for allocating data.
 */
void
paste_add_tail(struct paste_stack *ps, char *data, size_t size, u_int limit)
{
	struct paste_buffer	*pb;

	if (size == 0)
		return;

	while (ARRAY_LENGTH(ps) >= limit) {
		pb = ARRAY_LAST(ps);
		xfree(pb->data);
		xfree(pb);
		ARRAY_TRUNC(ps, 1);
	}

	pb = xmalloc(sizeof *pb);

	if (ARRAY_LENGTH(ps) > 0) {
		ARRAY_ADD(ps, ARRAY_FIRST(ps));
		ARRAY_SET(ps, 0, pb);
	} else {
		ARRAY_ADD(ps, pb);
	}
    //	ARRAY_INSERT(ps, 0, pb);

	pb->data = data;
	pb->size = size;
}
예제 #2
0
파일: JNI.cpp 프로젝트: restorer/lime
	value JObjectToHaxe (JNIEnv *inEnv, JNIType inType, jobject inObject) {
		
		if (inObject == 0) {
			
			return alloc_null ();
			
		}
		
		if (inType.isUnknownType ()) {
			
			jclass cls = inEnv->GetObjectClass (inObject);
			
			if (cls) {
				
				for (int i = 0; i < jniELEMENTS; i++) {
					
					if (JNIType::elementClass[i] == 0) continue;
					
					if (inEnv->IsSameObject (cls, JNIType::elementClass[i])) {
						
						inType = JNIType ((JNIElement)i, 0);
						break;
						
					}
					
				}
				
				if (inType.isUnknownType ()) {
					
					for (int i = 0; i < jniELEMENTS; i++) {
						
						if (JNIType::elementArrayClass[i] == 0) continue;
						
						if (inEnv->IsSameObject (cls, JNIType::elementArrayClass[i])) {
							
							inType = JNIType ((JNIElement)i, 1);
							break;
							
						}
						
					}
					
				}
				
				if (inType.isUnknownType ()) {
					
					if (inEnv->CallBooleanMethod (cls, isArrayClass)) {
						
						inType = JNIType (jniUnknown, 1);
						
					}
					
				}
				
			}
			
			if (inType.isUnknownType ()) {
				
				inType = JNIType (jniObject, 0);
				
			}
			
		}
		
		if (inType.arrayDepth > 1 || (inType.arrayDepth == 1 && inType.element < jniPODStart)) {
			
			int len = inEnv->GetArrayLength ((jarray)inObject);
			value result = alloc_array (len);
			JNIType child = inType.elemType ();
			
			for (int i = 0; i < len; i++) {
				
				val_array_set_i (result, i, JObjectToHaxe (inEnv, child, inEnv->GetObjectArrayElement ((jobjectArray)inObject, i)));
				
			}
			
			return result;
			
		} else if (inType.arrayDepth == 1) {
			
			int len = inEnv->GetArrayLength ((jarray)inObject);
			value result = alloc_array (len);
			
			switch (inType.element) {
				
				ARRAY_SET (Boolean, jboolean, alloc_bool)
				//ARRAY_SET (Byte, jbyte, alloc_int)
				ARRAY_SET (Char, jchar, alloc_int)
				ARRAY_SET (Short, jshort, alloc_int)
				ARRAY_SET (Int, jint, alloc_int)
				ARRAY_SET (Long, jlong, alloc_int)
				ARRAY_SET (Float, jfloat, alloc_float)
				ARRAY_SET (Double, jdouble, alloc_float)
				
				case jniByte:
				{
					if (len > 0) {
						
						jboolean copy;
						jbyte *data = inEnv->GetByteArrayElements ((jbyteArray)inObject, &copy);
						
						for (int i = 0; i < len; i++) {
							
							val_array_set_i (result, i, alloc_int (data[i]));
							
						}
						
						inEnv->ReleaseByteArrayElements ((jbyteArray)inObject, data, JNI_ABORT);
						
					}
				}
				break;
				
			}
			
			return result;
			
		} else {