Closed Bug 136756 Opened 22 years ago Closed 22 years ago

Strings requires unfrozen nsCRT class

Categories

(Core :: XPCOM, defect)

All
Windows 2000
defect
Not set
blocker

Tracking

()

RESOLVED FIXED

People

(Reporter: dougt, Assigned: dougt)

References

Details

(Keywords: embed, topembed+, Whiteboard: [driver:scc])

Attachments

(2 files, 4 obsolete files)

Strings requiring unfrozen the nsCRT class is a problem for components, plugins
and embedders that want to work in or with multiple version of mozilla and not
have to reimplement the string code.  The idea is to have these clients link in
the string code so that they can have a "snapshot" of our string implementation.
 This allows the freedom to change the string classes in mozilla without worring
about backwards compatibly (assuming that no interfaces changes - string
interfaces are (or will be) frozen, right!).  Basically, the clients get a copy
of the concrete implementation of the string interfaces.

Having string require this unfrozen class will cause problems when nsCRT
changes.  Any change could break compatiblity with built clients.
*** Bug 136755 has been marked as a duplicate of this bug. ***
Keywords: mozilla1.0, topembed
Keywords: topembedembed, topembed-
reconsider please.
Keywords: topembed-edt1.0.0, topembed
Attached patch Removes nsCRT v.1 (obsolete) — Splinter Review
Straightfoward patch which copies the nsCRT functionality into the string code.


There are a couple of issues with this patch with may be minor.  The first
where should we put the strlen(const PRUnichar* s) function.  I put it in
nsStr.cpp and extern'ed it where it was needed.

The second issues is why do we use nsCRT::ToUpper and nsCRT::ToLower instead of
the toupper and tolower?  In this patch, I just converted callers.  If this is
a problem, we can copy the nsCRT:: functions into this string code.
hmmm, |nsCRT| should be deprecated and replaced.  No outside caller should be
allowed, let alone encouraged to use this API.  Strings (hopefully temporary)
use of it won't break compatibility if we don't freeze this API, becuase no use
of it occurs in |inline|s and therefor, the dependency is not exposed.

I strongly recommend we do not allow outside callers of the largely unnecessary
|nsCRT|.
scc, you missed the point.  If I want to develop an xpcom component or plugin, I
can't use strings since it currently links to xpcom for nsCRT.  Since nsCRT is
not frozen, anyone that uses strings before we fix this bug will be broken when
we do fix this bug!


Blocks: 77153
uh... no.  Since the strings methods they use will be in the Mozilla/Netscape
binary, and as I said, no use of the |nsCRT| routines appears in any inline,
they _won't_ be broken by a later change to Strings internal dependencies. 
Maybe if this changed the structure of a string in their code, or changed the
composition of an inline.  But it doesn't.  So this does not break callers.
strings and glue are being linked INTO a application as static libraries.  This
is so that they may use the string concrete classes.  Since the application is
taking a "snapshot" of the string library and embedding it into their code, they
are protected against change in the mainline trunk.  Now, to do this, we need to
make sure that all of the dependencies on XPCOM in both glue and strings are
totally frozen.  The only dependency is nsCRT.

Below is the window import listing of nsTestSample.exe (xpcom/sample).  

With the above change:

bash-2.05a$ dumpbin /imports *.exe
Microsoft (R) COFF Binary File Dumper Version 6.00.8168
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.


Dump of file nsTestSample.exe

File Type: EXECUTABLE IMAGE

  Section contains the following imports:

    xpcom.dll
                40B0A0 Import Address Table
                40BFA0 Import Name Table
                     0 time date stamp
                     0 Index of first forwarder reference

                 840  NS_GetMemoryManager
                 85F  NS_ShutdownXPCOM
                 85D  NS_RegisterXPCOMExitRoutine
                 842  NS_InitXPCOM2

Without the change:

bash-2.05a$ dumpbin /imports *.exe
Microsoft (R) COFF Binary File Dumper Version 6.00.8168
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.


Dump of file nsTestSample.exe

File Type: EXECUTABLE IMAGE

  Section contains the following imports:

    xpcom.dll
                42F45C Import Address Table
                42F238 Import Name Table
                     0 time date stamp
                     0 Index of first forwarder reference

                 874  ?strncmp@nsCRT@@SAHPBG0I@Z
                 870  ?strlen@nsCRT@@SAIPBG@Z
                 7F8  ?ToUpper@nsCRT@@SADD@Z
                 523  ?HashCode@nsCRT@@SAIPBGPAI@Z
                 522  ?HashCode@nsCRT@@SAIPBDPAI@Z
                 8AA  NS_ShutdownXPCOM
                 7ED  ?ToLower@nsCRT@@SADD@Z
                 88D  NS_InitXPCOM2

Assignee: jaggernaut → dougt
Comment on attachment 82247 [details] [diff] [review]
Removes nsCRT  v.1

the |Compare1To1| fix is not symmetric: why not fix very positive numbers as
well?  You should be using |nsCharTraits<PRUnichar>::compare| in |Compare2To2|.
 In fact, in |Compare1To1| as well.

Ow!  An |extern| function declaration.	Evil.  You should probably include
nsCharTraits.h and use |nsCharTraits<PRUnichar>::length|.  It's really wrong to
write this function again.

It's too bad you had to copy the hash function.  There're to many copies of
this stuff already, and it denies guarantees of hash compatibility.  I don't
see any way around it though, without pulling the hash functions out into their
own library that everyone could use...	and that's way beyond the pale of this
bug.
Attachment #82247 - Flags: needs-work+
In case my grammar was ambiguous (and it was to me on re-reading), I meant:

  in |Compare1To1|  --use--> |nsCharTraits<char>::compare|
  in |Compare2To2|  --use--> |nsCharTraits<PRUnichar>::compare|
I discussed this with dougt.  I'm going to update his patch with the suggestions
made by me and jag (since doug is pressed for time) as noted in the bug.  I will
attach to the bug as an update of his patch.  We'll go on from there.  Jag and I
both strongly support getting a good fix in for this bug asap.
noting the bugs for which I am the driver
Whiteboard: [driver:scc]
Attached patch update of dougt's patch (obsolete) — Splinter Review
I'm happy to debate whether I should have changed |strlen(some_char_ptr)| to
|nsCharTraits<char>::length(some_char_ptr)|.  I did it for symmetry, since I
_had_ to do it for all the |PRUnichar| cases.  I could be talked out of it,
though I predict it makes exactly the same code and it may lower the overall
surprise factor.

I didn't include jag's suggested fix for |nsCharTraits<PRUnichar>::compare|
because I don't understand why he included hand-rolled code.  He and I should
discuss this, then he can further update this patch, which builds and runs on
my machines-of-the-moment (MacOS X, Linux)
Attachment #82247 - Attachment is obsolete: true
This does removed the nsCRT dependency and does not create any new dependencies
on XPCOM.  Great work scc.

Comment on attachment 83074 [details] [diff] [review]
update of dougt's patch

nit: spacing off in the comment.  Maybe intentional?:

>       // The following cases are rare and survivable caller errors.
>       //  Two null pointers are equal, but any string, even 0 length
>       //  is greater than a null pointer.  It might not really matter,
>       //  but we pick something reasonable anyway.
Attachment #83074 - Flags: review+
If you have for example PRUnichar(255) and PRUnichar(257), in a little endian
encoding those become |0xFF 0x00| and |0x01 0x01|. memcmp won't take the high
byte into account when comparing these two values and will thus say that
PRUnichar(255) is larger than PRUnichar(257). That's why I'm handrolling that loop.
diff -u please!  :-)

/be
I hated the spacing, but that's what emacs gave me and wouldn't let me fix; back
to vi.  My next patch will be -u.  Jag's going to add the |#include "nsCRT.h"|s
required on windows and Linux, I'll update for Mac.
thou shall not blame emacs.  send me your .emacs and I shall hack.
Attachment #83074 - Attachment is obsolete: true
Comment on attachment 83109 [details] [diff] [review]
Updated to include ::compare fix and nsCRT.h includes

thanks for finding all of these.  r=dougt
Attachment #83109 - Flags: review+
scc, are you happy with jag's last changes?  Happy enough to sr' them so that I 
can land these changes on the trunk?
his last patch is missing linux and mac changes to include nsCRT.h in files that
need it (now that they don't get it from string).  I'm adding the linux and mac
(OS X/mach-o) includes now.  We'll need to get a Mac buddy to build on classic
or carbon to find the real mac specific fixes.  I (for some reason I'm still
trying to understand) can't build non-mach-o builds on my Mac.
Blocks: 143200
No longer blocks: 143200
there's more to go here, but I have to stop for now.  Attaching my work so far,
so that someone else can continue from here.
Attachment #83109 - Attachment is obsolete: true
extra files that were touched:

mozilla/extensions/xmlextras/tests/TestXMLExtras.cpp
mozilla/extensions/p3p/src/nsP3PService.cpp
mozilla/extensions/interfaceinfo/src/iixprivate.h
mozilla/extensions/transformiix/source/base/Double.cpp

mozilla/xpfe/components/filepicker/src/nsFileView.cpp
mozilla/xpfe/components/xremote/src/XRemoteService.cpp

mozilla/gfx/src/mac/nsUnicodeMappingUtil.cpp
mozilla/gfx/src/mac/nsPrintOptionsX.cpp
mozilla/widget/src/mac/nsClipboard.cpp
mozilla/widget/src/mac/nsMacEventHandler.cpp
mozilla/widget/src/mac/nsMacWindow.cpp
mozilla/widget/src/mac/nsMenuX.cpp
mozilla/widget/src/mac/nsMimeMapper.cpp
mozilla/widget/src/mac/nsSound.cpp
mozilla/widget/src/mac/nsTextWidget.cpp
mozilla/embedding/browser/powerplant/source/CAppFileLocationProvider.cpp
mozilla/embedding/browser/powerplant/source/CBrowserApp.cp
mozilla/embedding/browser/powerplant/source/CBrowserShell.cpp
mozilla/embedding/browser/powerplant/source/CProfileManager.cpp
mozilla/embedding/browser/powerplant/source/CTextInputEventHandling.cpp
mozilla/xpfe/appshell/src/nsMacMIMEDataSource.cpp
Attachment #83512 - Attachment is obsolete: true
Hrm, and someone will have to do the same for the commercial builds...
Comment on attachment 83594 [details] [diff] [review]
builds on linux, windows, mac classic, solaris

r=/sr=jag
Attachment #83594 - Flags: superreview+
commerical is fine.  I got it covered.

waiting on scc for a r=.
Comment on attachment 83594 [details] [diff] [review]
builds on linux, windows, mac classic, solaris

r=scc; hope you caught them all or it'll be a long night :-)
Attachment #83594 - Flags: review+
Keywords: topembedtopembed+
um, doug?
+
+#ifndef nsCharTraits_h___
+#include "nsCharTratis.h"
+#endif

Is that a typo, or do we intentionally mispell nsCharTraits.h?
leaf: good catch.  I will fix it up when the tree opens.
i already fixed that on trunk
Comment on attachment 83594 [details] [diff] [review]
builds on linux, windows, mac classic, solaris

a=chofmann,dbaron,valeski for checkin to the 1.0 branch.
Attachment #83594 - Flags: approval+
Checked into trunk and branch
Status: NEW → RESOLVED
Closed: 22 years ago
Keywords: fixed1.0.0
Resolution: --- → FIXED
No longer blocks: 143200
I think there is a bug in DOMParser.cpp from this. In the ParseFromString method
in line :
  nsresult rv = ConvertWStringToStream(str, nsCRT::strlen(str),
getter_AddRefs(stream), &contentLength);
str is a PRUnichar * and strlen accept char*
Anyway I have a core dump each time I use this method from JS
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Cyril, 
File a seperate bug, attach a test case, and reference this bug.  closing again.
Status: REOPENED → RESOLVED
Closed: 22 years ago22 years ago
Resolution: --- → FIXED
Component: String → XPCOM
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: