Skip to content

[pigeon] Use a const for custom type ids for gobject generated files (#156100) #9306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

JesseRiemens
Copy link

Adds a custom type identifier to generated gobject headers for the user. Calling fl_value_new_custom_object is now possible with that constant.

This fixes flutter/flutter#156100

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2 3

@JesseRiemens JesseRiemens requested a review from tarrinneal as a code owner May 22, 2025 14:39
@JesseRiemens JesseRiemens force-pushed the pigeon/gobject-custom-class-const-id branch from 9ef0df9 to b660a0c Compare May 22, 2025 15:37
@JesseRiemens JesseRiemens force-pushed the pigeon/gobject-custom-class-const-id branch 2 times, most recently from 62b41ae to da4196c Compare May 22, 2025 16:10
@tarrinneal tarrinneal requested a review from stuartmorgan-g May 22, 2025 18:41
@JesseRiemens JesseRiemens force-pushed the pigeon/gobject-custom-class-const-id branch 2 times, most recently from 77d7394 to 3947e4e Compare May 23, 2025 08:41
@JesseRiemens
Copy link
Author

The FLValue headers in some places use int, and in some places use uint8_t:

// fl_value.h:303
FlValue* fl_value_new_custom(int type, // uses int
                             gconstpointer value,
                             GDestroyNotify destroy_notify);

// fl_standard_message_codec.h:148
gboolean fl_standard_message_codec_write_value(FlStandardMessageCodec* codec,
                                               GByteArray* buffer,  // uses GByteArray*, which is used (subclassed) in generated files:
                                               FlValue* value,
                                               GError** error);
// core_tests.gen.cc:2422
static gboolean
core_tests_pigeon_test_message_codec_write_core_tests_pigeon_test_an_enum(
    FlStandardMessageCodec* codec, GByteArray* buffer, FlValue* value,
    GError** error) {
  uint8_t type = core_tests_pigeon_test_an_enum_type_id; // appends uint8_t to buffer
  g_byte_array_append(buffer, &type, sizeof(uint8_t));
  return fl_standard_message_codec_write_value(codec, buffer, value, error);
}

I think this might be related to #152916. Maybe it is best to leave it as is, and for this PR use int for the types.

@stuartmorgan-g
Copy link
Contributor

The FLValue headers in some places use int, and in some places use uint8_t:

Where is the header using uint8_t for the type? I'm seeing in your snippet:

  • A header declaration that uses int for the type.
  • A header declaration that doesn't have the type at all.
  • A file that's not an engine header.

@JesseRiemens
Copy link
Author

JesseRiemens commented May 23, 2025

My mistake, it's not the FlValue header that uses uint8_t, but only the generated code using the engine header.
I did not fully understand how it worked, but now I see that the generated dart code at the other side also uses uint8:

class DartGenerator extends StructuredGenerator<InternalDartOptions> {
  (...)
  void writeGeneralCodec() {
    (...)
          indent.writeln('buffer.putUint8(4);');

dart_generator.dart:432

That makes more sense to me now. I guess that means we can keep it like it is.

…(#156100)

Adds a custom type identifier to generated gobject headers for the user. Calling fl_value_new_custom_object is now possible with that constant.
This fixes flutter/flutter#156100

Also updated the CONTRIBUTING.md file to include the gobject generator.
@JesseRiemens JesseRiemens force-pushed the pigeon/gobject-custom-class-const-id branch from 3947e4e to fc6b92d Compare May 23, 2025 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[pigeon] Expose custom object IDs for testing on Linux
2 participants