[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] lib/m2: SYS_gettimeofday expects pointers
From: |
Janneke Nieuwenhuizen |
Subject: |
Re: [PATCH] lib/m2: SYS_gettimeofday expects pointers |
Date: |
Tue, 24 Jan 2023 08:15:23 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) |
Meghan Denny writes:
Hello Meghan,
> As this is my first email to the list I wanted to start off by saying
> thanks for all this great work.
It's a pleasure, well most of the time :-) Glad you like it.
> While working on a project of my own I came across the wip-x86_64
> branch and discovered the attached patch and wanted to send it along
> in case it helped out.
Thanks for the patch, it does not work for me however.
Mes uses M2-Planet 1.10.0:
$ guix shell
guix shell: loading environment from
'/home/janneke/src/mes/wip-x86_64/guix.scm'...
07:28:13 janneke@drakenpad:~/src/mes/wip-x86_64 [env]
$ M2-Planet --version
M2-Planet v1.10.0
$ git am 0001-lib-m2-SYS_gettimeofday-expects-pointers.patch
Applying: lib/m2: SYS_gettimeofday expects pointers
07:28:41 janneke@drakenpad:~/src/mes/wip-x86_64 [env]
$ kaem
>>WARNING<<
>>WARNING<<
include/time.h:25:feature: #include_next unsupported in M2-Planet
[..]
lib/m2/time.c:35:ERROR in statement
MISSING ;
Subprocess error 1
ABORTING HARD
[1]07:28:45 janneke@drakenpad:~/src/mes/wip-x86_64 [env]
Is it for a newer version of M2-Planet? AFAIK, M2-Planet cannot not
allocate data for structs without using `malloc', so the current code
leads to a segfault. So, thanks for pointing this out. I'm now using
the attached patch.
Thanks!
Janneke
>From ee352a7b5c8ce40e3661bddf50e8d5c72d98017d Mon Sep 17 00:00:00 2001
From: "Jan (janneke) Nieuwenhuizen" <janneke@gnu.org>
Date: Tue, 24 Jan 2023 07:59:49 +0100
Subject: [PATCH] DRAFT lib/m2: time: Fix segfault by allocating timeval
struct.
Suggested by Meghan Denny <hello@nektro.net>.
* lib/m2/time.c (__tv): New global variable.
(time): Use it to allocate timeval struct.
---
lib/m2/time.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/lib/m2/time.c b/lib/m2/time.c
index c589de85..45ae1afb 100644
--- a/lib/m2/time.c
+++ b/lib/m2/time.c
@@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
- * Copyright © 2018,2019,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
+ * Copyright © 2018,2019,2022,2023 Jan (janneke) Nieuwenhuizen
<janneke@gnu.org>
*
* This file is part of GNU Mes.
*
@@ -22,13 +22,16 @@
#include <syscall.h>
#include <time.h>
+char *__tv;
+
long
time (long* result)
{
int r;
- struct timeval tv;
- struct timezone tz;
- r = _sys_call2 (SYS_gettimeofday, tv, tz);
+ if (__tv == 0)
+ __tv = malloc (sizeof (struct timeval));
+ struct timeval *tv = __tv;
+ r = _sys_call2 (SYS_gettimeofday, tv, 0);
if (r != 0)
return -1;
if (result != 0)
--
2.38.1
--
Janneke Nieuwenhuizen <janneke@gnu.org> | GNU LilyPond https://LilyPond.org
Freelance IT https://www.JoyOfSource.com | Avatar® https://AvatarAcademy.com