Bug 37808 - Binding generator bug, not generating correctly for out param.
Summary: Binding generator bug, not generating correctly for out param.
Status: RESOLVED FEATURE
Alias: None
Product: Android
Classification: Xamarin
Component: Bindings ()
Version: unspecified
Hardware: PC Windows
: Normal normal
Target Milestone: 7.3 (C11)
Assignee: Atsushi Eno
URL:
Depends on:
Blocks:
 
Reported: 2016-01-19 21:17 UTC by Robert
Modified: 2016-09-22 07:42 UTC (History)
7 users (show)

Tags: BZCU XATriaged
Is this bug a regression?: ---
Last known good build:


Attachments
JAR, Docs, with sample java usage. (2.87 MB, application/octet-stream)
2016-01-19 21:17 UTC, Robert
Details
screenshot of fixed code (64.05 KB, image/png)
2016-01-19 21:17 UTC, Robert
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FEATURE

Description Robert 2016-01-19 21:17:13 UTC
Created attachment 14633 [details]
JAR, Docs, with sample java usage.

There might be a bug in the bindings generator for an  out parameter type.

Example java usage of method: 

```
final int QueryStatusSize=4;
byte StatusBuffer[] = new byte[QueryStatusSize];
error_code = pos_sdk.systemQueryStatus(StatusBuffer,QueryStatusSize,1);
```


Xamarin generated class, method:

```
static IntPtr id_systemQueryStatus_arrayBII;
		// Metadata.xml XPath method reference: path="/api/package[@name='POSSDK']/class[@name='POSSDK']/method[@name='systemQueryStatus' and count(parameter)=3 and parameter[1][@type='byte[]'] and parameter[2][@type='int'] and parameter[3][@type='int']]"
		[Register ("systemQueryStatus", "([BII)I", "GetSystemQueryStatus_arrayBIIHandler")]
		public virtual unsafe int SystemQueryStatus (byte[] p0, int p1, int p2)
		{
			if (id_systemQueryStatus_arrayBII == IntPtr.Zero)
				id_systemQueryStatus_arrayBII = JNIEnv.GetMethodID (class_ref, "systemQueryStatus", "([BII)I");
			IntPtr native_p0 = JNIEnv.NewArray (p0);
			try {
				JValue* __args = stackalloc JValue [3];
				__args [0] = new JValue (native_p0);
				__args [1] = new JValue (p1);
				__args [2] = new JValue (p2);

				int __ret;
				if (GetType () == ThresholdType)
					__ret = JNIEnv.CallIntMethod  (Handle, id_systemQueryStatus_arrayBII, __args);
				else
					__ret = JNIEnv.CallNonvirtualIntMethod  (Handle, ThresholdClass, JNIEnv.GetMethodID (ThresholdClass, "systemQueryStatus", "([BII)I"), __args);
				return __ret;
			} finally {
				if (p0 != null) {
					JNIEnv.CopyArray (native_p0, p0);
					JNIEnv.DeleteLocalRef (native_p0);
				}
			}
		}
```

error if you just add an out to the signature without creating a byte in the method: ```

CS0269    Use of unassigned out parameter 'p0'    Droid.Hardware    C:\dev\git\Droid.Hardware\POSSDK.POSSDK.cs    1139

Severity    Code    Description    Project    File    Line
Error    CS0177    The out parameter 'p0' must be assigned to before control leaves the current method    .Droid.Hardware    C:\dev\git\.Droid.Hardware\POSSDK.POSSDK.cs    1151
```


Fixed code:

```
static IntPtr id_systemQueryStatus_arrayBII;
		// Metadata.xml XPath method reference: path="/api/package[@name='POSSDK']/class[@name='POSSDK']/method[@name='systemQueryStatus' and count(parameter)=3 and parameter[1][@type='byte[]'] and parameter[2][@type='int'] and parameter[3][@type='int']]"
		[Register ("systemQueryStatus", "([BII)I", "GetSystemQueryStatus_arrayBIIHandler")]
		public virtual unsafe int SystemQueryStatus (out byte[] p0, int p1, int p2)
		{
			if (id_systemQueryStatus_arrayBII == IntPtr.Zero)
				id_systemQueryStatus_arrayBII = JNIEnv.GetMethodID (class_ref, "systemQueryStatus", "([BII)I");
			p0 = new byte[64];
			IntPtr native_p0 = JNIEnv.NewArray (p0);
			try {
				JValue* __args = stackalloc JValue [3];
				__args [0] = new JValue (native_p0);
				__args [1] = new JValue (p1);
				__args [2] = new JValue (p2);

				int __ret;
				if (GetType () == ThresholdType)
					__ret = JNIEnv.CallIntMethod  (Handle, id_systemQueryStatus_arrayBII, __args);
				else
					__ret = JNIEnv.CallNonvirtualIntMethod  (Handle, ThresholdClass, JNIEnv.GetMethodID (ThresholdClass, "systemQueryStatus", "([BII)I"), __args);
				return __ret;
			} finally {
				if (p0 != null) {
					JNIEnv.CopyArray (native_p0, p0);
					JNIEnv.DeleteLocalRef (native_p0);
				}
			}
		}
```
```
Comment 1 Robert 2016-01-19 21:17:40 UTC
Created attachment 14634 [details]
screenshot of fixed code
Comment 2 Robert 2016-01-19 22:23:26 UTC
The dev(?) Jon Dick asked me to file it on bugzilla.
Comment 3 Atsushi Eno 2016-09-22 07:42:18 UTC
We never supported (and will never support) arbitrary "out" parameter. Our binding generator is not an ESP-er and does not interpret any arbitrary expression that people write as they expect.