DEVSENSE / Phalanger

PHP 5.4 compiler for .NET/Mono frameworks. Predecessor to the opensource PeachPie project (www.peachpie.io).
http://v4.php-compiler.net/
Apache License 2.0
382 stars 94 forks source link

bug in library wrappers generator? #36

Open proff opened 10 years ago

proff commented 10 years ago
        [ImplementsFunction("tieArrayValue")]
        public static object tieArrayValue([PhpRw] ref PhpArray arr, object key, object value)
        {
...
        }

        [ImplementsFunction("tieArrayValue")]
        public static object tieArrayValue([PhpRw] ref PhpArray arr, object key)
        {
...
        }
    public static object tieArrayValue([In] object obj0, [In] PhpStack obj1)
    {
      switch (obj1.ArgCount)
      {
        case 2:
          PhpReference phpReference1 = obj1.PeekReferenceUnchecked(0); //why 0? it's throws exception
          PhpArray phpArray1 = phpReference1.value as PhpArray;
          // ISSUE: explicit reference operation
          // ISSUE: variable of a reference type
          PhpArray& arr1 = @phpArray1;
          object key1 = obj1.PeekValueUnchecked(2);
          obj1.RemoveFrame();
          object obj2 = Common.tieArrayValue(arr1, key1);
          phpReference1.value = (object) phpArray1;
          return obj2;
        case 3:
          PhpReference phpReference2 = obj1.PeekReferenceUnchecked(0); //why 0? it's throws exception
          PhpArray phpArray2 = phpReference2.value as PhpArray;
          // ISSUE: explicit reference operation
          // ISSUE: variable of a reference type
          PhpArray& arr2 = @phpArray2;
          object key2 = obj1.PeekValueUnchecked(2);
          object obj3 = obj1.PeekValueUnchecked(3);
          obj1.RemoveFrame();
          object obj4 = Common.tieArrayValue(arr2, key2, obj3);
          phpReference2.value = (object) phpArray2;
          return obj4;
        default:
          PhpException.InvalidArgumentCount((string) null, "tieArrayValue");
          return (object) null;
      }
    }
jakubmisek commented 10 years ago

PeekReferenceUnchecked(0); should never work, will be fixed - THANKS!

ref causes explicit referencing the variable, maybe can be discussed?

proff commented 10 years ago

I need to change bool to PhpArray if i got bool in first argument (original methods has object as first argument and also has this bug)