Bug 325202: XDR uses lossless encoding for all string. r=brendan
authorigor@mir2.org
Tue, 21 Aug 2007 14:22:26 -0700
changeset 4875 d6abc6197346e44c4294ac83008a96e307a64dea
parent 4874 61acb2a1c7133568f4d78e8d5f3123bfdd6b7cb0
child 4876 939a94729316426c57de344a0840eab3a05f69ca
push id1
push userbsmedberg@mozilla.com
push dateThu, 20 Mar 2008 16:49:24 +0000
treeherderautoland@61007906a1f8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbrendan
bugs325202
milestone1.9a8pre
Bug 325202: XDR uses lossless encoding for all string. r=brendan
js/src/jsfun.c
js/src/jsobj.c
js/src/jsxdrapi.c
js/src/jsxdrapi.h
--- a/js/src/jsfun.c
+++ b/js/src/jsfun.c
@@ -1363,33 +1363,33 @@ fun_xdrObject(JSXDRState *xdr, JSObject 
                  * sprop->id here represents hidden names so we unhide it and
                  * encode as an atom. During decoding we read the atom and use
                  * js_AddHiddenProperty to reconstruct sprop with the hidden
                  * id.
                  */
                 propAtom = JSID_TO_ATOM(JSID_UNHIDE_NAME(sprop->id));
                 if (!JS_XDRUint32(xdr, &type) ||
                     !JS_XDRUint32(xdr, &userid) ||
-                    !js_XDRCStringAtom(xdr, &propAtom)) {
+                    !js_XDRStringAtom(xdr, &propAtom)) {
                     if (mark)
                         JS_ARENA_RELEASE(&cx->tempPool, mark);
                     goto bad;
                 }
             }
             if (mark)
                 JS_ARENA_RELEASE(&cx->tempPool, mark);
         } else {
             JSPropertyOp getter, setter;
 
             for (i = n; i != 0; i--) {
                 uintN attrs = JSPROP_PERMANENT;
 
                 if (!JS_XDRUint32(xdr, &type) ||
                     !JS_XDRUint32(xdr, &userid) ||
-                    !js_XDRCStringAtom(xdr, &propAtom)) {
+                    !js_XDRStringAtom(xdr, &propAtom)) {
                     goto bad;
                 }
                 JS_ASSERT(type == JSXDR_FUNARG || type == JSXDR_FUNVAR ||
                           type == JSXDR_FUNCONST);
                 if (type == JSXDR_FUNARG) {
                     getter = js_GetArgument;
                     setter = js_SetArgument;
                     JS_ASSERT(nargs++ <= fun->nargs);
--- a/js/src/jsobj.c
+++ b/js/src/jsobj.c
@@ -4643,17 +4643,17 @@ js_XDRObject(JSXDRState *xdr, JSObject *
      * name follows, only the id in xdr's class registry; 1 for a class def,
      * in which case the flag word is followed by the class name transferred
      * from or to atom; or a value greater than 1, an odd number that when
      * divided by two yields the JSProtoKey for class.  In the last case, as
      * in the 0 classDef case, no name is transferred via atom.
      */
     if (!JS_XDRUint32(xdr, &classDef))
         return JS_FALSE;
-    if (classDef == 1 && !js_XDRCStringAtom(xdr, &atom))
+    if (classDef == 1 && !js_XDRStringAtom(xdr, &atom))
         return JS_FALSE;
 
     if (!JS_XDRUint32(xdr, &classId))
         return JS_FALSE;
 
     if (xdr->mode == JSXDR_DECODE) {
         if (classDef) {
             /* NB: we know that JSProto_Null is 0 here, for backward compat. */
--- a/js/src/jsxdrapi.c
+++ b/js/src/jsxdrapi.c
@@ -670,66 +670,16 @@ js_XDRStringAtom(JSXDRState *xdr, JSAtom
         atom = js_AtomizeChars(cx, chars, nchars, 0);
     JS_ARENA_RELEASE(&cx->tempPool, mark);
     if (!atom)
         return JS_FALSE;
     *atomp = atom;
     return JS_TRUE;
 }
 
-/*
- * FIXME: This performs lossy conversion and we need to switch to
- * js_XDRStringAtom while allowing to read older XDR files. See bug 325202.
- */
-JSBool
-js_XDRCStringAtom(JSXDRState *xdr, JSAtom **atomp)
-{
-    JSString *str;
-    char *bytes;
-    JSBool ok;
-    uint32 nbytes;
-    JSAtom *atom;
-    JSContext *cx;
-    void *mark;
-
-    if (xdr->mode == JSXDR_ENCODE) {
-        JS_ASSERT(ATOM_IS_STRING(*atomp));
-        str = ATOM_TO_STRING(*atomp);
-        bytes = js_DeflateString(xdr->cx,
-                                 JSSTRING_CHARS(str),
-                                 JSSTRING_LENGTH(str));
-        if (!bytes)
-            return JS_FALSE;
-        ok = JS_XDRCString(xdr, &bytes);
-        JS_free(xdr->cx, bytes);
-        return ok;
-    }
-
-    /*
-     * Inline JS_XDRCString when decoding not to malloc temporary buffer
-     * just to free it after atomization. See bug 321985.
-     */
-    if (!JS_XDRUint32(xdr, &nbytes))
-        return JS_FALSE;
-    atom = NULL;
-    cx = xdr->cx;
-    mark = JS_ARENA_MARK(&cx->tempPool);
-    JS_ARENA_ALLOCATE_CAST(bytes, char *, &cx->tempPool,
-                           nbytes * sizeof *bytes);
-    if (!bytes)
-        JS_ReportOutOfMemory(cx);
-    else if (JS_XDRBytes(xdr, bytes, nbytes))
-        atom = js_Atomize(cx, bytes, nbytes, 0);
-    JS_ARENA_RELEASE(&cx->tempPool, mark);
-    if (!atom)
-        return JS_FALSE;
-    *atomp = atom;
-    return JS_TRUE;
-}
-
 JS_PUBLIC_API(JSBool)
 JS_XDRScript(JSXDRState *xdr, JSScript **scriptp)
 {
     if (!js_XDRScript(xdr, scriptp, NULL))
         return JS_FALSE;
     if (xdr->mode == JSXDR_DECODE)
         js_CallNewScriptHook(xdr->cx, *scriptp, NULL);
     return JS_TRUE;
--- a/js/src/jsxdrapi.h
+++ b/js/src/jsxdrapi.h
@@ -185,17 +185,18 @@ JS_XDRFindClassById(JSXDRState *xdr, uin
  * Magic numbers.
  */
 #define JSXDR_MAGIC_SCRIPT_1        0xdead0001
 #define JSXDR_MAGIC_SCRIPT_2        0xdead0002
 #define JSXDR_MAGIC_SCRIPT_3        0xdead0003
 #define JSXDR_MAGIC_SCRIPT_4        0xdead0004
 #define JSXDR_MAGIC_SCRIPT_5        0xdead0005
 #define JSXDR_MAGIC_SCRIPT_6        0xdead0006
-#define JSXDR_MAGIC_SCRIPT_CURRENT  JSXDR_MAGIC_SCRIPT_6
+#define JSXDR_MAGIC_SCRIPT_7        0xdead0007
+#define JSXDR_MAGIC_SCRIPT_CURRENT  JSXDR_MAGIC_SCRIPT_7
 
 /*
  * Bytecode version number.  Decrement the second term whenever JS bytecode
  * changes incompatibly.
  *
  * This version number should be XDR'ed once near the front of any file or
  * larger storage unit containing XDR'ed bytecode and other data, and checked
  * before deserialization of bytecode.  If the saved version does not match
@@ -207,18 +208,11 @@ JS_XDRFindClassById(JSXDRState *xdr, uin
  * Library-private functions.
  */
 extern JSBool
 js_XDRAtom(JSXDRState *xdr, JSAtom **atomp);
 
 extern JSBool
 js_XDRStringAtom(JSXDRState *xdr, JSAtom **atomp);
 
-/*
- * FIXME: This is non-unicode version of js_XDRStringAtom that performs lossy
- * conversion. Do not use it in the new code! See bug 325202.
- */
-extern JSBool
-js_XDRCStringAtom(JSXDRState *xdr, JSAtom **atomp);
-
 JS_END_EXTERN_C
 
 #endif /* ! jsxdrapi_h___ */