Repository navigation
tsbindgen: nullable pointers, and C++ structs in namespaces as tuples - #563
Merged
Merged
Conversation
- A pointer parameter or struct field is `T | null` (Opaque, a Reference, a @cpp class, a string, a function pointer): C lets it be null, and tslang lowers the union to the same pointer. A C++ reference and a result stay non-null. - A C++ struct in a namespace or a class (nvrhi::Color, nvrhi::TextureSubresourceSet) is declared under its own name, keyed by its qualified name; --filter matches either. Of two of one name, the next is named with its namespaces, less --namespace (`rt_Desc`), with a warning. - A C++ struct with constructors, methods or member initializers is a tuple when its fields are where a tuple's are; a polymorphic or derived one, or one with a field tsbindgen can't spell (std::string, a container), is `type X = Opaque;` with the reason. - Templates, their specializations (also one only named) and the classes inside them, local classes and lambdas still have no declaration: a pointer to one stays a plain Opaque. Tests: NamespacedStructTest.cpp; the unit tests' pointer expectations; test-bindgen-cpp passes a namespaced struct by reference and a null pointer to a virtual method of real C++. Checked on NVRHI (MSVC, Android x86_64 and aarch64), the whole MSVC STL and libc++ (--filter 'std::*') and windows.h + d3d12.h: no crash, and the output compiles. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes two tsbindgen gaps found while generating NVRHI's bindings in native_ts_graphics.
Nullable pointers
A pointer parameter or struct field is now
T | null—Opaque,Reference<T>, a@cppclass,string, a function pointer. C lets these be null (an optional out-parameter,queryFeatureSupport(f, null, 0), a desc's unused buffer). tslang lowersT | nullto the same pointer (checked: call arguments and tuple sizes are unchanged). A C++ reference stays non-null, and so does a result, so call sites aren't forced into null checks.C++ structs in namespaces
nvrhi::Color,nvrhi::TextureSubresourceSet) is declared under its own name, keyed by its qualified name;--filtermatches either.std::string, a container, an array, a bitfield), istype X = Opaque;with the reason in a// skipped:line.--namespace(rt_Desc), with a warning.TSK_Undeclared), classes inside them, local classes and lambdas still get no declaration: a pointer to one stays a plainOpaque /* C++ type */.Visible change: a field-less class in the main file now prints
// skipped: Widget — empty struct/type Widget = Opaque;where it used to be silent (README example updated).Tests
unittests/TsClangImporter/NamespacedStructTest.cpp; pointer expectations in the existing unit tests updated — 67/67 pass.test-bindgen-cpp: the fixture gainsfx::Extent(a namespaced struct with a constructor) andShape::fits(const Extent &, const Extent *), called from TS with a reference, a pointer andnullagainst real compiled C++ (exe and JIT).ctest -R "test-bindgen|cppvtable|cpp_slot": 46/46 on Windows.--filter 'std::*',windows.h+d3d12.h— no crash, and the output compiles with tslang.Downstream
native_ts_graphics#52 (merged) already accepts this output in
tools/gen_nvrhi_classes.py; its NVRHI tests pass with this tsbindgen on Windows and Android.🤖 Generated with Claude Code