diff options
| author | Stefan Monnier | 2022-01-28 13:19:11 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2022-01-28 13:19:11 -0500 |
| commit | 7531bf096eb3f1b0b6612e94eb5211405e049fee (patch) | |
| tree | 387cb37020e6256d7491f9407f8f844de90de6be /src/eval.c | |
| parent | 1f5fa1de7fc2f23ebd7e68db219da4faee916a6f (diff) | |
| download | emacs-7531bf096eb3f1b0b6612e94eb5211405e049fee.tar.gz emacs-7531bf096eb3f1b0b6612e94eb5211405e049fee.zip | |
Reduce code duplication in parts of (auto)load&defalias
* src/data.c (defalias): New function, extracted from `Fdefalias`.
(Fdefalias): Use it.
(Ffset): Don't handle `Vautoload_queue` here, handle it in
`defalias` instead.
* src/comp.c (comp--register-subr): Use `defalias` instead of
duplicating its code.
* src/eval.c (load_with_autoload_queue): New function, extracted from
`Fautoload_do_load`.
(Fautoload_do_load): Use it.
(un_autoload): Mark it as static.
* src/fns.c (Frequire): Use it as well.
* src/lisp.h (defalias, load_with_autoload_queue): New declarations.
(un_autoload): Remove declaration.
Diffstat (limited to 'src/eval.c')
| -rw-r--r-- | src/eval.c | 46 |
1 files changed, 28 insertions, 18 deletions
diff --git a/src/eval.c b/src/eval.c index 205a0b0db2a..b083a00a791 100644 --- a/src/eval.c +++ b/src/eval.c | |||
| @@ -2247,7 +2247,7 @@ this does nothing and returns nil. */) | |||
| 2247 | Qnil); | 2247 | Qnil); |
| 2248 | } | 2248 | } |
| 2249 | 2249 | ||
| 2250 | void | 2250 | static void |
| 2251 | un_autoload (Lisp_Object oldqueue) | 2251 | un_autoload (Lisp_Object oldqueue) |
| 2252 | { | 2252 | { |
| 2253 | Lisp_Object queue, first, second; | 2253 | Lisp_Object queue, first, second; |
| @@ -2269,6 +2269,32 @@ un_autoload (Lisp_Object oldqueue) | |||
| 2269 | } | 2269 | } |
| 2270 | } | 2270 | } |
| 2271 | 2271 | ||
| 2272 | Lisp_Object | ||
| 2273 | load_with_autoload_queue | ||
| 2274 | (Lisp_Object file, Lisp_Object noerror, Lisp_Object nomessage, | ||
| 2275 | Lisp_Object nosuffix, Lisp_Object must_suffix) | ||
| 2276 | { | ||
| 2277 | ptrdiff_t count = SPECPDL_INDEX (); | ||
| 2278 | |||
| 2279 | /* If autoloading gets an error (which includes the error of failing | ||
| 2280 | to define the function being called), we use Vautoload_queue | ||
| 2281 | to undo function definitions and `provide' calls made by | ||
| 2282 | the function. We do this in the specific case of autoloading | ||
| 2283 | because autoloading is not an explicit request "load this file", | ||
| 2284 | but rather a request to "call this function". | ||
| 2285 | |||
| 2286 | The value saved here is to be restored into Vautoload_queue. */ | ||
| 2287 | record_unwind_protect (un_autoload, Vautoload_queue); | ||
| 2288 | Vautoload_queue = Qt; | ||
| 2289 | Lisp_Object tem | ||
| 2290 | = save_match_data_load (file, noerror, nomessage, nosuffix, must_suffix); | ||
| 2291 | |||
| 2292 | /* Once loading finishes, don't undo it. */ | ||
| 2293 | Vautoload_queue = Qt; | ||
| 2294 | unbind_to (count, Qnil); | ||
| 2295 | return tem; | ||
| 2296 | } | ||
| 2297 | |||
| 2272 | /* Load an autoloaded function. | 2298 | /* Load an autoloaded function. |
| 2273 | FUNNAME is the symbol which is the function's name. | 2299 | FUNNAME is the symbol which is the function's name. |
| 2274 | FUNDEF is the autoload definition (a list). */ | 2300 | FUNDEF is the autoload definition (a list). */ |
| @@ -2281,8 +2307,6 @@ If equal to `macro', MACRO-ONLY specifies that FUNDEF should only be loaded if | |||
| 2281 | it defines a macro. */) | 2307 | it defines a macro. */) |
| 2282 | (Lisp_Object fundef, Lisp_Object funname, Lisp_Object macro_only) | 2308 | (Lisp_Object fundef, Lisp_Object funname, Lisp_Object macro_only) |
| 2283 | { | 2309 | { |
| 2284 | ptrdiff_t count = SPECPDL_INDEX (); | ||
| 2285 | |||
| 2286 | if (!CONSP (fundef) || !EQ (Qautoload, XCAR (fundef))) | 2310 | if (!CONSP (fundef) || !EQ (Qautoload, XCAR (fundef))) |
| 2287 | return fundef; | 2311 | return fundef; |
| 2288 | 2312 | ||
| @@ -2299,26 +2323,12 @@ it defines a macro. */) | |||
| 2299 | 2323 | ||
| 2300 | CHECK_SYMBOL (funname); | 2324 | CHECK_SYMBOL (funname); |
| 2301 | 2325 | ||
| 2302 | /* If autoloading gets an error (which includes the error of failing | ||
| 2303 | to define the function being called), we use Vautoload_queue | ||
| 2304 | to undo function definitions and `provide' calls made by | ||
| 2305 | the function. We do this in the specific case of autoloading | ||
| 2306 | because autoloading is not an explicit request "load this file", | ||
| 2307 | but rather a request to "call this function". | ||
| 2308 | |||
| 2309 | The value saved here is to be restored into Vautoload_queue. */ | ||
| 2310 | record_unwind_protect (un_autoload, Vautoload_queue); | ||
| 2311 | Vautoload_queue = Qt; | ||
| 2312 | /* If `macro_only' is set and fundef isn't a macro, assume this autoload to | 2326 | /* If `macro_only' is set and fundef isn't a macro, assume this autoload to |
| 2313 | be a "best-effort" (e.g. to try and find a compiler macro), | 2327 | be a "best-effort" (e.g. to try and find a compiler macro), |
| 2314 | so don't signal an error if autoloading fails. */ | 2328 | so don't signal an error if autoloading fails. */ |
| 2315 | Lisp_Object ignore_errors | 2329 | Lisp_Object ignore_errors |
| 2316 | = (EQ (kind, Qt) || EQ (kind, Qmacro)) ? Qnil : macro_only; | 2330 | = (EQ (kind, Qt) || EQ (kind, Qmacro)) ? Qnil : macro_only; |
| 2317 | save_match_data_load (Fcar (Fcdr (fundef)), ignore_errors, Qt, Qnil, Qt); | 2331 | load_with_autoload_queue (Fcar (Fcdr (fundef)), ignore_errors, Qt, Qnil, Qt); |
| 2318 | |||
| 2319 | /* Once loading finishes, don't undo it. */ | ||
| 2320 | Vautoload_queue = Qt; | ||
| 2321 | unbind_to (count, Qnil); | ||
| 2322 | 2332 | ||
| 2323 | if (NILP (funname) || !NILP (ignore_errors)) | 2333 | if (NILP (funname) || !NILP (ignore_errors)) |
| 2324 | return Qnil; | 2334 | return Qnil; |