Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Unexpected behavior of unsized array defaults

オープン
#1,959 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
45/100
issue の種類
ドキュメント
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
cpp

調査の方向性

まず、サイズ指定のない配列のデフォルト値について説明している OSL 言語仕様のセクションを確認し、その後、testshade と oslinfo で報告された動作を、既存の C++ シェーダーパーサーおよび単体テストと比較します。{} をサイズ指定のない配列に使用した場合の長さ 1 のデフォルト値が仕様に明確に記載され、関連するテストの期待値が更新されていれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
C++
スター
2.3k
フォーク
414
平均マージ
2日 14時間
マージ済み PR(30日)
13

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

AcademySoftwareFoundation/OpenShadingLanguage のほかの issue

AcademySoftwareFoundation/OpenShadingLanguage の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。