Skip to content

Apple Event descriptor identities, byte order and guest handler delivery - #46

Merged
colemancda merged 7 commits into
masterfrom
feature/apple-event-descriptors
Dec 1, 2026
Merged

colemancda merged 7 commits into
masterfrom
feature/apple-event-descriptors

Conversation

@colemancda

Copy link
Copy Markdown
Member

Starts section 4 of the BlueBox requirements: Apple Event descriptors and handler invocation that a Classic guest can use.

Descriptor byte order

Descriptor.fromBigEndian() / toBigEndian() (and converted(from:to:layouts:)) reverse the scalar fields of known types through lists, records, parameters and attributes, so a host needs no rule for individual events or attributes.

  • Numbers, codes, PSNs, QDpt/qdrt/cRGB, UTF-16 text, and the numeric headers of FSSpecs and alias handles are converted.
  • Text, file URLs, bundle IDs and unknown types stay as bytes; data of the wrong length is kept as it is.
  • Hosts can pass extra ScalarLayouts.

Descriptor identities

DescriptorTable holds descriptors behind a DescriptorID (slot and generation).

  • Disposing a descriptor bumps its slot's generation, so a stale identity (for example a disposed and reused guest Handle) gives errAENotAEDesc instead of reaching the new descriptor.
  • Descriptors are owned or borrowed. A handler's event and reply are lent for the call; AEDisposeDesc of a borrowed descriptor reports noErr and leaves it, and only the lender ends the loan.
  • removeAll() invalidates every identity, for cleanup at quit.

Guest handler delivery

  • Entry(eventClass:eventID:isSystem:guestProcedure:referenceConstant:) installs a guest handler as an opaque UPP and refcon.
  • beginDelivery lends the event and reply from a table and returns either .invoke(Invocation) (procedure, refcon, borrowed IDs, depth) or .finished(Outcome). complete(_:result:) takes the guest's signed OSErr.
  • Host handlers in the chain run directly.
  • errAEEventNotHandled from an application handler passes the event to the system table. A failing result goes in the reply as keyErrorNumber unless the handler set one.
  • Deliveries nest and finish innermost first; completing an outer one early is paramErr. abandon ends a delivery and every one inside it, for guest faults and instruction limits.

Behaviour changes

  • Handlers are looked up in the application table (exact match, then wildcards) before the system table. Previously a system exact match won over an application wildcard. This order is Apple's documented one and is not yet checked on Mac OS 9.
  • Synchronous dispatch and sendCoreEvent consider only host handlers; guest handlers run through beginDelivery.

Not in this PR

The launch-event lifecycle through EventAvail / GetNextEvent / WaitNextEvent, and checking the other special event masks.

Tests

New suites: DescriptorByteOrderTests, DescriptorTableTests and AppleEventDeliveryTests. The full suite passes.

@colemancda
colemancda merged commit 0311424 into master Dec 1, 2026
3 checks passed
@colemancda
colemancda deleted the feature/apple-event-descriptors branch December 1, 2026 04:32
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