Skip to content

Commit d43b3ee

Browse files
committed
Fix build with PyPy 5.9.0-alpha0 in libpython mode
Signed-off-by: Viacheslav Naydenov <vaclav@yandex.ru>
1 parent 3243261 commit d43b3ee

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

src/IntervalVar.c

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,22 @@ static udt_VariableType vt_Interval = {
3838
};
3939

4040

41+
// PyPy compatibility {
42+
43+
#ifndef PyDateTime_DELTA_GET_DAYS
44+
#define PyDateTime_DELTA_GET_DAYS(x) ((x)->days)
45+
#endif
46+
47+
#ifndef PyDateTime_DELTA_GET_SECONDS
48+
#define PyDateTime_DELTA_GET_SECONDS(x) ((x)->seconds)
49+
#endif
50+
51+
#ifndef PyDateTime_DELTA_GET_MICROSECONDS
52+
#define PyDateTime_DELTA_GET_MICROSECONDS(x) ((x)->microseconds)
53+
#endif
54+
55+
// }
56+
4157
//-----------------------------------------------------------------------------
4258
// IntervalVar_SetValue()
4359
// Set the value of the variable.
@@ -47,19 +63,21 @@ static int IntervalVar_SetValue(udt_Variable *var, uint32_t pos, dpiData *data,
4763
{
4864
dpiIntervalDS *interval;
4965
PyDateTime_Delta *delta;
66+
int32_t delta_seconds;
5067

5168
if (!PyDelta_Check(value)) {
5269
PyErr_SetString(PyExc_TypeError, "expecting timedelta data");
5370
return -1;
5471
}
5572
delta = (PyDateTime_Delta*) value;
5673
interval = &data->value.asIntervalDS;
57-
interval->days = delta->days;
58-
interval->hours = (int32_t) delta->seconds / 3600;
59-
interval->seconds = delta->seconds - interval->hours * 3600;
60-
interval->minutes = (int32_t) interval->seconds / 60;
61-
interval->seconds -= interval->minutes * 60;
62-
interval->fseconds = delta->microseconds * 1000;
74+
delta_seconds = PyDateTime_DELTA_GET_SECONDS(delta);
75+
interval->days = PyDateTime_DELTA_GET_DAYS(delta);
76+
interval->hours = delta_seconds / 3600;
77+
interval->seconds = delta_seconds % 3600;
78+
interval->minutes = interval->seconds / 60;
79+
interval->seconds = interval->seconds % 60;
80+
interval->fseconds = PyDateTime_DELTA_GET_MICROSECONDS(delta) * 1000;
6381
return 0;
6482
}
6583

0 commit comments

Comments
 (0)