dTHX;
#endif
Malloc_t ptr;
+ dSAVEDERRNO;
#ifdef USE_MDH
if (size + PERL_MEMORY_DEBUG_HEADER_SIZE < size)
Perl_croak_nocontext("panic: malloc, size=%" UVuf, (UV) size);
#endif
if (!size) size = 1; /* malloc(0) is NASTY on our system */
+ SAVE_ERRNO;
#ifdef PERL_DEBUG_READONLY_COW
if ((ptr = mmap(0, size, PROT_READ|PROT_WRITE,
MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) {
ptr = (Malloc_t)((char*)ptr+PERL_MEMORY_DEBUG_HEADER_SIZE);
DEBUG_m(PerlIO_printf(Perl_debug_log, "0x%" UVxf ": (%05ld) malloc %ld bytes\n",PTR2UV(ptr),(long)PL_an++,(long)size));
+ /* malloc() can modify errno() even on success, but since someone
+ writing perl code doesn't have any control over when perl calls
+ malloc() we need to hide that.
+ */
+ RESTORE_ERRNO;
}
else {
#ifdef USE_MDH
ptr = safesysmalloc(size);
}
else {
+ dSAVE_ERRNO;
#ifdef USE_MDH
where = (Malloc_t)((char*)where-PERL_MEMORY_DEBUG_HEADER_SIZE);
if (size + PERL_MEMORY_DEBUG_HEADER_SIZE < size)
maybe_protect_ro(header->prev);
#endif
ptr = (Malloc_t)((char*)ptr+PERL_MEMORY_DEBUG_HEADER_SIZE);
+
+ /* realloc() can modify errno() even on success, but since someone
+ writing perl code doesn't have any control over when perl calls
+ realloc() we need to hide that.
+ */
+ RESTORE_ERRNO;
}
/* In particular, must do that fixup above before logging anything via
/*
=head1 Miscellaneous Functions
-=for apidoc Am|char *|ninstr|char * big|char * bigend|char * little|char * little_end
+=for apidoc ninstr
Find the first (leftmost) occurrence of a sequence of bytes within another
sequence. This is the Perl version of C<strstr()>, extended to handle
/*
=head1 Miscellaneous Functions
-=for apidoc Am|char *|rninstr|char * big|char * bigend|char * little|char * little_end
+=for apidoc rninstr
Like C<L</ninstr>>, but instead finds the final (rightmost) occurrence of a
sequence of bytes within another sequence, returning C<NULL> if there is no
}
/*
-=for apidoc Am|SV *|mess|const char *pat|...
+=for apidoc mess
Take a sprintf-style format pattern and argument list. These are used to
generate a string message. If the message does not end with a newline,
}
/*
-=for apidoc Am|SV *|mess_sv|SV *basemsg|bool consume
+=for apidoc mess_sv
Expands a message, intended for the user, to include an indication of
the current location in the code, if the message does not already appear
}
/*
-=for apidoc Am|SV *|vmess|const char *pat|va_list *args
+=for apidoc vmess
C<pat> and C<args> are a sprintf-style format pattern and encapsulated
argument list, respectively. These are used to generate a string message. If
}
/*
-=for apidoc Am|OP *|die_sv|SV *baseex
+=for apidoc die_sv
Behaves the same as L</croak_sv>, except for the return type.
It should be used only where the C<OP *> return type is required.
=cut
*/
-#ifdef _MSC_VER
-# pragma warning( push )
-# pragma warning( disable : 4646 ) /* warning C4646: function declared with
- __declspec(noreturn) has non-void return type */
-# pragma warning( disable : 4645 ) /* warning C4645: function declared with
-__declspec(noreturn) has a return statement */
-#endif
+/* silence __declspec(noreturn) warnings */
+MSVC_DIAG_IGNORE(4646 4645)
OP *
Perl_die_sv(pTHX_ SV *baseex)
{
/* NOTREACHED */
NORETURN_FUNCTION_END;
}
-#ifdef _MSC_VER
-# pragma warning( pop )
-#endif
+MSVC_DIAG_RESTORE
/*
-=for apidoc Am|OP *|die|const char *pat|...
+=for apidoc die
Behaves the same as L</croak>, except for the return type.
It should be used only where the C<OP *> return type is required.
*/
#if defined(PERL_IMPLICIT_CONTEXT)
-#ifdef _MSC_VER
-# pragma warning( push )
-# pragma warning( disable : 4646 ) /* warning C4646: function declared with
- __declspec(noreturn) has non-void return type */
-# pragma warning( disable : 4645 ) /* warning C4645: function declared with
-__declspec(noreturn) has a return statement */
-#endif
+
+/* silence __declspec(noreturn) warnings */
+MSVC_DIAG_IGNORE(4646 4645)
OP *
Perl_die_nocontext(const char* pat, ...)
{
va_end(args);
NORETURN_FUNCTION_END;
}
-#ifdef _MSC_VER
-# pragma warning( pop )
-#endif
+MSVC_DIAG_RESTORE
+
#endif /* PERL_IMPLICIT_CONTEXT */
-#ifdef _MSC_VER
-# pragma warning( push )
-# pragma warning( disable : 4646 ) /* warning C4646: function declared with
- __declspec(noreturn) has non-void return type */
-# pragma warning( disable : 4645 ) /* warning C4645: function declared with
-__declspec(noreturn) has a return statement */
-#endif
+/* silence __declspec(noreturn) warnings */
+MSVC_DIAG_IGNORE(4646 4645)
OP *
Perl_die(pTHX_ const char* pat, ...)
{
va_end(args);
NORETURN_FUNCTION_END;
}
-#ifdef _MSC_VER
-# pragma warning( pop )
-#endif
+MSVC_DIAG_RESTORE
/*
-=for apidoc Am|void|croak_sv|SV *baseex
+=for apidoc croak_sv
This is an XS interface to Perl's C<die> function.
}
/*
-=for apidoc Am|void|vcroak|const char *pat|va_list *args
+=for apidoc vcroak
This is an XS interface to Perl's C<die> function.
}
/*
-=for apidoc Am|void|croak|const char *pat|...
+=for apidoc croak
This is an XS interface to Perl's C<die> function.
}
/*
-=for apidoc Am|void|croak_no_modify
+=for apidoc croak_no_modify
Exactly equivalent to C<Perl_croak(aTHX_ "%s", PL_no_modify)>, but generates
terser object code than using C<Perl_croak>. Less code used on exception code
}
/*
-=for apidoc Am|void|warn_sv|SV *baseex
+=for apidoc warn_sv
This is an XS interface to Perl's C<warn> function.
}
/*
-=for apidoc Am|void|vwarn|const char *pat|va_list *args
+=for apidoc vwarn
This is an XS interface to Perl's C<warn> function.
}
/*
-=for apidoc Am|void|warn|const char *pat|...
+=for apidoc warn
This is an XS interface to Perl's C<warn> function.
# if !defined(WIN32) && !defined(NETWARE)
+/*
+=for apidoc my_setenv
+
+A wrapper for the C library L<setenv(3)>. Don't use the latter, as the perl
+version has desirable safeguards
+
+=cut
+*/
+
void
Perl_my_setenv(pTHX_ const char *nam, const char *val)
{
#ifndef PERL_MICRO
#ifdef HAS_SIGACTION
+/*
+=for apidoc rsignal
+
+A wrapper for the C library L<signal(2)>. Don't use the latter, as the Perl
+version knows things that interact with the rest of the perl interpreter.
+
+=cut
+*/
+
Sighandler_t
Perl_rsignal(pTHX_ int signo, Sighandler_t handler)
{
dVAR;
# ifdef OLD_PTHREADS_API
pthread_addr_t t;
- int error = pthread_getspecific(PL_thr_key, &t)
+ int error = pthread_getspecific(PL_thr_key, &t);
if (error)
Perl_croak_nocontext("panic: pthread_getspecific, error=%d", error);
return (void*)t;
return NULL;
if (format[len - 2] != 'Q') {
char* fixed;
- Newx(fixed, len + 1, char);
+ Newx(fixed, len + 2, char);
memcpy(fixed, format, len - 1);
fixed[len - 1] = 'Q';
fixed[len ] = format[len - 1];
#ifdef PERL_IMPLICIT_CONTEXT
-/* Implements the MY_CXT_INIT macro. The first time a module is loaded,
-the global PL_my_cxt_index is incremented, and that value is assigned to
-that module's static my_cxt_index (who's address is passed as an arg).
-Then, for each interpreter this function is called for, it makes sure a
-void* slot is available to hang the static data off, by allocating or
-extending the interpreter's PL_my_cxt_list array */
-
-#ifndef PERL_GLOBAL_STRUCT_PRIVATE
-void *
-Perl_my_cxt_init(pTHX_ int *indexp, size_t size)
-{
- dVAR;
- void *p;
- int index;
- PERL_ARGS_ASSERT_MY_CXT_INIT;
-
- index = *indexp;
- /* do initial check without locking.
- * -1: not allocated or another thread currently allocating
- * other: already allocated by another thread
- */
- if (index == -1) {
- MUTEX_LOCK(&PL_my_ctx_mutex);
- /*now a stricter check with locking */
- index = *indexp;
- if (index == -1)
- /* this module hasn't been allocated an index yet */
- *indexp = PL_my_cxt_index++;
- index = *indexp;
- MUTEX_UNLOCK(&PL_my_ctx_mutex);
- }
-
- /* make sure the array is big enough */
- if (PL_my_cxt_size <= index) {
- if (PL_my_cxt_size) {
- IV new_size = PL_my_cxt_size;
- while (new_size <= index)
- new_size *= 2;
- Renew(PL_my_cxt_list, new_size, void *);
- PL_my_cxt_size = new_size;
- }
- else {
- PL_my_cxt_size = 16;
- Newx(PL_my_cxt_list, PL_my_cxt_size, void *);
- }
- }
- /* newSV() allocates one more than needed */
- p = (void*)SvPVX(newSV(size-1));
- PL_my_cxt_list[index] = p;
- Zero(p, size, char);
- return p;
-}
-
-#else /* #ifndef PERL_GLOBAL_STRUCT_PRIVATE */
+# ifdef PERL_GLOBAL_STRUCT_PRIVATE
+/* rather than each module having a static var holding its index,
+ * use a global array of name to index mappings
+ */
int
Perl_my_cxt_index(pTHX_ const char *my_cxt_key)
{
}
return -1;
}
+# endif
+
+
+/* Implements the MY_CXT_INIT macro. The first time a module is loaded,
+the global PL_my_cxt_index is incremented, and that value is assigned to
+that module's static my_cxt_index (who's address is passed as an arg).
+Then, for each interpreter this function is called for, it makes sure a
+void* slot is available to hang the static data off, by allocating or
+extending the interpreter's PL_my_cxt_list array */
void *
+# ifdef PERL_GLOBAL_STRUCT_PRIVATE
Perl_my_cxt_init(pTHX_ const char *my_cxt_key, size_t size)
+# else
+Perl_my_cxt_init(pTHX_ int *indexp, size_t size)
+# endif
{
dVAR;
void *p;
PERL_ARGS_ASSERT_MY_CXT_INIT;
+# ifdef PERL_GLOBAL_STRUCT_PRIVATE
index = Perl_my_cxt_index(aTHX_ my_cxt_key);
+# else
+ index = *indexp;
+# endif
/* do initial check without locking.
* -1: not allocated or another thread currently allocating
* other: already allocated by another thread
if (index == -1) {
MUTEX_LOCK(&PL_my_ctx_mutex);
/*now a stricter check with locking */
+# ifdef PERL_GLOBAL_STRUCT_PRIVATE
index = Perl_my_cxt_index(aTHX_ my_cxt_key);
+# else
+ index = *indexp;
+# endif
if (index == -1)
/* this module hasn't been allocated an index yet */
+# ifdef PERL_GLOBAL_STRUCT_PRIVATE
index = PL_my_cxt_index++;
/* Store the index in a global MY_CXT_KEY string to index mapping
}
}
PL_my_cxt_keys[index] = my_cxt_key;
-
+# else
+ *indexp = PL_my_cxt_index++;
+ index = *indexp;
+# endif
MUTEX_UNLOCK(&PL_my_ctx_mutex);
}
/* make sure the array is big enough */
if (PL_my_cxt_size <= index) {
- int old_size = PL_my_cxt_size;
- int i;
if (PL_my_cxt_size) {
IV new_size = PL_my_cxt_size;
while (new_size <= index)
PL_my_cxt_size = 16;
Newx(PL_my_cxt_list, PL_my_cxt_size, void *);
}
- for (i = old_size; i < PL_my_cxt_size; i++) {
- PL_my_cxt_list[i] = 0;
- }
}
/* newSV() allocates one more than needed */
p = (void*)SvPVX(newSV(size-1));
Zero(p, size, char);
return p;
}
-#endif /* #ifndef PERL_GLOBAL_STRUCT_PRIVATE */
+
#endif /* PERL_IMPLICIT_CONTEXT */
STRLEN len = strlen(templte);
int fd;
int attempts = 0;
+#ifdef VMS
+ int delete_on_close = flags & O_VMS_DELETEONCLOSE;
+
+ flags &= ~O_VMS_DELETEONCLOSE;
+#endif
if (len < 6 ||
templte[len-1] != 'X' || templte[len-2] != 'X' || templte[len-3] != 'X' ||
for (i = 1; i <= 6; ++i) {
templte[len-i] = TEMP_FILE_CH[(int)(Perl_internal_drand48() * TEMP_FILE_CH_COUNT)];
}
- fd = PerlLIO_open3(templte, O_RDWR | O_CREAT | O_EXCL | flags, 0600);
+#ifdef VMS
+ if (delete_on_close) {
+ fd = open(templte, O_RDWR | O_CREAT | O_EXCL | flags, 0600, "fop=dlt");
+ }
+ else
+#endif
+ {
+ fd = PerlLIO_open3(templte, O_RDWR | O_CREAT | O_EXCL | flags, 0600);
+ }
} while (fd == -1 && errno == EEXIST && ++attempts <= 100);
return fd;
Safefree(raw_frames);
return bt;
#else
- PERL_UNUSED_ARGV(depth);
- PERL_UNUSED_ARGV(skip);
+ PERL_UNUSED_ARG(depth);
+ PERL_UNUSED_ARG(skip);
return NULL;
#endif
}