mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-25 00:55:11 +01:00
Make struct impls private (opaque pointers)
This gives us flexibility to change sizeof(wuffs_foo__bar__struct) across Wuffs versions, while retaining ABI / API compatibility. In particular, this lets us add and remove fields.
This commit is contained in:
1 parent
26a448450e
commit
8b1ffec576
4 files changed
+86
-8
No files matched your search
@@ -336,7 +336,7 @@ func (g *gen) generate() ([]byte, error) {
|
|||||||
if err := g.genHeader(b); err != nil {
|
if err := g.genHeader(b); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
b.writex(wiStart)
|
b.writex(wiStartImpl)
|
||||||
if err := g.genImpl(b); err != nil {
|
if err := g.genImpl(b); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -394,11 +394,17 @@ func (g *gen) genHeader(b *buffer) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
b.writes("// ---------------- Struct Definitions\n\n")
|
b.writes("// ---------------- Struct Definitions\n\n")
|
||||||
|
b.writes("// These structs' fields, and the sizeof them, are private implementation\n")
|
||||||
|
b.writes("// details that aren't guaranteed to be stable across Wuffs versions.\n")
|
||||||
|
b.writes("//\n")
|
||||||
|
b.writes("// See https://en.wikipedia.org/wiki/Opaque_pointer#C\n")
|
||||||
|
b.writex(wiStart)
|
||||||
for _, n := range g.structList {
|
for _, n := range g.structList {
|
||||||
if err := g.writeStruct(b, n); err != nil {
|
if err := g.writeStruct(b, n); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
b.writex(wiEnd)
|
||||||
|
|
||||||
b.writes("\n#ifdef __cplusplus\n} // extern \"C\"\n#endif\n\n")
|
b.writes("\n#ifdef __cplusplus\n} // extern \"C\"\n#endif\n\n")
|
||||||
return nil
|
return nil
|
||||||
@@ -735,8 +741,9 @@ func (g *gen) writeCppMethods(b *buffer, n *a.Struct) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
wiStart = []byte("\n// WUFFS C HEADER ENDS HERE.\n#ifdef WUFFS_IMPLEMENTATION\n\n")
|
wiStartImpl = []byte("\n// WUFFS C HEADER ENDS HERE.\n#ifdef WUFFS_IMPLEMENTATION\n\n")
|
||||||
wiEnd = []byte("\n#endif // WUFFS_IMPLEMENTATION\n\n")
|
wiStart = []byte("\n#ifdef WUFFS_IMPLEMENTATION\n\n")
|
||||||
|
wiEnd = []byte("\n#endif // WUFFS_IMPLEMENTATION\n\n")
|
||||||
|
|
||||||
wigbpStart = []byte("\n#ifndef WUFFS_INCLUDE_GUARD__BASE_PUBLIC\n")
|
wigbpStart = []byte("\n#ifndef WUFFS_INCLUDE_GUARD__BASE_PUBLIC\n")
|
||||||
wigbpEnd = []byte("\n#endif // WUFFS_INCLUDE_GUARD__BASE_PUBLIC\n")
|
wigbpEnd = []byte("\n#endif // WUFFS_INCLUDE_GUARD__BASE_PUBLIC\n")
|
||||||
@@ -770,8 +777,8 @@ func (g *gen) writeUse(b *buffer, n *a.Use) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
trimmed := []byte(nil)
|
trimmed := []byte(nil)
|
||||||
if i := bytes.Index(usee, wiStart); i >= 0 {
|
if i := bytes.Index(usee, wiStartImpl); i >= 0 {
|
||||||
remaining := usee[i+len(wiStart):]
|
remaining := usee[i+len(wiStartImpl):]
|
||||||
if j := bytes.Index(remaining, wiEnd); j >= 0 {
|
if j := bytes.Index(remaining, wiEnd); j >= 0 {
|
||||||
trimmed = append(trimmed, usee[:i]...)
|
trimmed = append(trimmed, usee[:i]...)
|
||||||
trimmed = append(trimmed, '\n')
|
trimmed = append(trimmed, '\n')
|
||||||
|
|||||||
@@ -47,6 +47,7 @@
|
|||||||
- Added `WUFFS_CONFIG__STATIC_FUNCTIONS`.
|
- Added `WUFFS_CONFIG__STATIC_FUNCTIONS`.
|
||||||
- Added some C++ convenience methods.
|
- Added some C++ convenience methods.
|
||||||
- Added some Go and Rust benchmarks.
|
- Added some Go and Rust benchmarks.
|
||||||
|
- Made struct implementations private (opaque pointers).
|
||||||
- Sped up the `mimic_deflate_xxx` benchmarks.
|
- Sped up the `mimic_deflate_xxx` benchmarks.
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ rm -f a.out
|
|||||||
for a C compiler $CC, such as clang or gcc.
|
for a C compiler $CC, such as clang or gcc.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "wuffs/release/c/wuffs-unsupported-snapshot.h"
|
#include "wuffs/release/c/wuffs-unsupported-snapshot.h"
|
||||||
@@ -69,17 +70,23 @@ static const char* decode() {
|
|||||||
wuffs_base__io_writer dst_writer = wuffs_base__io_buffer__writer(&dst);
|
wuffs_base__io_writer dst_writer = wuffs_base__io_buffer__writer(&dst);
|
||||||
wuffs_base__io_reader src_reader = wuffs_base__io_buffer__reader(&src);
|
wuffs_base__io_reader src_reader = wuffs_base__io_buffer__reader(&src);
|
||||||
|
|
||||||
wuffs_deflate__decoder dec = ((wuffs_deflate__decoder){});
|
wuffs_deflate__decoder* dec = calloc(sizeof__wuffs_deflate__decoder(), 1);
|
||||||
|
if (!dec) {
|
||||||
|
return "out of memory";
|
||||||
|
}
|
||||||
wuffs_base__status z = wuffs_deflate__decoder__check_wuffs_version(
|
wuffs_base__status z = wuffs_deflate__decoder__check_wuffs_version(
|
||||||
&dec, sizeof dec, WUFFS_VERSION);
|
dec, sizeof__wuffs_deflate__decoder(), WUFFS_VERSION);
|
||||||
if (z) {
|
if (z) {
|
||||||
|
free(dec);
|
||||||
return z;
|
return z;
|
||||||
}
|
}
|
||||||
z = wuffs_deflate__decoder__decode(&dec, dst_writer, src_reader);
|
z = wuffs_deflate__decoder__decode(dec, dst_writer, src_reader);
|
||||||
if (z) {
|
if (z) {
|
||||||
|
free(dec);
|
||||||
return z;
|
return z;
|
||||||
}
|
}
|
||||||
ignore_return_value(write(1, dst.data.ptr, dst.meta.wi));
|
ignore_return_value(write(1, dst.data.ptr, dst.meta.wi));
|
||||||
|
free(dec);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2226,6 +2226,13 @@ wuffs_adler32__hasher__update(wuffs_adler32__hasher* self,
|
|||||||
|
|
||||||
// ---------------- Struct Definitions
|
// ---------------- Struct Definitions
|
||||||
|
|
||||||
|
// These structs' fields, and the sizeof them, are private implementation
|
||||||
|
// details that aren't guaranteed to be stable across Wuffs versions.
|
||||||
|
//
|
||||||
|
// See https://en.wikipedia.org/wiki/Opaque_pointer#C
|
||||||
|
|
||||||
|
#ifdef WUFFS_IMPLEMENTATION
|
||||||
|
|
||||||
struct wuffs_adler32__hasher__struct {
|
struct wuffs_adler32__hasher__struct {
|
||||||
// Do not access the private_impl's fields directly. There is no API/ABI
|
// Do not access the private_impl's fields directly. There is no API/ABI
|
||||||
// compatibility or safety guarantee if you do so. Instead, use the
|
// compatibility or safety guarantee if you do so. Instead, use the
|
||||||
@@ -2259,6 +2266,8 @@ struct wuffs_adler32__hasher__struct {
|
|||||||
|
|
||||||
}; // struct wuffs_adler32__hasher__struct
|
}; // struct wuffs_adler32__hasher__struct
|
||||||
|
|
||||||
|
#endif // WUFFS_IMPLEMENTATION
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
#endif
|
#endif
|
||||||
@@ -2302,6 +2311,13 @@ wuffs_crc32__ieee_hasher__update(wuffs_crc32__ieee_hasher* self,
|
|||||||
|
|
||||||
// ---------------- Struct Definitions
|
// ---------------- Struct Definitions
|
||||||
|
|
||||||
|
// These structs' fields, and the sizeof them, are private implementation
|
||||||
|
// details that aren't guaranteed to be stable across Wuffs versions.
|
||||||
|
//
|
||||||
|
// See https://en.wikipedia.org/wiki/Opaque_pointer#C
|
||||||
|
|
||||||
|
#ifdef WUFFS_IMPLEMENTATION
|
||||||
|
|
||||||
struct wuffs_crc32__ieee_hasher__struct {
|
struct wuffs_crc32__ieee_hasher__struct {
|
||||||
// Do not access the private_impl's fields directly. There is no API/ABI
|
// Do not access the private_impl's fields directly. There is no API/ABI
|
||||||
// compatibility or safety guarantee if you do so. Instead, use the
|
// compatibility or safety guarantee if you do so. Instead, use the
|
||||||
@@ -2334,6 +2350,8 @@ struct wuffs_crc32__ieee_hasher__struct {
|
|||||||
|
|
||||||
}; // struct wuffs_crc32__ieee_hasher__struct
|
}; // struct wuffs_crc32__ieee_hasher__struct
|
||||||
|
|
||||||
|
#endif // WUFFS_IMPLEMENTATION
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
#endif
|
#endif
|
||||||
@@ -2392,6 +2410,13 @@ wuffs_deflate__decoder__decode(wuffs_deflate__decoder* self,
|
|||||||
|
|
||||||
// ---------------- Struct Definitions
|
// ---------------- Struct Definitions
|
||||||
|
|
||||||
|
// These structs' fields, and the sizeof them, are private implementation
|
||||||
|
// details that aren't guaranteed to be stable across Wuffs versions.
|
||||||
|
//
|
||||||
|
// See https://en.wikipedia.org/wiki/Opaque_pointer#C
|
||||||
|
|
||||||
|
#ifdef WUFFS_IMPLEMENTATION
|
||||||
|
|
||||||
struct wuffs_deflate__decoder__struct {
|
struct wuffs_deflate__decoder__struct {
|
||||||
// Do not access the private_impl's fields directly. There is no API/ABI
|
// Do not access the private_impl's fields directly. There is no API/ABI
|
||||||
// compatibility or safety guarantee if you do so. Instead, use the
|
// compatibility or safety guarantee if you do so. Instead, use the
|
||||||
@@ -2483,6 +2508,8 @@ struct wuffs_deflate__decoder__struct {
|
|||||||
|
|
||||||
}; // struct wuffs_deflate__decoder__struct
|
}; // struct wuffs_deflate__decoder__struct
|
||||||
|
|
||||||
|
#endif // WUFFS_IMPLEMENTATION
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
#endif
|
#endif
|
||||||
@@ -2539,6 +2566,13 @@ wuffs_lzw__decoder__decode(wuffs_lzw__decoder* self,
|
|||||||
|
|
||||||
// ---------------- Struct Definitions
|
// ---------------- Struct Definitions
|
||||||
|
|
||||||
|
// These structs' fields, and the sizeof them, are private implementation
|
||||||
|
// details that aren't guaranteed to be stable across Wuffs versions.
|
||||||
|
//
|
||||||
|
// See https://en.wikipedia.org/wiki/Opaque_pointer#C
|
||||||
|
|
||||||
|
#ifdef WUFFS_IMPLEMENTATION
|
||||||
|
|
||||||
struct wuffs_lzw__decoder__struct {
|
struct wuffs_lzw__decoder__struct {
|
||||||
// Do not access the private_impl's fields directly. There is no API/ABI
|
// Do not access the private_impl's fields directly. There is no API/ABI
|
||||||
// compatibility or safety guarantee if you do so. Instead, use the
|
// compatibility or safety guarantee if you do so. Instead, use the
|
||||||
@@ -2594,6 +2628,8 @@ struct wuffs_lzw__decoder__struct {
|
|||||||
|
|
||||||
}; // struct wuffs_lzw__decoder__struct
|
}; // struct wuffs_lzw__decoder__struct
|
||||||
|
|
||||||
|
#endif // WUFFS_IMPLEMENTATION
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
#endif
|
#endif
|
||||||
@@ -2670,6 +2706,13 @@ wuffs_gif__decoder__decode_frame(wuffs_gif__decoder* self,
|
|||||||
|
|
||||||
// ---------------- Struct Definitions
|
// ---------------- Struct Definitions
|
||||||
|
|
||||||
|
// These structs' fields, and the sizeof them, are private implementation
|
||||||
|
// details that aren't guaranteed to be stable across Wuffs versions.
|
||||||
|
//
|
||||||
|
// See https://en.wikipedia.org/wiki/Opaque_pointer#C
|
||||||
|
|
||||||
|
#ifdef WUFFS_IMPLEMENTATION
|
||||||
|
|
||||||
struct wuffs_gif__decoder__struct {
|
struct wuffs_gif__decoder__struct {
|
||||||
// Do not access the private_impl's fields directly. There is no API/ABI
|
// Do not access the private_impl's fields directly. There is no API/ABI
|
||||||
// compatibility or safety guarantee if you do so. Instead, use the
|
// compatibility or safety guarantee if you do so. Instead, use the
|
||||||
@@ -2840,6 +2883,8 @@ struct wuffs_gif__decoder__struct {
|
|||||||
|
|
||||||
}; // struct wuffs_gif__decoder__struct
|
}; // struct wuffs_gif__decoder__struct
|
||||||
|
|
||||||
|
#endif // WUFFS_IMPLEMENTATION
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
#endif
|
#endif
|
||||||
@@ -2900,6 +2945,13 @@ wuffs_gzip__decoder__decode(wuffs_gzip__decoder* self,
|
|||||||
|
|
||||||
// ---------------- Struct Definitions
|
// ---------------- Struct Definitions
|
||||||
|
|
||||||
|
// These structs' fields, and the sizeof them, are private implementation
|
||||||
|
// details that aren't guaranteed to be stable across Wuffs versions.
|
||||||
|
//
|
||||||
|
// See https://en.wikipedia.org/wiki/Opaque_pointer#C
|
||||||
|
|
||||||
|
#ifdef WUFFS_IMPLEMENTATION
|
||||||
|
|
||||||
struct wuffs_gzip__decoder__struct {
|
struct wuffs_gzip__decoder__struct {
|
||||||
// Do not access the private_impl's fields directly. There is no API/ABI
|
// Do not access the private_impl's fields directly. There is no API/ABI
|
||||||
// compatibility or safety guarantee if you do so. Instead, use the
|
// compatibility or safety guarantee if you do so. Instead, use the
|
||||||
@@ -2951,6 +3003,8 @@ struct wuffs_gzip__decoder__struct {
|
|||||||
|
|
||||||
}; // struct wuffs_gzip__decoder__struct
|
}; // struct wuffs_gzip__decoder__struct
|
||||||
|
|
||||||
|
#endif // WUFFS_IMPLEMENTATION
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
#endif
|
#endif
|
||||||
@@ -3011,6 +3065,13 @@ wuffs_zlib__decoder__decode(wuffs_zlib__decoder* self,
|
|||||||
|
|
||||||
// ---------------- Struct Definitions
|
// ---------------- Struct Definitions
|
||||||
|
|
||||||
|
// These structs' fields, and the sizeof them, are private implementation
|
||||||
|
// details that aren't guaranteed to be stable across Wuffs versions.
|
||||||
|
//
|
||||||
|
// See https://en.wikipedia.org/wiki/Opaque_pointer#C
|
||||||
|
|
||||||
|
#ifdef WUFFS_IMPLEMENTATION
|
||||||
|
|
||||||
struct wuffs_zlib__decoder__struct {
|
struct wuffs_zlib__decoder__struct {
|
||||||
// Do not access the private_impl's fields directly. There is no API/ABI
|
// Do not access the private_impl's fields directly. There is no API/ABI
|
||||||
// compatibility or safety guarantee if you do so. Instead, use the
|
// compatibility or safety guarantee if you do so. Instead, use the
|
||||||
@@ -3058,6 +3119,8 @@ struct wuffs_zlib__decoder__struct {
|
|||||||
|
|
||||||
}; // struct wuffs_zlib__decoder__struct
|
}; // struct wuffs_zlib__decoder__struct
|
||||||
|
|
||||||
|
#endif // WUFFS_IMPLEMENTATION
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in new issue
Block a user