Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 25 Mar 2015 06:34:02 +0000 (UTC)
From:      Rui Paulo <rpaulo@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r280491 - projects/lua-bootloader/sys/boot/liblua
Message-ID:  <201503250634.t2P6Y2sF071352@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: rpaulo
Date: Wed Mar 25 06:34:01 2015
New Revision: 280491
URL: https://svnweb.freebsd.org/changeset/base/280491

Log:
  Fix several parts of lstd/lutils to be WARNS=3 compliant.
  
  Bring a several libc string functions which should probably live in
  libstand, but we're keeping everything in liblua for now.

Modified:
  projects/lua-bootloader/sys/boot/liblua/Makefile
  projects/lua-bootloader/sys/boot/liblua/lstd.c
  projects/lua-bootloader/sys/boot/liblua/lstd.h
  projects/lua-bootloader/sys/boot/liblua/lutils.c
  projects/lua-bootloader/sys/boot/liblua/lutils.h

Modified: projects/lua-bootloader/sys/boot/liblua/Makefile
==============================================================================
--- projects/lua-bootloader/sys/boot/liblua/Makefile	Wed Mar 25 06:10:41 2015	(r280490)
+++ projects/lua-bootloader/sys/boot/liblua/Makefile	Wed Mar 25 06:34:01 2015	(r280491)
@@ -14,6 +14,8 @@ SRCS=	lapi.c lcode.c lctype.c ldebug.c l
 # Our utilities.
 SRCS+=	lstd.c lutils.c
 
+WARNS=	3
+
 CFLAGS+= -I${.CURDIR} -DBOOT_LUA -ffreestanding -nostdlib -fno-stack-protector
 CFLAGS+= -I${LUA_PATH}
 

Modified: projects/lua-bootloader/sys/boot/liblua/lstd.c
==============================================================================
--- projects/lua-bootloader/sys/boot/liblua/lstd.c	Wed Mar 25 06:10:41 2015	(r280490)
+++ projects/lua-bootloader/sys/boot/liblua/lstd.c	Wed Mar 25 06:34:01 2015	(r280491)
@@ -1,4 +1,38 @@
 /*-
+ * Copyright (c) 1985, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+/*-
  * Copyright (c) 2014 Pedro Souza <pedrosouza@freebsd.org>
  * All rights reserved.
  *
@@ -46,19 +80,21 @@ floor(double v)
 	return ((double)a);
 }
 
+/*
+ * Find the first occurrence in s1 of a character in s2 (excluding NUL).
+ */
 char *
-strpbrk (const char *str1, const char *str2)
+strpbrk(const char *s1, const char *s2)
 {
-	while (*str1)
-	{
-		const char *tmp = str2;
-		while (*tmp)
-			if (*str1 == *tmp++)
-				return (str1);
-		++str1;
-	}
+	const char *scanp;
+	int c, sc;
 
-	return (0);
+	while ((c = *s1++) != 0) {
+		for (scanp = s2; (sc = *scanp++) != '\0';)
+			if (sc == c)
+				return ((char *)(s1 - 1));
+	}
+	return (NULL);
 }
 
 double
@@ -362,37 +398,36 @@ getc(FILE *stream)
 	return EOF;
 }
 
+/*
+ * Find the first occurrence of find in s.
+ */
 char *
-strstr(const char *str1, const char *str2)
+strstr(const char *s, const char *find)
 {
-	const char	*s1 = str1;
-	const char	*s2 = str2;
-	int		eq = 0;
+	char c, sc;
+	size_t len;
 
-	while (*s1)
-	{
-		while (*s2 && *s1)
-		{
-			if (*s2 != *s1)
-				break;
-			s1++; s2++;
-		}
-		if (*s2 == NULL)
-			return (char*)str1;
-		if (*s1 == NULL)
-			return NULL;
-		s1 = ++str1;
-		s2 = str2;
+	if ((c = *find++) != '\0') {
+		len = strlen(find);
+		do {
+			do {
+				if ((sc = *s++) == '\0')
+					return (NULL);
+			} while (sc != c);
+		} while (strncmp(s, find, len) != 0);
+		s--;
 	}
-	return NULL;
+	return ((char *)s);
 }
 
+#if 0
 void
 luai_writestring(const char *s, int i)
 {
 	while (i-- > 0)
 		putchar(*s++);
 }
+#endif
 
 int
 iscntrl(int c)
@@ -414,16 +449,17 @@ ispunct(int c)
 }
 
 void *
-memchr(const void *ptr, int value, size_t num)
+memchr(const void *s, int c, size_t n)
 {
-	const unsigned char * str = (const unsigned char*)ptr;
-	const unsigned char * end = (const unsigned char*)ptr + num;
-	while (str < end)
-	{
-		if (*str == (unsigned char)value) return str;
-		++str;
+	if (n != 0) {
+		const unsigned char *p = s;
+
+		do {
+			if (*p++ == (unsigned char)c)
+				return ((void *)(p - 1));
+		} while (--n != 0);
 	}
-	return NULL;
+	return (NULL);
 }
 
 #endif /* BOOT_LUA */

Modified: projects/lua-bootloader/sys/boot/liblua/lstd.h
==============================================================================
--- projects/lua-bootloader/sys/boot/liblua/lstd.h	Wed Mar 25 06:10:41 2015	(r280490)
+++ projects/lua-bootloader/sys/boot/liblua/lstd.h	Wed Mar 25 06:34:01 2015	(r280491)
@@ -33,15 +33,11 @@
 
 #include <stand.h>
 #include <sys/types.h>
-#include <sys/stddef.h>
 #include <sys/stdint.h>
 #include <limits.h>
 #include <string.h>
 #include <machine/stdarg.h>
 
-
-typedef __ptrdiff_t ptrdiff_t;
-
 typedef struct FILE
 {
 	int fd;

Modified: projects/lua-bootloader/sys/boot/liblua/lutils.c
==============================================================================
--- projects/lua-bootloader/sys/boot/liblua/lutils.c	Wed Mar 25 06:10:41 2015	(r280490)
+++ projects/lua-bootloader/sys/boot/liblua/lutils.c	Wed Mar 25 06:34:01 2015	(r280491)
@@ -30,11 +30,17 @@ __FBSDID("$FreeBSD$");
 
 #include <src/lua.h>
 #include <lstd.h>
+#include <lutils.h>
+
+/* XXX this needs to be fixed */
+extern void parse(int *, char ***, const char *);
+extern int perform(int, char **);
+extern void delay(int);
 
 int
 lua_perform(lua_State *L)
 {
-	int	argc, ret;
+	int	argc;
 	char	**argv;
 	int	res = -1;
 	int	n = lua_gettop(L);
@@ -56,7 +62,8 @@ lua_getchar(lua_State *L)
 	return 1;
 }
 
-int lua_ischar(lua_State *L)
+int
+lua_ischar(lua_State *L)
 {
 	lua_pushboolean(L, ischar());
 	return 1;
@@ -127,7 +134,7 @@ typedef struct data_chunk
 	size_t size;
 } data_chunk;
 
-const char *
+static const char *
 read_chunk(lua_State *L, void *chunk, size_t *sz)
 {
 	data_chunk * ds = (data_chunk *)chunk;
@@ -220,9 +227,6 @@ int
 lua_openfile(lua_State *L)
 {
 	const char	*str;
-	int		fd;
-	int		r;
-	struct stat	st;
 
 	if (lua_gettop(L) != 1)
 	{
@@ -326,7 +330,7 @@ typedef struct utils_func
 	const char *name;
 } utils_func;
 
-utils_func reg_funcs[] = {
+static utils_func reg_funcs[] = {
 			{lua_perform, "loader", "perform"},
 			{lua_delay, "loader", "delay"},
 			{lua_time, "loader", "time"},

Modified: projects/lua-bootloader/sys/boot/liblua/lutils.h
==============================================================================
--- projects/lua-bootloader/sys/boot/liblua/lutils.h	Wed Mar 25 06:10:41 2015	(r280490)
+++ projects/lua-bootloader/sys/boot/liblua/lutils.h	Wed Mar 25 06:34:01 2015	(r280491)
@@ -30,16 +30,20 @@
 
 #define lua_create() lua_newstate(lua_realloc, NULL)
 
-int lua_print(lua_State *L);
-
-int lua_perform(lua_State *L);
-
-void * lua_realloc(void *ud, void *ptr, size_t osize, size_t nsize);
-
-int ldo_string(lua_State *L, const char *str, size_t size);
-
-int ldo_file(lua_State *L, const char *filename);
-
-void lregister(const char *tname, const char *fname, int (*fptr)(lua_State *));
-
-void register_utils(lua_State *L);
+int	 lua_perform(lua_State *);
+int	 lua_print(lua_State *);
+int	 lua_getchar(lua_State *);
+int	 lua_ischar(lua_State *);
+int	 lua_gets(lua_State *);
+int	 lua_time(lua_State *);
+int	 lua_delay(lua_State *);
+int	 lua_getenv(lua_State *);
+void 	*lua_realloc(void *, void *, size_t, size_t);
+int	 ldo_string(lua_State *, const char *, size_t);
+int	 ldo_file(lua_State *, const char *);
+int	 lua_include(lua_State *);
+int	 lua_openfile(lua_State *);
+int	 lua_closefile(lua_State *L);
+int	 lua_readfile(lua_State *L);
+void	 lregister(lua_State *, const char *, const char *, int (*fptr)(lua_State *));
+void	 register_utils(lua_State *);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201503250634.t2P6Y2sF071352>