Skip to content

Commit f8690f4

Browse files
committed
Use C++ headers and reserved naming for vasprintf and fix CI/formatting
1 parent 97bb07c commit f8690f4

File tree

14 files changed

+201
-206
lines changed

14 files changed

+201
-206
lines changed

libcxx/include/__locale_dir/locale_base_api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ _LIBCPP_PUSH_MACROS
132132
// (by providing global non-reserved names) and the new API. As we move individual platforms
133133
// towards the new way of defining the locale base API, this should disappear since each platform
134134
// will define those directly.
135-
# if defined(_AIX)
135+
# if defined(_AIX)
136136
# include <__locale_dir/locale_base_api/ibm.h>
137137
# elif defined(__OpenBSD__)
138138
# include <__locale_dir/locale_base_api/openbsd.h>

libcxx/include/__locale_dir/support/zos.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ struct __locale_guard {
3232
_LIBCPP_HIDE_FROM_ABI __locale_guard(locale_t& __loc) : __old_loc_(std::uselocale(__loc)) {}
3333

3434
_LIBCPP_HIDE_FROM_ABI ~__locale_guard() {
35-
// if (__old_loc_)
3635
if (__old_loc_ != (locale_t)0)
3736
std::uselocale(__old_loc_);
3837
}
@@ -299,7 +298,7 @@ _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 3, 4) int __as
299298
va_list __va;
300299
va_start(__va, __format);
301300
__locale_guard __current(__loc);
302-
int __res = std::__ibm::vasprintf(__s, __format, __va); // non-standard
301+
int __res = std::__ibm::__vasprintf(__s, __format, __va); // non-standard
303302
va_end(__va);
304303
return __res;
305304
}

libcxx/include/__support/ibm/vasprintf.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,39 @@
99
#ifndef _LIBCPP___SUPPORT_IBMVASPRINTF_H
1010
#define _LIBCPP___SUPPORT_IBMVASPRINTF_H
1111

12-
#include <cstdlib> // malloc, realloc
13-
#include <stdarg.h> // va_copy, va_end
14-
#include <stdio.h> // vsnprintf
12+
#include <cstdarg> // va_copy, va_end
13+
#include <cstdio> // vsnprintf
14+
#include <cstdlib> // malloc, realloc
1515

1616
_LIBCPP_BEGIN_NAMESPACE_STD
1717
namespace __ibm {
1818

1919
inline _LIBCPP_HIDE_FROM_ABI
20-
_LIBCPP_ATTRIBUTE_FORMAT(__printf__, 2, 0) int vasprintf(char** strp, const char* fmt, va_list ap) {
20+
_LIBCPP_ATTRIBUTE_FORMAT(__printf__, 2, 0) int __vasprintf(char** __strp, const char* __fmt, va_list __ap) {
2121
const size_t buff_size = 256;
22-
if ((*strp = (char*)malloc(buff_size)) == nullptr) {
22+
if ((*__strp = (char*)std::malloc(buff_size)) == nullptr) {
2323
return -1;
2424
}
2525

2626
va_list ap_copy;
2727
// va_copy may not be provided by the C library in C++03 mode.
2828
#if defined(_LIBCPP_CXX03_LANG) && __has_builtin(__builtin_va_copy)
2929
# if defined(__MVS__) && !defined(_VARARG_EXT_)
30-
__builtin_zos_va_copy(ap_copy, ap);
30+
__builtin_zos_va_copy(ap_copy, __ap);
3131
# else
32-
__builtin_va_copy(ap_copy, ap);
32+
__builtin_va_copy(ap_copy, __ap);
3333
# endif
3434
#else
35-
va_copy(ap_copy, ap);
35+
va_copy(ap_copy, __ap);
3636
#endif
37-
int str_size = vsnprintf(*strp, buff_size, fmt, ap_copy);
37+
int str_size = vsnprintf(*__strp, buff_size, __fmt, ap_copy);
3838
va_end(ap_copy);
3939

4040
if ((size_t)str_size >= buff_size) {
41-
if ((*strp = (char*)realloc(*strp, str_size + 1)) == nullptr) {
41+
if ((*__strp = (char*)std::realloc(*__strp, str_size + 1)) == nullptr) {
4242
return -1;
4343
}
44-
str_size = vsnprintf(*strp, str_size + 1, fmt, ap);
44+
str_size = vsnprintf(*__strp, str_size + 1, __fmt, __ap);
4545
}
4646
return str_size;
4747
}

libcxx/src/support/ibm/localeconv.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,17 @@
1313

1414
_LIBCPP_BEGIN_NAMESPACE_STD
1515

16-
lconv *__libcpp_localeconv_l(locale_t& __l)
17-
{
16+
lconv* __libcpp_localeconv_l(locale_t& __l) {
1817
__locale::__locale_guard __current(__l);
1918

20-
lconv * lc = localeconv();
19+
lconv* lc = localeconv();
2120
static lconv newlc;
2221
newlc = *lc;
2322

24-
enum {max_char_num = 20};
25-
#define DeepCopy(mbr) \
26-
static char buf_##mbr[max_char_num]; \
27-
strncpy(buf_##mbr, lc->mbr, max_char_num); \
23+
enum { max_char_num = 20 };
24+
#define DeepCopy(mbr) \
25+
static char buf_##mbr[max_char_num]; \
26+
strncpy(buf_##mbr, lc->mbr, max_char_num); \
2827
newlc.mbr = buf_##mbr;
2928

3029
DeepCopy(decimal_point);

libcxx/src/support/ibm/mbsnrtowcs.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,11 @@ namespace __ibm {
2323
// Returns (size_t) -1 when an invalid sequence is encountered.
2424
// Leaves *`src` pointing to the next character to convert or NULL
2525
// if a null character was converted from *`src`.
26-
size_t mbsnrtowcs(
27-
wchar_t* __restrict dst,
28-
const char** __restrict src,
29-
size_t src_size_bytes,
30-
size_t max_dest_chars,
31-
mbstate_t* __restrict ps) {
26+
size_t mbsnrtowcs(wchar_t* __restrict dst,
27+
const char** __restrict src,
28+
size_t src_size_bytes,
29+
size_t max_dest_chars,
30+
mbstate_t* __restrict ps) {
3231
const size_t terminated_sequence = static_cast<size_t>(0);
3332
const size_t invalid_sequence = static_cast<size_t>(-1);
3433
const size_t incomplete_sequence = static_cast<size_t>(-2);
@@ -101,9 +100,7 @@ size_t mbsnrtowcs(
101100
return dest_converted;
102101
}
103102

104-
size_t __libcpp_mbsnrtowcs_l(wchar_t * dest, const char **src, size_t nms,
105-
size_t len, mbstate_t *ps, locale_t l)
106-
{
103+
size_t __libcpp_mbsnrtowcs_l(wchar_t* dest, const char** src, size_t nms, size_t len, mbstate_t* ps, locale_t l) {
107104
__locale::__locale_guard current(l);
108105
return mbsnrtowcs(dest, src, nms, len, ps);
109106
}

libcxx/src/support/ibm/wcsnrtombs.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@ namespace __ibm {
2222
// converted from *src, excluding the null terminator.
2323
// Returns (size_t) -1 if an error occurs and sets errno.
2424
// If `dst` is NULL, `dst_size_bytes` is ignored and no bytes are copied to `dst`.
25-
size_t wcsnrtombs(
26-
char* __restrict dst,
27-
const wchar_t** __restrict src,
28-
size_t max_source_chars,
29-
size_t dst_size_bytes,
30-
mbstate_t* __restrict ps) {
25+
size_t wcsnrtombs(char* __restrict dst,
26+
const wchar_t** __restrict src,
27+
size_t max_source_chars,
28+
size_t dst_size_bytes,
29+
mbstate_t* __restrict ps) {
3130
const size_t invalid_wchar = static_cast<size_t>(-1);
3231

3332
size_t source_converted;
@@ -98,9 +97,7 @@ size_t wcsnrtombs(
9897
return dest_converted;
9998
}
10099

101-
size_t __libcpp_wcsnrtombs_l(char *dest, const wchar_t **src, size_t nwc,
102-
size_t len, mbstate_t *ps, locale_t l)
103-
{
100+
size_t __libcpp_wcsnrtombs_l(char* dest, const wchar_t** src, size_t nwc, size_t len, mbstate_t* ps, locale_t l) {
104101
__locale::__locale_guard __current(l);
105102
return wcsnrtombs(dest, src, nwc, len, ps);
106103
}

0 commit comments

Comments
 (0)