Ver código fonte

- fixed issue in php.io.Process
- added runttime check for php.io.Socket.shutdown
- fixed php rethrow in Catch and added the possibility to catch native exceptions

Franco Ponticelli 17 anos atrás
pai
commit
495a6a34a7
4 arquivos alterados com 33 adições e 15 exclusões
  1. 3 1
      doc/CHANGES.txt
  2. 20 10
      genphp.ml
  3. 3 2
      std/php/io/Process.hx
  4. 7 2
      std/php/net/Socket.hx

+ 3 - 1
doc/CHANGES.txt

@@ -7,8 +7,10 @@ TODO inlining : allow inlined getter/setter
 TODO inlining : substitute class+function type parameters in order to have fully typed expressions
 TODO inlining : substitute class+function type parameters in order to have fully typed expressions
 
 
 2008-??-??: 2.01
 2008-??-??: 2.01
+	added runttime check for php.io.Socket.shutdown (uses fclose in php 5.1.x)
+	fixed php rethrow in catches and added the possibility to catch native exceptions
 	fixed php.Web.setCookie() for expire time
 	fixed php.Web.setCookie() for expire time
-	fixed php.net.Socket.setTimeout()
+	fixed php.net.Socket.setTimeout(), php.io.Process
 	fixed SPOD/MySql for PHP
 	fixed SPOD/MySql for PHP
 	fixed Type.enumParameters() and Type.typeOf() for PHP
 	fixed Type.enumParameters() and Type.typeOf() for PHP
 	fixed null references in class constructors for array arguments
 	fixed null references in class constructors for array arguments

+ 20 - 10
genphp.ml

@@ -1360,25 +1360,31 @@ and gen_expr ctx e =
 		spr ctx "try ";
 		spr ctx "try ";
 		gen_expr ctx (mk_block e);
 		gen_expr ctx (mk_block e);
 		let ex = define_local ctx "__e__" in
 		let ex = define_local ctx "__e__" in
-		print ctx "catch(HException %s$%s) {" (escphp ctx.quotes) ex;
+		print ctx "catch(Exception %s$%s) {" (escphp ctx.quotes) ex;
 		let p = escphp ctx.quotes in
 		let p = escphp ctx.quotes in
 		let first = ref true in
 		let first = ref true in
+		let catchall = ref false in
+		let evar = = define_local ctx "_ex_" in
+		newline ctx;
+		print ctx "%s$%s = (%s$%s instanceof HException) ? %s$%s->e : %s$%s" p evar p ex p ex p ex;
+		newline ctx;
 		List.iter (fun (v,t,e) ->
 		List.iter (fun (v,t,e) ->
 			let ev = define_local ctx v in
 			let ev = define_local ctx v in
 			newline ctx;
 			newline ctx;
+			
 			let b = save_locals ctx in
 			let b = save_locals ctx in
 			if not !first then spr ctx "else ";
 			if not !first then spr ctx "else ";
 			(match follow t with
 			(match follow t with
 			| TEnum (te,_) -> (match snd te.e_path with
 			| TEnum (te,_) -> (match snd te.e_path with
-				| "Bool"   -> print ctx "if(is_bool(%s$%s = %s$%s->e))"		p ev p ex
-				| _ -> print ctx "if((%s$%s = %s$%s->e) instanceof %s)"		p ev p ex (s_path ctx te.e_path te.e_extern e.epos));
+				| "Bool"   -> print ctx "if(is_bool(%s$%s = %s$%s))"		p ev p evar
+				| _ -> print ctx "if((%s$%s = %s$%s) instanceof %s)"		p ev p evar (s_path ctx te.e_path te.e_extern e.epos));
 				gen_expr ctx (mk_block e);
 				gen_expr ctx (mk_block e);
 			| TInst (tc,_) -> (match snd tc.cl_path with
 			| TInst (tc,_) -> (match snd tc.cl_path with
-				| "Int"	-> print ctx "if(is_int(%s$%s = %s$%s->e))"		 p ev p ex
-				| "Float"  -> print ctx "if(is_numeric(%s$%s = %s$%s->e))"	 p ev p ex
-				| "String" -> print ctx "if(is_string(%s$%s = %s$%s->e))"	  p ev p ex
-				| "Array"  -> print ctx "if(is_array(%s$%s = %s$%s->e))"	   p ev p ex
-				| _		-> print ctx "if((%s$%s = %s$%s->e) instanceof %s)" p ev p ex (s_path ctx tc.cl_path tc.cl_extern e.epos));
+				| "Int"	-> print ctx "if(is_int(%s$%s = %s$%s))"		 p ev p evar
+				| "Float"  -> print ctx "if(is_numeric(%s$%s = %s$%s))"	 p ev p evar
+				| "String" -> print ctx "if(is_string(%s$%s = %s$%s))"	  p ev p evar
+				| "Array"  -> print ctx "if(is_array(%s$%s = %s$%s))"	   p ev p evar
+				| _		-> print ctx "if((%s$%s = %s$%s) instanceof %s)" p ev p evar (s_path ctx tc.cl_path tc.cl_extern e.epos));
 				gen_expr ctx (mk_block e);
 				gen_expr ctx (mk_block e);
 			| TFun _
 			| TFun _
 			| TLazy _
 			| TLazy _
@@ -1387,14 +1393,18 @@ and gen_expr ctx e =
 				assert false
 				assert false
 			| TMono _
 			| TMono _
 			| TDynamic _ ->
 			| TDynamic _ ->
-				print ctx "{ %s$%s = %s$%s->e" p ev p ex;
+				catchall := true;
+				print ctx "{ %s$%s = %s$%s" p ev p ex;
 				newline ctx;
 				newline ctx;
 				gen_expr ctx (mk_block e);
 				gen_expr ctx (mk_block e);
 				spr ctx "}");
 				spr ctx "}");
 			b();
 			b();
 			first := false;
 			first := false;
 		) catchs;
 		) catchs;
-		spr ctx "}";
+		if !catchall then
+			spr ctx "}"
+		else
+			print ctx " else throw %s$%s; }" (escphp ctx.quotes) ex;
 	| TMatch (e,_,cases,def) ->
 	| TMatch (e,_,cases,def) ->
 		let b = save_locals ctx in
 		let b = save_locals ctx in
 		let tmp = define_local ctx "__t__" in
 		let tmp = define_local ctx "__t__" in

+ 3 - 2
std/php/io/Process.hx

@@ -69,7 +69,8 @@ private class Stdout extends haxe.io.Input {
 
 
 	public override function readBytes( str : haxe.io.Bytes, pos : Int, l : Int ) : Int {
 	public override function readBytes( str : haxe.io.Bytes, pos : Int, l : Int ) : Int {
 		if(untyped __call__('feof', p)) return throw new haxe.io.Eof();
 		if(untyped __call__('feof', p)) return throw new haxe.io.Eof();
-		var r : String = untyped __call__('fread', p, 1);
+		var r : String = untyped __call__('fread', p, l);
+		if(untyped __physeq__(r, "")) return throw new haxe.io.Eof();
 		if(untyped __physeq__(r, false)) return throw haxe.io.Error.Custom('An error occurred');
 		if(untyped __physeq__(r, false)) return throw haxe.io.Error.Custom('An error occurred');
 		var b = haxe.io.Bytes.ofString(r);
 		var b = haxe.io.Bytes.ofString(r);
 		str.blit(pos, b, 0, r.length);
 		str.blit(pos, b, 0, r.length);
@@ -90,7 +91,7 @@ class Process {
 			['pipe', 'w'],
 			['pipe', 'w'],
 			['pipe', 'w']
 			['pipe', 'w']
 		];
 		];
-		// TODO: check how args are passed in neko 
+		// TODO: check how args are passed in neko
 		p = untyped __call__('proc_open', cmd, descriptorspec, pipes, null, __php__("array('args' => join(' ', $args))"));
 		p = untyped __call__('proc_open', cmd, descriptorspec, pipes, null, __php__("array('args' => join(' ', $args))"));
 		if(untyped __physeq__(p, false)) throw "Process creation failure : "+cmd;
 		if(untyped __physeq__(p, false)) throw "Process creation failure : "+cmd;
 		stdin  = new Stdin(pipes[0]);
 		stdin  = new Stdin(pipes[0]);

+ 7 - 2
std/php/net/Socket.hx

@@ -86,8 +86,13 @@ class Socket {
 	}
 	}
 
 
 	public function shutdown( read : Bool, write : Bool ){
 	public function shutdown( read : Bool, write : Bool ){
-		var rw = read && write ? 2 : (write ? 1 : (read ? 0 : 2));
-		var r = untyped __call__('stream_socket_shutdown', __s, rw);
+		var r;
+		if(untyped __call__("function_exists", "stream_socket_shutdown")) {
+			var rw = read && write ? 2 : (write ? 1 : (read ? 0 : 2));
+			r = untyped __call__('stream_socket_shutdown', __s, rw);
+		} else {
+			r = untyped __call__('fclose', __s);
+		}
 		checkError(r, 0, 'Unable to Shutdown');
 		checkError(r, 0, 'Unable to Shutdown');
 	}
 	}