Skip to content

with get c.libcurl: generated facade presents 15/152 functions; the easy, slist and mime APIs all stay raw #3111

Done

Description

@ehartford

Summary

with get c.libcurl (8.23.0, with v0.16.0.8, darwin-aarch64) writes a facade that presents 15 of 152 public functions safely. None of the API an HTTP client needs is among them: curl_easy_*, curl_slist_*, curl_mime_*. A project that just wants to make HTTP requests has to write the libcurl facade itself, which §16.2b.15 / D121 say a user never does for a with get package.

The generated .with/deps/c/libcurl/8.23.0/facade.w contains only CurlURL (curl_url/curl_url_dup/curl_url_cleanup) and six lends (curl_strequal, checkday, …).

Repro

with init . && with get c.libcurl
cat .with/deps/c/libcurl/8.23.0/facade.w
grep -E "curl_easy_|curl_slist|curl_mime" .with/deps/c/libcurl/8.23.0/facade-report.txt

What the report says (excerpt)

facade libcurl: 152 functions, 15 presented safely, 137 raw; 3956 internal (no prototype declares them)
curl_easy_init: raw: returns *mut c_void, a pointer to no record
curl_easy_setopt: raw: retains param 0 (passed to Curl_eapi_enter at param 1, passed to Curl_ssl_scache_is_locked_by_current_thread at param 0, passed to cf_ssl_scache_get at param 0, passed to Curl_failf at param 0, passed to trc_write at param 0, stored); its lifetime contract is not proven
curl_easy_perform / curl_easy_cleanup / curl_easy_getinfo / curl_easy_reset / curl_easy_duphandle: (same "retains param 0" chain)
curl_slist_append: raw: retains param 0 (passed to Curl_slist_append_nodup at param 0, passed to slist_get_last at param 0, stored in a global); its lifetime contract is not proven
curl_slist_free_all: raw: retains param 0 (stored in a global); its lifetime contract is not proven
curl_mime: destroyed but never produced here; no resource
curl_mime_init: raw: retains param 0 (passed to Curl_rand_alnum ... passed to random, which no unit defines); its lifetime contract is not proven
curl_mime_free: destroyer, param 0 (proof: frees it)
curl_mime_addpart: raw: retains param 0 (stored in a field); its lifetime contract is not proven
curl_mime_name / _filename / _type: raw: parameter of unmodeled pointer type *mut curl_mimepart
curl_mime_data: raw: retains param 0 (passed to cleanup_part_content at param 0, stored); its lifetime contract is not proven
curl_easy_strerror: raw: returns *const c_char, a pointer to no record
curl_version_info: raw: returns *mut curl_version_info_data unproven: returns global state

Observations:

  1. CURL is typedef void CURL. So curl_easy_init returns *mut c_void and is rejected as "a pointer to no record". The whole easy API hangs off a void * handle, so this one refusal takes all of it out.
  2. The "retains param 0" proof over-approximates. The handle passing through Curl_eapi_enter / Curl_failf / trc_write / the SSL session cache is the library storing its own handle in its own state. It isn't the caller's object being retained past the handle's lifetime. curl_easy_cleanup in particular is reported as retaining the handle it destroys.
  3. curl_slist_free_all "retains param 0 (stored in a global)" contradicts it being the list's destroyer. Likewise curl_slist_append is the list's producer (NULL in creates a list) and returns the head.
  4. curl_mime is "destroyed but never produced" even though curl_mime_init produces it; the producer was refused for the Curl_rand_alnum → random chain on the easy parameter (which may be NULL since 7.87.0).
  5. curl_easy_strerror / curl_version return static text but come out raw ("a pointer to no record").

The registry has no c/libcurl/facts.w (only libxml2, zlib), so nothing backstops the proof.

Expected

At least the surface lib/facades/libcurl.w hand-models, presented safely by with get (proof or registry facts):

  • resource Easy (init / cleanup / abandon reset), setopt variadic cases, perform, strerror
  • curl_slist as a resource with append, plus CURLOPT_HTTPHEADER retaining it
  • curl_mime / parts with CURLOPT_MIMEPOST retaining it
  • curl_easy_getinfo for CURLINFO_RESPONSE_CODE and friends

Facade-grammar gaps hit while writing the project override

Writing that surface by hand in a project c facade libcurl: block, the compiler refuses these. A registry facts file would hit the same walls, so they are probably needed too (separate issues if you prefer):

  1. Variadic out-pointer cases. case CURLINFO_RESPONSE_CODE: &mut c_long → "a case states an integer C type ('c_long', 'curl_off_t', an enum) or 'str'". curl_easy_getinfo has no safe form.
  2. A retained pointer case that is a resource. case CURLOPT_HTTPHEADER: &HeaderList retains by param 0 until curl_easy_reset → "a retained pointer case's type is caller-managed storage". The same applies to CURLOPT_MIMEPOST: &Mime. A list/mime resource borrowed by the easy handle for the transfer is the D194 retention shape with a resource instead of a buffer.
  3. A producer whose resource parameter is NULL on creation. fn curl_slist_append / rename new / param list fixed null → "param 0 … receives a modeled resource; a resource is passed by the value that owns it, never fixed". curl_slist_append(NULL, s) creates; curl_slist_append(list, s) appends and returns the same head (or NULL, list untouched).
  4. curl_mime_init(easy) is presented on Easy and collides with Easy.new ("function 'Easy.new' is already defined") even with rename new on the mime producer; param easy fixed null hits gap 3.
  5. resource Part wraps *mut curl_mimepart with no producer (parts are owned by the mime, from curl_mime_addpart) → returns borrow Part from param 0 generates BorrowedPart[Mime] that then fails as "unknown type: BorrowedPart".
  6. A second callback pair on the same resource. With both case CURLOPT_WRITEFUNCTION: … userdata param CURLOPT_WRITEDATA retains by param 0 and case CURLOPT_HEADERFUNCTION: callback param 2 as curl_write_callback userdata param CURLOPT_HEADERDATA retains by param 0, the HEADERFUNCTION setter call fails with "cannot infer generic method type parameter 'U'", while the WRITEFUNCTION one compiles.

Workaround in use: the facade models Easy + scalar/string options + POSTFIELDS. curl_slist, curl_mime and getinfo are raw calls inside one safe With function that owns the list/mime as locals declared before the handle.

Activity

  1. added
    bug
    on Nov 9, 2026
  2. ehartford commented on Nov 9, 2026

    @ehartford
    ContributorAuthor

    Split for tracking under the epic #3115: grammar gaps 1–4 are #3119–#3122 (5 and 6 were already #3114 and #3113); proof observations 1–5 are #3123–#3127; the registry facts for libcurl are #3143. This issue stays as the libcurl umbrella.

  3. added
    blocked
    on Nov 24, 2026
  4. ehartford commented on Nov 24, 2026

    @ehartford
    ContributorAuthor

    Labelled blocked: this is the libcurl umbrella, and each remaining piece waits on a decision recorded on its own issue: #3119 (case K: fills T words), #3120 (a retained case naming a resource), #3121 (a failed production that hands the input back), #3122 (the §16.2b.11 words and the version floor), #3124 (a library storing its own handle in its own state). The parts that needed no ruling are merged (#3588, #3589, #3590). It comes back when those are ruled.

  5. removed
    blocked
    on Nov 27, 2026
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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions