Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions locale.c
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,8 @@ S_positional_newlocale(int mask, const char * locale, locale_t base)
* in C. This macro substitutes C for the locale appropriately, expanding to
* nothing on the more typical case where all possible categories present on
* the platform are handled. */
# ifdef HAS_IGNORED_LOCALE_CATEGORIES_
# if defined(HAS_IGNORED_LOCALE_CATEGORIES_) \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Point of information for a non-C programmer: Is there a difference between this syntax:

# ifdef SOMETHING

and this syntax:

# if defined(SOMETHING)

Why do you use one or the other?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#ifdef can only deal with one singe symbol
#if defined(FOO) is equal to #ifdef FOO, but when testing on more than one single symbol, like in this code, the second syntax is required
#if defined(FOO) || defined(BAR) does not have an #ifdef variant

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#ifdef FOO is subsumed by the form #if defined FOO (or equivalently, #if defined ( FOO )). As for why both forms exist, I believe #ifdef (and #ifndef) came first historically and defined was added later when people needed more complex conditionals.

Choosing between them is mostly a matter of taste (personally I don't like the extra parentheses in the defined (FOO) form, for example). Some purists argue that you should limit yourself to #ifdef because anything more complex than that is a sign that you're abusing the preprocessor for things it was never meant to do (and you should presumably move complex configuration logic to a separate stage that emits simple macro definitions). In perl, that train has sailed.

|| defined(HAS_MISSING_LANGINFO_ITEM_)
# define need_to_override_category(i) (! category_available[i])
# define override_ignored_category(i, new_locale) \
((need_to_override_category(i)) ? "C" : (new_locale))
Expand Down Expand Up @@ -866,7 +867,8 @@ STATIC void (*update_functions[]) (pTHX_ const char *, bool force) = {
NULL, /* No update for unknown category */
};

# if defined(HAS_IGNORED_LOCALE_CATEGORIES_)
# if defined(HAS_IGNORED_LOCALE_CATEGORIES_) \
|| defined(HAS_MISSING_LANGINFO_ITEM_)

/* Indicates if each category on this platform is available to use not in
* the C locale */
Expand Down Expand Up @@ -6060,7 +6062,7 @@ S_external_call_langinfo(pTHX_ const nl_item item,

} /* End of switch on item */

#if defined(HAS_MISSING_LANGINFO_ITEM_)
# if defined(HAS_MISSING_LANGINFO_ITEM_)

/* If the above didn't find the category's index, it has to be because the
* item is unknown to us (and the callee will handle that), or the category
Expand Down Expand Up @@ -6169,7 +6171,7 @@ S_langinfo_sv_i(pTHX_
"Entering langinfo_sv_i item=%ld, using locale %s\n",
(long) item, locale));

# ifdef HAS_IGNORED_LOCALE_CATEGORIES_
# ifdef HAS_MISSING_LANGINFO_ITEM_

if (! category_available[cat_index]) {
return emulate_langinfo(item, locale, sv, utf8ness);
Expand Down
56 changes: 28 additions & 28 deletions locale_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
PERL_LOCALE_TABLE_ENTRY(CTYPE, NULL)

# define HAS_IGNORED_LOCALE_CATEGORIES_
# define LC_CTYPE_AVAIL_ false
# define LC_CTYPE_AVAIL_ 0
# else

PERL_LOCALE_TABLE_ENTRY(CTYPE, S_new_ctype)

# define LC_CTYPE_AVAIL_ true
# define LC_CTYPE_AVAIL_ 1
# define USE_LOCALE_CTYPE
# endif
#endif
Expand All @@ -43,12 +43,12 @@
PERL_LOCALE_TABLE_ENTRY(NUMERIC, NULL)

# define HAS_IGNORED_LOCALE_CATEGORIES_
# define LC_NUMERIC_AVAIL_ false
# define LC_NUMERIC_AVAIL_ 0
# else

PERL_LOCALE_TABLE_ENTRY(NUMERIC, S_new_numeric)

# define LC_NUMERIC_AVAIL_ true
# define LC_NUMERIC_AVAIL_ 1
# define USE_LOCALE_NUMERIC
# endif
#endif
Expand All @@ -62,12 +62,12 @@
PERL_LOCALE_TABLE_ENTRY(COLLATE, NULL)

# define HAS_IGNORED_LOCALE_CATEGORIES_
# define LC_COLLATE_AVAIL_ false
# define LC_COLLATE_AVAIL_ 0
# else

PERL_LOCALE_TABLE_ENTRY(COLLATE, S_new_collate)

# define LC_COLLATE_AVAIL_ true
# define LC_COLLATE_AVAIL_ 1
# define USE_LOCALE_COLLATE
# endif
#endif
Expand All @@ -77,9 +77,9 @@

# if defined(NO_LOCALE) || defined(NO_LOCALE_TIME)
# define HAS_IGNORED_LOCALE_CATEGORIES_
# define LC_TIME_AVAIL_ false
# define LC_TIME_AVAIL_ 0
# else
# define LC_TIME_AVAIL_ true
# define LC_TIME_AVAIL_ 1
# define USE_LOCALE_TIME
# endif
#endif
Expand All @@ -89,9 +89,9 @@

# if defined(NO_LOCALE) || defined(NO_LOCALE_MESSAGES)
# define HAS_IGNORED_LOCALE_CATEGORIES_
# define LC_MESSAGES_AVAIL_ false
# define LC_MESSAGES_AVAIL_ 0
# else
# define LC_MESSAGES_AVAIL_ true
# define LC_MESSAGES_AVAIL_ 1
# define USE_LOCALE_MESSAGES
# endif
#endif
Expand All @@ -101,9 +101,9 @@

# if defined(NO_LOCALE) || defined(NO_LOCALE_MONETARY)
# define HAS_IGNORED_LOCALE_CATEGORIES_
# define LC_MONETARY_AVAIL_ false
# define LC_MONETARY_AVAIL_ 0
# else
# define LC_MONETARY_AVAIL_ true
# define LC_MONETARY_AVAIL_ 1
# define USE_LOCALE_MONETARY
# endif
#endif
Expand All @@ -113,9 +113,9 @@

# if defined(NO_LOCALE) || defined(NO_LOCALE_ADDRESS)
# define HAS_IGNORED_LOCALE_CATEGORIES_
# define LC_ADDRESS_AVAIL_ false
# define LC_ADDRESS_AVAIL_ 0
# else
# define LC_ADDRESS_AVAIL_ true
# define LC_ADDRESS_AVAIL_ 1
# define USE_LOCALE_ADDRESS
# endif
#endif
Expand All @@ -125,9 +125,9 @@

# if defined(NO_LOCALE) || defined(NO_LOCALE_IDENTIFICATION)
# define HAS_IGNORED_LOCALE_CATEGORIES_
# define LC_IDENTIFICATION_AVAIL_ false
# define LC_IDENTIFICATION_AVAIL_ 0
# else
# define LC_IDENTIFICATION_AVAIL_ true
# define LC_IDENTIFICATION_AVAIL_ 1
# define USE_LOCALE_IDENTIFICATION
# endif
#endif
Expand All @@ -137,9 +137,9 @@

# if defined(NO_LOCALE) || defined(NO_LOCALE_MEASUREMENT)
# define HAS_IGNORED_LOCALE_CATEGORIES_
# define LC_MEASUREMENT_AVAIL_ false
# define LC_MEASUREMENT_AVAIL_ 0
# else
# define LC_MEASUREMENT_AVAIL_ true
# define LC_MEASUREMENT_AVAIL_ 1
# define USE_LOCALE_MEASUREMENT
# endif
#endif
Expand All @@ -149,9 +149,9 @@

# if defined(NO_LOCALE) || defined(NO_LOCALE_PAPER)
# define HAS_IGNORED_LOCALE_CATEGORIES_
# define LC_PAPER_AVAIL_ false
# define LC_PAPER_AVAIL_ 0
# else
# define LC_PAPER_AVAIL_ true
# define LC_PAPER_AVAIL_ 1
# define USE_LOCALE_PAPER
# endif
#endif
Expand All @@ -161,9 +161,9 @@

# if defined(NO_LOCALE) || defined(NO_LOCALE_TELEPHONE)
# define HAS_IGNORED_LOCALE_CATEGORIES_
# define LC_TELEPHONE_AVAIL_ false
# define LC_TELEPHONE_AVAIL_ 0
# else
# define LC_TELEPHONE_AVAIL_ true
# define LC_TELEPHONE_AVAIL_ 1
# define USE_LOCALE_TELEPHONE
# endif
#endif
Expand All @@ -173,9 +173,9 @@

# if defined(NO_LOCALE) || defined(NO_LOCALE_NAME)
# define HAS_IGNORED_LOCALE_CATEGORIES_
# define LC_NAME_AVAIL_ false
# define LC_NAME_AVAIL_ 0
# else
# define LC_NAME_AVAIL_ true
# define LC_NAME_AVAIL_ 1
# define USE_LOCALE_NAME
# endif
#endif
Expand All @@ -185,9 +185,9 @@

# if defined(NO_LOCALE) || defined(NO_LOCALE_SYNTAX)
# define HAS_IGNORED_LOCALE_CATEGORIES_
# define LC_SYNTAX_AVAIL_ false
# define LC_SYNTAX_AVAIL_ 0
# else
# define LC_SYNTAX_AVAIL_ true
# define LC_SYNTAX_AVAIL_ 1
# define USE_LOCALE_SYNTAX
# endif
#endif
Expand All @@ -197,9 +197,9 @@

# if defined(NO_LOCALE) || defined(NO_LOCALE_TOD)
# define HAS_IGNORED_LOCALE_CATEGORIES_
# define LC_TOD_AVAIL_ false
# define LC_TOD_AVAIL_ 0
# else
# define LC_TOD_AVAIL_ true
# define LC_TOD_AVAIL_ 1
# define USE_LOCALE_TOD
# endif
#endif
16 changes: 7 additions & 9 deletions perl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,13 @@ violations are fatal.
# include <xlocale.h>
#endif

/* Even if not using locales, this header should be #included so as to #define
* some symbols which avoid #ifdefs to get things to compile. But make sure
* the macro it calls does nothing */
#undef PERL_LOCALE_TABLE_ENTRY
#define PERL_LOCALE_TABLE_ENTRY(name, call_back)
#include "locale_table.h"

#include "perl_langinfo.h" /* Needed for _NL_LOCALE_NAME */

/* =========================================================================
Expand Down Expand Up @@ -1159,15 +1166,6 @@ violations are fatal.
#define */
#endif

/* Even if not using locales, this header should be #included so as to #define
* some symbols which avoid #ifdefs to get things to compile. But make sure
* the macro it calls does nothing */
#ifndef USE_LOCALE
# undef PERL_LOCALE_TABLE_ENTRY
# define PERL_LOCALE_TABLE_ENTRY(name, call_back)
# include "locale_table.h"
#endif

/* XXX The Configure probe for categories must be updated when adding new
* categories here */

Expand Down
16 changes: 16 additions & 0 deletions perl_langinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,4 +318,20 @@ typedef int nl_item; /* Substitute 'int' for emulated nl_langinfo() */
# define HAS_MISSING_LANGINFO_ITEM_
#endif

/* All these categories have to be emulated if not available on the platform */
#if ! LC_CTYPE_AVAIL \
|| ! LC_MESSAGES_AVAIL \
|| ! LC_MONETARY_AVAIL \
|| ! LC_NUMERIC_AVAIL \
|| ! LC_TIME_AVAIL \
|| ! LC_ADDRESS_AVAIL_ \
|| ! LC_IDENTIFICATION_AVAIL_ \
|| ! LC_MEASUREMENT_AVAIL_ \
|| ! LC_NAME_AVAIL_ \
|| ! LC_PAPER_AVAIL_ \
|| ! LC_TELEPHONE_AVAIL_

# define HAS_MISSING_LANGINFO_ITEM_
#endif

#endif /* PERL_LANGINFO_H */