Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

`stdLambda` `stack` issue

Abierto
#68 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
25/100
Tipo de issue
Error
Claridad
Necesita aclaración
Estado de actividad
Estancado
Área
tooling

Línea de trabajo

Start by reading the evaluate path for iType.oAccess and the pushV and CopyVariant entry points shown in the issue. Reproduce the object-valued stack access case from the included minimal examples, then establish a replacement approach that avoids the reported array-locking error and preserves existing stack behavior.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

enhancement lib-stdLambda

Currently in evaluate:

            Case iType.oAccess
                Select Case op.subType
                    Case ISubType.argument
                        Dim iArgIndex As Long: iArgIndex = val(mid(op.value, 2)) + LBound(vLastArgs) - 1
                        If iArgIndex <= UBound(vLastArgs) Then
                            Call pushV(stack, stackPtr, vLastArgs(iArgIndex))
                        Else
                            Call Throw("Argument " & iArgIndex & " not supplied to Lambda.")
                        End If
                    Case Else
                        Call pushV(stack, stackPtr, stack(stackPtr - op.value))

Call pushV(stack, stackPtr, stack(stackPtr - op.value)) can sometimes error when the variable at stack(stackPtr - op.value) is an object. See explanation for details. As a temporary work around we can do the following:

 '@FIX bug where if stack(stackPtr-op.value) was an object, then array will become locked. Array locking occurs by compiler to try to protect
'instances when re-allocation would move the array, and thus corrupt the pointers. By copying the variant we redivert the compiler's efforts,
'but we might actually open ourselves to errors...
Dim vAccessVar: Call CopyVariant(vAccessVar, stack(stackPtr - op.value))
Call pushV(stack, stackPtr, vAccessVar)

This may still break so we need to consider a better solution. Our suggestion is to use a Collection (i.e. linked list) instead of a dynamic array. This should have fewer issues but might sacrifice on some performance.


Explanation:

Minimal examples where error occurs:

Sub Example()
    'Initialize the array with 3 elements
    Dim myArray() As string
    ReDim myArray(0)
    Set myArray(0) = "yop"
    Call Push(myArray, myArray(0))
End Sub

Sub Push(ByRef myArray() As string, ByRef element As string)
    'Lock the array to prevent deallocation of memory for the reference parameter
    ReDim Preserve myArray(UBound(myArray) + 1)
    If IsObject(element) Then
      Set myArray(UBound(myArray)) = element
    Else
      myArray(UBound(myArray)) = element
    End If
End Sub

The issue is that element, in this case is a reference to an element within myArray... The solution to above is change element to ByVal:

Sub Push(ByRef myArray() As string, ByVal element As string)

When extended to the variant case however:

Sub Push(ByRef myArray() As variant, ByVal element As variant)

Objects are also pointers... so

Sub Example()
    'Initialize the array with 3 elements
    Dim myArray() As Variant
    ReDim myArray(0)
    Set myArray(0) = CreateObject("scripting.dictionary")
    Call Push(myArray, myArray(0))
End Sub

Sub Push(ByRef myArray() As Variant, ByVal element As Variant)
    'Lock the array to prevent deallocation of memory for the reference parameter
    ReDim Preserve myArray(UBound(myArray) + 1)
    If IsObject(element) Then
      Set myArray(UBound(myArray)) = element
    Else
      myArray(UBound(myArray)) = element
    End If
End Sub

Also errors because we have a pointer directly to myArray(0) object. So the real work around is

Sub Example()
    'Initialize the array with 3 elements
    Dim myArray() As Variant
    ReDim myArray(0)
    Set myArray(0) = CreateObject("scripting.dictionary")
    Dim v: CopyVariant(v, myArray(0))
    Call Push(myArray, v)
End Sub
Lenguaje dominante
VBA
Estrellas
412
Forks
70
Merge medio
16 h 10 min
PR fusionados (30 d)
3

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de sancarn/stdVBA

Todos los issues de sancarn/stdVBA

Issues similares

Más issues de DevTools

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.