aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
authorAndrea Corallo2021-02-21 22:08:01 +0100
committerAndrea Corallo2021-02-21 22:08:01 +0100
commitcf1e8e792f60949e09e3ad4c53fb61b0b7628229 (patch)
tree35080229c9e3b46e5db14a2f051c001ab8c6e586 /src/alloc.c
parent39792cf62987ecc1a772f6a2027d6b32c70e8312 (diff)
parentd0c47652e527397cae96444c881bf60455c763c1 (diff)
downloademacs-cf1e8e792f60949e09e3ad4c53fb61b0b7628229.tar.gz
emacs-cf1e8e792f60949e09e3ad4c53fb61b0b7628229.zip
Merge remote-tracking branch 'savannah/master' into HEAD
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/alloc.c b/src/alloc.c
index 0ed5b9346f6..af083361770 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -3519,6 +3519,38 @@ usage: (make-byte-code ARGLIST BYTE-CODE CONSTANTS DEPTH &optional DOCSTRING INT
3519 return val; 3519 return val;
3520} 3520}
3521 3521
3522DEFUN ("make-closure", Fmake_closure, Smake_closure, 1, MANY, 0,
3523 doc: /* Create a byte-code closure from PROTOTYPE and CLOSURE-VARS.
3524Return a copy of PROTOTYPE, a byte-code object, with CLOSURE-VARS
3525replacing the elements in the beginning of the constant-vector.
3526usage: (make-closure PROTOTYPE &rest CLOSURE-VARS) */)
3527 (ptrdiff_t nargs, Lisp_Object *args)
3528{
3529 Lisp_Object protofun = args[0];
3530 CHECK_TYPE (COMPILEDP (protofun), Qbyte_code_function_p, protofun);
3531
3532 /* Create a copy of the constant vector, filling it with the closure
3533 variables in the beginning. (The overwritten part should just
3534 contain placeholder values.) */
3535 Lisp_Object proto_constvec = AREF (protofun, COMPILED_CONSTANTS);
3536 ptrdiff_t constsize = ASIZE (proto_constvec);
3537 ptrdiff_t nvars = nargs - 1;
3538 if (nvars > constsize)
3539 error ("Closure vars do not fit in constvec");
3540 Lisp_Object constvec = make_uninit_vector (constsize);
3541 memcpy (XVECTOR (constvec)->contents, args + 1, nvars * word_size);
3542 memcpy (XVECTOR (constvec)->contents + nvars,
3543 XVECTOR (proto_constvec)->contents + nvars,
3544 (constsize - nvars) * word_size);
3545
3546 /* Return a copy of the prototype function with the new constant vector. */
3547 ptrdiff_t protosize = PVSIZE (protofun);
3548 struct Lisp_Vector *v = allocate_vectorlike (protosize, false);
3549 v->header = XVECTOR (protofun)->header;
3550 memcpy (v->contents, XVECTOR (protofun)->contents, protosize * word_size);
3551 v->contents[COMPILED_CONSTANTS] = constvec;
3552 return make_lisp_ptr (v, Lisp_Vectorlike);
3553}
3522 3554
3523 3555
3524/*********************************************************************** 3556/***********************************************************************
@@ -7605,6 +7637,7 @@ N should be nonnegative. */);
7605 defsubr (&Srecord); 7637 defsubr (&Srecord);
7606 defsubr (&Sbool_vector); 7638 defsubr (&Sbool_vector);
7607 defsubr (&Smake_byte_code); 7639 defsubr (&Smake_byte_code);
7640 defsubr (&Smake_closure);
7608 defsubr (&Smake_list); 7641 defsubr (&Smake_list);
7609 defsubr (&Smake_vector); 7642 defsubr (&Smake_vector);
7610 defsubr (&Smake_record); 7643 defsubr (&Smake_record);