[OPEN-ILS-DEV] PATCH: osrf_json_object.c (jsonObjectToJSONRaw)

Scott McKellar mck9 at swbell.net
Mon Sep 3 19:10:05 EDT 2007


This patch affects the jsonObjectToJSONRaw function in two separate 
ways.  Summary:

1. It adds some sanity checking to prevent undefined behavior when
a floating point payload is not representable as an int.

2. It streamlines the serialization of hashes and arrays by 
eliminating a layer of allocation and deallocation.

Details:

1. A jsonObject represents a number as a double.  When we extract it
to a text representation, we test whether ( x = (int) x ) in order to
decide whether to represent a decimal point and a following decimal
fraction.

However if the integral portion of the floating point number is too
big or too small to be represented as an int, converting it to an
int results in undefined behavior.

I added some comparisons to INT_MAX and INT_MIN avoid this unhappy
circumstance.

2. In the original code, whenever we encounter a hash or an array,
we extract it into a string, append it to the buffer, and then 
deallocate the string.

The new version extracts the hash or array directly onto the end of
the original buffer, thereby eliminating a layer of allocation,
copying, and deallocation.  In my benchmarks I could demonstrate a 
modest but definite speed-up, depending on the contents of the 
jsonObject.

Scott McKellar
http://home.swbell.net/mck9/ct/

Developer's Certificate of Origin 1.1 By making a contribution to
this project, I certify that:

(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license indicated
in the file; or

(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source license
and I have the right under that license to submit that work with
modifications, whether created in whole or in part by me, under the
same open source license (unless I am permitted to submit under a
different license), as indicated in the file; or

(c) The contribution was provided directly to me by some other person
who certified (a), (b) or (c) and I have not modified it; and

(d) In the case of each of (a), (b), or (c), I understand and agree
that this project and the contribution are public and that a record
of the contribution (including all personal information I submit
with it, including my sign-off) is maintained indefinitely and may
be redistributed consistent with this project or the open source
license indicated in the file.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: osrf_json_object_c_2.patch
Type: text/x-patch
Size: 2997 bytes
Desc: 1250261772-osrf_json_object_c_2.patch
Url : http://list.georgialibraries.org/pipermail/open-ils-dev/attachments/20070903/3b861526/osrf_json_object_c_2.bin


More information about the Open-ils-dev mailing list