Name public API structs so they can be forward declared #1627

issue achow101 openend this issue on October 28, 2024
  1. achow101 commented at 7:36 pm on October 28, 2024: member

    Currently all of the structs in the public API are only typedef’d, rather than both named and typedef’d. As such, the structs cannot be forward declared and instead using the struct name (typedef) in a header requires including the library headers. This can be problematic for projects which want to reduce the inclusion tree as much as possible.


    For some context behind this request, in my MuSig2 PR to Bitcoin Core, since the secp256k1_musig_secnonce cannot be copied or serialized, I have to pass around a pointer to the object in various functions, so many headers need to include secp256k1_musig.h just for the struct’s declaration. Including secp256k1_musig.h in those headers result in needing to directly link libsecp256k1 in several of build targets that did not previously require it. This issue seems like it can be avoided by forward declaring that (and other) struct, but in order to do so, it needs to be named in the libsecp headers.

    My current workaround is to pass void * and then cast them as necessary but I don’t really like doing that.

  2. achow101 added the label feature on Oct 28, 2024
  3. sipa commented at 5:14 pm on October 29, 2024: contributor
    Concept ACK, I guess. It shouldn’t hurt us to turn every typedef struct { ... } secp256k1_foobar into typedef struct secp256k1_foobar_struct { ... } secp256k1_foobar?
  4. achow101 commented at 5:38 pm on October 29, 2024: member

    turn every typedef struct { ... } secp256k1_foobar into typedef struct secp256k1_foobar_struct { ... } secp256k1_foobar?

    I’d prefer to have both names be the same, i.e. typedef struct secp256k1_foobar {...} secp256k1_foobar.

  5. jonasnick added this to the milestone 0.6.0 on Oct 30, 2024
  6. sipa commented at 5:26 pm on October 31, 2024: contributor
    @achow101 Want to open a PR?
  7. achow101 commented at 5:52 pm on October 31, 2024: member
    Sure
  8. achow101 commented at 5:57 pm on October 31, 2024: member
  9. real-or-random closed this on Nov 1, 2024

  10. hebasto referenced this in commit a38d879a1a on Nov 1, 2024


achow101 sipa

Labels
feature

Milestone
0.6.0


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin-core/secp256k1. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-11-21 08:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me