Skip to content

Commit

Permalink
Fix "zero" Date literal in Java and Dart (#1260)
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Kamkha <[email protected]>
  • Loading branch information
DanielKamkha authored Feb 8, 2022
1 parent 3c42c61 commit a0c13f8
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Gluecodium project Release Notes

## Unreleased
### Bug fixes:
* Fixed compilation issues in Java and Dart when a `Date` literal is exactly at 0 seconds since Unix "epoch".

## 10.7.0
Release date: 2022-02-08
### Features:
Expand Down
1 change: 1 addition & 0 deletions functional-tests/functional/input/lime/DateDefaults.lime
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ struct DateDefaults {
dateTime: Date = "2022-02-04T11:15:17+02:00"
dateTimeUtc: Date = "2022-02-04T09:15:17Z"
beforeEpoch: Date = "1922-02-04T09:15:17Z"
exactlyEpoch: Date = "1970-01-01T00:00:00Z"

field constructor()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ internal class DartNameResolver(
}
is LimeValue.KeyValuePair -> "${resolveValue(limeValue.key)}: ${resolveValue(limeValue.value)}"
is LimeValue.Duration -> resolveDurationValue(limeValue)
is LimeValue.Date -> "DateTime.fromMillisecondsSinceEpoch(${limeValue.epochSeconds}000)"
is LimeValue.Date -> "DateTime.fromMillisecondsSinceEpoch(${limeValue.epochSeconds * 1000})"
}

private fun resolveDurationValue(limeValue: LimeValue.Duration): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ internal class JavaValueResolver(private val nameResolver: JavaNameResolver) {
"new AbstractMap.SimpleEntry<>($keyValue, $valueValue)"
}
is LimeValue.Duration -> mapDurationValue(limeValue)
is LimeValue.Date -> "new Date(${limeValue.epochSeconds}000L)"
is LimeValue.Date -> "new Date(${limeValue.epochSeconds * 1000}L)"
}

private fun mapInitializerList(limeValue: LimeValue.InitializerList): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ struct DateDefaults {
dateTime: Date = "2022-02-04T11:15:17+02:00"
dateTimeUtc: Date = "2022-02-04T09:15:17Z"
beforeEpoch: Date = "1922-02-04T09:15:17Z"
exactlyEpoch: Date = "1970-01-01T00:00:00Z"
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@ public final class DateDefaults {
public Date dateTimeUtc;
@NonNull
public Date beforeEpoch;
@NonNull
public Date exactlyEpoch;
public DateDefaults() {
this.dateTime = new Date(1643966117000L);
this.dateTimeUtc = new Date(1643966117000L);
this.beforeEpoch = new Date(-1511793883000L);
this.exactlyEpoch = new Date(0L);
}
public DateDefaults(@NonNull final Date dateTime, @NonNull final Date dateTimeUtc, @NonNull final Date beforeEpoch) {
public DateDefaults(@NonNull final Date dateTime, @NonNull final Date dateTimeUtc, @NonNull final Date beforeEpoch, @NonNull final Date exactlyEpoch) {
this.dateTime = dateTime;
this.dateTimeUtc = dateTimeUtc;
this.beforeEpoch = beforeEpoch;
this.exactlyEpoch = exactlyEpoch;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ struct _GLUECODIUM_CPP_EXPORT DateDefaults {
::std::chrono::system_clock::time_point date_time = ::std::chrono::system_clock::from_time_t(1643966117);
::std::chrono::system_clock::time_point date_time_utc = ::std::chrono::system_clock::from_time_t(1643966117);
::std::chrono::system_clock::time_point before_epoch = ::std::chrono::system_clock::from_time_t(-1511793883);
::std::chrono::system_clock::time_point exactly_epoch = ::std::chrono::system_clock::from_time_t(0);
DateDefaults( );
DateDefaults( ::std::chrono::system_clock::time_point date_time, ::std::chrono::system_clock::time_point date_time_utc, ::std::chrono::system_clock::time_point before_epoch );
DateDefaults( ::std::chrono::system_clock::time_point date_time, ::std::chrono::system_clock::time_point date_time_utc, ::std::chrono::system_clock::time_point before_epoch, ::std::chrono::system_clock::time_point exactly_epoch );
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ class DateDefaults {
DateTime dateTime;
DateTime dateTimeUtc;
DateTime beforeEpoch;
DateDefaults(this.dateTime, this.dateTimeUtc, this.beforeEpoch);
DateTime exactlyEpoch;
DateDefaults(this.dateTime, this.dateTimeUtc, this.beforeEpoch, this.exactlyEpoch);
DateDefaults.withDefaults()
: dateTime = DateTime.fromMillisecondsSinceEpoch(1643966117000), dateTimeUtc = DateTime.fromMillisecondsSinceEpoch(1643966117000), beforeEpoch = DateTime.fromMillisecondsSinceEpoch(-1511793883000);
: dateTime = DateTime.fromMillisecondsSinceEpoch(1643966117000), dateTimeUtc = DateTime.fromMillisecondsSinceEpoch(1643966117000), beforeEpoch = DateTime.fromMillisecondsSinceEpoch(-1511793883000), exactlyEpoch = DateTime.fromMillisecondsSinceEpoch(0);
}
// DateDefaults "private" section, not exported.
final _smokeDatedefaultsCreateHandle = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Pointer<Void> Function(Uint64, Uint64, Uint64),
Pointer<Void> Function(int, int, int)
Pointer<Void> Function(Uint64, Uint64, Uint64, Uint64),
Pointer<Void> Function(int, int, int, int)
>('library_smoke_DateDefaults_create_handle'));
final _smokeDatedefaultsReleaseHandle = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Void Function(Pointer<Void>),
Expand All @@ -30,30 +31,39 @@ final _smokeDatedefaultsGetFieldbeforeEpoch = __lib.catchArgumentError(() => __l
Uint64 Function(Pointer<Void>),
int Function(Pointer<Void>)
>('library_smoke_DateDefaults_get_field_beforeEpoch'));
final _smokeDatedefaultsGetFieldexactlyEpoch = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
Uint64 Function(Pointer<Void>),
int Function(Pointer<Void>)
>('library_smoke_DateDefaults_get_field_exactlyEpoch'));
Pointer<Void> smokeDatedefaultsToFfi(DateDefaults value) {
final _dateTimeHandle = dateToFfi(value.dateTime);
final _dateTimeUtcHandle = dateToFfi(value.dateTimeUtc);
final _beforeEpochHandle = dateToFfi(value.beforeEpoch);
final _result = _smokeDatedefaultsCreateHandle(_dateTimeHandle, _dateTimeUtcHandle, _beforeEpochHandle);
final _exactlyEpochHandle = dateToFfi(value.exactlyEpoch);
final _result = _smokeDatedefaultsCreateHandle(_dateTimeHandle, _dateTimeUtcHandle, _beforeEpochHandle, _exactlyEpochHandle);
dateReleaseFfiHandle(_dateTimeHandle);
dateReleaseFfiHandle(_dateTimeUtcHandle);
dateReleaseFfiHandle(_beforeEpochHandle);
dateReleaseFfiHandle(_exactlyEpochHandle);
return _result;
}
DateDefaults smokeDatedefaultsFromFfi(Pointer<Void> handle) {
final _dateTimeHandle = _smokeDatedefaultsGetFielddateTime(handle);
final _dateTimeUtcHandle = _smokeDatedefaultsGetFielddateTimeUtc(handle);
final _beforeEpochHandle = _smokeDatedefaultsGetFieldbeforeEpoch(handle);
final _exactlyEpochHandle = _smokeDatedefaultsGetFieldexactlyEpoch(handle);
try {
return DateDefaults(
dateFromFfi(_dateTimeHandle),
dateFromFfi(_dateTimeUtcHandle),
dateFromFfi(_beforeEpochHandle)
dateFromFfi(_beforeEpochHandle),
dateFromFfi(_exactlyEpochHandle)
);
} finally {
dateReleaseFfiHandle(_dateTimeHandle);
dateReleaseFfiHandle(_dateTimeUtcHandle);
dateReleaseFfiHandle(_beforeEpochHandle);
dateReleaseFfiHandle(_exactlyEpochHandle);
}
}
void smokeDatedefaultsReleaseFfiHandle(Pointer<Void> handle) => _smokeDatedefaultsReleaseHandle(handle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ struct DateDefaults {
dateTime: Date = "2022-02-04T09:15:17Z"
dateTimeUtc: Date = "2022-02-04T09:15:17Z"
beforeEpoch: Date = "1922-02-04T09:15:17Z"
exactlyEpoch: Date = "1970-01-01T00:00:00Z"
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ public struct DateDefaults {
public var dateTime: Date
public var dateTimeUtc: Date
public var beforeEpoch: Date
public init(dateTime: Date = Date(timeIntervalSince1970: 1643966117), dateTimeUtc: Date = Date(timeIntervalSince1970: 1643966117), beforeEpoch: Date = Date(timeIntervalSince1970: -1511793883)) {
public var exactlyEpoch: Date
public init(dateTime: Date = Date(timeIntervalSince1970: 1643966117), dateTimeUtc: Date = Date(timeIntervalSince1970: 1643966117), beforeEpoch: Date = Date(timeIntervalSince1970: -1511793883), exactlyEpoch: Date = Date(timeIntervalSince1970: 0)) {
self.dateTime = dateTime
self.dateTimeUtc = dateTimeUtc
self.beforeEpoch = beforeEpoch
self.exactlyEpoch = exactlyEpoch
}
internal init(cHandle: _baseRef) {
dateTime = moveFromCType(smoke_DateDefaults_dateTime_get(cHandle))
dateTimeUtc = moveFromCType(smoke_DateDefaults_dateTimeUtc_get(cHandle))
beforeEpoch = moveFromCType(smoke_DateDefaults_beforeEpoch_get(cHandle))
exactlyEpoch = moveFromCType(smoke_DateDefaults_exactlyEpoch_get(cHandle))
}
}
internal func copyFromCType(_ handle: _baseRef) -> DateDefaults {
Expand All @@ -29,7 +32,8 @@ internal func copyToCType(_ swiftType: DateDefaults) -> RefHolder {
let c_dateTime = moveToCType(swiftType.dateTime)
let c_dateTimeUtc = moveToCType(swiftType.dateTimeUtc)
let c_beforeEpoch = moveToCType(swiftType.beforeEpoch)
return RefHolder(smoke_DateDefaults_create_handle(c_dateTime.ref, c_dateTimeUtc.ref, c_beforeEpoch.ref))
let c_exactlyEpoch = moveToCType(swiftType.exactlyEpoch)
return RefHolder(smoke_DateDefaults_create_handle(c_dateTime.ref, c_dateTimeUtc.ref, c_beforeEpoch.ref, c_exactlyEpoch.ref))
}
internal func moveToCType(_ swiftType: DateDefaults) -> RefHolder {
return RefHolder(ref: copyToCType(swiftType).ref, release: smoke_DateDefaults_release_handle)
Expand All @@ -54,7 +58,8 @@ internal func copyToCType(_ swiftType: DateDefaults?) -> RefHolder {
let c_dateTime = moveToCType(swiftType.dateTime)
let c_dateTimeUtc = moveToCType(swiftType.dateTimeUtc)
let c_beforeEpoch = moveToCType(swiftType.beforeEpoch)
return RefHolder(smoke_DateDefaults_create_optional_handle(c_dateTime.ref, c_dateTimeUtc.ref, c_beforeEpoch.ref))
let c_exactlyEpoch = moveToCType(swiftType.exactlyEpoch)
return RefHolder(smoke_DateDefaults_create_optional_handle(c_dateTime.ref, c_dateTimeUtc.ref, c_beforeEpoch.ref, c_exactlyEpoch.ref))
}
internal func moveToCType(_ swiftType: DateDefaults?) -> RefHolder {
return RefHolder(ref: copyToCType(swiftType).ref, release: smoke_DateDefaults_release_optional_handle)
Expand Down

0 comments on commit a0c13f8

Please sign in to comment.