Przeglądaj źródła

[cpp] Do not access stirng '__s' directly. Load cppia scripts from bytes, not string

hughsando 6 lat temu
rodzic
commit
3ec78ebbbd

+ 3 - 3
src/generators/gencpp.ml

@@ -2593,7 +2593,7 @@ let retype_expression ctx request_type function_args function_type expression_tr
                else if fieldName="cca" && obj.cpptype=TCppString then
                   CppFunction( FuncInternal(obj,"cca","."), TCppScalar("int")), TCppDynamic
                else if fieldName="__s" && obj.cpptype=TCppString then
-                  CppVar( VarInternal(obj,".","__s")), TCppPointer("ConstPointer", TCppScalar("char"))
+                  CppVar( VarInternal(obj,".","utf8_str()")), TCppPointer("ConstPointer", TCppScalar("char"))
                else if fieldName="__Index" then
                   CppEnumIndex(obj), TCppScalar("int")
                else if is_internal_member fieldName || cpp_is_real_array obj then begin
@@ -3116,7 +3116,7 @@ let retype_expression ctx request_type function_args function_type expression_tr
          match cpp_variant_type_of cppExpr.cpptype with
          | TCppVoidStar
          | TCppScalar _ -> cppExpr
-         | TCppString ->  mk_cppexpr (CppVar(VarInternal(cppExpr,".","__s"))) (TCppPointer("ConstPointer", TCppScalar("char")))
+         | TCppString ->  mk_cppexpr (CppVar(VarInternal(cppExpr,".","raw_ptr()"))) (TCppPointer("ConstPointer", TCppScalar("char")))
          | TCppDynamic ->  mk_cppexpr (CppCastNative(cppExpr)) TCppVoidStar
          | _ -> let toDynamic = mk_cppexpr (CppCast(cppExpr, TCppDynamic)) TCppDynamic in
                 mk_cppexpr (CppCastNative(toDynamic)) TCppVoidStar
@@ -4593,7 +4593,7 @@ let gen_member_def ctx class_def is_static is_interface field =
 
          output (tcppStr ^ " " ^ remap_name ^ ";\n" );
          if not is_static && (is_gc_element ctx tcpp) then begin
-            let getPtr = match tcpp with | TCppString -> ".__s" | _ -> ".mPtr" in
+            let getPtr = match tcpp with | TCppString -> ".raw_ref()" | _ -> ".mPtr" in
             output ("\t\tinline " ^ tcppStr ^ " _hx_set_" ^ remap_name ^ "(hx::StackContext *_hx_ctx," ^ tcppStr ^ " _hx_v) { HX_OBJ_WB(this,_hx_v" ^ getPtr ^ ") return " ^ remap_name ^ "=_hx_v; }\n");
          end;
 

+ 2 - 2
std/cpp/NativeString.hx

@@ -24,10 +24,10 @@
 extern class NativeString {
 
 	public static inline function raw( inString:String ) : RawConstPointer<Char> {
-      return untyped inString.__s;
+      return untyped inString.raw_ptr();
    }
 	public static inline function c_str( inString:String ) : ConstPointer<Char> {
-		return cpp.ConstPointer.fromPointer(untyped inString.__s);
+		return cpp.ConstPointer.fromPointer(untyped inString.c_str());
    }
 	public static inline function fromPointer(inPtr:ConstPointer<Char> ) : String {
       return untyped __global__.String(inPtr.ptr);

+ 2 - 2
std/cpp/cppia/Host.hx

@@ -58,8 +58,8 @@ class Host
       }
       else
       {
-         var source = sys.io.File.getContent(script);
-         var module = Module.fromString(source);
+         var source = sys.io.File.getBytes(script);
+         var module = Module.fromData(source.getData());
          module.boot();
          module.run();
       }

+ 3 - 0
std/cpp/cppia/Module.hx

@@ -28,6 +28,9 @@ extern class Module
 {
    @:native("__scriptable_cppia_from_string")
    public static function fromString(sourceCode:String) : Module;
+   @:native("__scriptable_cppia_from_data")
+   public static function fromData(data:haxe.io.BytesData) : Module;
+
    public function boot():Void;
    public function run():Void;
    public function resolveClass(inName:String):Class<Dynamic>;