Browse Source

- php : enhanced FileInput.readLine using native fgets function (issue 103)
- minor fixes related to previous fixings

Franco Ponticelli 15 years ago
parent
commit
f6394e39e7
6 changed files with 44 additions and 13 deletions
  1. 2 0
      doc/CHANGES.txt
  2. 8 3
      genphp.ml
  3. 6 1
      std/php/db/Manager.hx
  4. 0 1
      std/php/db/Object.hx
  5. 8 0
      std/php/io/FileInput.hx
  6. 20 8
      std/php/io/Process.hx

+ 2 - 0
doc/CHANGES.txt

@@ -41,6 +41,8 @@
 	php : added error message when using 2 fields with different cases in the same class/enum
 	php : fixed field declaration for properties with getter and setter (issue 124)
 	php : fixed comparison issues between strings (issue 132)
+	php : enhanced FileInput.readLine using native fgets function (issue 103)
+	
 2010-01-09: 2.05
 	js : added js.Scroll
 	js : package names are now checked at runtime to avoid clashes with existing libs

+ 8 - 3
genphp.ml

@@ -1661,7 +1661,8 @@ let generate_field ctx static f =
 						newline ctx);
 				if not (is_method_defined ctx m2 static) then (
 					generate_self_method ctx rights m2 static true;
-					print ctx "%s $%s" rights (s_ident m2));
+					print ctx "%s $%s" rights (s_ident m2);
+					newline ctx);
 				false
 			| CallAccess m, _ ->
 				if not (is_method_defined ctx m static) then generate_self_method ctx rights m static false;
@@ -1917,12 +1918,16 @@ let generate com =
 	List.iter (fun t ->
 		(match t with
 		| TClassDecl c ->
+			let fname f = (String.lowercase f.cf_name) ^ match follow f.cf_type with
+			| TFun _ -> "m_";
+			| _ -> 		"f_" in
+			
 			let lc_names = ref [] in
 			List.iter(fun f -> (
-				if List.exists (fun n -> n = String.lowercase f.cf_name) !lc_names then
+				if List.exists (fun n -> n = fname f) !lc_names then
 					unsupported ("'" ^ f.cf_name ^ "' already exists with different case") c.cl_pos
 				else
-					!lc_names <- (String.lowercase f.cf_name) :: !lc_names
+					!lc_names <- (fname f) :: !lc_names
 			)) (c.cl_ordered_fields @ c.cl_ordered_statics)
 		| TEnumDecl e ->
 			let e_names = ref [] in

+ 6 - 1
std/php/db/Manager.hx

@@ -262,7 +262,12 @@ class Manager<T : Object> {
 		s.add("UPDATE ");
 		s.add(table_name);
 		s.add(" SET ");
-		var cache = Reflect.field(x,cache_field);
+		var cache = Reflect.field(x, cache_field);
+		if (null == cache)
+		{
+			cache = cacheObject(x, false);
+			Reflect.setField(x, cache_field, cache);
+		}
 		var mod = false;
 		for( f in table_fields ) {
 			var v = Reflect.field(x,f);

+ 0 - 1
std/php/db/Object.hx

@@ -58,7 +58,6 @@ class Object #if spod_rtti implements haxe.rtti.Infos #end {
 
 	private function __init_object() {
 		__noupdate__ = false;
-
 		__manager__ = Manager.managers.get(Type.getClassName(Type.getClass(this)));
 		var rl : Array<Dynamic>;
 		try {

+ 8 - 0
std/php/io/FileInput.hx

@@ -23,6 +23,7 @@
  * DAMAGE.
  */
 package php.io;
+import haxe.io.Eof;
 import php.io.File;
 
 /**
@@ -73,4 +74,11 @@ class FileInput extends haxe.io.Input {
 		if(untyped __physeq__(r, false)) return throw haxe.io.Error.Custom('An error occurred');
 		return cast r;
 	}
+
+	override function readLine() : String {
+		var r : String = untyped __call__('fgets', __f);
+		if (untyped __physeq__(false, r))
+			throw new Eof();
+		return untyped __call__("rtrim", r, "\r\n");
+	}
 }

+ 20 - 8
std/php/io/Process.hx

@@ -23,6 +23,7 @@
  * DAMAGE.
  */
 package php.io;
+import php.NativeArray;
 
 private class Stdin extends haxe.io.Output {
 	var p : Void;
@@ -80,6 +81,8 @@ private class Stdout extends haxe.io.Input {
 
 class Process {
 	var p : Void;
+	var st : NativeArray;
+	var cl : Int;
 	public var stdout(default,null) : haxe.io.Input;
 	public var stderr(default,null) : haxe.io.Input;
 	public var stdin(default,null) : haxe.io.Output;
@@ -97,6 +100,14 @@ class Process {
 		stdout = new Stdout(pipes[1]);
 		stderr = new Stdout(pipes[2]);
 	}
+	
+	public function close() {
+		if(null == st)
+			st = untyped __call__('proc_get_status', p);
+		replaceStream(stderr);
+		replaceStream(stdout);
+		cl = untyped __call__('proc_close', p);
+	}
 
 	function sargs(args : Array<String>) {
 		var b = '';
@@ -126,15 +137,16 @@ class Process {
 	}
 
 	public function exitCode() : Int {
-		var status = untyped __call__('proc_get_status', p);
-		while(status[untyped 'running']) {
-			php.Sys.sleep(0.01);
-			status = untyped __call__('proc_get_status', p);
+		if (null == cl)
+		{
+			st = untyped __call__('proc_get_status', p);
+			while(st[untyped 'running']) {
+				php.Sys.sleep(0.01);
+				st = untyped __call__('proc_get_status', p);
+			}
+			close();
 		}
-		replaceStream(stderr);
-		replaceStream(stdout);
-		var cl : Int = untyped __call__('proc_close', p);
-		return (cast status[untyped 'exitcode']) < 0 ? cl : cast status[untyped 'exitcode'];
+		return (cast st[untyped 'exitcode']) < 0 ? cl : cast st[untyped 'exitcode'];
 
 	}
 }