aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
authorTom Tromey2013-08-19 21:53:07 -0600
committerTom Tromey2013-08-19 21:53:07 -0600
commit6d75555c5cc3d2a629646cee7629e67530fa7a36 (patch)
tree3852804dd234ad613ea8691332e10b92c027e87d /src/alloc.c
parentcc231cbe45d27a1906d268fb72d3b4105a2e9c65 (diff)
parent8c2f38aaab7a7a2f0605416fc2ee38701e41ab61 (diff)
downloademacs-6d75555c5cc3d2a629646cee7629e67530fa7a36.tar.gz
emacs-6d75555c5cc3d2a629646cee7629e67530fa7a36.zip
merge from trunk
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/src/alloc.c b/src/alloc.c
index 0eb54f8b271..4cc9b3e1a13 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -788,10 +788,19 @@ xpalloc (void *pa, ptrdiff_t *nitems, ptrdiff_t nitems_incr_min,
788char * 788char *
789xstrdup (const char *s) 789xstrdup (const char *s)
790{ 790{
791 size_t len = strlen (s) + 1; 791 ptrdiff_t size;
792 char *p = xmalloc (len); 792 eassert (s);
793 memcpy (p, s, len); 793 size = strlen (s) + 1;
794 return p; 794 return memcpy (xmalloc (size), s, size);
795}
796
797/* Like above, but duplicates Lisp string to C string. */
798
799char *
800xlispstrdup (Lisp_Object string)
801{
802 ptrdiff_t size = SBYTES (string) + 1;
803 return memcpy (xmalloc (size), SSDATA (string), size);
795} 804}
796 805
797/* Like putenv, but (1) use the equivalent of xmalloc and (2) the 806/* Like putenv, but (1) use the equivalent of xmalloc and (2) the
@@ -4057,7 +4066,7 @@ live_string_p (struct mem_node *m, void *p)
4057{ 4066{
4058 if (m->type == MEM_TYPE_STRING) 4067 if (m->type == MEM_TYPE_STRING)
4059 { 4068 {
4060 struct string_block *b = (struct string_block *) m->start; 4069 struct string_block *b = m->start;
4061 ptrdiff_t offset = (char *) p - (char *) &b->strings[0]; 4070 ptrdiff_t offset = (char *) p - (char *) &b->strings[0];
4062 4071
4063 /* P must point to the start of a Lisp_String structure, and it 4072 /* P must point to the start of a Lisp_String structure, and it
@@ -4080,7 +4089,7 @@ live_cons_p (struct mem_node *m, void *p)
4080{ 4089{
4081 if (m->type == MEM_TYPE_CONS) 4090 if (m->type == MEM_TYPE_CONS)
4082 { 4091 {
4083 struct cons_block *b = (struct cons_block *) m->start; 4092 struct cons_block *b = m->start;
4084 ptrdiff_t offset = (char *) p - (char *) &b->conses[0]; 4093 ptrdiff_t offset = (char *) p - (char *) &b->conses[0];
4085 4094
4086 /* P must point to the start of a Lisp_Cons, not be 4095 /* P must point to the start of a Lisp_Cons, not be
@@ -4106,7 +4115,7 @@ live_symbol_p (struct mem_node *m, void *p)
4106{ 4115{
4107 if (m->type == MEM_TYPE_SYMBOL) 4116 if (m->type == MEM_TYPE_SYMBOL)
4108 { 4117 {
4109 struct symbol_block *b = (struct symbol_block *) m->start; 4118 struct symbol_block *b = m->start;
4110 ptrdiff_t offset = (char *) p - (char *) &b->symbols[0]; 4119 ptrdiff_t offset = (char *) p - (char *) &b->symbols[0];
4111 4120
4112 /* P must point to the start of a Lisp_Symbol, not be 4121 /* P must point to the start of a Lisp_Symbol, not be
@@ -4132,7 +4141,7 @@ live_float_p (struct mem_node *m, void *p)
4132{ 4141{
4133 if (m->type == MEM_TYPE_FLOAT) 4142 if (m->type == MEM_TYPE_FLOAT)
4134 { 4143 {
4135 struct float_block *b = (struct float_block *) m->start; 4144 struct float_block *b = m->start;
4136 ptrdiff_t offset = (char *) p - (char *) &b->floats[0]; 4145 ptrdiff_t offset = (char *) p - (char *) &b->floats[0];
4137 4146
4138 /* P must point to the start of a Lisp_Float and not be 4147 /* P must point to the start of a Lisp_Float and not be
@@ -4156,7 +4165,7 @@ live_misc_p (struct mem_node *m, void *p)
4156{ 4165{
4157 if (m->type == MEM_TYPE_MISC) 4166 if (m->type == MEM_TYPE_MISC)
4158 { 4167 {
4159 struct marker_block *b = (struct marker_block *) m->start; 4168 struct marker_block *b = m->start;
4160 ptrdiff_t offset = (char *) p - (char *) &b->markers[0]; 4169 ptrdiff_t offset = (char *) p - (char *) &b->markers[0];
4161 4170
4162 /* P must point to the start of a Lisp_Misc, not be 4171 /* P must point to the start of a Lisp_Misc, not be
@@ -4183,7 +4192,7 @@ live_vector_p (struct mem_node *m, void *p)
4183 if (m->type == MEM_TYPE_VECTOR_BLOCK) 4192 if (m->type == MEM_TYPE_VECTOR_BLOCK)
4184 { 4193 {
4185 /* This memory node corresponds to a vector block. */ 4194 /* This memory node corresponds to a vector block. */
4186 struct vector_block *block = (struct vector_block *) m->start; 4195 struct vector_block *block = m->start;
4187 struct Lisp_Vector *vector = (struct Lisp_Vector *) block->data; 4196 struct Lisp_Vector *vector = (struct Lisp_Vector *) block->data;
4188 4197
4189 /* P is in the block's allocation range. Scan the block 4198 /* P is in the block's allocation range. Scan the block