Fixed filter bins issue

Fixed filter bins issue

--- src/aerospike/aerospike.c
+++ src/aerospike/aerospike.c
@@ -506,7 +506,7 @@
  *******************************************************************************************************
  * Gets a record from the Aerospike database.
  * Method prototype for PHP userland:
- * public int Aerospike::get ( array $key, array &$record [, array $filter [,array $options]] )
+ * public int Aerospike::get ( array $key, array $record [, array $filter [,array $options]] )
  *******************************************************************************************************
  */
 PHP_METHOD(Aerospike, get)
@@ -560,10 +560,8 @@
         options_p = NULL;
     }

-    if (PHP_TYPE_ISNOTARR(record_p)) {
-        zval_dtor(record_p);
-        array_init(record_p);
-    }
+    zval_dtor(record_p);
+    array_init(record_p);

     if (AEROSPIKE_OK != (status = aerospike_transform_iterate_for_rec_key_params(Z_ARRVAL_P(key_record_p),
                                                                                &as_key_for_get_record,
@@ -671,7 +669,7 @@
  *******************************************************************************************************
  * Return an array of objects for the nodes in the Aerospike cluster.
  * Method prototype for PHP userland:
- * public int Aerospike::getNodes ( array &$metadata [, array $options ] )
+ * public int Aerospike::getNodes ( array $metadata [, array $options ] )
  *******************************************************************************************************
  */
 PHP_METHOD(Aerospike, getNodes)
@@ -877,7 +875,7 @@
  *******************************************************************************************************
  * Check if a record exists in the Aerospike database.
  * Method prototype for PHP userland:
- * public int Aerospike::exists ( array $key, array &$metadata [, array $options] )
+ * public int Aerospike::exists ( array $key, array $metadata [, array $options] )
  *******************************************************************************************************
  */
 PHP_METHOD(Aerospike, exists)
@@ -926,7 +924,7 @@
  *******************************************************************************************************
  * Check if a record exists in the Aerospike database.
  * Method prototype for PHP userland:
- * public int Aerospike::getMetadata ( array $key, array &$metadata [, array $options ] )
+ * public int Aerospike::getMetadata ( array $key, array $metadata [, array $options ] )
  *******************************************************************************************************
  */
 PHP_METHOD(Aerospike, getMetadata)


Added Record Class and Exposed its methods.

--- src/aerospike/aerospike.c
+++ src/aerospike/aerospike.c
@@ -148,9 +148,155 @@
 	{ NULL, NULL, NULL }
 };

+/**
+ *  Mapper for PHP Record class to C SDK's struct as_record
+ */
+typedef struct Record_object {
+	/**
+     *  Standard zend_object to represent PHP Record class.
+     *  zend_object.
+     */
+	zend_object std;
+	/**
+     *  C SDK's as_record
+     *  Double pointer to as_record
+     */
+	as_record **rec;
+} Record_object;
+
+ZEND_METHOD(Record, __construct)
+{
+   zval *object = getThis();
+   Record_object *obj = (Record_object *)zend_object_store_get_object(object TSRMLS_CC);
+   obj->rec = (as_record **)emalloc(sizeof(as_record *));
+   *obj->rec = NULL;
+}
+
+/**
+ *  Appends a bin and value to input parameter bins_array
+ *
+ *  @param name      Bin name
+ *  @param value     Bin value
+ *  @param bins_array      Bin array to be appended to.
+ *
+ *  @return true if success. Otherwise false.
+ */
+bool
+update_bins_array(const char * name, const as_val * value, zval *bins_array)
+{
+
+	switch ( as_val_type(value) ) {
+		case AS_NIL:
+				add_assoc_null(bins_array, name);
+				break;
+		case AS_INTEGER:
+				add_assoc_long(bins_array, name, as_integer_get(as_integer_fromval(value)));
+				break;
+		case AS_STRING:
+				add_assoc_stringl(bins_array, name, as_string_get(as_string_fromval(value)), strlen(as_string_get(as_string_fromval(value))), 1);
+				break;
+		case AS_BYTES:
+				//TODO: Handle bytes
+				break;
+		case AS_LIST:
+				//TODO: Handle list
+				break;
+		case AS_MAP:
+				//TODO: Handle map
+				break;
+		case AS_REC:
+				//TODO: Handle Record
+				break;
+		case AS_UNDEF:
+				//TODO: Handle Undef
+				break;
+		default:
+				zend_error(E_ERROR, "Invalid bin type: %d\n", as_val_type(value));
+				return false;
+	}
+
+	return true;
+}
+
+ZEND_METHOD(Record, getBins)
+{
+	array_init(return_value);
+	zval *object = getThis();
+	Record_object *obj = (Record_object *)zend_object_store_get_object(object TSRMLS_CC);
+	as_record_foreach(*obj->rec, (as_rec_foreach_callback) update_bins_array, return_value);
+	return;
+}
+
+ZEND_METHOD(Record, getBin)
+{
+	char *bin_name;
+	int bin_name_length;
+	zval *object = getThis();
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &bin_name, &bin_name_length) == FAILURE) {
+		// TODO: Error Handling
+		return;
+	}
+
+	Record_object *obj = (Record_object *)zend_object_store_get_object(object TSRMLS_CC);
+	as_val *value = as_record_get(*obj->rec, bin_name);
+	switch ( as_val_type(value) ) {
+		case AS_NIL:
+			RETURN_NULL();
+			break;
+		case AS_INTEGER:
+			RETURN_LONG(as_integer_get(as_integer_fromval(value)));
+			break;
+		case AS_STRING:
+			RETURN_STRINGL(as_string_get(as_string_fromval(value)), strlen(as_string_get(as_string_fromval(value))), 1);
+			break;
+		case AS_BYTES:
+			//TODO: Handle bytes
+			break;
+		case AS_LIST:
+			//TODO: Handle list
+			break;
+		case AS_MAP:
+			//TODO: Handle map
+			break;
+		case AS_REC:
+			//TODO: Handle Record
+			break;
+		case AS_UNDEF:
+			//TODO: Handle Undef
+			break;
+		default:
+			zend_error(E_ERROR, "Invalid bin type: %d\n", as_val_type(value));
+	}
+}
+
+ZEND_METHOD(Record, getGen)
+{
+	zval *object = getThis();
+	Record_object *obj = (Record_object *)zend_object_store_get_object(object TSRMLS_CC);
+	RETURN_LONG((*obj->rec)->gen);
+}
+
+ZEND_METHOD(Record, getTTL)
+{
+	zval *object = getThis();
+	Record_object *obj = (Record_object *)zend_object_store_get_object(object TSRMLS_CC);
+	RETURN_LONG((*obj->rec)->ttl);
+}
+
+static zend_function_entry Record_class_functions[] =
+{
+	ZEND_ME(Record, __construct, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
+	ZEND_ME(Record, getBins, NULL, ZEND_ACC_PUBLIC)
+	ZEND_ME(Record, getBin, NULL, ZEND_ACC_PUBLIC)
+	ZEND_ME(Record, getGen, NULL, ZEND_ACC_PUBLIC)
+	ZEND_ME(Record, getTTL, NULL, ZEND_ACC_PUBLIC)
+	{NULL, NULL, NULL}
+};
+
 static zend_class_entry *Aerospike_ce;
-
-static zend_object_handlers Aerospike_handlers;
+static zend_class_entry *Record_ce;
+
+static zend_object_handlers Aerospike_handlers, Record_handlers;

 aerospike as;

@@ -192,7 +338,38 @@

 	retval.handle = zend_objects_store_put(intern, Aerospike_object_dtor, (zend_objects_free_object_storage_t) Aerospike_object_free_storage, NULL TSRMLS_CC);
 	retval.handlers = &Aerospike_handlers;
-	//php_printf("**New Object**\n");
+	return retval;
+}
+
+static void Record_object_free_storage(void *object TSRMLS_DC)
+{
+	Record_object *obj = (Record_object *)object;
+	efree(obj->rec);
+
+	zend_hash_destroy(obj->std.properties);
+	FREE_HASHTABLE(obj->std.properties);
+
+	efree(obj);
+}
+
+zend_object_value Record_object_create_handler(zend_class_entry *type TSRMLS_DC)
+{
+	zval *tmp;
+	zend_object_value retval;
+
+	Record_object *obj = (Record_object *)emalloc(sizeof(Record_object));
+	memset(obj, 0, sizeof(Record_object));
+	obj->std.ce = type;
+
+	ALLOC_HASHTABLE(obj->std.properties);
+	zend_hash_init(obj->std.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
+	zend_hash_copy(obj->std.properties, &type->default_properties,
+		(copy_ctor_func_t)zval_add_ref, (void *)&tmp, sizeof(zval *));
+
+	retval.handle = zend_objects_store_put(obj, NULL,
+		Record_object_free_storage, NULL TSRMLS_CC);
+	retval.handlers = &Record_handlers;
+
 	return retval;
 }

@@ -215,7 +392,6 @@
 	zval *host;
 	char *arrkey;
 	Aerospike_object *intern = (Aerospike_object *) zend_object_store_get_object(object TSRMLS_CC);
-

 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &host) == FAILURE) {
 		// TODO: Error Handling
@@ -263,13 +439,12 @@
 		if (Z_TYPE_P(*hostdata) != IS_ARRAY) {
 				// TODO: Error Handling
 				return;
-		}
+		}

 		HashTable *hostdataindex = Z_ARRVAL_P(*hostdata);
 		HashPosition hostdatapointer;
-		zval **hostdatavalue;
+		zval **hostdatavalue;
 		for (zend_hash_internal_pointer_reset_ex(hostdataindex, &hostdatapointer); zend_hash_get_current_data_ex(hostdataindex, (void**)&hostdatavalue, &hostdatapointer) == SUCCESS; zend_hash_move_forward_ex(hostdataindex, &hostdatapointer)) {
-
 			uint arrkey_len, arrkey_type;
 			ulong index;

@@ -281,8 +456,8 @@
 						config.hosts[i].addr = Z_STRVAL_PP(hostdatavalue);
 						break;
 					default:
-						zend_error(E_NOTICE, "zval_to_object: could not convert %d\n",Z_TYPE_P(*hostdatavalue));
-						break;
+						zend_error(E_ERROR, "Invalid host address type: %d\n",Z_TYPE_P(*hostdatavalue));
+						break;
 				}
 			} else if (strcmp(arrkey,"port") == 0) {
 				switch (Z_TYPE_P(*hostdatavalue)) {
@@ -290,21 +465,21 @@
 						config.hosts[i].port = Z_LVAL_PP(hostdatavalue);
 						break;
 					default:
-						zend_error(E_NOTICE, "zval_to_object: could not convert %d\n",Z_TYPE_P(*hostdatavalue));
-						break;
+						zend_error(E_ERROR, "Invalid host port type: %d\n",Z_TYPE_P(*hostdatavalue));
+						break;
 				}
-		    } else {
-		    	// TODO: Error Handling
-		    }
+			} else {
+				// TODO: Error Handling
+			}
 		}
-
-		i++;
+		i++;
 	}
 	// XXX -- Should process constructor arguments here.

 	// XXX -- For now, if none are supplied, default to localhost.

 	// Add a seed host for cluster discovery.
+
 #if 0
 	// XXX -- This doesn't work with the current build options.
 	config.hosts[0] = { .addr = "127.0.0.1", .port = 3000 };
@@ -355,334 +530,108 @@
 	RETURN_TRUE;
 }

-/*
- *  Cluster Management APIs:
- */
-
-/* PHP Method:  bool Aerospike::isConnected()
-   Is the client connected to the Aerospike cluster? */
-PHP_METHOD(Aerospike, isConnected)
-{
-	zval *object = getThis();
-	Aerospike_object *intern = (Aerospike_object *) zend_object_store_get_object(object TSRMLS_CC);
-
-	// DEBUG
-	php_printf("**In Aerospike::isConnected() method**\n");
-
-	/*** TO BE IMPLEMENTED ***/
-
-	RETURN_TRUE;
-}
-
-/* PHP Method:  bool Aerospike::close()
-   Disconnect the client to an Aerospike cluster. */
-PHP_METHOD(Aerospike, close)
-{
-	zval *object = getThis();
-	Aerospike_object *intern = (Aerospike_object *) zend_object_store_get_object(object TSRMLS_CC);
-
-	// DEBUG
-	php_printf("**In Aerospike::close() method**\n");
-
+/* PHP Method:  bool Aerospike::get()
+	Read record header(s) and bin(s) for specified key(s) in one batch call. */
+PHP_METHOD(Aerospike, get)
+{
+
+	zval *record_identifier, **record_key, *record;
+	char *arrkey, *namespace, *set;
+	zval *bins;
+
+	//array_init(return_value);
+	// DEBUG
+	php_printf("**In Aerospike::get() method**\n");
+
+	zval *object = getThis();
+	Aerospike_object *intern = (Aerospike_object *) zend_object_store_get_object(object TSRMLS_CC);
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|a", &record_identifier, &record, &bins) == FAILURE) {
+		// TODO: Error Handling
+		return;
+	}
+
+	Record_object *obj = (Record_object *)zend_object_store_get_object(record TSRMLS_CC);
+
 	// Errors populate this object.
 	as_error err;

-    // We are finished with the client.
-    if (aerospike_close(&as, &err) != AEROSPIKE_OK) {
-		// An error occurred, so we log it.
-		fprintf(stderr, "error(%d) %s at [%s:%d]\n", err.code, err.message, err.file, err.line);
-	} else {
-		fprintf(stderr, "It worked!\n");
-	}
-
-	/*** TO BE IMPLEMENTED ***/
-
-	RETURN_TRUE;
-}
-
-/* PHP Method:  bool Aerospike::getNodes()
-   Return an array of objects for the nodes in the Aerospike cluster. */
-PHP_METHOD(Aerospike, getNodes)
-{
-	zval *object = getThis();
-	Aerospike_object *intern = (Aerospike_object *) zend_object_store_get_object(object TSRMLS_CC);
-
-	// DEBUG
-	php_printf("**In Aerospike::getNodes() method**\n");
-
-	/*** TO BE IMPLEMENTED ***/
-
-	RETURN_TRUE;
-}
-
-/* PHP Method:  bool Aerospike::info()
-   Send an Info. request to an Aerospike cluster. */
-PHP_METHOD(Aerospike, info)
-{
-	zval *object = getThis();
-	Aerospike_object *intern = (Aerospike_object *) zend_object_store_get_object(object TSRMLS_CC);
-
-	// DEBUG
-	php_printf("**In Aerospike::info() method**\n");
-
-	/*** TO BE IMPLEMENTED ***/
-
-	RETURN_TRUE;
-}
-
-/*
- *  Key Value Store (KVS) APIs:
- */
-
-/* PHP Method:  bool Aerospike::()
-    Add integer bin values to existing bin values. */
-PHP_METHOD(Aerospike, add)
-{
-	zval *object = getThis();
-	Aerospike_object *intern = (Aerospike_object *) zend_object_store_get_object(object TSRMLS_CC);
-
-	// DEBUG
-	php_printf("**In Aerospike::add() method**\n");
-
-	/*** TO BE IMPLEMENTED ***/
-
-	RETURN_TRUE;
-}
-
-/* PHP Method:  bool Aerospike::append()
-    Append bin string values to existing record bin values. */
-PHP_METHOD(Aerospike, append)
-{
-	zval *object = getThis();
-	Aerospike_object *intern = (Aerospike_object *) zend_object_store_get_object(object TSRMLS_CC);
-
-	// DEBUG
-	php_printf("**In Aerospike::append() method**\n");
-
-	/*** TO BE IMPLEMENTED ***/
-
-	RETURN_TRUE;
-}
-
-/* PHP Method:  bool Aerospike::delete()
-    Delete record for specified key. */
-PHP_METHOD(Aerospike, delete)
-{
-	zval *object = getThis();
-	Aerospike_object *intern = (Aerospike_object *) zend_object_store_get_object(object TSRMLS_CC);
-
-	// DEBUG
-	php_printf("**In Aerospike::delete() method**\n");
-
-	/*** TO BE IMPLEMENTED ***/
-
-	RETURN_TRUE;
-}
-
-/* PHP Method:  bool Aerospike::exists()
-    Check if record key(s) exist in one batch call. */
-PHP_METHOD(Aerospike, exists)
-{
-	zval *object = getThis();
-	Aerospike_object *intern = (Aerospike_object *) zend_object_store_get_object(object TSRMLS_CC);
-
-	// DEBUG
-	php_printf("**In Aerospike::exists() method**\n");
-
-	/*** TO BE IMPLEMENTED ***/
-
-	RETURN_TRUE;
-}
-
-/**
- *  return as_val struct for specified bin.
- *
- *  @param p_rec      as_record type
- *  @param bin        name of bin.
- *
- *  @return as_val struct if exists. Otherwise NULL.
- */
-
-as_val* as_get_record_get(const as_record* p_rec,char *bin)
-{
-	if (! p_rec) {
-	fprintf(stderr," null as_record object");
-	return;
-	}
-	as_val *asval = (as_val *)as_record_get(p_rec, bin);
-	return asval;
-}
-
-
-/* PHP Method:  bool Aerospike::get()
-    Read record header(s) and bin(s) for specified key(s) in one batch call. */
-PHP_METHOD(Aerospike, get)
-{
-
-	zval *keyval, **rkey;
-	char *arrkey, *ns, *set;
-	char *binname;
-	int   binname_len;
-
-	//array_init(return_value);
-	// DEBUG
-	php_printf("**In Aerospike::get() method**\n");
-
-	zval *object = getThis();
-	Aerospike_object *intern = (Aerospike_object *) zend_object_store_get_object(object TSRMLS_CC);
-
-	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zs", &keyval, &binname, &binname_len) == FAILURE) {
-		// TODO: Error Handling
-		return;
-	}
-
-	// Errors populate this object.
-	as_error err;
-
 	as_key key;
 	as_record *rec = NULL;

-	HashTable *keyindex = Z_ARRVAL_P(keyval);
+	HashTable *keyindex = Z_ARRVAL_P(record_identifier);
 	HashPosition pointer;
 	zval **data;

 	for (zend_hash_internal_pointer_reset_ex(keyindex, &pointer); zend_hash_get_current_data_ex(keyindex, (void**)&data, &pointer) == SUCCESS; zend_hash_move_forward_ex(keyindex, &pointer)) {
-
 		uint arrkey_len, arrkey_type;
 		ulong index;

 		arrkey_type = zend_hash_get_current_key_ex(keyindex, &arrkey, &arrkey_len, &index, 0, &pointer);

 		if (strcmp(arrkey,"ns") == 0) {
-			ns = Z_STRVAL_PP(data);
+			namespace = Z_STRVAL_PP(data);
 		} else if (strcmp(arrkey,"set") == 0) {
 			set = Z_STRVAL_PP(data);
 		} else if (strcmp(arrkey,"key") == 0) {
-			rkey = data;
+			record_key = data;
 		} else {
 			// TODO: Error Handling
 			return;
-	    }
-	}
-
-		switch (Z_TYPE_P(*rkey)) {
-			case IS_LONG:
-				as_key_init_int64(&key, ns, set, (int64_t)Z_LVAL_P(*rkey));
-				break;
-			case IS_STRING:
-				as_key_init_str(&key, ns, set, (char *)Z_STRVAL_P(*rkey));
-				break;
-			default:
-				zend_error(E_NOTICE, "zval_to_object: could not convert %d\n",Z_TYPE_P(*rkey));
-				RETURN_FALSE;
 		}
+	}
+
+	switch ( Z_TYPE_PP(record_key) ) {
+		case IS_LONG:
+			as_key_init_int64(&key, namespace, set, (int64_t)Z_LVAL_PP(record_key));
+			break;
+		case IS_STRING:
+			as_key_init_str(&key, namespace, set, (char *)Z_STRVAL_PP(record_key));
+			break;
+		default:
+			zend_error(E_ERROR, "Invalid Key Type: %d\n",Z_TYPE_PP(record_key));
+			RETURN_FALSE;
+	}

-
-	if (aerospike_key_get(&as, &err, NULL, &key, &rec) != AEROSPIKE_OK) {
+	if ( ZEND_NUM_ARGS() == 2 && aerospike_key_get(&as, &err, NULL, &key, obj->rec) != AEROSPIKE_OK ) {
+			// An error occurred, so we log it.
+			fprintf(stderr, "error(%d) %s at [%s:%d]\n", err.code, err.message, err.file, err.line);
+			// XXX -- Release any allocated resources and throw and exception.
+			as_record_destroy(*(obj->rec));
+			// TODO: Error Handling
+	} else if ( ZEND_NUM_ARGS() == 3 ) {
+		HashTable *bins_array =  Z_ARRVAL_P(bins);
+		HashPosition pointer1;
+		int bins_count = zend_hash_num_elements(bins_array);
+		const char *select[bins_count];
+		zval **bin_names;
+		uint i=0;
+
+		for (zend_hash_internal_pointer_reset_ex(bins_array, &pointer1); zend_hash_get_current_data_ex(bins_array, (void**)&bin_names, &pointer1) == SUCCESS; zend_hash_move_forward_ex(bins_array, &pointer1)) {
+			switch (Z_TYPE_PP(bin_names)) {
+					case IS_STRING:
+						select[i++] = Z_STRVAL_PP(bin_names);
+						break;
+					default:
+						zend_error(E_ERROR, "Invalid bin name type: %d\n", Z_TYPE_P(*bin_names));
+						break;
+				}
+		}
+
+		select[bins_count] = NULL;
+		if (aerospike_key_select(&as, &err, NULL, &key, select, obj->rec) != AEROSPIKE_OK) {
 		// An error occurred, so we log it.
-		fprintf(stderr, "error(%d) %s at [%s:%d]\n", err.code, err.message, err.file, err.line);
+		fprintf(stderr, "error(%d) %s at [%s:%d]\n", err.code, err.message, err.file, err.line);
 		// XXX -- Release any allocated resources and throw and exception.
-		as_record_destroy(rec);
+		as_record_destroy(*(obj->rec));
 		// TODO: Error Handling
-	} else {
-		//fprintf(stderr, "It worked!\n");
-		as_integer *integer;
-		as_string *string;
-		/*zval **res = rec;
-		RETURN_ZVAL(res);*/
-		as_val  *asval = as_get_record_get(rec,binname);
-		switch (asval->type) {
-			case 0:
-				//TODO: handling AS_UNDEF
-				break;
-			case 1:
-				//TODO: handling AS_NIL
-				break;
-			case 2:
-				//TODO: handling AS_BOOLEAN
-				break;
-			case 3:
-				integer = as_integer_fromval(asval);
-				//php_printf("%d",(int)as_integer_get(integer));
-				RETURN_LONG((int)as_integer_get(integer));
-				break;
-			case 4:
-				string = as_string_fromval(asval);
-				//php_printf("%s",(char *)as_string_get(string));
-				RETURN_STRING((char *)as_string_get(string),1);
-				break;
-			case 5:
-				//TODO: handling AS_LIST
-				break;
-			case 6:
-				//TODO: handling AS_MAP
-				break;
-			case 7:
-				//TODO: handling AS_REC
-				break;
-			case 8:
-				//TODO: handling AS_PAIR
-				break;
-			case 9:
-				//TODO: handling AS_BYTES
-				break;
-			default:
-				zend_error(E_NOTICE, "Type not found. %d\n",asval->type);
-				break;
-
 		}
-		as_record_destroy(rec);
-	}
-}
-
-
-/* PHP Method:  bool Aerospike::getHeader()
-    Read record generation and expiration for specified key(s) in one batch call. */
-PHP_METHOD(Aerospike, getHeader)
-{
-	zval *object = getThis();
-	Aerospike_object *intern = (Aerospike_object *) zend_object_store_get_object(object TSRMLS_CC);
-
-	// DEBUG
-	php_printf("**In Aerospike::getHeader() method**\n");
-
-	/*** TO BE IMPLEMENTED ***/
-
-	RETURN_TRUE;
-}
-
-/* PHP Method:  bool Aerospike::operate()
-    Perform multiple read/write operations on a single key in one batch call. */
-PHP_METHOD(Aerospike, operate)
-{
-	zval *object = getThis();
-	Aerospike_object *intern = (Aerospike_object *) zend_object_store_get_object(object TSRMLS_CC);
-
-	// DEBUG
-	php_printf("**In Aerospike::operate() method**\n");
-
-	/*** TO BE IMPLEMENTED ***/
-
-	RETURN_TRUE;
-}
-
-/* PHP Method:  bool Aerospike::prepend()
-    Prepend bin string values to existing record bin values. */
-PHP_METHOD(Aerospike, prepend)
-{
-	zval *object = getThis();
-	Aerospike_object *intern = (Aerospike_object *) zend_object_store_get_object(object TSRMLS_CC);
-
-	// DEBUG
-	php_printf("**In Aerospike::prepend() method**\n");
-
-	/*** TO BE IMPLEMENTED ***/
-
-	RETURN_TRUE;
-}
+	}
+}
+

 /* PHP Method:  bool Aerospike::put()
-    Write record bin(s). */
+	Write record bin(s). */
 PHP_METHOD(Aerospike, put)
 {
 	// DEBUG
@@ -692,7 +641,6 @@
 	zval *keyval,*recval, **rkey, **binvalue;
 	char *binname , *arrkey, *ns, *set;
 	as_record rec;
-

 	Aerospike_object *intern = (Aerospike_object *) zend_object_store_get_object(object TSRMLS_CC);
 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &keyval,&recval) == FAILURE) {
@@ -720,14 +668,13 @@
 	} else {
 		// TODO: Error Handling
 		return;
-    }
+	}
 }
 	HashTable *recvalindex = Z_ARRVAL_P(recval);
 	HashPosition pointer1;
 	zval **dataval;
 	int array_count;
-	int returnvalue;
-
+
 	array_count = zend_hash_num_elements(recvalindex);

 	as_record_inita(&rec, array_count);
@@ -741,12 +688,11 @@

 		binname = arrkey;
 		binvalue = dataval;
-		returnvalue = as_put_value(rkey,binname,binvalue,rec,ns,set);
-		if (returnvalue == 0) {
+		if (as_put_value(rkey,binname,binvalue,rec,ns,set) == FAILURE) {
 			RETURN_FALSE;
 		}
 	}
-	RETURN_TRUE;
+	RETURN_TRUE;
 }

 /**
@@ -759,14 +705,14 @@
  *  @param namespace 		ns.
  *  @param set 				set.
  *
- *  @return 1 for SUCCESS. Otherwise 0.
- */
-int as_put_value(zval **rkey,char *binname,zval **binvalue,as_record rec,char *ns,char *set)
+ *  @return SUCCESS for SUCCESS. Otherwise FAILURE.
+ */
+int
+as_put_value(zval **rkey,char *binname,zval **binvalue,as_record rec,char *ns,char *set)
 {
 	as_error err;
 	as_key key;

-
 	switch (Z_TYPE_P(*rkey)) {
 		case IS_LONG:
 			as_key_init_int64(&key, ns, set, (int64_t)Z_LVAL_P(*rkey));
@@ -776,7 +722,7 @@
 			break;
 		default:
 			zend_error(E_NOTICE, "zval_to_object: could not convert %d\n",Z_TYPE_P(*rkey));
-			return 0;
+			return FAILURE;
 	}

 	switch (Z_TYPE_P(*binvalue)) {
@@ -802,10 +748,10 @@
 				ulong index;

 				if (zend_hash_get_current_key_ex(arr_hash, &key, &arrkey_len, &index, 0, &pointer) == HASH_KEY_IS_STRING) {
-        	    	//strcpy(values[counter].bin_name, key);
-            	} else {
-
-            	}
+					//strcpy(values[counter].bin_name, key);
+				} else {
+
+				}
 			}

 			as_record_set_list(&rec, binname, (as_list *)Z_ARRVAL_P (*binvalue));*/
@@ -821,12 +767,199 @@
 		// XXX -- Release any allocated resources and throw and exception.
 		// TODO: Error Handling
 	} else {
-		return 1;
-	}
-}
+		return SUCCESS;
+	}
+}
+
+
+/*
+ *  Cluster Management APIs:
+ */
+
+/* PHP Method:  bool Aerospike::isConnected()
+   Is the client connected to the Aerospike cluster? */
+PHP_METHOD(Aerospike, isConnected)
+{
+	zval *object = getThis();
+	Aerospike_object *intern = (Aerospike_object *) zend_object_store_get_object(object TSRMLS_CC);
+
+	// DEBUG
+	php_printf("**In Aerospike::isConnected() method**\n");
+
+	/*** TO BE IMPLEMENTED ***/
+
+	RETURN_TRUE;
+}
+
+/* PHP Method:  bool Aerospike::close()
+   Disconnect the client to an Aerospike cluster. */
+PHP_METHOD(Aerospike, close)
+{
+	zval *object = getThis();
+	Aerospike_object *intern = (Aerospike_object *) zend_object_store_get_object(object TSRMLS_CC);
+
+	// DEBUG
+	php_printf("**In Aerospike::close() method**\n");
+
+	// Errors populate this object.
+	as_error err;
+
+	// We are finished with the client.
+	if (aerospike_close(&as, &err) != AEROSPIKE_OK) {
+		// An error occurred, so we log it.
+		fprintf(stderr, "error(%d) %s at [%s:%d]\n", err.code, err.message, err.file, err.line);
+	} else {
+		fprintf(stderr, "It worked!\n");
+	}
+
+	/*** TO BE IMPLEMENTED ***/
+
+	RETURN_TRUE;
+}
+
+/* PHP Method:  bool Aerospike::getNodes()
+   Return an array of objects for the nodes in the Aerospike cluster. */
+PHP_METHOD(Aerospike, getNodes)
+{
+	zval *object = getThis();
+	Aerospike_object *intern = (Aerospike_object *) zend_object_store_get_object(object TSRMLS_CC);
+
+	// DEBUG
+	php_printf("**In Aerospike::getNodes() method**\n");
+
+	/*** TO BE IMPLEMENTED ***/
+
+	RETURN_TRUE;
+}
+
+/* PHP Method:  bool Aerospike::info()
+   Send an Info. request to an Aerospike cluster. */
+PHP_METHOD(Aerospike, info)
+{
+	zval *object = getThis();
+	Aerospike_object *intern = (Aerospike_object *) zend_object_store_get_object(object TSRMLS_CC);
+
+	// DEBUG
+	php_printf("**In Aerospike::info() method**\n");
+
+	/*** TO BE IMPLEMENTED ***/
+
+	RETURN_TRUE;
+}
+
+/*
+ *  Key Value Store (KVS) APIs:
+ */
+
+/* PHP Method:  bool Aerospike::()
+	Add integer bin values to existing bin values. */
+PHP_METHOD(Aerospike, add)
+{
+	zval *object = getThis();
+	Aerospike_object *intern = (Aerospike_object *) zend_object_store_get_object(object TSRMLS_CC);
+
+	// DEBUG
+	php_printf("**In Aerospike::add() method**\n");
+
+	/*** TO BE IMPLEMENTED ***/
+
+	RETURN_TRUE;
+}
+
+/* PHP Method:  bool Aerospike::append()
+	Append bin string values to existing record bin values. */
+PHP_METHOD(Aerospike, append)
+{
+	zval *object = getThis();
+	Aerospike_object *intern = (Aerospike_object *) zend_object_store_get_object(object TSRMLS_CC);
+
+	// DEBUG
+	php_printf("**In Aerospike::append() method**\n");
+
+	/*** TO BE IMPLEMENTED ***/
+
+	RETURN_TRUE;
+}
+
+/* PHP Method:  bool Aerospike::delete()
+	Delete record for specified key. */
+PHP_METHOD(Aerospike, delete)
+{
+	zval *object = getThis();
+	Aerospike_object *intern = (Aerospike_object *) zend_object_store_get_object(object TSRMLS_CC);
+
+	// DEBUG
+	php_printf("**In Aerospike::delete() method**\n");
+
+	/*** TO BE IMPLEMENTED ***/
+
+	RETURN_TRUE;
+}
+
+/* PHP Method:  bool Aerospike::exists()
+	Check if record key(s) exist in one batch call. */
+PHP_METHOD(Aerospike, exists)
+{
+	zval *object = getThis();
+	Aerospike_object *intern = (Aerospike_object *) zend_object_store_get_object(object TSRMLS_CC);
+
+	// DEBUG
+	php_printf("**In Aerospike::exists() method**\n");
+
+	/*** TO BE IMPLEMENTED ***/
+
+	RETURN_TRUE;
+}
+
+
+/* PHP Method:  bool Aerospike::getHeader()
+	Read record generation and expiration for specified key(s) in one batch call. */
+PHP_METHOD(Aerospike, getHeader)
+{
+	zval *object = getThis();
+	Aerospike_object *intern = (Aerospike_object *) zend_object_store_get_object(object TSRMLS_CC);
+
+	// DEBUG
+	php_printf("**In Aerospike::getHeader() method**\n");
+
+	/*** TO BE IMPLEMENTED ***/
+
+	RETURN_TRUE;
+}
+
+/* PHP Method:  bool Aerospike::operate()
+	Perform multiple read/write operations on a single key in one batch call. */
+PHP_METHOD(Aerospike, operate)
+{
+	zval *object = getThis();
+	Aerospike_object *intern = (Aerospike_object *) zend_object_store_get_object(object TSRMLS_CC);
+
+	// DEBUG
+	php_printf("**In Aerospike::operate() method**\n");
+
+	/*** TO BE IMPLEMENTED ***/
+
+	RETURN_TRUE;
+}
+
+/* PHP Method:  bool Aerospike::prepend()
+	Prepend bin string values to existing record bin values. */
+PHP_METHOD(Aerospike, prepend)
+{
+	zval *object = getThis();
+	Aerospike_object *intern = (Aerospike_object *) zend_object_store_get_object(object TSRMLS_CC);
+
+	// DEBUG
+	php_printf("**In Aerospike::prepend() method**\n");
+
+	/*** TO BE IMPLEMENTED ***/
+
+	RETURN_TRUE;
+}
+

 /* PHP Method:  bool Aerospike::touch()
-    Create record if it does not already exist. */
+	Create record if it does not already exist. */
 PHP_METHOD(Aerospike, touch)
 {
 	zval *object = getThis();
@@ -913,6 +1046,18 @@
 	ZEND_INIT_MODULE_GLOBALS(aerospike, aerospike_globals_ctor, aerospike_globals_dtor);

 	zend_class_entry ce;
+	INIT_CLASS_ENTRY(ce, "Aerospike", Aerospike_class_functions);
+		INIT_CLASS_ENTRY(ce, "Record", Record_class_functions);
+
+		if (!(Record_ce = zend_register_internal_class(&ce TSRMLS_CC))) {
+			return FAILURE;
+		} else {
+			Record_ce->create_object = Record_object_create_handler;
+			memcpy(&Record_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
+			Record_handlers.clone_obj = NULL;
+		}
+
+
 	INIT_CLASS_ENTRY(ce, "Aerospike", Aerospike_class_functions);

 	if (!(Aerospike_ce = zend_register_internal_class(&ce TSRMLS_CC))) {


print reason if gridfs test_create fails

--- tests/test-mongoc-gridfs.c
+++ tests/test-mongoc-gridfs.c
@@ -46,6 +46,10 @@
    assert (client);

    gridfs = mongoc_client_get_gridfs (client, "test", "foo", &error);
+   if (!gridfs) {
+      printf ("mongoc_client_get_gridfs err: %s\n", error.message);
+   }
+
    assert (gridfs);

    mongoc_gridfs_drop (gridfs, &error);


Soft field repeat support for deinterlacer

Signed-off-by: Laurent Aimar <2e4ef4899efb9d4b7a6d090f80ae8072b0abe38d@videolan.org>

--- modules/video_filter/deinterlace.c
+++ modules/video_filter/deinterlace.c
@@ -126,7 +126,16 @@
     "mode", NULL
 };

+/* Used for framerate doublers */
+#define METADATA_SIZE (3)
+typedef struct {
+    mtime_t pi_date[METADATA_SIZE];
+    int     pi_nb_fields[METADATA_SIZE];
+    bool    pb_top_field_first[METADATA_SIZE];
+} metadata_history_t;
+
 #define HISTORY_SIZE (3)
+#define CUSTOM_PTS -1
 struct filter_sys_t
 {
     int  i_mode;        /* Deinterlace mode */
@@ -136,11 +145,77 @@
     void (*pf_merge) ( void *, const void *, const void *, size_t );
     void (*pf_end_merge) ( void );

-    mtime_t i_last_date;
+    /* Metadata history (PTS, nb_fields, TFF). Used for framerate doublers. */
+    metadata_history_t meta;
+
+    /* Output frame timing / framerate doubler control (see below) */
+    int i_frame_offset;

     /* Yadif */
     picture_t *pp_history[HISTORY_SIZE];
 };
+
+/*  NOTE on i_frame_offset:
+
+    This value indicates the offset between input and output frames in the currently active deinterlace algorithm.
+    See the rationale below for why this is needed and how it is used.
+
+    Valid range: 0 <= i_frame_offset < METADATA_SIZE, or i_frame_offset = CUSTOM_PTS.
+                 The special value CUSTOM_PTS is only allowed if b_double_rate is false.
+
+                 If CUSTOM_PTS is used, the algorithm must compute the outgoing PTSs itself,
+                 and additionally, read the TFF/BFF information itself (if it needs it)
+                 from the incoming frames.
+
+    Meaning of values:
+    0 = output frame corresponds to the current input frame
+        (no frame offset; default if not set),
+    1 = output frame corresponds to the previous input frame
+        (e.g. Yadif and Yadif2x work like this),
+    ...
+
+    If necessary, i_frame_offset should be updated by the active deinterlace algorithm
+    to indicate the correct delay for the *next* input frame. It does not matter at which i_order
+    the algorithm updates this information, but the new value will only take effect upon the
+    next call to Deinterlace() (i.e. at the next incoming frame).
+
+    The first-ever frame that arrives to the filter after Open() is always handled as having
+    i_frame_offset = 0. For the second and all subsequent frames, each algorithm is responsible
+    for setting the offset correctly. (The default is 0, so if that is correct, there's no need
+    to do anything.)
+
+    This solution guarantees that i_frame_offset:
+      1) is up to date at the start of each frame,
+      2) does not change (as far as Deinterlace() is concerned) during a frame, and
+      3) does not need a special API for setting the value at the start of each input frame,
+         before the algorithm starts rendering the (first) output frame for that input frame.
+
+    The deinterlace algorithm is allowed to behave differently for different input frames.
+    This is especially important for startup, when full history (as defined by each algorithm)
+    is not yet available. During the first-ever input frame, it is clear that it is the
+    only possible source for information, so i_frame_offset = 0 is necessarily correct.
+    After that, what to do is up to each algorithm.
+
+    Having the correct offset at the start of each input frame is critically important in order to:
+      1) Allocate the correct number of output frames for framerate doublers, and to
+      2) Pass correct TFF/BFF information to the algorithm.
+
+    These points are important for proper soft field repeat support. This feature is used in some
+    streams originating from film. In soft NTSC telecine, the number of fields alternates as 3,2,3,2,...
+    and the video field dominance flips every two frames (after every "3"). Also, some streams
+    request an occasional field repeat (nb_fields = 3), after which the video field dominance flips.
+    To render such streams correctly, the nb_fields and TFF/BFF information must be taken from
+    the specific input frame that the algorithm intends to render.
+
+    Additionally, the output PTS is automatically computed by Deinterlace() from i_frame_offset and i_order.
+
+    It is possible to use the special value CUSTOM_PTS to indicate that the algorithm computes
+    the output PTSs itself. In this case, Deinterlace() will pass them through. This special value
+    is not valid for framerate doublers, as by definition they are field renderers, so they need to
+    use the original field timings to work correctly. Basically, this special value is only intended
+    for algorithms that need to perform nontrivial framerate conversions (such as IVTC).
+*/
+

 /*****************************************************************************
  * SetFilterMethod: setup the deinterlace method to use.
@@ -208,6 +283,8 @@
         p_sys->b_double_rate = false;
         p_sys->b_half_height = false;
     }
+
+    p_sys->i_frame_offset = 0; /* reset to default when method changes */

     msg_Dbg( p_filter, "using %s deinterlace method", psz_method );
 }
@@ -1440,7 +1517,7 @@
     filter_sys_t *p_sys = p_filter->p_sys;

     /* */
-    assert( i_order == 0 || i_order == 1 );
+    assert( i_order >= 0 && i_order <= 2 ); /* 2 = soft field repeat */
     assert( i_field == 0 || i_field == 1 );

     if( i_order == 0 )
@@ -1465,6 +1542,41 @@
     picture_t *p_cur  = p_sys->pp_history[1];
     picture_t *p_next = p_sys->pp_history[2];

+    /* Account for soft field repeat.
+
+       The "parity" parameter affects the algorithm like this (from yadif.h):
+       uint8_t *prev2= parity ? prev : cur ;
+       uint8_t *next2= parity ? cur  : next;
+
+       The original parity expression that was used here is:
+       (i_field ^ (i_order == i_field)) & 1
+
+       Truth table:
+       i_field = 0, i_order = 0  => 1
+       i_field = 1, i_order = 1  => 0
+       i_field = 1, i_order = 0  => 1
+       i_field = 0, i_order = 1  => 0
+
+       => equivalent with e.g.  (1 - i_order)  or  (i_order + 1) % 2
+
+       Thus, in a normal two-field frame,
+             parity 1 = first field  (i_order == 0)
+             parity 0 = second field (i_order == 1)
+
+       Now, with three fields, where the third is a copy of the first,
+             i_order = 0  =>  parity 1 (as usual)
+             i_order = 1  =>  due to the repeat, prev = cur, but also next = cur.
+                              Because in such a case there is no motion (otherwise field repeat makes no sense),
+                              we don't actually need to invoke Yadif's filter(). Thus, set "parity" to 2,
+                              and use this to bypass the filter.
+             i_order = 2  =>  parity 0 (as usual)
+    */
+    int yadif_parity;
+    if( p_cur  &&  p_cur->i_nb_fields > 2 )
+        yadif_parity = (i_order + 1) % 3; /* 1, *2*, 0; where 2 is a special value meaning "bypass filter". */
+    else
+        yadif_parity = (i_order + 1) % 2; /* 1, 0 */
+
     /* Filter if we have all the pictures we need */
     if( p_prev && p_cur && p_next )
     {
@@ -1486,7 +1598,7 @@

             for( int y = 1; y < dstp->i_visible_lines - 1; y++ )
             {
-                if( (y % 2) == i_field )
+                if( (y % 2) == i_field  ||  yadif_parity == 2 )
                 {
                     vlc_memcpy( &dstp->p_pixels[y * dstp->i_pitch],
                                 &curp->p_pixels[y * curp->i_pitch], dstp->i_visible_pitch );
@@ -1505,7 +1617,7 @@
                             &nextp->p_pixels[y * nextp->i_pitch],
                             dstp->i_visible_pitch,
                             curp->i_pitch,
-                            (i_field ^ (i_order == i_field)) & 1 );
+                            yadif_parity );
                 }

                 /* We duplicate the first and last lines */
@@ -1516,18 +1628,23 @@
             }
         }

-        /* */
-        p_dst->date = (p_next->date - p_cur->date) * i_order / 2 + p_cur->date;
+        p_sys->i_frame_offset = 1; /* p_curr will be rendered at next frame, too */
+
         return VLC_SUCCESS;
     }
     else if( !p_prev && !p_cur && p_next )
     {
+        /* NOTE: For the first frame, we use the default frame offset
+                 as set by Open() or SetFilterMethod(). It is always 0. */
+
         /* FIXME not good as it does not use i_order/i_field */
         RenderX( p_dst, p_next );
         return VLC_SUCCESS;
     }
     else
     {
+        p_sys->i_frame_offset = 1; /* p_curr will be rendered at next frame */
+
         return VLC_EGENERIC;
     }
 }
@@ -1535,10 +1652,11 @@
 /*****************************************************************************
  * video filter2 functions
  *****************************************************************************/
+#define DEINTERLACE_DST_SIZE 3
 static picture_t *Deinterlace( filter_t *p_filter, picture_t *p_pic )
 {
     filter_sys_t *p_sys = p_filter->p_sys;
-    picture_t *p_dst[2];
+    picture_t *p_dst[DEINTERLACE_DST_SIZE];

     /* Request output picture */
     p_dst[0] = filter_NewPicture( p_filter );
@@ -1549,25 +1667,116 @@
     }
     picture_CopyProperties( p_dst[0], p_pic );

+    /* Any unused p_dst pointers must be NULL, because they are used to check how many output frames we have. */
+    for( int i = 1; i < DEINTERLACE_DST_SIZE; ++i )
+        p_dst[i] = NULL;
+
+    /* Slide the metadata history. */
+    for( int i = 1; i < METADATA_SIZE; i++ )
+    {
+        p_sys->meta.pi_date[i-1]            = p_sys->meta.pi_date[i];
+        p_sys->meta.pi_nb_fields[i-1]       = p_sys->meta.pi_nb_fields[i];
+        p_sys->meta.pb_top_field_first[i-1] = p_sys->meta.pb_top_field_first[i];
+    }
+    /* The last element corresponds to the current input frame. */
+    p_sys->meta.pi_date[METADATA_SIZE-1]            = p_pic->date;
+    p_sys->meta.pi_nb_fields[METADATA_SIZE-1]       = p_pic->i_nb_fields;
+    p_sys->meta.pb_top_field_first[METADATA_SIZE-1] = p_pic->b_top_field_first;
+
+    /* Remember the frame offset that we should use for this frame.
+       The value in p_sys will be updated to reflect the correct value
+       for the *next* frame when we call the renderer. */
+    int i_frame_offset = p_sys->i_frame_offset;
+    int i_meta_idx     = (METADATA_SIZE-1) - i_frame_offset;
+
+    /* These correspond to the current *outgoing* frame. */
+    bool b_top_field_first;
+    int i_nb_fields;
+    if( i_frame_offset != CUSTOM_PTS )
+    {
+        /* Pick the correct values from the history. */
+        b_top_field_first = p_sys->meta.pb_top_field_first[i_meta_idx];
+        i_nb_fields       = p_sys->meta.pi_nb_fields[i_meta_idx];
+    }
+    else
+    {
+        /* Framerate doublers must not request CUSTOM_PTS, as they need the original field timings,
+           and need Deinterlace() to allocate the correct number of output frames. */
+        assert( !p_sys->b_double_rate );
+
+        /* NOTE: i_nb_fields is only used for framerate doublers, so it is unused in this case.
+                 b_top_field_first is only passed to the algorithm. We assume that algorithms that
+                 request CUSTOM_PTS will, if necessary, extract the TFF/BFF information themselves.
+        */
+        b_top_field_first = p_pic->b_top_field_first; /* this is not guaranteed to be meaningful */
+        i_nb_fields       = p_pic->i_nb_fields;       /* unused */
+    }
+
+    /* For framerate doublers, determine field duration and allocate output frames. */
+    mtime_t i_field_dur = 0;
+    int i_double_rate_alloc_end = 0; /* One past last for allocated output frames in p_dst[].
+                                        Used only for framerate doublers. Will be inited below.
+                                        Declared here because the PTS logic needs the result. */
     if( p_sys->b_double_rate )
     {
-        p_dst[0]->p_next =
-        p_dst[1]         = filter_NewPicture( p_filter );
-        if( p_dst[1] )
-        {
-            picture_CopyProperties( p_dst[1], p_pic );
-            /* XXX it's not really good especially for the first picture, but
-             * I don't think that delaying by one frame is worth it */
-            if( p_sys->i_last_date > VLC_TS_INVALID && p_pic->date > VLC_TS_INVALID )
-                p_dst[1]->date = p_pic->date + (p_pic->date - p_sys->i_last_date) / 2;
-        }
-        p_sys->i_last_date = p_pic->date;
-    }
-    else
-    {
-        p_dst[1] = NULL;
-    }
-
+        /* Calculate one field duration. */
+        int i = 0;
+        int iend = METADATA_SIZE-1;
+        /* Find oldest valid logged date. Note: the current input frame doesn't count. */
+        for( ; i < iend; i++ )
+            if( p_sys->meta.pi_date[i] > VLC_TS_INVALID )
+                break;
+        if( i < iend )
+        {
+            /* Count how many fields the valid history entries (except the new frame) represent. */
+            int i_fields_total = 0;
+            for( int j = i ; j < iend; j++ )
+                i_fields_total += p_sys->meta.pi_nb_fields[j];
+            /* One field took this long. */
+            i_field_dur = (p_pic->date - p_sys->meta.pi_date[i]) / i_fields_total;
+        }
+        /* Note that we default to field duration 0 if it could not be determined.
+           This behaves the same as the old code - leaving the extra output frame
+           dates the same as p_pic->date if the last cached date was not valid.
+        */
+
+        i_double_rate_alloc_end = i_nb_fields;
+        if( i_nb_fields > DEINTERLACE_DST_SIZE )
+        {
+            /* Note that the effective buffer size depends also on the constant private_picture in vout_wrapper.c,
+               since that determines the maximum number of output pictures filter_NewPicture() will successfully
+               allocate for one input frame.
+            */
+            msg_Err( p_filter, "Framerate doubler: output buffer too small; fields = %d, buffer size = %d. Dropping the remaining fields.", i_nb_fields, DEINTERLACE_DST_SIZE );
+            i_double_rate_alloc_end = DEINTERLACE_DST_SIZE;
+        }
+
+        /* Allocate output frames. */
+        for( int i = 1; i < i_double_rate_alloc_end ; ++i )
+        {
+            p_dst[i-1]->p_next =
+            p_dst[i]           = filter_NewPicture( p_filter );
+            if( p_dst[i] )
+            {
+                picture_CopyProperties( p_dst[i], p_pic );
+            }
+            else
+            {
+                msg_Err( p_filter, "Framerate doubler: could not allocate output frame %d", i+1 );
+                i_double_rate_alloc_end = i; /* Inform the PTS logic about the correct end position. */
+                break; /* If this happens, the rest of the allocations aren't likely to work, either... */
+            }
+        }
+        /* Now we have allocated *up to* the correct number of frames; normally, exactly the correct number.
+           Upon alloc failure, we may have succeeded in allocating *some* output frames, but fewer than
+           were desired. In such a case, as many will be rendered as were successfully allocated.
+
+           Note that now p_dst[i] != NULL for 0 <= i < i_double_rate_alloc_end. */
+    }
+    assert( p_sys->b_double_rate == true  ||  p_dst[1] == NULL );
+    assert( i_nb_fields > 2  ||  p_dst[2] == NULL );
+
+    /* Render */
     switch( p_sys->i_mode )
     {
         case DEINTERLACE_DISCARD:
@@ -1575,15 +1784,19 @@
             break;

         case DEINTERLACE_BOB:
-            RenderBob( p_filter, p_dst[0], p_pic, !p_pic->b_top_field_first );
+            RenderBob( p_filter, p_dst[0], p_pic, !b_top_field_first );
             if( p_dst[1] )
-                RenderBob( p_filter, p_dst[1], p_pic, p_pic->b_top_field_first );
+                RenderBob( p_filter, p_dst[1], p_pic, b_top_field_first );
+            if( p_dst[2] )
+                RenderBob( p_filter, p_dst[2], p_pic, !b_top_field_first );
             break;;

         case DEINTERLACE_LINEAR:
-            RenderLinear( p_filter, p_dst[0], p_pic, !p_pic->b_top_field_first );
+            RenderLinear( p_filter, p_dst[0], p_pic, !b_top_field_first );
             if( p_dst[1] )
-                RenderLinear( p_filter, p_dst[1], p_pic, p_pic->b_top_field_first );
+                RenderLinear( p_filter, p_dst[1], p_pic, b_top_field_first );
+            if( p_dst[2] )
+                RenderLinear( p_filter, p_dst[2], p_pic, !b_top_field_first );
             break;

         case DEINTERLACE_MEAN:
@@ -1604,24 +1817,58 @@
             break;

         case DEINTERLACE_YADIF2X:
-            if( RenderYadif( p_filter, p_dst[0], p_pic, 0, !p_pic->b_top_field_first ) )
+            if( RenderYadif( p_filter, p_dst[0], p_pic, 0, !b_top_field_first ) )
                 goto drop;
             if( p_dst[1] )
-                RenderYadif( p_filter, p_dst[1], p_pic, 1, p_pic->b_top_field_first );
+                RenderYadif( p_filter, p_dst[1], p_pic, 1, b_top_field_first );
+            if( p_dst[2] )
+                RenderYadif( p_filter, p_dst[2], p_pic, 2, !b_top_field_first );
             break;
     }

+    /* Set output timestamps, if the algorithm didn't request CUSTOM_PTS for this frame. */
+    assert( i_frame_offset <= METADATA_SIZE  ||  i_frame_offset == CUSTOM_PTS );
+    if( i_frame_offset != CUSTOM_PTS )
+    {
+        mtime_t i_base_pts = p_sys->meta.pi_date[i_meta_idx];
+
+        /* Note: in the usual case (i_frame_offset = 0  and  b_double_rate = false),
+                 this effectively does nothing. This is needed to correct the timestamp
+                 when i_frame_offset > 0. */
+        p_dst[0]->date = i_base_pts;
+
+        if( p_sys->b_double_rate )
+        {
+            /* Processing all actually allocated output frames. */
+            for( int i = 1; i < i_double_rate_alloc_end; ++i )
+            {
+                /* XXX it's not really good especially for the first picture, but
+                 * I don't think that delaying by one frame is worth it */
+                if( i_base_pts > VLC_TS_INVALID )
+                    p_dst[i]->date = i_base_pts + i * i_field_dur;
+                else
+                    p_dst[i]->date = VLC_TS_INVALID;
+            }
+        }
+    }
+
     p_dst[0]->b_progressive = true;
-    if( p_dst[1] )
-        p_dst[1]->b_progressive = true;
+    for( int i = 1; i < DEINTERLACE_DST_SIZE; ++i )
+    {
+        if( p_dst[i] )
+            p_dst[i]->b_progressive = true;
+    }

     picture_Release( p_pic );
     return p_dst[0];

 drop:
     picture_Release( p_dst[0] );
-    if( p_dst[1] )
-        picture_Release( p_dst[1] );
+    for( int i = 1; i < DEINTERLACE_DST_SIZE; ++i )
+    {
+        if( p_dst[i] )
+            picture_Release( p_dst[i] );
+    }
     picture_Release( p_pic );
     return NULL;
 }
@@ -1630,7 +1877,13 @@
 {
     filter_sys_t *p_sys = p_filter->p_sys;

-    p_sys->i_last_date = VLC_TS_INVALID;
+    for( int i = 0; i < METADATA_SIZE; i++ )
+    {
+        p_sys->meta.pi_date[i] = VLC_TS_INVALID;
+        p_sys->meta.pi_nb_fields[i] = 2;
+        p_sys->meta.pb_top_field_first[i] = true;
+    }
+    p_sys->i_frame_offset = 0; /* reset to default value (first frame after flush cannot have offset) */
     for( int i = 0; i < HISTORY_SIZE; i++ )
     {
         if( p_sys->pp_history[i] )
@@ -1669,7 +1922,13 @@
     p_sys->i_mode = DEINTERLACE_BLEND;
     p_sys->b_double_rate = false;
     p_sys->b_half_height = true;
-    p_sys->i_last_date = VLC_TS_INVALID;
+    for( int i = 0; i < METADATA_SIZE; i++ )
+    {
+        p_sys->meta.pi_date[i] = VLC_TS_INVALID;
+        p_sys->meta.pi_nb_fields[i] = 2;
+        p_sys->meta.pb_top_field_first[i] = true;
+    }
+    p_sys->i_frame_offset = 0; /* start with default value (first-ever frame cannot have offset) */
     for( int i = 0; i < HISTORY_SIZE; i++ )
         p_sys->pp_history[i] = NULL;


Fixed warnings in IGT module

Fixed warnings in IGT module

--- Modules/IGT/TrackingDevices/mitkOptitrackTrackingTool.h
+++ Modules/IGT/TrackingDevices/mitkOptitrackTrackingTool.h
@@ -97,12 +97,14 @@
     * \brief Set the position to a given one
     * @throw mitk::IGTException Throws an exception if
     */
+    using Superclass::SetPosition;
     void SetPosition(mitk::Point3D position, ScalarType eps=0.0);

     /**
     * \brief Set the orientation to a given one using a quaternion nomenclature
     * @throw mitk::IGTException Throws an exception if
     */
+    using Superclass::SetOrientation;
     void SetOrientation(mitk::Quaternion orientation, ScalarType eps=0.0);

     /**


Issue #188: marked BroadcastDaemon class as unavailable in Python

--- src/api/broadcastdaemon.h
+++ src/api/broadcastdaemon.h
@@ -20,6 +20,9 @@
 //! (http://www.oodesign.com/visitor-pattern.html) to
 //! an IVideoSource object for augmenting that
 //! object's functionality.
+//!
+//! \attention <b>In Python:</b> This class is \b not
+//! available yet.
 //!
 class BroadcastDaemon
 {


[X86][AVX512BW] Replace attributes with __DEFAULT_FN_ATTRS

git-svn-id: ffe668792ed300d6c2daa1f6eba2e0aa28d7ec6c@243512 91177308-0d34-0410-b5e6-96231b3b80d8

--- lib/Headers/avx512bwintrin.h
+++ lib/Headers/avx512bwintrin.h
@@ -1294,7 +1294,7 @@
                (__mmask32) __U);
 }

-static __inline__ __m512i __attribute__((__always_inline__, __nodebug__))
+static __inline__ __m512i __DEFAULT_FN_ATTRS
 _mm512_maddubs_epi16 (__m512i __X, __m512i __Y) {
   return (__m512i) __builtin_ia32_pmaddubsw512_mask ((__v64qi) __X,
                  (__v64qi) __Y,
@@ -1303,7 +1303,7 @@
                  (__mmask32) -1);
 }

-static __inline__ __m512i __attribute__((__always_inline__, __nodebug__))
+static __inline__ __m512i __DEFAULT_FN_ATTRS
 _mm512_mask_maddubs_epi16 (__m512i __W, __mmask32 __U, __m512i __X,
          __m512i __Y) {
   return (__m512i) __builtin_ia32_pmaddubsw512_mask ((__v64qi) __X,
@@ -1312,7 +1312,7 @@
                  (__mmask32) __U);
 }

-static __inline__ __m512i __attribute__((__always_inline__, __nodebug__))
+static __inline__ __m512i __DEFAULT_FN_ATTRS
 _mm512_maskz_maddubs_epi16 (__mmask32 __U, __m512i __X, __m512i __Y) {
   return (__m512i) __builtin_ia32_pmaddubsw512_mask ((__v64qi) __X,
                  (__v64qi) __Y,
@@ -1321,7 +1321,7 @@
                  (__mmask32) __U);
 }

-static __inline__ __m512i __attribute__((__always_inline__, __nodebug__))
+static __inline__ __m512i __DEFAULT_FN_ATTRS
 _mm512_madd_epi16 (__m512i __A, __m512i __B) {
   return (__m512i) __builtin_ia32_pmaddwd512_mask ((__v32hi) __A,
                (__v32hi) __B,
@@ -1330,7 +1330,7 @@
                (__mmask16) -1);
 }

-static __inline__ __m512i __attribute__((__always_inline__, __nodebug__))
+static __inline__ __m512i __DEFAULT_FN_ATTRS
 _mm512_mask_madd_epi16 (__m512i __W, __mmask16 __U, __m512i __A,
       __m512i __B) {
   return (__m512i) __builtin_ia32_pmaddwd512_mask ((__v32hi) __A,
@@ -1339,7 +1339,7 @@
                (__mmask16) __U);
 }

-static __inline__ __m512i __attribute__((__always_inline__, __nodebug__))
+static __inline__ __m512i __DEFAULT_FN_ATTRS
 _mm512_maskz_madd_epi16 (__mmask16 __U, __m512i __A, __m512i __B) {
   return (__m512i) __builtin_ia32_pmaddwd512_mask ((__v32hi) __A,
                (__v32hi) __B,


tests BUGFIX server_thread one last forgotten relative path replaced

--- tests/test_server_thread.c
+++ tests/test_server_thread.c
@@ -619,7 +619,7 @@

     ret = nc_client_tls_set_cert_key_paths(TESTS_DIR"/data/client.crt", TESTS_DIR"/data/client.key");
     assert(!ret);
-    ret = nc_client_tls_set_trusted_ca_paths(NULL, "data");
+    ret = nc_client_tls_set_trusted_ca_paths(NULL, TESTS_DIR"/data");
     assert(!ret);

     session = nc_connect_tls("127.0.0.1", 6501, NULL);


tests CHANGE doing authentication ourselves is not needed anymore

--- tests/test_server_thread.c
+++ tests/test_server_thread.c
@@ -256,58 +256,36 @@
     return NULL;
 }

+static int
+ssh_hostkey_check_clb(const char *hostname, ssh_session session)
+{
+    (void)hostname;
+    (void)session;
+
+    return 0;
+}
+
 static void *
 ssh_client_thread(void *arg)
 {
     (void)arg;
     int ret;
-    long timeout = CLIENT_SSH_AUTH_TIMEOUT;
-    uint32_t port;
-    ssh_session sshsession;
-    ssh_key pubkey, privkey;
     struct nc_session *session;

-    /* We cannot use nc_connect_ssh(), because we want to skip the knownhost check.
+    /* skip the knownhost check */
+    nc_client_ssh_set_auth_hostkey_check_clb(ssh_hostkey_check_clb);
+
     ret = nc_client_ssh_set_username("test");
-    assert_int_equal(ret, 0);
-
-    ret = nc_client_ssh_add_keypair("data/key_dsa.pub", "data/key_dsa");
-    assert_int_equal(ret, 0);
+    assert(!ret);
+
+    ret = nc_client_ssh_add_keypair(TESTS_DIR"/data/key_dsa.pub", TESTS_DIR"/data/key_dsa");
+    assert(!ret);

     nc_client_ssh_set_auth_pref(NC_SSH_AUTH_PUBLICKEY, 1);
     nc_client_ssh_set_auth_pref(NC_SSH_AUTH_PASSWORD, -1);
     nc_client_ssh_set_auth_pref(NC_SSH_AUTH_INTERACTIVE, -1);

-    session = nc_session_connect("127.0.0.1", NC_PORT_SSH, NULL);*/
-
-    port = 6001;
-
-    sshsession = ssh_new();
-    ssh_options_set(sshsession, SSH_OPTIONS_HOST, "127.0.0.1");
-    ssh_options_set(sshsession, SSH_OPTIONS_PORT, &port);
-    ssh_options_set(sshsession, SSH_OPTIONS_USER, "test");
-    ssh_options_set(sshsession, SSH_OPTIONS_TIMEOUT, &timeout);
-    ssh_options_set(sshsession, SSH_OPTIONS_HOSTKEYS, "ssh-ed25519,ssh-rsa,ssh-dss,ssh-rsa1");
-
-    ret = ssh_connect(sshsession);
-    assert(ret == SSH_OK);
-
-    /* authentication */
-    ret = ssh_userauth_none(sshsession, NULL);
-    assert(ret == SSH_AUTH_DENIED);
-    assert(ssh_userauth_list(sshsession, NULL) & SSH_AUTH_METHOD_PUBLICKEY);
-    ret = ssh_pki_import_pubkey_file(TESTS_DIR"/data/key_dsa.pub", &pubkey);
-    assert(ret == SSH_OK);
-    ret = ssh_userauth_try_publickey(sshsession, NULL, pubkey);
-    assert(ret == SSH_AUTH_SUCCESS);
-    ret = ssh_pki_import_privkey_file(TESTS_DIR"/data/key_dsa", NULL, NULL, NULL, &privkey);
-    assert(ret == SSH_OK);
-    ret = ssh_userauth_publickey(sshsession, NULL, privkey);
-    assert(ret == SSH_AUTH_SUCCESS);
-    ssh_key_free(pubkey);
-    ssh_key_free(privkey);
-
-    session = nc_connect_libssh(sshsession, NULL);
+    session = nc_connect_ssh("127.0.0.1", 6001, NULL);
     assert(session);

     nc_session_free(session);


Oops missed on file in last commit: core2ndmomentmodel

--- sansmodels/include/coresecondmoment.h
+++ sansmodels/include/coresecondmoment.h
@@ -5,7 +5,7 @@
 /**
  * Structure definition for sphere parameters
  */
- //[PYTHONCLASS] = CoreSecondMomentModel
+ //[PYTHONCLASS] = Core2ndMomentModel
  //[DISP_PARAMS] = radius_core
  //[DESCRIPTION] =<text>Calculate CoreSecondMoment Model
  //
@@ -22,7 +22,7 @@
  //[FIXED]=  radius_core.width
  //[ORIENTATION_PARAMS]= <text> </text>

-class CoreSecondMomentModel{
+class Core2ndMomentModel{
 public:
   // Model parameters
   /// Scale factor
@@ -63,7 +63,7 @@
  Parameter background;

   // Constructor
- CoreSecondMomentModel();
+ Core2ndMomentModel();

   // Operators to get I(Q)
   double operator()(double q);


r8590/sofa-dev : FIX : compil windows

r8590/sofa-dev : FIX : compil windows

 //partial sync (1/3 changes)//

--- modules/sofa/component/interactionforcefield/JointSpringForceField.h
+++ modules/sofa/component/interactionforcefield/JointSpringForceField.h
@@ -44,15 +44,17 @@
 {
 using namespace sofa::defaulttype;

-template<class DataTypes>
+template<typename DataTypes>
 class JointSpring
 {
 public:
+
+    typedef typename DataTypes::Coord    Coord   ;
+    typedef typename Coord::value_type   Real    ;
+    typedef typename DataTypes::Deriv    Deriv   ;
     typedef typename DataTypes::VecCoord VecCoord;
     typedef typename DataTypes::VecDeriv VecDeriv;
-    typedef typename DataTypes::Coord Coord;
-    typedef typename DataTypes::Deriv Deriv;
-    typedef typename Coord::value_type Real;
+
     enum { N=DataTypes::spatial_dimensions };
     typedef defaulttype::Mat<N,N,Real> Mat;
     typedef Vec<N,Real> Vector;


set ITSDONE on the xs before calling scsi_done()

--- dev/pci/arc.c
+++ dev/pci/arc.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: arc.c,v 1.78 2009/02/16 21:19:07 miod Exp $ */
+/*	$OpenBSD: arc.c,v 1.79 2009/08/13 11:10:27 dlg Exp $ */

 /*
  * Copyright (c) 2006 David Gwynne <dlg@openbsd.org>
@@ -726,6 +726,7 @@
 		xs->sense.flags = SKEY_ILLEGAL_REQUEST;
 		xs->sense.add_sense_code = 0x20;
 		xs->error = XS_SENSE;
+		xs->flags |= ITSDONE;
 		s = splbio();
 		scsi_done(xs);
 		splx(s);
@@ -737,6 +738,7 @@
 	splx(s);
 	if (ccb == NULL) {
 		xs->error = XS_DRIVER_STUFFUP;
+		xs->flags |= ITSDONE;
 		s = splbio();
 		scsi_done(xs);
 		splx(s);
@@ -747,6 +749,7 @@

 	if (arc_load_xs(ccb) != 0) {
 		xs->error = XS_DRIVER_STUFFUP;
+		xs->flags |= ITSDONE;
 		s = splbio();
 		arc_put_ccb(sc, ccb);
 		scsi_done(xs);
@@ -787,6 +790,7 @@
 		rv = COMPLETE;
 		if (arc_complete(sc, ccb, xs->timeout) != 0) {
 			xs->error = XS_DRIVER_STUFFUP;
+			xs->flags |= ITSDONE;
 			scsi_done(xs);
 		}
 	}


Add some debug facility.

Add some debug facility.

--- dev/pci/ips.c
+++ dev/pci/ips.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: ips.c,v 1.4 2006/11/28 00:11:44 grange Exp $	*/
+/*	$OpenBSD: ips.c,v 1.5 2006/11/28 14:28:39 grange Exp $	*/

 /*
  * Copyright (c) 2006 Alexander Yurchenko <grange@openbsd.org>
@@ -35,6 +35,20 @@
 #include <dev/pci/pcidevs.h>
 #include <dev/pci/pcireg.h>
 #include <dev/pci/pcivar.h>
+
+#define IPS_DEBUG	/* XXX: remove when the driver becomes stable */
+
+/* Debug levels */
+#define IPS_D_ERR	0x0001
+#define IPS_D_INFO	0x0002
+#define IPS_D_XFER	0x0004
+
+#ifdef IPS_DEBUG
+#define DPRINTF(a, b)	if (ips_debug & (a)) printf b
+int ips_debug = 0;
+#else
+#define DPRINTF(a, b)
+#endif

 /*
  * Register definitions.


Started Exercise 5-14

Started Exercise 5-14

error: pathspec 'exercise_5-14.c' did not match any file(s) known to git

--- exercise_5-14.c
+++ exercise_5-14.c
@@ -0,0 +1,172 @@
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdbool.h>
+
+enum
+{
+    MAX_NUM_LINES = 5000,
+    BUFFER_SIZE = 10000,
+    MAX_LINE_LENGTH = 1000
+};
+
+static char alloc_buffer[BUFFER_SIZE];
+static char* next_free = alloc_buffer;
+
+char* alloc(int n)
+{
+    if ((alloc_buffer + BUFFER_SIZE) - next_free >= n)
+    {
+        next_free += n;
+        return next_free - n;
+    }
+    else
+    {
+        return NULL;
+    }
+}
+
+int get_line(char line[])
+{
+    int current_char;
+    int index = 0;
+
+    while (index < MAX_LINE_LENGTH && (current_char = getchar()) != EOF && current_char != '\n')
+    {
+        line[index++] = current_char;
+    }
+
+    if (current_char == '\n')
+    {
+        line[index++] = current_char;
+    }
+
+    line[index] = '\0';
+
+    return index;
+}
+
+int read_lines(char* lines[])
+{
+    char line[MAX_LINE_LENGTH] = { 0 };
+    char* line_ptr;
+
+    int line_length = 0;
+    int num_lines = 0;
+
+    while ((line_length = get_line(line)) > 0)
+    {
+        if (num_lines >= MAX_NUM_LINES || (line_ptr = alloc(line_length)) == NULL)
+        {
+            return -1;
+        }
+        else
+        {
+            line[line_length - 1] = '\0';
+            strcpy(line_ptr, line);
+            lines[num_lines++] = line_ptr;
+        }
+    }
+
+    return num_lines;
+}
+
+void write_lines(char* lines[], int num_lines)
+{
+    for (int i = 0; i < num_lines; ++i)
+    {
+        puts(lines[i]);
+    }
+}
+
+int numeric_cmp(char* a, char* b)
+{
+    double a_val = atof(a);
+    double b_val = atof(b);
+
+    if (a_val < b_val)
+    {
+        return -1;
+    }
+    else if (a_val > b_val)
+    {
+        return 1;
+    }
+    else
+    {
+        return 0;
+    }
+}
+
+int lexicographic_cmp(char* a, char* b)
+{
+    int index;
+
+    for (index = 0; a[index] == b[index]; ++index)
+    {
+        if (a[index] == '\0')
+        {
+            return 0;
+        }
+    }
+
+    return a[index] - b[index];
+}
+
+void swap(void* v[], int i, int j)
+{
+    void* tmp = v[i];
+    v[i] = v[j];
+    v[j] = tmp;
+}
+
+void quick_sort(void* v[], int left, int right, int (*cmp)(void*, void*))
+{
+    int index;
+    int last;
+
+    if (left >= right)
+    {
+        return;
+    }
+
+    swap(v, left, (left + right) / 2);
+    last = left;
+
+    for (index = left + 1; index <= right; ++index)
+    {
+        if ((*cmp)(v[index], v[left]) < 0)
+        {
+            swap(v, ++last, index);
+        }
+    }
+
+    swap(v, left, last);
+    quick_sort(v, left, last - 1, cmp);
+    quick_sort(v, last + 1, right, cmp);
+}
+
+int main(int argc, char* argv[])
+{
+    int num_lines;
+    char* lines[MAX_NUM_LINES];
+
+    bool sort_numerically = false;
+
+    if (argc > 1 && strcmp(argv[1], "-n") == 0)
+    {
+        sort_numerically = true;
+    }
+
+    if ((num_lines = read_lines(lines)) >= 0)
+    {
+        quick_sort((void**) lines, 0, num_lines - 1, (int(*)(void*, void*))(sort_numerically ? numeric_cmp : lexicographic_cmp));
+        write_lines(lines, num_lines);
+        return 0;
+    }
+    else
+    {
+        printf("error: input too large to sort\n");
+        return 1;
+    }
+}


little of fix for get_last_error()

little of fix for get_last_error()

--- ext/gxconsole.h
+++ ext/gxconsole.h
@@ -28,9 +28,9 @@

 	HANDLE stdout_read=INVALID_HANDLE_VALUE;		// parent process's stdout read handle
 	HANDLE stdout_write=INVALID_HANDLE_VALUE;	// child process' stdout write handle
-	if(!CreatePipe( &stdout_read, &stdout_write, &sa, REDIR_BUFFER_SIZE )){ fprintf( stdout, "[redir] CreatePipe(stdout) failed: %s\n", os::get_last_error() ); return; }
-	if(stdout_read==INVALID_HANDLE_VALUE||stdout_write==INVALID_HANDLE_VALUE){ fprintf( stdout, "[redir] CreatePipe(stdout) failed: %s\n", os::get_last_error() ); return; }
-	if(!SetHandleInformation(stdout_read,HANDLE_FLAG_INHERIT,0)){ fprintf( stdout, "[redir] SetHandleInformation() failed: %s\n", os::get_last_error() ); return; }
+	if(!CreatePipe( &stdout_read, &stdout_write, &sa, REDIR_BUFFER_SIZE )){ fprintf( stdout, "[redir] CreatePipe(stdout) failed: %s\n", wtoa(os::get_last_error()) ); return; }
+	if(stdout_read==INVALID_HANDLE_VALUE||stdout_write==INVALID_HANDLE_VALUE){ fprintf( stdout, "[redir] CreatePipe(stdout) failed: %s\n", wtoa(os::get_last_error()) ); return; }
+	if(!SetHandleInformation(stdout_read,HANDLE_FLAG_INHERIT,0)){ fprintf( stdout, "[redir] SetHandleInformation() failed: %s\n", wtoa(os::get_last_error()) ); return; }

 	// additional configuration for non-buffered IO
 	setvbuf( stdout, nullptr, _IONBF, 0 );	// absolutely needed
@@ -48,7 +48,7 @@
 	si.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;

 	// Launch the child process.
-	if(!CreateProcessW(nullptr, (LPWSTR)cmd, nullptr, nullptr, TRUE, 0, nullptr, path::cwd(), &si, &pi )) return void(fprintf( stdout, "[redir] CreateProcess() failed: %s\n", os::get_last_error() ));
+	if(!CreateProcessW(nullptr, (LPWSTR)cmd, nullptr, nullptr, TRUE, 0, nullptr, path::cwd(), &si, &pi )) return void(fprintf( stdout, "[redir] CreateProcess() failed: %s\n", wtoa(os::get_last_error()) ));

 	// infinite loop to read
 	read_redir( stdout_read, pi.hProcess );


Create exceptions in a more platform independent way. (#813)

* Create exceptions in a more platform independent way.

* Reformat file with `clang-format`.

--- ext/oj/object.c
+++ ext/oj/object.c
@@ -67,9 +67,9 @@

 // The much faster approach (4x faster)
 static int parse_num(const char *str, const char *end, int cnt) {
-    int n = 0;
+    int  n = 0;
     char c;
-    int i;
+    int  i;

     for (i = cnt; 0 < i; i--, str++) {
         c = *str;
@@ -83,9 +83,9 @@

 VALUE
 oj_parse_xml_time(const char *str, int len) {
-    VALUE args[8];
+    VALUE       args[8];
     const char *end = str + len;
-    int n;
+    int         n;

     // year
     if (0 > (n = parse_num(str, end, 4))) {
@@ -369,11 +369,17 @@
 }

 void oj_set_obj_ivar(Val parent, Val kval, VALUE value) {
-    rb_ivar_set(parent->val, oj_attr_intern(kval->key, kval->klen), value);
+    if (kval->klen == 5 && strncmp("~mesg", kval->key, 5) == 0 && rb_obj_is_kind_of(parent->val, rb_eException)) {
+        parent->val = rb_funcall(parent->val, rb_intern("exception"), 1, value);
+    } else if (kval->klen == 3 && strncmp("~bt", kval->key, 3) == 0 && rb_obj_is_kind_of(parent->val, rb_eException)) {
+        rb_funcall(parent->val, rb_intern("set_backtrace"), 1, value);
+    } else {
+        rb_ivar_set(parent->val, oj_attr_intern(kval->key, kval->klen), value);
+    }
 }

 static void hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, const char *orig) {
-    const char *   key    = kval->key;
+    const char    *key    = kval->key;
     int            klen   = kval->klen;
     Val            parent = stack_peek(&pi->stack);
     volatile VALUE rval   = Qnil;
@@ -446,7 +452,7 @@
 }

 static void hash_set_num(ParseInfo pi, Val kval, NumInfo ni) {
-    const char *   key    = kval->key;
+    const char    *key    = kval->key;
     int            klen   = kval->klen;
     Val            parent = stack_peek(&pi->stack);
     volatile VALUE rval   = Qnil;


Two major changes.  First removed minfo_key type.  It is now replaced by just an integer.  This reduced profiling overhead by 50% due to the removal of memory allocation.  Also switched API to use PROCESS_TIME, WALL_TIME and CPU_TIME.

git-svn-id: a649f8b53cef7d15963550bf81aeba716f52dec1@39 5fb4a865-4516-0410-ae3b-a609ddf12040

--- ext/ruby_prof.c
+++ ext/ruby_prof.c
@@ -49,10 +49,10 @@
 #endif

 typedef struct {
+    /* Cache hash value for speed reasons. */
+    st_data_t key;
     prof_clock_t start_time;
     prof_clock_t child_cost;
-    VALUE klass;
-    ID mid;
 } prof_data_t;

 typedef struct {
@@ -62,12 +62,16 @@
 } prof_stack_t;

 typedef struct {
+    VALUE klass;
+    ID mid;
     int called;
     prof_clock_t self_time;
     prof_clock_t total_time;
 } prof_call_info_t;

 typedef struct {
+    /* Cache hash value for speed reasons. */
+    st_data_t key;
     VALUE klass;
     ID mid;
     int thread_id;
@@ -91,13 +95,14 @@
     st_table* minfo_table;
 } thread_data_t;

-ID toplevel_id;
+static VALUE toplevel_id;
+static st_data_t toplevel_key;
 static int clock_mode;
 static st_table *threads_tbl = NULL;
 static VALUE class_tbl = Qnil;

-#define CLOCK_MODE_CLOCK 0
-#define CLOCK_MODE_GETTIMEOFDAY 1
+#define CLOCK_MODE_PROCESS 0
+#define CLOCK_MODE_WALL 1
 #if defined(_WIN32) || (defined(__GNUC__) && (defined(__i386__) || defined(__powerpc__) || defined(__ppc__)))
 #define CLOCK_MODE_CPU 2
 static double cpu_frequency;
@@ -199,11 +204,11 @@
     unsigned long long x, y;
     double frequency;
     x = cpu_get_clock();
+
     /* Use the windows sleep function, not Ruby's */
     Sleep(500);
     y = cpu_get_clock();
     frequency = 2*(y-x);
-    printf("clock speed: %f", frequency);
     return frequency;
 }
 #endif
@@ -241,6 +246,7 @@

 static prof_clock_t (*get_clock)() = clock_get_clock;
 static double (*clock2sec)(prof_clock_t) = clock_clock2sec;
+

 /* Helper method to get the id of a Ruby thread. */
 static inline int
@@ -249,86 +255,16 @@
     return NUM2INT(rb_obj_id(thread));
 }

-
-
-/* -- Stack to track methods call sequence and times ---- */
-static prof_stack_t *
-stack_create()
-{
-    prof_stack_t *stack;
-
-    stack = ALLOC(prof_stack_t);
-    stack->start = stack->ptr =
-	ALLOC_N(prof_data_t, INITIAL_STACK_SIZE);
-    stack->end = stack->start + INITIAL_STACK_SIZE;
-    return stack;
-}
-
-static void
-stack_free(prof_stack_t *stack)
-{
-    xfree(stack->start);
-    xfree(stack);
-}
-
-static inline prof_data_t *
-stack_push(prof_stack_t *stack)
-{
-    if (stack->ptr == stack->end) {
-	int len, new_capa;
-
-	len = stack->ptr - stack->start;
-	new_capa = (stack->end - stack->start) * 2;
-	REALLOC_N(stack->start, prof_data_t, new_capa);
-	stack->ptr = stack->start + len;
-	stack->end = stack->start + new_capa;
-    }
-    return stack->ptr++;
-}
-
-static inline prof_data_t *
-stack_pop(prof_stack_t *stack)
-{
-    if (stack->ptr == stack->start)
-	    return NULL;
+static VALUE
+method_name(VALUE klass, ID mid)
+{
+    VALUE result;
+    VALUE method_name;
+
+    if (mid == ID_ALLOCATOR)
+        method_name = rb_str_new2("allocate");
     else
-	    return --stack->ptr;
-}
-
-static inline prof_data_t *
-stack_peek(prof_stack_t *stack)
-{
-    if (stack->ptr == stack->start)
-	    return NULL;
-    else
-	    return stack->ptr - 1;
-}
-
-
-/* -- Hash keyed on calss/method_id to hold information
-      about each method ---- */
-typedef struct {
-    VALUE klass;
-    ID mid;
-} minfo_t;
-
-static int
-minfo_cmp(minfo_t *x, minfo_t *y)
-{
-    return x->klass != y->klass || x->mid != y->mid;
-}
-
-static int
-minfo_hash(minfo_t *m)
-{
-    return m->klass ^ m->mid;
-}
-
-static VALUE
-minfo_name(VALUE klass, ID mid)
-{
-    VALUE result;
-    VALUE method_name = rb_String(ID2SYM(mid));
+        method_name = rb_String(ID2SYM(mid));

     if (klass == Qnil)
         result = rb_str_new2("#");
@@ -375,9 +311,83 @@
     return result;
 }

-static struct st_hash_type type_minfo_hash = {
-    minfo_cmp,
-    minfo_hash,
+static inline st_data_t
+method_key(VALUE klass, ID mid)
+{
+    return klass ^ mid;
+}
+
+
+/* -- Stack to track methods call sequence and times ---- */
+static prof_stack_t *
+stack_create()
+{
+    prof_stack_t *stack;
+
+    stack = ALLOC(prof_stack_t);
+    stack->start = stack->ptr =
+	ALLOC_N(prof_data_t, INITIAL_STACK_SIZE);
+    stack->end = stack->start + INITIAL_STACK_SIZE;
+    return stack;
+}
+
+static void
+stack_free(prof_stack_t *stack)
+{
+    xfree(stack->start);
+    xfree(stack);
+}
+
+static inline prof_data_t *
+stack_push(prof_stack_t *stack)
+{
+    if (stack->ptr == stack->end) {
+	int len, new_capa;
+	len = stack->ptr - stack->start;
+	new_capa = (stack->end - stack->start) * 2;
+	REALLOC_N(stack->start, prof_data_t, new_capa);
+	stack->ptr = stack->start + len;
+	stack->end = stack->start + new_capa;
+    }
+    return stack->ptr++;
+}
+
+static inline prof_data_t *
+stack_pop(prof_stack_t *stack)
+{
+    if (stack->ptr == stack->start)
+	    return NULL;
+    else
+	    return --stack->ptr;
+}
+
+static inline prof_data_t *
+stack_peek(prof_stack_t *stack)
+{
+    if (stack->ptr == stack->start)
+	    return NULL;
+    else
+	    return stack->ptr - 1;
+}
+
+
+/* -- Hash keyed on class/method_id to hold information
+      about each method ---- */
+static int
+value_cmp(int x, int y)
+{
+    return x != y;
+}
+
+static inline int
+value_hash(int v)
+{
+    return v;
+}
+
+static struct st_hash_type type_value_hash = {
+    value_cmp,
+    value_hash,
 #if RUBY_VERSION_CODE >= 190
     st_nothing_key_free,
     st_nothing_key_clone
@@ -388,33 +398,24 @@
 static st_table *
 minfo_table_create()
 {
-    return st_init_table(&type_minfo_hash);
+    return st_init_table(&type_value_hash);
 }

 static inline int
-minfo_table_insert(st_table *table, VALUE klass, ID mid, prof_method_t *val)
-{
-    minfo_t* key;
-
-    key = ALLOC(minfo_t);
-    key->klass = klass;
-    key->mid = mid;
-    return st_insert(table, (st_data_t ) key, (st_data_t) val);
+minfo_table_insert(st_table *table, st_data_t key, prof_method_t *val)
+{
+    return st_insert(table, key, (st_data_t) val);
 }

 static inline prof_method_t *
-minfo_table_lookup(st_table *table, VALUE klass, ID mid)
-{
-    minfo_t key;
+minfo_table_lookup(st_table *table, st_data_t key)
+{
     st_data_t val;
-
-    key.klass = klass;
-    key.mid = mid;
-    if (st_lookup(table, (st_data_t) &key, &val)) {
-	return (prof_method_t *) val;
+    if (st_lookup(table, key, &val)) {
+	    return (prof_method_t *) val;
     }
     else {
-	return NULL;
+	    return NULL;
     }
 }

@@ -430,28 +431,20 @@
 static st_table *
 child_table_create()
 {
-    return st_init_table(&type_minfo_hash);
+    return st_init_table(&type_value_hash);
 }

 static inline int
-child_table_insert(st_table *table, VALUE klass, ID mid, prof_call_info_t *val)
-{
-    minfo_t* key;
-    key = ALLOC(minfo_t);
-    key->klass = klass;
-    key->mid = mid;
-    return st_insert(table, (st_data_t ) key, (st_data_t) val);
+child_table_insert(st_table *table, st_data_t key, prof_call_info_t *val)
+{
+    return st_insert(table, key, (st_data_t) val);
 }

 static inline prof_call_info_t *
-child_table_lookup(st_table *table, VALUE klass, ID mid)
-{
-    minfo_t key;
+child_table_lookup(st_table *table, st_data_t key)
+{
     st_data_t val;
-
-    key.klass = klass;
-    key.mid = mid;
-    if (st_lookup(table, (st_data_t) &key, &val)) {
+    if (st_lookup(table, key, &val)) {
 	    return (prof_call_info_t *) val;
     }
     else {
@@ -466,11 +459,13 @@

 /* :nodoc: */
 static prof_call_info_t *
-call_info_create()
+call_info_create(VALUE klass, ID mid)
 {
     prof_call_info_t *result;

     result = ALLOC(prof_call_info_t);
+    result->klass = klass;
+    result->mid = mid;
     result->called = 0;
     result->total_time = 0;
     result->self_time = 0;
@@ -576,6 +571,7 @@
     rb_hash_aset(class_tbl, klass, Qnil);

     result = ALLOC(prof_method_t);
+    result->key = method_key(klass, mid);
     result->called = 0;
     result->total_time = 0;
     result->self_time = 0;
@@ -716,7 +712,7 @@
 prof_method_name(VALUE self)
 {
     prof_method_t *method = get_prof_method(self);
-    return minfo_name(method->klass, method->mid);
+    return method_name(method->klass, method->mid);
 }

 static int
@@ -761,7 +757,7 @@
         prof_method_t *parent = (prof_method_t *)(FIX2INT(item));

         /* Now get the call info */
-        call_info = child_table_lookup(parent->children, child->klass, child->mid);
+        call_info = child_table_lookup(parent->children, child->key);
         if (call_info == NULL)
             rb_raise(rb_eTypeError, "Could not find parent call info");

@@ -769,7 +765,7 @@
            keyed on the parent's name.  We use the parent's name because
            we want to see that printed out for parent records in
            a call graph. */
-        rb_hash_aset(result, minfo_name(parent->klass, parent->mid),
+        rb_hash_aset(result, method_name(parent->klass, parent->mid),
                      call_info_new(call_info));
     }

@@ -780,9 +776,8 @@
 static int
 prof_method_collect_children(st_data_t key, st_data_t value, st_data_t result)
 {
-    minfo_t *minfo = (minfo_t*) key;
-    VALUE name = minfo_name(minfo->klass, minfo->mid);
     prof_call_info_t *call_info = (prof_call_info_t *) value;
+    VALUE name = method_name(call_info->klass, call_info->mid);
     VALUE hash = (VALUE) result;

     /* Create a new Ruby CallInfo object and store it into the hash
@@ -837,12 +832,8 @@
 collect_methods(st_data_t key, st_data_t value, st_data_t result)
 {
     prof_method_t *method = (prof_method_t *) value;
-    minfo_t *minfo = (minfo_t*) key;
-    VALUE name = minfo_name(minfo->klass, minfo->mid);
+    VALUE name = method_name(method->klass, method->mid);
     VALUE hash = (VALUE) result;
-
-    xfree((void *) key);
-
     rb_hash_aset(hash, name, prof_method_new(method));
     return ST_CONTINUE;
 }
@@ -869,26 +860,6 @@

 /* ---- Hash, keyed on thread, that stores thread's stack
         and methods---- */
-static int
-value_cmp(VALUE x, VALUE y)
-{
-    return x != y;
-}
-
-static int
-value_hash(VALUE v)
-{
-    return v;
-}
-
-static struct st_hash_type type_value_hash = {
-    value_cmp,
-    value_hash,
-#if RUBY_VERSION_CODE >= 190
-    st_nothing_key_free,
-    st_nothing_key_clone
-#endif
-};

 static st_table *
 threads_table_create()
@@ -927,7 +898,7 @@
         toplevel->called = 1;
         toplevel->total_time = 0;
         toplevel->self_time = 0;
-        minfo_table_insert(result->minfo_table, Qnil, toplevel_id, toplevel);
+        minfo_table_insert(result->minfo_table, toplevel->key, toplevel);

         /* Insert the table */
         threads_table_insert(threads_tbl, thread, result);
@@ -968,11 +939,11 @@
 {
     /* Update child information on parent (ie, the method that
        called the current method) */
-    prof_call_info_t *parent_call_info = child_table_lookup(parent->children, child->klass, child->mid);
+    prof_call_info_t *parent_call_info = child_table_lookup(parent->children, child->key);
     if (parent_call_info == NULL)
     {
-        parent_call_info = call_info_create();
-        child_table_insert(parent->children, child->klass, child->mid, parent_call_info);
+        parent_call_info = call_info_create(child->klass, child->mid);
+        child_table_insert(parent->children, child->key, parent_call_info);
     }

     parent_call_info->called++;
@@ -981,7 +952,7 @@

     /* Slight hack here - if the child is the top level method then we want
        to update its total time */
-    if (parent->klass == Qnil && parent->mid == toplevel_id)
+    if (parent->key == toplevel_key)
         parent->total_time += total_time;

     /* Update information about the child (ie, the current method) */
@@ -990,21 +961,20 @@
     child->self_time += self_time;

     /* Store pointer to parent */
-    if (minfo_table_lookup(child->parents, parent->klass, parent->mid) == NULL)
-        minfo_table_insert(child->parents, parent->klass, parent->mid, parent);
+    if (minfo_table_lookup(child->parents, parent->key) == NULL)
+        minfo_table_insert(child->parents, parent->key, parent);
 }

 static void
 prof_event_hook(rb_event_t event, NODE *node, VALUE self, ID mid, VALUE klass)
 {
     thread_data_t* thread_data;
+    st_data_t key;
     prof_data_t *data;
     VALUE thread;
     static int profiling = 0;
-
+
     if (profiling) return;
-
-    if (mid == ID_ALLOCATOR) return;

     /* Special case - skip any methods from the mProf
        module, such as Prof.stop, since they clutter
@@ -1020,6 +990,17 @@
     if (BUILTIN_TYPE(klass) == T_ICLASS)
         klass = RBASIC(klass)->klass;

+    key = method_key(klass, mid);
+
+    /*{
+        Debug code:
+            VALUE temp_name = temp_name = rb_String(klass);
+            char* class_name = StringValuePtr(temp_name);
+            char* method_name = rb_id2name(mid);
+
+            printf("Event: %2d, Key: %d, Method: %s#%s\n", event, key, class_name, method_name);
+    }
+*/
     thread = rb_thread_current();

     thread_data = threads_table_lookup(threads_tbl, thread);
@@ -1032,16 +1013,16 @@
 	    prof_method_t *child;

         data = stack_push(thread_data->stack);
+        data->key = key;
 	    data->start_time = get_clock();
 	    data->child_cost = 0;
-        data->klass = klass;
-        data->mid = mid;
-
-   	    child = minfo_table_lookup(thread_data->minfo_table, klass, mid);
+
+   	    child = minfo_table_lookup(thread_data->minfo_table, key);
 	    if (child == NULL) {
 		    child = prof_method_create(klass, mid, thread);
-		    minfo_table_insert(thread_data->minfo_table, klass, mid, child);
+		    minfo_table_insert(thread_data->minfo_table, key, child);
 	    }
+
         /* Increment count of number of times this child has been called on
            the current stack. */
         child->stack_count++;
@@ -1061,11 +1042,12 @@
            profiling started after this method was entered, thus
            we are seeing the returns but not the enters.  So just
            skip this method.*/
-        child = minfo_table_lookup(thread_data->minfo_table, klass, mid);
+        child = minfo_table_lookup(thread_data->minfo_table, key);
         if (child == NULL)
             break;

 	    data = stack_pop(thread_data->stack);
+
         if (data == NULL)
         {
             /* For reasons I don't understand, this is sometimes triggered.  I've only
@@ -1090,14 +1072,12 @@
         caller = stack_peek(thread_data->stack);

 	    if (caller == NULL)
-        {
             /* We are at the top of the stack, so grab the toplevel method */
-    	    parent = minfo_table_lookup(thread_data->minfo_table, Qnil, toplevel_id);
-        }
+            parent = minfo_table_lookup(thread_data->minfo_table, toplevel_key);
         else
         {
             caller->child_cost += total_time;
-    	    parent = minfo_table_lookup(thread_data->minfo_table, caller->klass, caller->mid);
+    	    parent = minfo_table_lookup(thread_data->minfo_table, caller->key);
         }

         /* Decrement count of number of times this child has been called on
@@ -1184,9 +1164,9 @@
 static VALUE
 result_toplevel(VALUE self, VALUE thread_id)
 {
-    VALUE key = minfo_name(Qnil, toplevel_id);
     VALUE threads = rb_iv_get(self, "@threads");
     VALUE methods = rb_hash_aref(threads, thread_id);
+    VALUE key = method_name(Qnil, toplevel_id);
     VALUE result = rb_hash_aref(methods, key);

     if (result == Qnil)
@@ -1199,9 +1179,9 @@
    clock_mode -> clock_mode

    Returns the current clock mode.  Valid values include:
-   *RubyProf::CLOCK - Use clock. This is default.
-   *RubyProf::GETTIMEOFDAY - Use gettimeofday.
-   *RubyProf::CPU - Use the CPU clock counter.  This mode is only supported on Pentium or PowerPC platforms. */
+   *RubyProf::PROCESS_TIME - Measure process time.  This is default.  It is implemented using the clock function in the C Runtime library.
+   *RubyProf::WALL_TIME - Measure wall time using gettimeofday on Linx and GetLocalTime on Windows
+   *RubyProf::CPU_TIME - Measure time using the CPU clock counter.  This mode is only supported on Pentium or PowerPC platforms. */
 static VALUE
 prof_get_clock_mode(VALUE self)
 {
@@ -1212,9 +1192,9 @@
    clock_mode=value -> void

    Specifies the method ruby-prof uses to measure time.  Valid values include:
-   *RubyProf::CLOCK - Use clock. This is default.
-   *RubyProf::GETTIMEOFDAY - Use gettimeofday.
-   *RubyProf::CPU - Use the CPU clock counter.  This mode is only supported on Pentium or PowerPC platforms. */
+   *RubyProf::PROCESS_TIME - Measure process time.  This is default.  It is implemented using the clock function in the C Runtime library.
+   *RubyProf::WALL_TIME - Measure wall time using gettimeofday on Linx and GetLocalTime on Windows
+   *RubyProf::CPU_TIME - Measure time using the CPU clock counter.  This mode is only supported on Pentium or PowerPC platforms. */
 static VALUE
 prof_set_clock_mode(VALUE self, VALUE val)
 {
@@ -1225,11 +1205,11 @@
     }

     switch (mode) {
-    case CLOCK_MODE_CLOCK:
+    case CLOCK_MODE_PROCESS:
     	get_clock = clock_get_clock;
 	    clock2sec = clock_clock2sec;
     	break;
-    case CLOCK_MODE_GETTIMEOFDAY:
+    case CLOCK_MODE_WALL:
 	    get_clock = gettimeofday_get_clock;
 	    clock2sec = gettimeofday_clock2sec;
 	    break;
@@ -1260,6 +1240,7 @@
 prof_start(VALUE self)
 {
     toplevel_id = rb_intern("toplevel");
+    toplevel_key = method_key(Qnil, toplevel_id);

     if (threads_tbl != NULL) {
         rb_raise(rb_eRuntimeError, "RubyProf.start was already called");
@@ -1337,10 +1318,10 @@
     rb_define_module_function(mProf, "profile", prof_profile, 0);
     rb_define_singleton_method(mProf, "clock_mode", prof_get_clock_mode, 0);
     rb_define_singleton_method(mProf, "clock_mode=", prof_set_clock_mode, 1);
-    rb_define_const(mProf, "CLOCK", INT2NUM(CLOCK_MODE_CLOCK));
-    rb_define_const(mProf, "GETTIMEOFDAY", INT2NUM(CLOCK_MODE_GETTIMEOFDAY));
+    rb_define_const(mProf, "PROCESS_TIME", INT2NUM(CLOCK_MODE_PROCESS));
+    rb_define_const(mProf, "WALL_TIME", INT2NUM(CLOCK_MODE_WALL));
 #ifdef CLOCK_MODE_CPU
-    rb_define_const(mProf, "CPU", INT2NUM(CLOCK_MODE_CPU));
+    rb_define_const(mProf, "CPU_TIME", INT2NUM(CLOCK_MODE_CPU));
     rb_define_singleton_method(mProf, "cpu_frequency",
 			       prof_get_cpu_frequency, 0);
     rb_define_singleton_method(mProf, "cpu_frequency=",


%f->%g for coefs

%f->%g for coefs

--- fastlib2/mlpack/svm/svm.h
+++ fastlib2/mlpack/svm/svm.h
@@ -729,13 +729,13 @@
   // save models: bias, coefficients and support vectors
   fprintf(fp, "bias ");
   for (i = 0; i < num_models_; i++)
-    fprintf(fp, "%f ", models_[i].bias_);
+    fprintf(fp, "%g ", models_[i].bias_);
   fprintf(fp, "\n");

   fprintf(fp, "SV_coefs\n");
   for (i = 0; i < total_num_sv_; i++) {
     for (j = 0; j < num_classes_-1; j++) {
-      fprintf(fp, "%f ", sv_coef_.get(j,i));
+      fprintf(fp, "%g ", sv_coef_.get(j,i));
     }
     fprintf(fp, "\n");
   }
@@ -743,7 +743,7 @@
   fprintf(fp, "SVs\n");
   for (i = 0; i < total_num_sv_; i++) {
     for (j = 0; j < num_features_; j++) { // n_rows-1
-      fprintf(fp, "%f ", sv_.get(j,i));
+      fprintf(fp, "%g ", sv_.get(j,i));
     }
     fprintf(fp, "\n");
   }


add deprectation message to ble store header

--- nimble/host/store/ram/include/store/ram/ble_store_ram.h
+++ nimble/host/store/ram/include/store/ram/ble_store_ram.h
@@ -15,6 +15,11 @@
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.
+ */
+
+/* This package has been deprecated and you should
+ * use the store/config package. For a RAM-only BLE store,
+ * use store/config and set BLE_STORE_CONFIG_PERSIST to 0.
  */

 #ifndef H_BLE_STORE_RAM_


Fix documentation, incorrect file name

Fix documentation, incorrect file name

--- src/core/FCYCubicBezier.h
+++ src/core/FCYCubicBezier.h
@@ -10,7 +10,7 @@
 /**
  * Makes Cubic Bezier calculations
  *
- * @note If you import `FCYCubicBezier+CATimingFunction` you can
+ * @note If you import `FCYCubicBezier+CAMediaTimingFunction.h` you can
  * use a `CATimingFunction` from QuartzCore to make a new instance
  * to make custom animations using the standard values of the platform.
  */
@@ -46,4 +46,4 @@

 - (CGPoint)bezierPointForAxisX:(CGFloat)x;

-@end+@end


central compliant with libwebsockets v1.23

--- src/apps/central/channel-http.c
+++ src/apps/central/channel-http.c
@@ -116,7 +116,6 @@
         /* kill the connection after we sent one file */
         return -1;

-#if 0
     case LWS_CALLBACK_HTTP_WRITEABLE:
         /*
          * we can send more of whatever it is we were sending
@@ -168,7 +167,6 @@
 #endif
         /* if we returned non-zero from here, we kill the connection */
         break;
-#endif

     default:
         break;


Add getter for simulation embedding mode

--- STEER/STEER/AliSimulation.h
+++ STEER/STEER/AliSimulation.h
@@ -53,6 +53,9 @@
                    {fMakeSDigits = detectors;};
   void           MergeWith(const char* fileName, Int_t nSignalPerBkgrd = 0);
   void           EmbedInto(const char* fileName, Int_t nSignalPerBkgrd = 0);
+
+  Bool_t         GetEmbeddingFlag() const {return fEmbeddingFlag;}
+
   void           SetUseBkgrdVertex(Bool_t useBkgrdVertex)
                    {fUseBkgrdVertex = useBkgrdVertex;};
   void           SetRegionOfInterest(Bool_t flag) {fRegionOfInterest = flag;};


constant timestamp in the samples

constant timestamp in the samples

--- src/apps/rfc5769/rfc5769check.c
+++ src/apps/rfc5769/rfc5769check.c
@@ -76,9 +76,7 @@

 	const char mac_key[33] = "ZksjpweoixXmvn67534m";
 	const size_t mac_key_length=strlen(mac_key);
-	uint64_t token_timestamp0 = turn_time();
-	const uint64_t token_timestamp = token_timestamp0 << 16;
-	printf("key timestamp: %llu\n",(unsigned long long)token_timestamp);
+	const uint64_t token_timestamp = 92470300704768;
 	const uint32_t token_lifetime = 3600;

 	const char kid[33] = "2783466234";


changed random movement

changed random movement

--- mud/usr/common/obj/wander_mobile.c
+++ mud/usr/common/obj/wander_mobile.c
@@ -27,31 +27,34 @@

 void random_move(void)
 {
-  int    num_ex, ctr;
-  object exit, dest;
-  string reason;
+    int    num_ex, ctr;
+    object exit, dest;
+    string reason;

-  num_ex = location->num_exits();
-  if(num_ex > 0)
-    {
-      int dir;
+    if (TAGD->get_tag_value(this_object()->get_body(), "Combat"))
+        return;

-      ctr = random(num_ex + 10);
-      if (ctr >= (num_ex - 1))
-          return;
-      exit = location->get_exit_num(ctr);
-      if(!exit)
-          error("Internal error!  Can't get exit!");
-
-      dir = exit->get_direction();
-      dest = exit->get_destination();
+    num_ex = location->num_exits();
+    if(num_ex > 0) {
+        int dir;

-      if (ZONED->get_zone_for_room(dest) != ZONED->get_zone_for_room(location))
-          return;
-
-      reason = this_object()->move(dir);
-      if(reason)
-          error(reason);
+        ctr = random(100);
+        if (ctr >= 60)
+            return;
+        ctr = random(num_ex);
+        exit = location->get_exit_num(ctr);
+        if(!exit)
+            error("Błąd wewnętrzny! Nie mogę pobrać wyjścia!");
+
+        dir = exit->get_direction();
+        dest = exit->get_destination();
+
+        if (ZONED->get_zone_for_room(dest) != ZONED->get_zone_for_room(location))
+            return;
+
+        reason = this_object()->move(dir);
+        if(reason)
+            error(reason);
     }
 }


makeZero was renamed to setZero - update the dox

--- doc/dox-common-ops.h
+++ doc/dox-common-ops.h
@@ -170,13 +170,13 @@
 /**
  * Set all entries to zero.
  */
-void makeZero();
+void setZero();

 /**
  * Set all entries to zero where the mask is set. I.e. a 4-vector with a mask of 0111 would
  * set the last three entries to 0.
  */
-void makeZero(const MASK_TYPE &mask);
+void setZero(const MASK_TYPE &mask);

 /**
  * Store the vector data to \p memory.


Update MaterialElement.h

Update MaterialElement.h

--- SimModule/MaterialElement.h
+++ SimModule/MaterialElement.h
@@ -9,27 +9,19 @@
 //===============================Material element==============================
 class MaterialElement
 {
-private:
-
-	double Mass;   	// in kg
-	double Charge; 	// in Coulomb
-	Point Position; // m
-	Force NetForce; // Newton
-    Velocity V;		// m/s
-
-	virtual void updateSpeedandPosition(Acceleration a, double dt);
-
 public:

 	//Constructors & destructor
 	MaterialElement();
-    MaterialElement(Point p, double masse =0, double charge_=0);
+
+	MaterialElement(Point p, Force res = Force() , Velocity vel = Velocity() , double masse = 0, double charge_ = 0);
 	~MaterialElement();

 	//Accessors
-    Point *pointerToPosition(); //** necessary for display
-    double getMass(); //** necessary for display
+    Point *pointerToPosition();
+    double getMass();
+	double getCharge();

 	//Display
 	virtual void consoleShow();
@@ -38,10 +30,29 @@
     void setPosition(Point &p);
 	void setPosition(double x, double y, double z);
 	void setMass(double m);
-
+	void setCharge(double c);
+	void setResultant(Force F);
+
 	//Simulation tool
-	virtual void update(double dt); //computes and updates the state of the element at t+dt
+	virtual void update(double dt); //computes and updates the state of the element to t+dt
 	virtual Acceleration getAcceleration();
+
+private:
+	double		Charge; 	// in Coulomb
+	double		Mass;   	// in kg
+	Velocity	V;			// m/s
+	Force		NetForce;	// Newton
+	Point		Position;	// m
+
+	virtual void updateSpeedandPosition(Acceleration a, double dt);
+
+};
+
+class MaterialPoint : public MaterialElement
+{
+	public:
+		MaterialPoint();
+		~MaterialPoint();
 };

@@ -56,6 +67,4 @@

-
-
 #endif


Phobos

Phobos

--- DevTools/rev.c
+++ DevTools/rev.c
@@ -1,5 +1,5 @@
 /*
-	rev.exe [/D N     b | /T | /U rW | [/P] [POSIX-Time]]
+	rev.exe [/D N     b | /E POSIX-Time | /T | /U rW | [/P] [POSIX-Time]]

 		/D ... w POSIX- \B
 		/E ... w POSIX- Nb\BA 0 ̂Ƃ͌, 32535244800 ȏ̂Ƃ 1970/1/1 0:0:0 \B


[media] cx25821-audio-upstream.c: Change line endings

Change obscure line endings to less obscure ones. (improve readability)

Signed-off-by: Leonid V. Fedorenchik <821bceacbe0db68e83c10d9c637ab8351f6a3129@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <ad86ba2154032c9f55743a190faa2459a9d61d42@redhat.com>

--- drivers/media/video/cx25821/cx25821-audio-upstream.c
+++ drivers/media/video/cx25821/cx25821-audio-upstream.c
@@ -175,10 +175,8 @@
 		}

 		rp = cx25821_risc_field_upstream_audio(dev, rp,
-						       dev->
-						       _audiodata_buf_phys_addr
-						       + databuf_offset, bpl,
-						       fifo_enable);
+				dev->_audiodata_buf_phys_addr + databuf_offset,
+				bpl, fifo_enable);

 		if (USE_RISC_NOOP_AUDIO) {
 			for (i = 0; i < NUM_NO_OPS; i++)
@@ -305,8 +303,8 @@
 		for (i = 0; i < dev->_audio_lines_count; i++) {
 			pos = file_offset;

-			vfs_read_retval =
-			    vfs_read(myfile, mybuf, line_size, &pos);
+			vfs_read_retval = vfs_read(myfile, mybuf, line_size,
+									&pos);

 			if (vfs_read_retval > 0 && vfs_read_retval == line_size
 			    && dev->_audiodata_buf_virt_addr != NULL) {
@@ -328,8 +326,8 @@
 		if (i > 0)
 			dev->_audioframe_count++;

-		dev->_audiofile_status =
-		    (vfs_read_retval == line_size) ? IN_PROGRESS : END_OF_FILE;
+		dev->_audiofile_status = (vfs_read_retval == line_size) ?
+						IN_PROGRESS : END_OF_FILE;

 		set_fs(old_fs);
 		filp_close(myfile, NULL);
@@ -340,8 +338,8 @@

 static void cx25821_audioups_handler(struct work_struct *work)
 {
-	struct cx25821_dev *dev =
-	    container_of(work, struct cx25821_dev, _audio_work_entry);
+	struct cx25821_dev *dev = container_of(work, struct cx25821_dev,
+			_audio_work_entry);

 	if (!dev) {
 		pr_err("ERROR %s(): since container_of(work_struct) FAILED!\n",
@@ -395,8 +393,8 @@
 			for (i = 0; i < dev->_audio_lines_count; i++) {
 				pos = offset;

-				vfs_read_retval =
-				    vfs_read(myfile, mybuf, line_size, &pos);
+				vfs_read_retval = vfs_read(myfile, mybuf,
+						line_size, &pos);

 				if (vfs_read_retval > 0 &&
 				    vfs_read_retval == line_size &&
@@ -423,8 +421,8 @@
 				break;
 		}

-		dev->_audiofile_status =
-		    (vfs_read_retval == line_size) ? IN_PROGRESS : END_OF_FILE;
+		dev->_audiofile_status = (vfs_read_retval == line_size) ?
+						IN_PROGRESS : END_OF_FILE;

 		set_fs(old_fs);
 		myfile->f_pos = 0;
@@ -444,9 +442,8 @@

 	cx25821_free_memory_audio(dev);

-	dev->_risc_virt_addr =
-	    pci_alloc_consistent(dev->pci, dev->audio_upstream_riscbuf_size,
-				 &dma_addr);
+	dev->_risc_virt_addr = pci_alloc_consistent(dev->pci,
+			dev->audio_upstream_riscbuf_size, &dma_addr);
 	dev->_risc_virt_start_addr = dev->_risc_virt_addr;
 	dev->_risc_phys_start_addr = dma_addr;
 	dev->_risc_phys_addr = dma_addr;
@@ -461,9 +458,8 @@
 	memset(dev->_risc_virt_addr, 0, dev->_audiorisc_size);

 	/* For Audio Data buffer allocation */
-	dev->_audiodata_buf_virt_addr =
-	    pci_alloc_consistent(dev->pci, dev->audio_upstream_databuf_size,
-				 &data_dma_addr);
+	dev->_audiodata_buf_virt_addr = pci_alloc_consistent(dev->pci,
+			dev->audio_upstream_databuf_size, &data_dma_addr);
 	dev->_audiodata_buf_phys_addr = data_dma_addr;
 	dev->_audiodata_buf_size = dev->audio_upstream_databuf_size;

@@ -480,9 +476,8 @@
 		return ret;

 	/* Creating RISC programs */
-	ret =
-	    cx25821_risc_buffer_upstream_audio(dev, dev->pci, bpl,
-					       dev->_audio_lines_count);
+	ret = cx25821_risc_buffer_upstream_audio(dev, dev->pci, bpl,
+						dev->_audio_lines_count);
 	if (ret < 0) {
 		printk(KERN_DEBUG
 			pr_fmt("ERROR creating audio upstream RISC programs!\n"));
@@ -661,9 +656,9 @@

 	/* Set the input mode to 16-bit */
 	tmp = cx_read(sram_ch->aud_cfg);
-	tmp |=
-	    FLD_AUD_SRC_ENABLE | FLD_AUD_DST_PK_MODE | FLD_AUD_CLK_ENABLE |
-	    FLD_AUD_MASTER_MODE | FLD_AUD_CLK_SELECT_PLL_D | FLD_AUD_SONY_MODE;
+	tmp |= FLD_AUD_SRC_ENABLE | FLD_AUD_DST_PK_MODE | FLD_AUD_CLK_ENABLE |
+		FLD_AUD_MASTER_MODE | FLD_AUD_CLK_SELECT_PLL_D |
+		FLD_AUD_SONY_MODE;
 	cx_write(sram_ch->aud_cfg, tmp);

 	/* Read and write back the interrupt status register to clear it */
@@ -678,12 +673,11 @@
 	tmp = cx_read(sram_ch->int_msk);
 	cx_write(sram_ch->int_msk, tmp |= _intr_msk);

-	err =
-	    request_irq(dev->pci->irq, cx25821_upstream_irq_audio,
+	err = request_irq(dev->pci->irq, cx25821_upstream_irq_audio,
 			IRQF_SHARED, dev->name, dev);
 	if (err < 0) {
-		pr_err("%s: can't get upstream IRQ %d\n",
-		       dev->name, dev->pci->irq);
+		pr_err("%s: can't get upstream IRQ %d\n", dev->name,
+				dev->pci->irq);
 		goto fail_irq;
 	}