Skip to content

Commit 4472350

Browse files
committed
Adding TruffleBoundary
1 parent 5acacf8 commit 4472350

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/PythonAbstractObject.java

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ public LocalDate asDate(@Shared("getClassNode") @Cached GetLazyClassNode getClas
680680
int year = castToIntNode.execute(lib.readMember(this, "year"));
681681
int month = castToIntNode.execute(lib.readMember(this, "month"));
682682
int day = castToIntNode.execute(lib.readMember(this, "day"));
683-
return LocalDate.of(year, month, day);
683+
return createLocalDate(year, month, day);
684684
} catch (UnsupportedMessageException | UnknownIdentifierException ex) {
685685
throw UnsupportedMessageException.create();
686686
}
@@ -693,7 +693,7 @@ public LocalDate asDate(@Shared("getClassNode") @Cached GetLazyClassNode getClas
693693
int year = castToIntNode.execute(lib.readMember(this, "tm_year"));
694694
int month = castToIntNode.execute(lib.readMember(this, "tm_mon"));
695695
int day = castToIntNode.execute(lib.readMember(this, "tm_mday"));
696-
return LocalDate.of(year, month, day);
696+
return createLocalDate(year, month, day);
697697
} catch (UnsupportedMessageException | UnknownIdentifierException ex) {
698698
throw UnsupportedMessageException.create();
699699
}
@@ -739,7 +739,7 @@ public LocalTime asTime(@Shared("getClassNode") @Cached GetLazyClassNode getClas
739739
int min = castToIntNode.execute(lib.readMember(this, "minute"));
740740
int sec = castToIntNode.execute(lib.readMember(this, "second"));
741741
int micro = castToIntNode.execute(lib.readMember(this, "microsecond"));
742-
return LocalTime.of(hour, min, sec, micro);
742+
return createLocalTime(hour, min, sec, micro);
743743
} catch (UnsupportedMessageException | UnknownIdentifierException ex) {
744744
throw UnsupportedMessageException.create();
745745
}
@@ -752,7 +752,7 @@ public LocalTime asTime(@Shared("getClassNode") @Cached GetLazyClassNode getClas
752752
int hour = castToIntNode.execute(lib.readMember(this, "tm_hour"));
753753
int min = castToIntNode.execute(lib.readMember(this, "tm_min"));
754754
int sec = castToIntNode.execute(lib.readMember(this, "tm_sec"));
755-
return LocalTime.of(hour, min, sec);
755+
return createLocalTime(hour, min, sec, 0);
756756
} catch (UnsupportedMessageException | UnknownIdentifierException ex) {
757757
throw UnsupportedMessageException.create();
758758
}
@@ -834,7 +834,7 @@ public ZoneId asTimeZone(@Shared("getClassNode") @Cached GetLazyClassNode getCla
834834
Object delta = lib.invokeMember(tzinfo, "utcoffset", new Object[]{this});
835835
if (delta != PNone.NONE) {
836836
int seconds = castToIntNode.execute(lib.readMember(delta, "seconds"));
837-
return ZoneId.ofOffset("UTC", ZoneOffset.ofTotalSeconds(seconds));
837+
return createZoneId(seconds);
838838
}
839839
}
840840
} catch (UnsupportedMessageException | UnknownIdentifierException | ArityException | UnsupportedTypeException ex) {
@@ -847,7 +847,7 @@ public ZoneId asTimeZone(@Shared("getClassNode") @Cached GetLazyClassNode getCla
847847
Object delta = lib.invokeMember(tzinfo, "utcoffset", new Object[]{PNone.NONE});
848848
if (delta != PNone.NONE) {
849849
int seconds = castToIntNode.execute(lib.readMember(delta, "seconds"));
850-
return ZoneId.ofOffset("UTC", ZoneOffset.ofTotalSeconds(seconds));
850+
return createZoneId(seconds);
851851
}
852852
}
853853
} catch (UnsupportedMessageException | UnknownIdentifierException | ArityException | UnsupportedTypeException ex) {
@@ -864,10 +864,10 @@ public ZoneId asTimeZone(@Shared("getClassNode") @Cached GetLazyClassNode getCla
864864
Object tm_gmtoffset = lib.readMember(this, "tm_gmtoff");
865865
if (tm_gmtoffset != PNone.NONE) {
866866
int seconds = castToIntNode.execute(tm_gmtoffset);
867-
return ZoneId.ofOffset("UTC", ZoneOffset.ofTotalSeconds(seconds));
867+
return createZoneId(seconds);
868868
}
869869
if (tm_zone instanceof String) {
870-
return ZoneId.of((String) tm_zone);
870+
return createZoneId((String) tm_zone);
871871
}
872872
}
873873
} catch (UnsupportedMessageException | UnknownIdentifierException ex) {
@@ -878,6 +878,26 @@ public ZoneId asTimeZone(@Shared("getClassNode") @Cached GetLazyClassNode getCla
878878
throw UnsupportedMessageException.create();
879879
}
880880

881+
@TruffleBoundary
882+
private ZoneId createZoneId(int utcDeltaInSeconds) {
883+
return ZoneId.ofOffset("UTC", ZoneOffset.ofTotalSeconds(utcDeltaInSeconds));
884+
}
885+
886+
@TruffleBoundary
887+
private ZoneId createZoneId(String zone) {
888+
return ZoneId.of(zone);
889+
}
890+
891+
@TruffleBoundary
892+
private LocalTime createLocalTime(int hour, int min, int sec, int micro) {
893+
return LocalTime.of(hour, min, sec, micro);
894+
}
895+
896+
@TruffleBoundary
897+
private LocalDate createLocalDate(int year, int month, int day) {
898+
return LocalDate.of(year, month, day);
899+
}
900+
881901
@GenerateUncached
882902
public abstract static class PKeyInfoNode extends Node {
883903
private static final int NONE = 0;

0 commit comments

Comments
 (0)