Skip to content

Carbon: move the Resource Manager to Swift over Graphite - #463

Merged
colemancda merged 5 commits into
masterfrom
feature/carbon-resources
Nov 26, 2026
Merged

colemancda merged 5 commits into
masterfrom
feature/carbon-resources

Conversation

@colemancda

Copy link
Copy Markdown
Member

Phase 2 of Documentation/Plans/graphite.md, second of three PRs, against master: resources.c moves to Swift over GraphiteResources (PureSwift/Graphite#13).

Carbon

  • Sources/PerryCarbon/Resources.swift exports the Resource Manager's calls over Graphite's maps, files and chain.
  • Resource forks go through the File Manager (Carbon: move the File Manager to Swift over Graphite #462): ._name, name.rsrc, and data-fork files with FSOpenResourceFile. A file's reference number is its fork's.
  • Handles keep their identity. A resource is a CoreServices Memory Manager handle, the same one each time a program asks while its file is open. ReleaseResource disposes of it, DetachResource gives it to the program, and CloseResFile disposes of the file's handles.
  • SetResLoad(false) gives empty handles that LoadResource fills.
  • Bytes are returned as stored, big-endian, as resources.c returned them to i386 programs; no flippers.
  • Maps are checked: every offset is validated, and a damaged fork is mapReadErr instead of a read past its end.
  • ResError is kept per call, and a recursive lock guards the state, since a program's calls can come from any thread.

New exports (566 → 588)

  • Writing: AddResource, ChangedResource, WriteResource, RemoveResource, UpdateResFile, SetResInfo, SetResAttrs and GetResAttrs. Changed handles are written by WriteResource, UpdateResFile or CloseResFile, as the Resource Manager did.
  • Creating files: FSCreateResFile and FSpCreateResFile, which also write the type and creator.
  • Indexed lookups and IDs: CountTypes, Count1Types, GetIndType, Get1IndType, GetIndResource, Get1IndResource, UniqueID and Unique1ID.
  • Sizes and strings: GetResourceSizeOnDisk, GetMaxResourceSize, GetIndString (STR#) and GetString (STR ).
  • resources.c stays for the C build, fenced out of SwiftPM with PERRY_CARBON_SWIFT. It gets C versions of these names so both builds export the same list: the indexed and string calls work over its parser, and the writing calls report wrPermErr.

Checks

  • Built natively on Debian arm64 with Swift 6.4.2, with no warnings in the new Swift or C.
  • Scripts/check-carbon-exports.sh passes on the SwiftPM library and on the C-only one: 588 exports, as listed.
  • Not run: the i386 and ppc builds (perry-dev image) and the Carbon fixtures; CI covers those.

@colemancda
colemancda merged commit 387030e into master Nov 26, 2026
6 checks passed
@colemancda
colemancda deleted the feature/carbon-resources branch November 26, 2026 05:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant