Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use localtime_r instead of localtime #381

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion sources/system/unix-date-interface.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ define method native-clock-to-tm (time :: <machine-word>) => (tm :: <machine-wor
:= primitive-unwrap-machine-word(time);
let tm = primitive-wrap-machine-word
(primitive-cast-pointer-as-raw
(%call-c-function ("localtime")
(%call-c-function ("system_localtime")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use with-storage ... you can get the size from a call into C, I guess (or another magic constant), but a define constant $tm-size = primitive-whatever(%call-c-function("dylan_sizeof_tm") ... ); shouldn't be that bad.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(And I know that with-storage uses GC_malloc ... that's something that will change later.)

(time :: <raw-c-pointer>) => (tm :: <raw-c-pointer>)
(primitive-cast-raw-as-pointer(primitive-unwrap-machine-word(timeloc)))
end));
Expand Down
7 changes: 7 additions & 0 deletions sources/system/unix-portability.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <signal.h>
#include <errno.h>
#include <dlfcn.h>
#include <time.h>

#ifdef __APPLE__
#include <crt_externs.h>
Expand All @@ -15,6 +16,12 @@ char **system_environ(void)
return environ;
}

struct tm *system_localtime(const time_t *timep)
{
struct tm *res = GC_malloc(sizeof(struct tm));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if we keep this style of code, we shouldn't be doing this GC_malloc thing since we don't just support Boehm ... this is on my list of things to address globally one day (soon).

return localtime_r(timep, res);
}

/* Adapted from the SBCL run-time system, which in turn is derived
* from the CMU CL system, which was written at Carnegie Mellon
* University and released into the public domain.
Expand Down