Skip to content

Commit

Permalink
Fix extern type usage with non-nullable ptrs
Browse files Browse the repository at this point in the history
When non-nullable pointers are set, externally defined
interface types were not being treated the same as file-local
interface types, causing missing import headers and incorrect
pointer types to be used in C++ generated code.
  • Loading branch information
trblunt committed Jul 14, 2024
1 parent 9a74ee9 commit 6f52b82
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/source/CppMarshal.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*
* This file has been modified by Snap, Inc.
*/

Expand Down Expand Up @@ -117,7 +117,12 @@ class CppMarshal(spec: Spec) extends Marshal(spec) {
case e: MExtern => e.defType match {
// Do not forward declare extern types, they might be in arbitrary namespaces.
// This isn't a problem as extern types cannot cause dependency cycles with types being generated here
case DInterface => List(ImportRef("<memory>"), ImportRef(e.cpp.header))
case DInterface =>
val base = List(ImportRef("<memory>"), ImportRef(e.cpp.header))
spec.cppNnHeader match {
case Some(nnHdr) => ImportRef(nnHdr) :: base
case _ => base
}
case _ => List(ImportRef(resolveExtCppHdr(e.cpp.header)))
}
case p: MProtobuf =>
Expand Down Expand Up @@ -211,13 +216,23 @@ class CppMarshal(spec: Spec) extends Marshal(spec) {
case DInterface => s"${nnType}<${withNamespace(idCpp.ty(d.name))}>"
case _ => base(tm.base) + args
}
case e: MExtern =>
e.defType match {
case DInterface => s"${nnType}<${e.cpp.typename}>"
case _ => base(tm.base) + args
}
case MOptional =>
tm.args.head.base match {
case d: MDef =>
d.defType match {
case DInterface => s"std::shared_ptr<${withNamespace(idCpp.ty(d.name))}>"
case _ => base(tm.base) + args
}
case e: MExtern =>
e.defType match {
case DInterface => s"std::shared_ptr<${e.cpp.typename}>"
case _ => base(tm.base) + args
}
case _ => base(tm.base) + args
}
case _ => base(tm.base) + args
Expand Down

0 comments on commit 6f52b82

Please sign in to comment.