diff options
author | Karl Williamson <khw@cpan.org> | 2023-02-02 18:11:26 -0700 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2023-03-01 17:00:52 -0700 |
commit | 32346b7cdde5bcf8a0c8c9ee89ef541d8fe9a7b7 (patch) | |
tree | c1c1d1654e828dff1e17af76834bb73383a0f114 | |
parent | 4a7bea40c45452cd472c087fe36c369a1b5ffc36 (diff) | |
download | perl-32346b7cdde5bcf8a0c8c9ee89ef541d8fe9a7b7.tar.gz |
Inline get_context() for non-Win32
This trivial function should get optimized out. But I couldn't get it
to work for Windows, because the two likely hdr files don't have
PL_thr_key defined in them. I suppose a new hdr file could be created
that gets included later. But I didn't think it was worth it.
-rw-r--r-- | embed.fnc | 4 | ||||
-rw-r--r-- | embed.h | 6 | ||||
-rw-r--r-- | inline.h | 33 | ||||
-rw-r--r-- | proto.h | 17 | ||||
-rw-r--r-- | util.c | 29 |
5 files changed, 52 insertions, 37 deletions
@@ -1184,8 +1184,6 @@ ERXp |SV * |get_and_check_backslash_N_name \ |NN const char **error_msg AOdp |AV * |get_av |NN const char *name \ |I32 flags - -CRTdp |void * |get_context AOdp |CV * |get_cv |NN const char *name \ |I32 flags Adp |CV * |get_cvn_flags |NN const char *name \ @@ -6152,6 +6150,7 @@ Cp |int |do_spawn |NN char *cmd Cp |int |do_spawn_nowait|NN char *cmd #endif /* defined(VMS) || defined(WIN32) */ #if defined(WIN32) +CRTdp |void * |get_context p |bool |get_win32_message_utf8ness \ |NULLOK const char *string Teor |void |win32_croak_not_implemented \ @@ -6160,6 +6159,7 @@ Teor |void |win32_croak_not_implemented \ p |bool |do_exec3 |NN const char *incmd \ |int fd \ |int do_report +CRTdip |void * |get_context #endif /* !defined(WIN32) */ : ex: set ts=8 sts=4 sw=4 noet: @@ -236,7 +236,6 @@ # define forbid_outofblock_ops(a,b) Perl_forbid_outofblock_ops(aTHX_ a,b) # define free_tmps() Perl_free_tmps(aTHX) # define get_av(a,b) Perl_get_av(aTHX_ a,b) -# define get_context Perl_get_context # define get_cv(a,b) Perl_get_cv(aTHX_ a,b) # define get_cvn_flags(a,b,c) Perl_get_cvn_flags(aTHX_ a,b,c) # define get_hv(a,b) Perl_get_hv(aTHX_ a,b) @@ -2162,6 +2161,11 @@ # define do_spawn(a) Perl_do_spawn(aTHX_ a) # define do_spawn_nowait(a) Perl_do_spawn_nowait(aTHX_ a) # endif /* defined(VMS) || defined(WIN32) */ +# if defined(WIN32) +# define get_context Perl_get_context +# else /* if !defined(WIN32) */ +# define get_context Perl_get_context +# endif /* !defined(WIN32) */ #endif /* !defined(PERL_NO_SHORT_NAMES) */ /* ex: set ro ft=C: */ @@ -3652,6 +3652,39 @@ Perl_savesharedsvpv(pTHX_ SV *sv) return savesharedpvn(pv, len); } +#ifndef PERL_GET_CONTEXT_DEFINED + +/* +=for apidoc_section $embedding +=for apidoc get_context + +Implements L<perlapi/C<PERL_GET_CONTEXT>>, which you should use instead. + +=cut +*/ + +PERL_STATIC_INLINE void * +Perl_get_context(void) +{ +# if defined(USE_ITHREADS) +# ifdef OLD_PTHREADS_API + pthread_addr_t t; + int error = pthread_getspecific(PL_thr_key, &t); + if (error) + Perl_croak_nocontext("panic: pthread_getspecific, error=%d", error); + return (void*)t; +# elif defined(I_MACH_CTHREADS) + return (void*)cthread_data(cthread_self()); +# else + return (void*)PTHREAD_GETSPECIFIC(PL_thr_key); +# endif +# else + return (void*)NULL; +# endif +} + +#endif + PERL_STATIC_INLINE MGVTBL* Perl_get_vtbl(pTHX_ int vtbl_id) { @@ -1198,11 +1198,6 @@ Perl_get_av(pTHX_ const char *name, I32 flags); #define PERL_ARGS_ASSERT_GET_AV \ assert(name) -PERL_CALLCONV void * -Perl_get_context(void) - __attribute__warn_unused_result__; -#define PERL_ARGS_ASSERT_GET_CONTEXT - PERL_CALLCONV CV * Perl_get_cv(pTHX_ const char *name, I32 flags); #define PERL_ARGS_ASSERT_GET_CV \ @@ -10095,6 +10090,13 @@ S_PerlEnv_putenv(pTHX_ char *str); # endif /* !defined(PERL_IMPLICIT_SYS) */ # endif /* defined(USE_ITHREADS) */ +# if !defined(WIN32) +PERL_STATIC_INLINE void * +Perl_get_context(void) + __attribute__warn_unused_result__; +# define PERL_ARGS_ASSERT_GET_CONTEXT + +# endif /* !defined(WIN32) */ #endif /* !defined(PERL_NO_INLINE_FUNCTIONS) */ #if defined(PERL_USE_3ARG_SIGHANDLER) PERL_CALLCONV Signal_t @@ -10498,6 +10500,11 @@ Perl_do_spawn_nowait(pTHX_ char *cmd); #endif /* defined(VMS) || defined(WIN32) */ #if defined(WIN32) +PERL_CALLCONV void * +Perl_get_context(void) + __attribute__warn_unused_result__; +# define PERL_ARGS_ASSERT_GET_CONTEXT + PERL_CALLCONV bool Perl_get_win32_message_utf8ness(pTHX_ const char *string) __attribute__visibility__("hidden"); @@ -3562,35 +3562,6 @@ Perl_find_script(pTHX_ const char *scriptname, bool dosearch, /* =for apidoc_section $embedding -=for apidoc get_context - -Implements L<perlapi/C<PERL_GET_CONTEXT>>, which you should use instead. - -=cut -*/ - -void * -Perl_get_context(void) -{ -#if defined(USE_ITHREADS) -# ifdef OLD_PTHREADS_API - pthread_addr_t t; - int error = pthread_getspecific(PL_thr_key, &t); - if (error) - Perl_croak_nocontext("panic: pthread_getspecific, error=%d", error); - return (void*)t; -# elif defined(I_MACH_CTHREADS) - return (void*)cthread_data(cthread_self()); -# else - return (void*)PTHREAD_GETSPECIFIC(PL_thr_key); -# endif -#else - return (void*)NULL; -#endif -} - -/* -=for apidoc_section $embedding =for apidoc set_context Implements L<perlapi/C<PERL_SET_CONTEXT>>, which you should use instead. |