[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 1/3] Remove include xalloc.h from libpoke/pkl-env.c
From: |
Tim Rühsen |
Subject: |
[PATCH 1/3] Remove include xalloc.h from libpoke/pkl-env.c |
Date: |
Sat, 16 May 2020 18:23:35 +0200 |
2020-05-16 Tim Rühsen <address@hidden>
* libpoke/pkl-env.c: Remove include xalloc.h.
(pkl_env_new): Use calloc instead of xzalloc.
(pkl_env_push_frame): Check for allocation failure.
(pkl_env_dup_toplevel): Likewise.
* libpoke/pkl-tab.y: Likewise.
* libpoke/pkl.c (pkl_execute_buffer): Likewise.
(pkl_execute_statement): Likewise.
(pkl_compile_expression): Likewise.
(pkl_execute_expression): Likewise.
(pkl_execute_file): Likewise.
---
ChangeLog | 13 +++++++++++++
jitter | 2 +-
libpoke/pkl-env.c | 9 ++++++---
libpoke/pkl-tab.y | 2 ++
libpoke/pkl.c | 11 +++++++++++
5 files changed, 33 insertions(+), 4 deletions(-)
diff --git a/jitter b/jitter
index c3cfd9c4..bdfaf90d 160000
--- a/jitter
+++ b/jitter
@@ -1 +1 @@
-Subproject commit c3cfd9c4fd806725307c7c5920797035ef4892d2
+Subproject commit bdfaf90d73d141f30c2faaf46c8c557309e8b3cd
diff --git a/libpoke/pkl-env.c b/libpoke/pkl-env.c
index e1a74d42..d538a7c1 100644
--- a/libpoke/pkl-env.c
+++ b/libpoke/pkl-env.c
@@ -19,7 +19,6 @@
#include <config.h>
#include <stdlib.h>
-#include <xalloc.h>
#include <string.h>
#include <assert.h>
@@ -159,7 +158,7 @@ get_ns_table (pkl_env env, int namespace)
pkl_env
pkl_env_new ()
{
- return xzalloc (sizeof (struct pkl_env));
+ return calloc (1, sizeof (struct pkl_env));
}
void
@@ -179,7 +178,9 @@ pkl_env_push_frame (pkl_env env)
{
pkl_env frame = pkl_env_new ();
- frame->up = env;
+ if (frame)
+ frame->up = env;
+
return frame;
}
@@ -325,6 +326,8 @@ pkl_env_dup_toplevel (pkl_env env)
assert (pkl_env_toplevel_p (env));
new = pkl_env_new ();
+ if (!new)
+ return NULL;
for (i = 0; i < HASH_TABLE_SIZE; ++i)
{
diff --git a/libpoke/pkl-tab.y b/libpoke/pkl-tab.y
index 23c1fd8a..9ef6519e 100644
--- a/libpoke/pkl-tab.y
+++ b/libpoke/pkl-tab.y
@@ -414,6 +414,8 @@ pushlevel:
%empty
{
pkl_parser->env = pkl_env_push_frame (pkl_parser->env);
+ if (!pkl_parser->env)
+ YYERROR;
}
;
diff --git a/libpoke/pkl.c b/libpoke/pkl.c
index 46336f79..eb41c499 100644
--- a/libpoke/pkl.c
+++ b/libpoke/pkl.c
@@ -280,6 +280,8 @@ pkl_execute_buffer (pkl_compiler compiler,
compiler->compiling = PKL_COMPILING_PROGRAM;
env = pkl_env_dup_toplevel (compiler->env);
+ if (!env)
+ goto error;
/* Parse the input routine into an AST. */
ret = pkl_parse_buffer (compiler, &env, &ast,
@@ -331,6 +333,8 @@ pkl_execute_statement (pkl_compiler compiler,
compiler->compiling = PKL_COMPILING_STATEMENT;
env = pkl_env_dup_toplevel (compiler->env);
+ if (!env)
+ goto error;
/* Parse the input routine into an AST. */
ret = pkl_parse_buffer (compiler, &env, &ast,
@@ -374,6 +378,8 @@ pkl_compile_expression (pkl_compiler compiler,
compiler->compiling = PKL_COMPILING_EXPRESSION;
env = pkl_env_dup_toplevel (compiler->env);
+ if (!env)
+ goto error;
/* Parse the input program into an AST. */
ret = pkl_parse_buffer (compiler, &env, &ast,
@@ -413,6 +419,8 @@ pkl_execute_expression (pkl_compiler compiler,
compiler->compiling = PKL_COMPILING_EXPRESSION;
env = pkl_env_dup_toplevel (compiler->env);
+ if (!env)
+ goto error;
/* Parse the input routine into an AST. */
ret = pkl_parse_buffer (compiler, &env, &ast,
@@ -464,6 +472,9 @@ pkl_execute_file (pkl_compiler compiler, const char *fname)
}
env = pkl_env_dup_toplevel (compiler->env);
+ if (!env)
+ goto error;
+
ret = pkl_parse_file (compiler, &env, &ast, fp, fname);
if (ret == 1)
/* Parse error. */
--
2.26.2
- [PATCH 1/3] Remove include xalloc.h from libpoke/pkl-env.c,
Tim Rühsen <=