1

in iOSapi.Foundation.pas we have this row :

//procedure NSLogv(format: PNSString; args: va_list); cdecl; external libFoundation name _PU + 'NSLogv';

Why it is commented / deactivated ? This procedure is defined like this in the header :

FOUNDATION_EXPORT void NSLogv(NSString *format, va_list args) NS_FORMAT_FUNCTION(1,0) NS_NO_TAIL_CALL;

When i try to uncomment it, i have an error: va_list not defined. If i not make any mistake, va_list is just a pointer ?

After how to call this function ? NB: i need to call this exact function, not any other log function ....

RaelB
  • 3,301
  • 5
  • 35
  • 55
zeus
  • 12,173
  • 9
  • 63
  • 184

1 Answers1

3

NSLogv exists when you need to wrap a call to NSLog with your own variadic function. But since you can't write a variadic function in Delphi, that scenario cannot apply.

Call NSLog instead. This is an externally defined variadic function. Although Delphi cannot be used to write such things, it is capable of consuming them.

For more details refer to this topic: Difference between NSLog and NSLogv.

Further reading:

Community
  • 1
  • 1
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • thanks David, so you mean we can not translate / call in delphi any ios function with va_list ? NSLogv was taken as example, because i need to call this function in a 3rd library: `void FIRCrashLogv(NSString *format, va_list ap);` that is similar to NSLogv ... is their any workaround ? – zeus May 08 '17 at 08:02
  • Call [`FIRCrashLog`](https://firebase.google.com/docs/reference/ios/firebasecrash/api/reference/Functions#/c:FIRCrashLog.h@F@FIRCrashLog) instead – David Heffernan May 08 '17 at 08:03
  • Thanks david, but FIRCrashLog is defined like this in the FIRCrashLog.h; `FOUNDATION_STATIC_INLINE NS_FORMAT_FUNCTION(1, 2) void FIRCrashLog(NSString *format, ...) {...}` and it's seam i can not import it in delphi because miss the keyword `extern` ... only FIRCrashLogv have the keyword `extern` ... or their is a way to import in delphi such static inlined function ? – zeus May 08 '17 at 08:16
  • OK, then you are in trouble. I don't think that you can readily make a va_list in Delphi. No doube the body of `FIRCrashLog` includes the macros `va_start`, `va_arg` and `va_end`. But this is a different question now, isn't it? You asked about `NSLogv`. I do think I answered the question that was asked. – David Heffernan May 08 '17 at 08:21
  • you are right! you answer well this question thanks ... i start a new question here: http://stackoverflow.com/questions/43843006/how-to-call-in-delphi-an-ios-variadic-function – zeus May 08 '17 at 08:27
  • Just a remark: i discover that delphi have the `varargs` parameters ... but don't find out how to use it ... – zeus May 08 '17 at 08:48
  • @loki you can't use `varargs` to call `NSLogv` or `FIRCrashLogv`, it would be used for calling `NSLog` or `FIRCrashLog` instead. `varargs` is Delphi's implementation of C's `...` syntax in a variadic parameter list. – Remy Lebeau May 08 '17 at 15:46
  • @RemyLebeau : quite strangely it's work with varargs ! i try on FIRCrashLogv with declaring the procedure like this : `procedure FIRCrashLogv(format: PNSString); cdecl; varargs; external 'FirebaseCrash' name 'FIRCrashLogv';` and it's work ! – zeus May 08 '17 at 16:41
  • It won't be working. You might fluke it if you have zero or one variadic args. But that's it. – David Heffernan May 08 '17 at 16:58
  • @loki: It can't work that way. Calling a function with a `varargs` parameter list is different than calling a function with a `va_list` parameter. They are related, but the call stacks are very different. – Remy Lebeau May 08 '17 at 16:59
  • @RemyLebeau : i believe you but i assure you it's work ! and if you look the source code of delphi, they also do the same for 2 functions : CFStringCreateWithFormatAndArguments and CFStringAppendFormatAndArguments – zeus May 08 '17 at 19:37
  • Either you believe us or you don't. – David Heffernan May 08 '17 at 19:51
  • @loki: `varargs` is NOT compatible with `va_list` - period. That is not what `varargs` is designed for, that is not how the compiler implements it. If Embarcadero declared `va_list` functions using `varargs` instead, then they did the wrong thing, and that is a ticking time bomb waiting to crash someone's code. Try it with a function that takes a whole bunch of variadic values as input, not just 1 or 2, and see what happens. Best case, you get garbage output. Worse case, it corrupts memory and/or crashes. – Remy Lebeau May 09 '17 at 00:39
  • @RemyLebeau hmm so i m just lucky that it's work, maybe because i don't pass any arguments to varargs. And delphi (as often) translate badly some ios function. Real question, is their any way in delphi to use va_list ? – zeus May 09 '17 at 09:35
  • 1
    @loki I already said exactly that. Of course if you don't pass any arguments, then it will appear to work. – David Heffernan May 09 '17 at 10:05