Commit Graph

6 Commits

Author SHA1 Message Date
Brendan Raykoff
9b12ddb595 [upstream_utils] Patch protobuf to remove deprecated ATOMIC_VAR_INIT (#7585) 2024-12-23 16:14:15 -06:00
Thad House
a9ac5b8e24 Don't read protobuf static data across shared library lines directly (#6979)
Reading exported data from shared objects on windows is broken. It requires __declspec(dllimport). However, this is problematic, as we use the same static libraries both from a shared and static context. So we can't just blindly apply dllimport.

The linker should have caught this, as data members are exported in a different way. However, due to a bug in native-utils, data member symbols were exposed directly. However, interacting with those data member was completely broken.

The only way we can really solve this is to just not use static data members. We're pretty good about this in WPILib itself. However, protobuf is absolutely terrible at this. There are a ton of inline functions that access global data. For the protobuf library itself, we can solve this easily enough.

However, for the generated protobuf code, this is much more problematic. The member needed to bypass the global data is private. This means using just the stock protobuf code, this problem is not solvable. But, protobuf generated code has insertion points. Those insertion points let us add our own code into the generated code via a protoc plugin. And it just so happens that an insertion point exists to add extra public methodsto the generated protobuf header. There is also an insertion point to let us add to the cpp file.

The methods we need are the getters, for unpacking protobufs. For any protobuf that has a message as a member, we generate a new wpi_x() getter (the existing one is just x(), where x is the field name). We then implement this in the cpp file. A trick we can use is in the cpp file, we can safely call the x() function, as the cpp file is in the same library as the global. Thus we can call that inline method, and not actually need to directly access any internal private state of the protobuf object.

TL;DR, all protobuf classes that have messages as fields now have a wpi_x() accessor that must be used instead of x() if you want the code to work on windows. After wpilibsuite/native-utils#212, the bad code will fail to link, rather then just fail at runtime.
2024-08-21 07:53:20 -07:00
Thad House
9280054eab Revert "[build] Export wpimath protobuf symbols (#5952)"
This reverts commit c80b2d2017.
2023-11-23 22:40:47 -08:00
Peter Johnson
c80b2d2017 [build] Export wpimath protobuf symbols (#5952) 2023-11-23 11:27:54 -08:00
Tyler Veness
fa6b171e1c [wpiutil] Suppress protobuf warning false positives on GCC 13 (#5907) 2023-11-10 15:12:18 -08:00
Peter Johnson
638f04f626 [wpiutil] Add protobuf to thirdparty sources (#5746) 2023-10-14 21:54:17 -07:00