Skip to content

Facade grammar: a retained pointer case cannot be a resource (CURLOPT_HTTPHEADER: &HeaderList, CURLOPT_MIMEPOST: &Mime kept until the transfer ends) #3120

Done

Description

@ehartford

Part of #3115; gap 2 of #3111.

case CURLOPT_HTTPHEADER: &HeaderList retains by param 0 until curl_easy_reset is refused: "a retained pointer case's type is caller-managed storage". The manual: "libcurl does not copy the list, it needs to be kept around until after the transfer has completed" (and the same for CURLOPT_MIMEPOST).

This is D194's retained-borrow shape (already modeled for CURLOPT_POSTFIELDS: &str) with a resource in place of a buffer: the handle holds a borrow of the caller's HeaderList until reset or cleanup, so the list must outlive the handle (declared before it) and cannot be mutated or dropped while borrowed. Without it, request headers, the most basic HTTP need, go through raw calls.

Done when: a retained case may name a facade resource, with the borrow checked like the &str case; fixture: headers and a multipart body set on an easy handle, a drop of the list before the handle refused.

Activity

  1. ehartford commented on Nov 24, 2026

    @ehartford
    ContributorAuthor

    Brief for Eric: a retained case that names a facade resource

    State (main a784b42). case CURLOPT_HTTPHEADER: &HeaderList retains by param 0 until curl_easy_reset is refused at SemaFacade.with:2750: a retained pointer case accepts &CString, &CStr, and &[u8] / &str with a length option, and nothing else. D194 ruled those as "caller-managed storage" and named C interop and ownership as not delegable, so widening the set is yours. The list itself is now constructible (HeaderList.new(s), #3588), so this is the next thing between a user and request headers.

    The question. When a C handle keeps a pointer to another modeled resource (the header list, the mime body), who holds what?

    Option A, the borrow (the issue's own reading; D194 with a resource in place of a buffer). The case passes the resource's representation and the handle holds a shared borrow of it for D194's window (until the case is set again, an until operation, abandonment or destruction). While it is held, the list cannot be dropped or moved, and cannot be given to an operation that consumes it or that its contract does not mark preserves. No hidden state in the handle.

    Option B, the handle takes it. The case consumes the list, and the generated handle keeps it and frees it when the window ends (as it already keeps boxed callback userdata in retained_ptrs).

    • Cost: a list cannot be shared by two handles, which libcurl allows; and the handle grows a cell per retained resource.

    • What the others do. The Rust curl crate does B: Easy::http_headers(list) takes the List by value and the handle owns it. Go and Python bindings copy into their own structure. Zig binds the raw call.

    • What the spec says. §16.2b.5 says of a variadic case's retained userdata: "The retained userdata is never a copy or an owned cell." D194 applied the same reasoning to a retained pointer case, and §16.2b.9 "Retained borrows" gives the window. Neither sentence mentions a retained resource; extended in the same spirit, they choose A.

    • Mission fit. A states the C fact and adds no state; B is what a user would rather write. The spec sentence and D194's reasoning (no secret owned cell beside the handle) point at A; if Facades present C's call shape: the user must learn "check every setopt against CURLE_OK", "declare the sink before the handle", "build the handle in a helper" from compile errors #3128's declare-order cost is to be removed, that is a separate presentation on top of A, not a different ownership.

    • Prediction: A, 65%.

    If A: the words are one clause in §16.2b.5 adding "a borrow of a facade resource" to the retained forms, with the rule that an operation not marked preserves on that resource is refused while the borrow is live. The fixture is the one in this issue: headers and a multipart body set on a handle, and a drop of the list before the handle refused.

    Labelling human attn needed.

  2. ehartford commented on Nov 25, 2026

    @ehartford
    ContributorAuthor

    Ruled by Eric, 2026-11-25 (answers to briefs.md).

    A: the borrow. The handle holds a shared borrow of the retained resource for D194's window; no hidden state in the handle (B would forbid sharing a list between handles, which libcurl allows). I bring the exact §16.2b.5 sentence before landing it. Label removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions