瀏覽代碼

Merge branch 'feature/libuv-prepare' into feature/eval-libuv

# Conflicts:
#	libs/uv/uv_stubs.c
Simon Krajewski 6 年之前
父節點
當前提交
1a107365b3

+ 5 - 4
libs/uv/uv_stubs.c

@@ -11,8 +11,8 @@
 #include <string.h>
 #include <uv.h>
 
-#if (UV_VERSION_MAJOR <= 0)
-#	error "libuv1-dev required, uv version 0.x found"
+#if (UV_VERSION_HEX < (1 << 16 | 31 << 8))
+#    error "Compiling Haxe requires libuv version 1.31.0+"
 #endif
 
 // ------------- UTILITY MACROS -------------------------------------
@@ -28,6 +28,7 @@
 	Handle-specific macros are defined further, in the HANDLE DATA section.
 **/
 
+
 // access the data of a request
 #define UV_REQ_DATA(r) (((uv_req_t *)(r))->data)
 #define UV_REQ_DATA_A(r) ((value *)(&UV_REQ_DATA(r)))
@@ -559,7 +560,7 @@ static void handle_stream_cb_alloc(uv_handle_t *handle, size_t suggested_size, u
 	buf->len = suggested_size;
 }
 
-static void handle_stream_cb_read(uv_stream_t *stream, long int nread, const uv_buf_t *buf) {
+static void handle_stream_cb_read(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) {
 	CAMLparam0();
 	CAMLlocal2(cb, res);
 	cb = UV_HANDLE_DATA_SUB(stream, stream).cb_read;
@@ -744,7 +745,7 @@ CAMLprim value w_tcp_getpeername(value handle) {
 
 // ------------- UDP ------------------------------------------------
 
-static void handle_udp_cb_recv(uv_udp_t *handle, long int nread, const uv_buf_t *buf, const struct sockaddr *addr, unsigned int flags) {
+static void handle_udp_cb_recv(uv_udp_t *handle, ssize_t nread, const uv_buf_t *buf, const struct sockaddr *addr, unsigned int flags) {
 	CAMLparam0();
 	CAMLlocal2(cb, res);
 	cb = UV_HANDLE_DATA_SUB(handle, udp).cb_read;

+ 2 - 1
src/context/typecore.ml

@@ -382,8 +382,9 @@ let rec can_access ctx ?(in_overload=false) c cf stat =
 		true
 	else if not in_overload && ctx.com.config.pf_overload && Meta.has Meta.Overload cf.cf_meta then
 		true
+	else if c == ctx.curclass then
+		true
 	else
-	(* TODO: should we add a c == ctx.curclass short check here? *)
 	(* has metadata path *)
 	let rec make_path c f = match c.cl_kind with
 		| KAbstractImpl a -> fst a.a_path @ [snd a.a_path; f.cf_name]

+ 16 - 10
src/typing/typerDisplay.ml

@@ -541,16 +541,22 @@ let handle_display ?resume_typing ctx e_ast dk with_type =
 				| Yes -> true
 				| YesButPrivate ->
 					if (Meta.has Meta.PrivateAccess ctx.meta) then true
-					else begin
-						let path = (mt.pack,mt.name) in
-						let rec loop c =
-							if c.cl_path = path then true
-							else match c.cl_super with
-								| Some(c,_) -> loop c
-								| None -> false
-						in
-						loop ctx.curclass
-					end
+					else
+						begin
+							match ctx.curclass.cl_kind with
+							| KAbstractImpl { a_path = (pack, name) } -> pack = mt.pack && name = mt.name
+							| _ -> false
+						end
+						|| begin
+							let path = (mt.pack,mt.name) in
+							let rec loop c =
+								if c.cl_path = path then true
+								else match c.cl_super with
+									| Some(c,_) -> loop c
+									| None -> false
+							in
+							loop ctx.curclass
+						end
 				| No -> false
 				| Maybe ->
 					begin try

+ 12 - 0
std/lua/NativeStringTools.hx

@@ -145,6 +145,18 @@ extern class NativeStringTools {
 		function must be a Lua function without upvalues.
 	**/
 	public static function dump(d:Dynamic):Dynamic;
+
+
+    /**
+        Returns a string that is the concatenation of n copies of
+        the string s separated by the string sep. The default value
+        for sep is the empty string (that is, no separator).
+        Returns the empty string if n is not positive.  (Note that
+        it is very easy to exhaust the memory of your machine with
+        a single call to this function.)
+    **/
+    public static function rep(s:String, n : Int, ?sep : String) : String;
+
 }
 
 @:multiReturn extern class StringFind {

+ 3 - 3
std/lua/_std/Sys.hx

@@ -23,7 +23,7 @@
 import lua.Boot;
 import lua.Io;
 import lua.Lua;
-import lua.Os;
+import lua.lib.luv.Os;
 import lua.lib.luv.Misc;
 import sys.io.FileInput;
 import sys.io.FileOutput;
@@ -109,11 +109,11 @@ class Sys {
 		Misc.chdir(s);
 
 	public inline static function getEnv(s:String):String {
-		return Misc.os_getenv(s);
+		return Os.getenv(s);
 	}
 
 	public inline static function putEnv(s:String, v:String):Void {
-		Misc.os_setenv(s, v);
+		Os.setenv(s, v);
 	}
 
 	public inline static function setTimeLocale(loc:String):Bool {

+ 0 - 6
std/lua/lib/luv/Misc.hx

@@ -26,9 +26,6 @@ package lua.lib.luv;
 extern class Misc {
 	public static function chdir(path:String):Bool;
 
-	public static function os_homedir():String;
-	public static function os_tmpdir():String;
-	public static function os_get_passwd():String;
 	public static function cpu_info():Table<Int, CpuInfo>;
 
 	public static function cwd():String;
@@ -38,9 +35,6 @@ extern class Misc {
 	public static function get_free_memory():Int;
 	public static function getpid():Int;
 
-	public static function os_getenv(env:String):String;
-	public static function os_setenv(env:String, value:String):Void;
-
 	// TODO Windows only?
 	public static function getuid():Int;
 	public static function setuid(from:Int, to:Int):String;

+ 43 - 0
std/lua/lib/luv/Os.hx

@@ -0,0 +1,43 @@
+/*
+ * Copyright (C)2005-2019 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+package lua.lib.luv;
+
+@:luaRequire("luv")
+extern class Os {
+    @:native("os_homedir")
+	public static function homedir():String;
+
+    @:native("os_tmpdir")
+	public static function tmpdir():String;
+
+    @:native("os_get_passwd")
+	public static function get_passwd():String;
+
+    @:native("os_getenv")
+	public static function getenv(env:String):String;
+
+    @:native("os_setenv")
+	public static function setenv(env:String, value:String):Void;
+
+}
+

+ 31 - 0
std/php/JsonSerializable.hx

@@ -0,0 +1,31 @@
+/*
+ * Copyright (C)2005-2019 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+package php;
+
+/**
+	@see https://www.php.net/manual/en/class.jsonserializable.php
+**/
+@:native('JsonSerializable')
+extern interface JsonSerializable<T> {
+	private function jsonSerialize():T;
+}

+ 6 - 1
std/php/_std/Array.hx

@@ -26,7 +26,7 @@ import php.ArrayIterator as NativeArrayIterator;
 using php.Global;
 
 @:coreApi
-final class Array<T> implements ArrayAccess<Int, T> implements IteratorAggregate<T> {
+final class Array<T> implements ArrayAccess<Int, T> implements IteratorAggregate<T> implements JsonSerializable<NativeIndexedArray<T>> {
 	public var length(default, null):Int;
 
 	var arr:NativeIndexedArray<T>;
@@ -234,6 +234,11 @@ final class Array<T> implements ArrayAccess<Int, T> implements IteratorAggregate
 		return new NativeArrayIterator(arr);
 	}
 
+	@:noCompletion @:keep
+	function jsonSerialize():NativeIndexedArray<T> {
+		return arr;
+	}
+
 	static function wrap<T>(arr:NativeIndexedArray<T>):Array<T> {
 		var a = new Array();
 		a.arr = arr;

+ 23 - 0
tests/display/src/cases/Issue8789.hx

@@ -0,0 +1,23 @@
+package cases;
+
+class Issue8789 extends DisplayTestCase {
+	/**
+		abstract Int8(Int) {
+			inline function new(value:Int) {
+				this = value;
+			}
+
+			inline function pvt() {}
+
+			public function test() {
+				var i = new Int8{-1-}(10);
+				i.{-2-}
+			}
+		}
+	**/
+	function test() {
+		var r = toplevel(pos(1));
+		eq(true, hasToplevel(r, "type", "Int8"));
+		eq(true, hasField(fields(pos(2)), "pvt", "Void -> Void"));
+	}
+}