Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
cee703d7
Commit
cee703d7
authored
Aug 29, 2015
by
Joshua Haberman
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #776 from haberman/pyfix
Fix for
https://github.com/google/protobuf/issues/758
parents
26f0c678
4472b4ad
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
15 deletions
+18
-15
message.cc
python/google/protobuf/pyext/message.cc
+18
-15
No files found.
python/google/protobuf/pyext/message.cc
View file @
cee703d7
...
@@ -340,7 +340,7 @@ static int InsertEmptyWeakref(PyTypeObject *base_type) {
...
@@ -340,7 +340,7 @@ static int InsertEmptyWeakref(PyTypeObject *base_type) {
}
// namespace message_meta
}
// namespace message_meta
PyTypeObject
PyMessageMeta_Type
{
PyTypeObject
PyMessageMeta_Type
=
{
PyVarObject_HEAD_INIT
(
&
PyType_Type
,
0
)
PyVarObject_HEAD_INIT
(
&
PyType_Type
,
0
)
FULL_MODULE_NAME
".MessageMeta"
,
// tp_name
FULL_MODULE_NAME
".MessageMeta"
,
// tp_name
sizeof
(
PyMessageMeta
),
// tp_basicsize
sizeof
(
PyMessageMeta
),
// tp_basicsize
...
@@ -1776,22 +1776,25 @@ class PythonFieldValuePrinter : public TextFormat::FieldValuePrinter {
...
@@ -1776,22 +1776,25 @@ class PythonFieldValuePrinter : public TextFormat::FieldValuePrinter {
// Python floats to ensure consistency.
// Python floats to ensure consistency.
string
PrintFloat
(
float
value
)
const
{
return
PrintDouble
(
value
);
}
string
PrintFloat
(
float
value
)
const
{
return
PrintDouble
(
value
);
}
string
PrintDouble
(
double
value
)
const
{
string
PrintDouble
(
double
value
)
const
{
// Same as float.__str__()
// This implementation is not highly optimized (it allocates two temporary
char
*
buf
=
PyOS_double_to_string
(
// Python objects) but it is simple and portable. If this is shown to be a
value
,
// performance bottleneck, we can optimize it, but the results will likely
#if PY_MAJOR_VERSION < 3
// be more complicated to accommodate the differing behavior of double
'g'
,
PyFloat_STR_PRECISION
,
// Output is rounded to 12 digits.
// formatting between Python 2 and Python 3.
#else
//
'r'
,
0
,
// (Though a valid question is: do we really want to make out output
#endif
// dependent on the Python version?)
Py_DTSF_ADD_DOT_0
,
// Trailing .0 is always printed.
ScopedPyObjectPtr
py_value
(
PyFloat_FromDouble
(
value
));
NULL
);
if
(
!
py_value
.
get
())
{
if
(
!
buf
)
{
return
string
();
return
string
();
}
}
string
result
(
buf
);
PyMem_Free
(
buf
);
ScopedPyObjectPtr
py_str
(
PyObject_Str
(
py_value
.
get
()));
return
result
;
if
(
!
py_str
.
get
())
{
return
string
();
}
return
string
(
PyString_AsString
(
py_str
.
get
()));
}
}
};
};
...
...
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