Boo
  1. Boo
  2. BOO-1202

Unsafe code support (pointer manipulation within `unsafe' block)

    Details

    • Type: New Feature New Feature
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 0.9.1
    • Fix Version/s: 0.9.2
    • Component/s: Compiler
    • Labels:
      None
    • Testcase included:
      yes
    • Number of attachments :
      0

      Description

      Usage:

      unsafe [<ptrName> as <ptrType> = <data>]+:
          <body>
      

      unsafe blocks are only allowed when "-unsafe" flag as been passed to the compiler (CompilerParameters.Unsafe == true), otherwise an error is reported.
      It declares pointer(s) to one or more value type references (<data>).
      In the context of an unsafe block, an explode operator on a declared pointer is replaced with the indirection operator.

      sizeof built-in meta-method is introduced, it accepts both type references (as in C#) and also variable references.

      Example:

      src = array[of byte](8)
      src[3] = 1
      dst = array[of byte](8)
      dst[6] = 1
      
      #replace an uint at a time from src to dst only if src is not zero
      unsafe psrc as uint = src, pdst as uint = dst:
      	for i in range(len(src) / sizeof(psrc)):
      		*pdst = *psrc unless *psrc == 0
      		psrc++
      		pdst++
      
      assert dst[3] == 1 #this has been copied from src
      assert dst[6] == 1 #this has not been replaced since src[4:8] is 0
      

        Activity

        Cedric Vivier made changes -
        Field Original Value New Value
        Description Testcase:
        {code}
        bytes = array(byte, 128)
        fixed pointer as int = bytes:
        pointer = 0xFFFFFFFF
        pointer++

        assert bytes[0] == 255
        assert bytes[128] == 255
        {code}


        `fixed' is implemented as a macro that creates a new pinned local-scope variable. Ld*a opcodes are then used in EmitAssembly when such a variable is manipulated.

        Syntax for `fixed' is :
        fixed <pointer> as <type> = <source>

        pointer = name of the pointer
        type = type of the pointer, no need to specify type* as in C# (anyways we already use T* for enumerable ;) )
        source = any value type or array of value types


        Usage of that macro will be allowed when "-unsafe" flag as been passed to the compiler (CompilerParameters.Unsafe == true), otherwise an error is reported.
        Testcase:
        {code}
        bytes = array(byte, 128)
        fixed pointer as int = bytes:
                for i in range(len(bytes) / sizeof(pointer)):
        pointer = 0xFFFFFFFF
        pointer++

        assert bytes[0] == 255
        assert bytes[128] == 255
        {code}


        `fixed' is implemented as a macro that creates a new pinned local-scope variable. Ld*a opcodes are then used in EmitAssembly when such a variable is manipulated.

        Syntax for `fixed' is :
        {code}
        fixed <pointer> as <type> = <source>

        pointer = name of the pointer
        type = type of the pointer, no need to specify type* as in C# (anyways we already use T* for enumerable ;) )
        source = any value type or array of value types
        {code}

        Usage of that macro will be allowed when "-unsafe" flag as been passed to the compiler (CompilerParameters.Unsafe == true), otherwise an error is reported.

        Two new builtins sizeof(System.ValueType) and sizeof(System.Array ) are added.

        Cedric Vivier made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        Cedric Vivier made changes -
        Description Testcase:
        {code}
        bytes = array(byte, 128)
        fixed pointer as int = bytes:
                for i in range(len(bytes) / sizeof(pointer)):
        pointer = 0xFFFFFFFF
        pointer++

        assert bytes[0] == 255
        assert bytes[128] == 255
        {code}


        `fixed' is implemented as a macro that creates a new pinned local-scope variable. Ld*a opcodes are then used in EmitAssembly when such a variable is manipulated.

        Syntax for `fixed' is :
        {code}
        fixed <pointer> as <type> = <source>

        pointer = name of the pointer
        type = type of the pointer, no need to specify type* as in C# (anyways we already use T* for enumerable ;) )
        source = any value type or array of value types
        {code}

        Usage of that macro will be allowed when "-unsafe" flag as been passed to the compiler (CompilerParameters.Unsafe == true), otherwise an error is reported.

        Two new builtins sizeof(System.ValueType) and sizeof(System.Array ) are added.

        Testcase:
        {code}
        bytes = array(byte, 128)
        fixed pointer as int = bytes:
                for i in range(len(bytes) / sizeof(pointer)):
        pointer = 0xFFFFFFFF
        pointer++

        assert bytes[0] == 255
        assert bytes[128] == 255
        {code}


        `fixed' is implemented as a macro that creates a new pinned local-scope variable. (Ld|St)*a opcodes are then used in EmitAssembly when such a variable is manipulated.

        Syntax for `fixed' is :
        {code}
        fixed <pointer> as <type> = <source>

        pointer = name of the pointer
        type = type of the pointer, no need to specify type* as in C# (anyways we already use T* for enumerable ;) )
        source = any value type or array of value types
        {code}

        Usage of that macro will be allowed when "-unsafe" flag as been passed to the compiler (CompilerParameters.Unsafe == true), otherwise an error is reported.

        Two new builtins sizeof(System.ValueType) and sizeof(System.Array ) are added.

        Cedric Vivier made changes -
        Description Testcase:
        {code}
        bytes = array(byte, 128)
        fixed pointer as int = bytes:
                for i in range(len(bytes) / sizeof(pointer)):
        pointer = 0xFFFFFFFF
        pointer++

        assert bytes[0] == 255
        assert bytes[128] == 255
        {code}


        `fixed' is implemented as a macro that creates a new pinned local-scope variable. (Ld|St)*a opcodes are then used in EmitAssembly when such a variable is manipulated.

        Syntax for `fixed' is :
        {code}
        fixed <pointer> as <type> = <source>

        pointer = name of the pointer
        type = type of the pointer, no need to specify type* as in C# (anyways we already use T* for enumerable ;) )
        source = any value type or array of value types
        {code}

        Usage of that macro will be allowed when "-unsafe" flag as been passed to the compiler (CompilerParameters.Unsafe == true), otherwise an error is reported.

        Two new builtins sizeof(System.ValueType) and sizeof(System.Array ) are added.

        Testcase:
        {code}
        bytes = array(byte, 128)
        fixed pointer as int = bytes:
                for i in range(len(bytes) / sizeof(pointer)):
        pointer = 0xFFFFFFFF
        pointer++

        assert bytes[0] == 255
        assert bytes[128] == 255
        {code}


        `fixed' is implemented as a macro that creates a new pinned local-scope variable. (Ld|St)*a opcodes are then used in EmitAssembly when such a variable is manipulated.

        Syntax for `fixed' is :
        {code}
        fixed <pointer> as <type> = <source>

        pointer = name of the pointer
        type = type of the pointer, no need to specify type* as in C# (anyways we already use T* for enumerable ;) )
        source = any value type or array of value types
        {code}

        Usage of that macro is allowed when "-unsafe" flag as been passed to the compiler (CompilerParameters.Unsafe == true), otherwise an error is reported.

        Two new builtins sizeof(System.ValueType) and sizeof(System.Array ) are added.
        Cedric Vivier made changes -
        Description Testcase:
        {code}
        bytes = array(byte, 128)
        fixed pointer as int = bytes:
                for i in range(len(bytes) / sizeof(pointer)):
        pointer = 0xFFFFFFFF
        pointer++

        assert bytes[0] == 255
        assert bytes[128] == 255
        {code}


        `fixed' is implemented as a macro that creates a new pinned local-scope variable. (Ld|St)*a opcodes are then used in EmitAssembly when such a variable is manipulated.

        Syntax for `fixed' is :
        {code}
        fixed <pointer> as <type> = <source>

        pointer = name of the pointer
        type = type of the pointer, no need to specify type* as in C# (anyways we already use T* for enumerable ;) )
        source = any value type or array of value types
        {code}

        Usage of that macro is allowed when "-unsafe" flag as been passed to the compiler (CompilerParameters.Unsafe == true), otherwise an error is reported.

        Two new builtins sizeof(System.ValueType) and sizeof(System.Array ) are added.
        Testcase:
        {code}
        bytes = array(byte, 128)
        fixed pointer as int = bytes:
                for i in range(len(bytes) / sizeof(pointer)):
        *pointer = 0xFFFFFFFF
        pointer++

        assert bytes[0] == 255
        assert bytes[128] == 255
        {code}


        `fixed' is implemented as a macro that creates a new pinned local-scope variable. (Ld|St)*a opcodes are then used in EmitAssembly when such a variable is manipulated.

        Syntax for `fixed' is :
        {code}
        fixed <pointer> as <type> = <source>

        pointer = name of the pointer
        type = type of the pointer, no need to specify type* as in C# (anyways we already use T* for enumerable ;) )
        source = any value type or array of value types
        {code}

        Usage of that macro is allowed when "-unsafe" flag as been passed to the compiler (CompilerParameters.Unsafe == true), otherwise an error is reported.

        Two new builtins sizeof(System.ValueType) and sizeof(System.Array ) are added.
        Cedric Vivier made changes -
        Summary Fixed statement for pointer manipulation (unsafe code) BOO-1202: unsafe code support (pointer manipulation within `unsafe' block)
        Description Testcase:
        {code}
        bytes = array(byte, 128)
        fixed pointer as int = bytes:
                for i in range(len(bytes) / sizeof(pointer)):
        *pointer = 0xFFFFFFFF
        pointer++

        assert bytes[0] == 255
        assert bytes[128] == 255
        {code}


        `fixed' is implemented as a macro that creates a new pinned local-scope variable. (Ld|St)*a opcodes are then used in EmitAssembly when such a variable is manipulated.

        Syntax for `fixed' is :
        {code}
        fixed <pointer> as <type> = <source>

        pointer = name of the pointer
        type = type of the pointer, no need to specify type* as in C# (anyways we already use T* for enumerable ;) )
        source = any value type or array of value types
        {code}

        Usage of that macro is allowed when "-unsafe" flag as been passed to the compiler (CompilerParameters.Unsafe == true), otherwise an error is reported.

        Two new builtins sizeof(System.ValueType) and sizeof(System.Array ) are added.
        Usage:
        {code}
        unsafe [<ptrName> as <ptrType> = <data>]+
        {code}
        `unsafe' blocks are only allowed when "-unsafe" flag as been passed to the compiler (CompilerParameters.Unsafe == true), otherwise an error is reported.
        It declares pointer(s) to one or more value type references (<data>).
        In the context of an unsafe block, an explode operator on a declared pointer is replaced with the indirection operator.

        sizeof built-in meta-method is introduced, it accepts both type references (as in C#) and also variable references.


        Example:
        {code}
        src = array[of byte](8)
        src[3] = 1
        dst = array[of byte](8)
        dst[6] = 1

        #replace an uint at a time from src to dst only if src is not zero
        unsafe psrc as uint = src, pdst as uint = dst:
        for i in range(len(src) / sizeof(psrc)):
        *pdst = *psrc unless *psrc == 0
        psrc++
        pdst++

        assert dst[3] == 1 #this has not been replaced since dst[0:4] is 0
        assert dst[6] == 1 #this has been copied
        {code}
        Cedric Vivier made changes -
        Description Usage:
        {code}
        unsafe [<ptrName> as <ptrType> = <data>]+
        {code}
        `unsafe' blocks are only allowed when "-unsafe" flag as been passed to the compiler (CompilerParameters.Unsafe == true), otherwise an error is reported.
        It declares pointer(s) to one or more value type references (<data>).
        In the context of an unsafe block, an explode operator on a declared pointer is replaced with the indirection operator.

        sizeof built-in meta-method is introduced, it accepts both type references (as in C#) and also variable references.


        Example:
        {code}
        src = array[of byte](8)
        src[3] = 1
        dst = array[of byte](8)
        dst[6] = 1

        #replace an uint at a time from src to dst only if src is not zero
        unsafe psrc as uint = src, pdst as uint = dst:
        for i in range(len(src) / sizeof(psrc)):
        *pdst = *psrc unless *psrc == 0
        psrc++
        pdst++

        assert dst[3] == 1 #this has not been replaced since dst[0:4] is 0
        assert dst[6] == 1 #this has been copied
        {code}
        Usage:
        {code}
        unsafe [<ptrName> as <ptrType> = <data>]+
        {code}
        `unsafe' blocks are only allowed when "-unsafe" flag as been passed to the compiler (CompilerParameters.Unsafe == true), otherwise an error is reported.
        It declares pointer(s) to one or more value type references (<data>).
        In the context of an unsafe block, an explode operator on a declared pointer is replaced with the indirection operator.

        sizeof built-in meta-method is introduced, it accepts both type references (as in C#) and also variable references.


        Example:
        {code}
        src = array[of byte](8)
        src[3] = 1
        dst = array[of byte](8)
        dst[6] = 1

        #replace an uint at a time from src to dst only if src is not zero
        unsafe psrc as uint = src, pdst as uint = dst:
        for i in range(len(src) / sizeof(psrc)):
        *pdst = *psrc unless *psrc == 0
        psrc++
        pdst++

        assert dst[3] == 1 #this has been copied from src
        assert dst[6] == 1 #this has not been replaced since src[4:8] is 0
        {code}
        Cedric Vivier made changes -
        Description Usage:
        {code}
        unsafe [<ptrName> as <ptrType> = <data>]+
        {code}
        `unsafe' blocks are only allowed when "-unsafe" flag as been passed to the compiler (CompilerParameters.Unsafe == true), otherwise an error is reported.
        It declares pointer(s) to one or more value type references (<data>).
        In the context of an unsafe block, an explode operator on a declared pointer is replaced with the indirection operator.

        sizeof built-in meta-method is introduced, it accepts both type references (as in C#) and also variable references.


        Example:
        {code}
        src = array[of byte](8)
        src[3] = 1
        dst = array[of byte](8)
        dst[6] = 1

        #replace an uint at a time from src to dst only if src is not zero
        unsafe psrc as uint = src, pdst as uint = dst:
        for i in range(len(src) / sizeof(psrc)):
        *pdst = *psrc unless *psrc == 0
        psrc++
        pdst++

        assert dst[3] == 1 #this has been copied from src
        assert dst[6] == 1 #this has not been replaced since src[4:8] is 0
        {code}
        Usage:
        {code}
        unsafe [<ptrName> as <ptrType> = <data>]+:
            <body>
        {code}
        unsafe blocks are only allowed when "-unsafe" flag as been passed to the compiler (CompilerParameters.Unsafe == true), otherwise an error is reported.
        It declares pointer(s) to one or more value type references (<data>).
        In the context of an unsafe block, an explode operator on a declared pointer is replaced with the indirection operator.

        sizeof built-in meta-method is introduced, it accepts both type references (as in C#) and also variable references.


        Example:
        {code}
        src = array[of byte](8)
        src[3] = 1
        dst = array[of byte](8)
        dst[6] = 1

        #replace an uint at a time from src to dst only if src is not zero
        unsafe psrc as uint = src, pdst as uint = dst:
        for i in range(len(src) / sizeof(psrc)):
        *pdst = *psrc unless *psrc == 0
        psrc++
        pdst++

        assert dst[3] == 1 #this has been copied from src
        assert dst[6] == 1 #this has not been replaced since src[4:8] is 0
        {code}
        Cedric Vivier made changes -
        Summary BOO-1202: unsafe code support (pointer manipulation within `unsafe' block) Unsafe code support (pointer manipulation within `unsafe' block)
        Hide
        Cedric Vivier added a comment -

        Landed in rev. 3309

        Show
        Cedric Vivier added a comment - Landed in rev. 3309
        Cedric Vivier made changes -
        Status In Progress [ 3 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]

          People

          • Assignee:
            Cedric Vivier
            Reporter:
            Cedric Vivier
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: