Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions pineforge_codegen/codegen/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,12 @@ def tz_time_field_lambda(field_expr: str, ts_arg: str, tz_arg: str) -> str:
# ``_bar_hour()`` helpers. For UTC-exchange data (the crypto corpus,
# SymInfo's constructor default) the lambda takes the gmtime_r fast
# path and is value-identical to the old emission.
# Route through the engine's cached pine_hour/pine_minute/... (session_time.hpp)
# instead of an inline per-call setenv+tzset lambda — the lambda's TZ churn
# caused a macOS tzset()->notifyd IPC storm (KI-35). The engine helpers are
# value-identical (same tm fields + Pine offsets) but tzset-churn-free.
**{
name: tz_time_field_lambda(
TIME_FIELD_EXPRS[name], "current_bar_.timestamp", "syminfo_.timezone"
)
name: f"pine_{name}(current_bar_.timestamp, syminfo_.timezone)"
for name in ("hour", "minute", "second", "dayofmonth", "dayofweek",
"month", "year", "weekofyear")
},
Expand Down
11 changes: 6 additions & 5 deletions pineforge_codegen/codegen/visit_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,11 +715,12 @@ def _visit_func_call(self, node: FuncCall) -> str:
# mutex-guarded setenv+localtime_r block as the 2-arg
# form.
tz_arg = "syminfo_.timezone"
# 2-arg form — honor the tz argument. The shared
# ``tz_time_field_lambda`` (codegen/tables.py) also backs the
# bare variable forms (``hour`` etc. via BAR_BUILTINS), so the
# numbers agree across both forms.
return tz_time_field_lambda(field_expr, ts_arg, tz_arg)
# Route through the engine's cached pine_<field>() (session_time.hpp),
# same as the bare variable forms (BAR_BUILTINS) — value-identical but
# free of the per-call setenv+tzset churn (KI-35). field_expr is unused
# now (the engine applies the Pine offsets internally).
del field_expr
return f"pine_{func_name}((int64_t)({ts_arg}), {tz_arg})"

# time(timeframe) or time(timeframe, session[, tz])
if func_name == "time" and namespace is None and (node.args or node.kwargs):
Expand Down
Loading