Unexpected behavior of unsized array defaults
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
- Área
- compilers, documentation
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
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de AcademySoftwareFoundation/OpenShadingLanguage
-
build / testing / port / CI
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
AcademySoftwareFoundation/OpenShadingLanguage#2148 · 5 comentarios ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
AcademySoftwareFoundation/OpenShadingLanguage#2109 · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
Tracesets handling proposalAbierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
AcademySoftwareFoundation/OpenShadingLanguage#2146 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
AcademySoftwareFoundation/OpenShadingLanguage#2135 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 52/100
AcademySoftwareFoundation/OpenShadingLanguage#2132 · 6 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de AcademySoftwareFoundation/OpenShadingLanguage
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
hyprwm/aquamarine#426 ·
Los mantenedores suelen responder en 1 día
-
Winget hash mismatch for 5.0.3.0Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
amnezia-vpn/amnezia-client#3222 ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
valkey-io/valkey-search#1465 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
KhronosGroup/Vulkan-Tutorial#524 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
microsoft/onnxruntime-genai#2633 ·
Los mantenedores suelen responder en 1 día