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

Unexpected behavior of unsized array defaults

Abierto
#1,959 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
45/100
Tipo de issue
Documentación
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
cpp

Línea de trabajo

Comienza con la sección de la especificación del lenguaje OSL que describe los valores predeterminados de los arrays sin tamaño y, después, compara el comportamiento informado en testshade y oslinfo con el parser de shaders existente en C++ y la prueba unitaria. Se considera terminado cuando la especificación documente claramente el valor predeterminado de longitud uno para {} en arrays sin tamaño y se hayan actualizado las expectativas de prueba relevantes.

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

Descripción

Consider the following shader, in particular the declaration of the unsized array param:

shader test(int param[] = {})
{
    printf("array length %d\n", arraylength(param));
}

When running this in testshade, it prints:

array length 1

I think most people would reasonably expect that the {} in the declaration would produce a default array of length zero for param, so the resulting array with a single entry is surprising.

If a shader writer authored a for loop, for example, that did something for each value of an input array, e.g.:

shader test(int param[] = {})
{
    for (int i=0; i < arraylength(param), i++) {
        doStuff(param[i]);
    }
}

They might be surprised that their shader is executing doStuff() even when nothing is connected to param. In practice, however, we have worked around this behavior by guarding the for loop behind something like isconnected(param).

The peculiar behavior of unsized arrays makes sense, however, when considering that it's impossible to declare a fixed size array of length zero in OSL. Therefore, the best fix for this issue might be little more than adding a disclaimer in the section of the OSL language spec describing unsized array defaults.

As a footnote, we stumbled on this issue because we have a unit test that verifies the default input parameters of a set of C++ shaders and OSL shaders match, in order to prevent code drift. oslinfo always returned defaults of arrays of length one for the OSL shaders with unsized array parameters while our C++ shader parser produced zero-length arrays.

Lenguaje dominante
C++
Estrellas
2.3k
Forks
415
Merge medio
3 d 16 h
PR fusionados (30 d)
10

Preparar el entorno

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 AcademySoftwareFoundation/OpenShadingLanguage

Todos los issues de AcademySoftwareFoundation/OpenShadingLanguage

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.