Skip to content
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

Objective C's va_list struct is parsed inconsistently #309

Closed
liamappelbe opened this issue Apr 11, 2022 · 4 comments · Fixed by dart-archive/ffigen#311
Closed

Objective C's va_list struct is parsed inconsistently #309

liamappelbe opened this issue Apr 11, 2022 · 4 comments · Fixed by dart-archive/ffigen#311
Assignees
Labels
lang-objective_c Related to Objective C support package:ffigen

Comments

@liamappelbe
Copy link
Contributor

va_list is being parsed differently on different Mac machines.

--- a/test/native_objc_test/native_objc_test_bindings.dart
+++ b/test/native_objc_test/native_objc_test_bindings.dart
@@ -158,7 +158,7 @@ class NativeObjCLibrary {
 
   void NSLogv(
     ffi.Pointer<ObjCObject> format,
-    ffi.Pointer<__va_list_tag> args,
+    va_list args,
   ) {
     return _NSLogv(
       format,
@@ -168,10 +168,9 @@ class NativeObjCLibrary {
 
   late final _NSLogvPtr = _lookup<
       ffi.NativeFunction<
-          ffi.Void Function(
-              ffi.Pointer<ObjCObject>, ffi.Pointer<__va_list_tag>)>>('NSLogv');
-  late final _NSLogv = _NSLogvPtr.asFunction<
-      void Function(ffi.Pointer<ObjCObject>, ffi.Pointer<__va_list_tag>)>();
+          ffi.Void Function(ffi.Pointer<ObjCObject>, va_list)>>('NSLogv');
+  late final _NSLogv =
+      _NSLogvPtr.asFunction<void Function(ffi.Pointer<ObjCObject>, va_list)>();
 
   late final ffi.Pointer<NSInteger> _NSNotFound =
       _lookup<NSInteger>('NSNotFound');
@@ -4615,18 +4614,8 @@ class ObjCObject extends ffi.Opaque {}
 class ObjCSel extends ffi.Opaque {}
 
 typedef NSUInteger = pkg_ffi.UnsignedLong;
-
-class __va_list_tag extends ffi.Struct {
-  @pkg_ffi.UnsignedInt()
-  external int gp_offset;
-
-  @pkg_ffi.UnsignedInt()
-  external int fp_offset;
-
-  external ffi.Pointer<ffi.Void> overflow_arg_area;
-
-  external ffi.Pointer<ffi.Void> reg_save_area;
-}
+typedef va_list = __builtin_va_list;
+typedef __builtin_va_list = ffi.Pointer<pkg_ffi.Char>;
 
 abstract class NSComparisonResult {
   static const int NSOrderedAscending = -1;
@liamappelbe liamappelbe added the lang-objective_c Related to Objective C support label Apr 11, 2022
@liamappelbe liamappelbe self-assigned this Apr 11, 2022
@liamappelbe
Copy link
Contributor Author

cc @brianquinlan

@liamappelbe
Copy link
Contributor Author

Actually this inconsistency only matters for our test infrastructure. It's not like the BOOL inconsistency, which was much more fundamental. I'm just going to exclude this irrelevant stuff from the test.

@dcharkes
Copy link
Collaborator

Less unused generated stuff in the tests is better. 👍

dart:ffi does not support the valist calling conventions from C. Did I reverse engineer from the diff correctly that one just passes a pointer in ObjectiveC for valists?

@liamappelbe
Copy link
Contributor Author

Yep, one of the internal headers defines the va_list struct (in a way that differs depending on the user's setup), and then that struct is passed around by pointer.

@liamappelbe liamappelbe transferred this issue from dart-archive/ffigen Nov 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang-objective_c Related to Objective C support package:ffigen
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants