Skip to content

Commit

Permalink
support for long -> bson int in C encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Dirolf committed Feb 19, 2009
1 parent e37432d commit 1e0b09a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pymongo/_cbsonmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ static PyObject* _cbson_element_to_bson(PyObject* self, PyObject* args) {
} else if (PyInt_CheckExact(value)) {
int int_value = (int)PyInt_AsLong(value);
return build_element(0x10, name, 4, (char*)&int_value);
} else if (PyLong_CheckExact(value)) {
int int_value = (int)PyLong_AsLong(value); // TODO handle overflow here
return build_element(0x10, name, 4, (char*)&int_value);
} else if (PyBool_Check(value)) {
long bool = PyInt_AsLong(value);
char c = bool ? 0x01 : 0x00;
Expand Down
1 change: 1 addition & 0 deletions test/test_bson.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def helper(dict):
self.assertTrue(isinstance(BSON.from_dict({"hello": "world"}).to_dict()["hello"],
types.UnicodeType))
helper({"mike": -10120})
helper({"long": long(10)})
helper({u"hello": 0.0013109})
helper({"something": True})
helper({"false": False})
Expand Down

0 comments on commit 1e0b09a

Please sign in to comment.