Skip to content

Modeled C D66: variadic cases that pair a callback with its userdata option (case CURLOPT_WRITEFUNCTION: callback … userdata param CURLOPT_WRITEDATA) or retain the pointed-to data (case CURLOPT_POSTFIELDS: … retains by param 0) are refused, not modeled #1652

Closed

Description

@ehartford

Spec §16.2b.5 "Discriminated variadic contracts" (D66) lists three case contracts beyond a scalar and a copied str:

  • a callback with its userdata pairing — case CURLOPT_WRITEFUNCTION: callback param 2 userdata param CURLOPT_WRITEDATA
  • a retained pointer where the docs say "not copied" — a str/pointer case stating retains … by param 0 (curl's CURLOPT_POSTFIELDS)

The compiler (PR for D66: variadic param N selected by param P: with scalar and str cases) refuses both spellings in the parser with a diagnostic naming this issue, and lib/facades/libcurl.w leaves CURLOPT_WRITEFUNCTION/CURLOPT_WRITEDATA/CURLOPT_POSTFIELDS out. Setting them goes through the raw curl_easy_setopt under unsafe.

What is missing, from the facade-language side (analysis while implementing):

  1. The callback case has no type. callback param 2 userdata param CURLOPT_WRITEDATA names the variadic position (2) as the callback and the option that carries its userdata, but the callback's C signature is not in the header for a variadic slot (curl declares it as a separate typedef, curl_write_callback). D51's inference test forbids inferring it: a wrong callback type is unsafety. The case needs the type stated, e.g. case CURLOPT_WRITEFUNCTION: curl_write_callback userdata param CURLOPT_WRITEDATA — a spelling for Eric to bless, since the spec's example has none.
  2. The pairing spans two calls. easy.setopt(CURLOPT_WRITEFUNCTION, cb) and easy.setopt(CURLOPT_WRITEDATA, &data) are two presented calls; the userdata's With type U is fixed by the second and the callback's void * parameter must be typed &U by the first. That is a typed slot on the resource (Easy keeps a U per option pair) rather than a per-call pairing (stage 9's callback param N userdata param M types both in one call). It also needs the retention machinery: the callback and the userdata are kept by the handle until it is destroyed or the option is overwritten (retains … by param 0), and the userdata's borrow must outlive the handle.
  3. The retained case (CURLOPT_POSTFIELDS: "the data pointed to is NOT copied") is the same retention mechanism on a str/pointer case: the presented call must keep the caller's storage alive for the handle's life (§16.3c's retains rule: a str that would coerce to a call-scoped temporary is refused; the caller passes storage it keeps).

Until these land the facade is honest about it: the cases are absent, the raw function stays available under unsafe, and the compiler refuses the spellings loudly rather than rendering a plain value.

Activity

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