Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
2e64c348
Commit
2e64c348
authored
Mar 27, 2002
by
Martin v. Löwis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expose C library's gettext. Fixes #516412.
parent
4208d4f7
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
448 additions
and
342 deletions
+448
-342
Doc/lib/liblocale.tex
Doc/lib/liblocale.tex
+18
-0
Misc/NEWS
Misc/NEWS
+2
-0
Modules/_localemodule.c
Modules/_localemodule.c
+96
-2
configure
configure
+327
-338
configure.in
configure.in
+2
-2
pyconfig.h.in
pyconfig.h.in
+3
-0
No files found.
Doc/lib/liblocale.tex
View file @
2e64c348
...
...
@@ -467,3 +467,21 @@ application doesn't want this to happen, it should remove the
\module
{_
locale
}
extension module (which does all the work) from the
table of built-in modules in the
\file
{
config.c
}
file, and make sure
that the
\module
{_
locale
}
module is not accessible as a shared library.
\subsection
{
Access to message catalogs
}
The locale module exposes the C library's gettext interface on systems
that provide this interface. It consists of the functions
\function
{
gettext
}
,
\function
{
dgettext
}
,
\function
{
dcgettext
}
,
\function
{
textdomain
}
, and
\function
{
bindtextdomain
}
. These are
similar to the same functions in the
\module
{
gettext
}
module, but use
the C library's binary format for message catalogs, and the C
library's search algorithms for locating message catalogs.
Python applications should normally find no need to invoke these
functions, and should use
\module
{
gettext
}
instead. A known exception
to this rule are applications that link use additional C libraries
which internally invoke
\function
{
gettext
}
or
\function
{
dgettext
}
. For
these applications, it may be necessary to bind the text domain, so
that the libraries can properly locate their message catalogs.
Misc/NEWS
View file @
2e64c348
...
...
@@ -31,6 +31,8 @@ Core and builtins
Extension modules
- The locale module now exposes the C library's gettext interface.
- A security hole ("double free") was found in zlib-1.1.3, a popular
third party compression library used by some Python modules. The
hole was quickly plugged in zlib-1.1.4, and the Windows build of
...
...
Modules/_localemodule.c
View file @
2e64c348
...
...
@@ -21,6 +21,10 @@ This software comes with no warranty. Use at your own risk.
#include <langinfo.h>
#endif
#ifdef HAVE_LIBINTL_H
#include <libintl.h>
#endif
#if defined(MS_WIN32)
#define WINDOWS_LEAN_AND_MEAN
#include <windows.h>
...
...
@@ -521,7 +525,86 @@ PyLocale_nl_langinfo(PyObject* self, PyObject* args)
return
NULL
;
}
#endif
/* HAVE_LANGINFO_H */
#ifdef HAVE_LIBINTL_H
static
char
gettext__doc__
[]
=
"gettext(msg) -> string
\n
"
"Return translation of msg."
;
static
PyObject
*
PyIntl_gettext
(
PyObject
*
self
,
PyObject
*
args
)
{
char
*
in
;
if
(
!
PyArg_ParseTuple
(
args
,
"z"
,
&
in
))
return
0
;
return
PyString_FromString
(
gettext
(
in
));
}
static
char
dgettext__doc__
[]
=
"dgettext(domain, msg) -> string
\n
"
"Return translation of msg in domain."
;
static
PyObject
*
PyIntl_dgettext
(
PyObject
*
self
,
PyObject
*
args
)
{
char
*
domain
,
*
in
;
if
(
!
PyArg_ParseTuple
(
args
,
"zz"
,
&
domain
,
&
in
))
return
0
;
return
PyString_FromString
(
dgettext
(
domain
,
in
));
}
static
char
dcgettext__doc__
[]
=
"dcgettext(domain, msg, category) -> string
\n
"
"Return translation of msg in domain and category."
;
static
PyObject
*
PyIntl_dcgettext
(
PyObject
*
self
,
PyObject
*
args
)
{
char
*
domain
,
*
msgid
;
int
category
;
if
(
!
PyArg_ParseTuple
(
args
,
"zzi"
,
&
domain
,
&
msgid
,
&
category
))
return
0
;
return
PyString_FromString
(
dcgettext
(
domain
,
msgid
,
category
));
}
static
char
textdomain__doc__
[]
=
"textdomain(domain) -> string
\n
"
"Set the C library's textdmain to domain, returning the new domain."
;
static
PyObject
*
PyIntl_textdomain
(
PyObject
*
self
,
PyObject
*
args
)
{
char
*
domain
;
if
(
!
PyArg_ParseTuple
(
args
,
"z"
,
&
domain
))
return
0
;
domain
=
textdomain
(
domain
);
if
(
!
domain
)
{
PyErr_SetFromErrno
(
PyExc_OSError
);
return
NULL
;
}
return
PyString_FromString
(
domain
);
}
static
char
bindtextdomain__doc__
[]
=
"bindtextdomain(domain, dir) -> string
\n
"
"Bind the C library's domain to dir."
;
static
PyObject
*
PyIntl_bindtextdomain
(
PyObject
*
self
,
PyObject
*
args
)
{
char
*
domain
,
*
dirname
;
if
(
!
PyArg_ParseTuple
(
args
,
"zz"
,
&
domain
,
&
dirname
))
return
0
;
dirname
=
bindtextdomain
(
domain
,
dirname
);
if
(
!
dirname
)
{
PyErr_SetFromErrno
(
PyExc_OSError
);
return
NULL
;
}
return
PyString_FromString
(
dirname
);
}
#endif
static
struct
PyMethodDef
PyLocale_Methods
[]
=
{
{
"setlocale"
,
(
PyCFunction
)
PyLocale_setlocale
,
...
...
@@ -539,7 +622,18 @@ static struct PyMethodDef PyLocale_Methods[] = {
{
"nl_langinfo"
,
(
PyCFunction
)
PyLocale_nl_langinfo
,
METH_VARARGS
,
nl_langinfo__doc__
},
#endif
#ifdef HAVE_LANGINFO_H
{
"gettext"
,(
PyCFunction
)
PyIntl_gettext
,
METH_VARARGS
,
gettext__doc__
},
{
"dgettext"
,(
PyCFunction
)
PyIntl_dgettext
,
METH_VARARGS
,
dgettext__doc__
},
{
"dcgettext"
,(
PyCFunction
)
PyIntl_dcgettext
,
METH_VARARGS
,
dcgettext__doc__
},
{
"textdomain"
,(
PyCFunction
)
PyIntl_textdomain
,
METH_VARARGS
,
textdomain__doc__
},
{
"bindtextdomain"
,(
PyCFunction
)
PyIntl_bindtextdomain
,
METH_VARARGS
,
bindtextdomain__doc__
},
#endif
{
NULL
,
NULL
}
};
...
...
configure
View file @
2e64c348
This diff is collapsed.
Click to expand it.
configure.in
View file @
2e64c348
...
...
@@ -520,8 +520,8 @@ dnl AC_MSG_RESULT($cpp_type)
# checks for header files
AC_HEADER_STDC
AC_CHECK_HEADERS(dlfcn.h fcntl.h grp.h limits.h langinfo.h
locale.h
\
ncurses.h poll.h pthread.h \
AC_CHECK_HEADERS(dlfcn.h fcntl.h grp.h limits.h langinfo.h \
libintl.h locale.h
ncurses.h poll.h pthread.h \
signal.h stdarg.h stddef.h stdlib.h thread.h unistd.h utime.h termios.h \
sys/audioio.h sys/file.h sys/lock.h sys/modem.h db_185.h db.h \
sys/param.h sys/poll.h sys/select.h sys/socket.h sys/time.h sys/times.h \
...
...
pyconfig.h.in
View file @
2e64c348
...
...
@@ -645,6 +645,9 @@
/* Define if you have the <langinfo.h> header file. */
#undef HAVE_LANGINFO_H
/* Define if you have the <libintl.h> header file. */
#undef HAVE_LIBINTL_H
/* Define if you have the <libutil.h> header file. */
#undef HAVE_LIBUTIL_H
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment