summaryrefslogtreecommitdiff
path: root/scope.h
diff options
context:
space:
mode:
authorAlbert Dvornik <bert@genscan.com>1998-09-17 15:23:07 -0400
committerGurusamy Sarathy <gsar@cpan.org>1998-09-23 10:41:39 +0000
commit455ece5e082708b1bd94cff001612bd4efb4d2e9 (patch)
treee6679b1c862a8bfef5d2dcca86151ec7f7d39148 /scope.h
parent9ad0a0f606dfe6bb2ec67942ae23eef93c8ce770 (diff)
downloadperl-455ece5e082708b1bd94cff001612bd4efb4d2e9.tar.gz
SSNEW() API for allocating memory on the savestack
Message-Id: <tqemtae338.fsf@puma.genscan.com> Subject: [PATCH 5.005_51] (was: why SAVEDESTRUCTOR()...) p4raw-id: //depot/perl@1852
Diffstat (limited to 'scope.h')
-rw-r--r--scope.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/scope.h b/scope.h
index 0dde4e12a0..a9d4ba33e3 100644
--- a/scope.h
+++ b/scope.h
@@ -26,6 +26,7 @@
#define SAVEt_HELEM 25
#define SAVEt_OP 26
#define SAVEt_HINTS 27
+#define SAVEt_ALLOC 28
#define SSCHECK(need) if (PL_savestack_ix + need > PL_savestack_max) savestack_grow()
#define SSPUSHINT(i) (PL_savestack[PL_savestack_ix++].any_i32 = (I32)(i))
@@ -110,6 +111,23 @@
} \
} STMT_END
+/* SSNEW() temporarily allocates a specified number of bytes of data on the
+ * savestack. It returns an integer index into the savestack, because a
+ * pointer would get broken if the savestack is moved on reallocation.
+ * SSNEWa() works like SSNEW(), but also aligns the data to the specified
+ * number of bytes. MEM_ALIGNBYTES is perhaps the most useful. The
+ * alignment will be preserved therough savestack reallocation *only* if
+ * realloc returns data aligned to a size divisible by `align'!
+ *
+ * SSPTR() converts the index returned by SSNEW/SSNEWa() into a pointer.
+ */
+
+#define SSNEW(size) save_alloc(size, 0)
+#define SSNEWa(size,align) save_alloc(size, \
+ (align - ((int)((caddr_t)&PL_savestack[PL_savestack_ix]) % align)) % align)
+
+#define SSPTR(off,type) ((type) ((char*)PL_savestack + off))
+
/* A jmpenv packages the state required to perform a proper non-local jump.
* Note that there is a start_env initialized when perl starts, and top_env
* points to this initially, so top_env should always be non-null.