Developer forums (C::B DEVELOPMENT STRICTLY!) > Development

issue on NullLoader class

<< < (2/5) > >>

blueshake:
can somebody fixed this problem?

so I can upload my real-time parse patch.thanks.

MortenMacFly:

--- Quote from: blueshake on December 03, 2009, 07:02:11 am ---can somebody fixed this problem?

--- End quote ---
How? As you see: It's nt that easy it seems. Probably Thomas (The creator of the NullLoader) can say something...?!

thomas:
I don't see what the issue is with NullLoader. NullLoader does what its name says, it loads nothing. It's a do-nothing dummy object with an empty operator() that can be inserted to FileManager's queue without making it crash. As a side effect, it also allows you to pass a file name and a byte buffer (pointer+size) to a callback function which is normally called after a file was loaded, so you don't have to implement the same function twice.

Yes, NullLoader's buffer member (inherited from LoaderBase) is a char*. That's what it should be. A loader does what it name says, it shuffles bytes from disk or some other medium (null, in this case) to some byte buffer. It does not know whether these bytes can be interpreted as unicode characters or not, and that's not its task either.
No, NullLoader (or LoaderBase for that matter) should not have a wxChar* buffer.

I haven't really looked in-depth what this is about, since it's code completion which I stay away from as far as I can, but here is an uneducated guess.
The first line in that snippet if(reuseEditors) looks like text that's in an editor is being sent to some other function (presumably one that parses the text). NullLoader doesn't care what the data is. The sending and the receiving end have to make sure that they talk about the same thing.
So, since you're saying that the data isn't read correctly, the probable reason is unicode text being copied from the editor and multibyte expected in the parser, or something similar.

blueshake:

--- Quote ---So, since you're saying that the data isn't read correctly, the probable reason is unicode text being copied from the editor and multibyte expected in the parser, or something similar.
--- End quote ---

hello,Thomas
what is your way to solve this issue.

my friend VisualFC give me such a way to solve it.


codes:
before :

--- Code: --- NullLoader(const wxString& name, char* buffer, size_t size) { fileName = name; data = buffer; len = size; Ready(); };
--- End code ---


VisualFC's  advice:

--- Code: ---    NullLoader(const wxString& name, const wxString& str)
    {
         //fileName = name; data = buffer; len = size; Ready();
        data = new char[str.Len()*2 + 1];
        strcpy(data, (const char*)str.mb_str());
        fileName = name; len = strlen(data);Ready();
    };
--- End code ---

and change the associate calling.

--- Code: ---                if(ed && fileName == ed->GetFilename())
                {
                    //wxString s(ed->GetControl()->GetText());
                    //#if wxCHECK_VERSION(2, 9, 0)
                    //NullLoader *nl = new NullLoader(file, (char*) s.wx_str(), s.length() * sizeof(wxChar));
                    //#else
                    //NullLoader *nl = new NullLoader(file, (char*) s.c_str(), s.length() * sizeof(wxChar));
                    //#endif
                    NullLoader *nl = new NullLoader(file, ed->GetControl()->GetText());
                    return nl;
                }
--- End code ---


yes , it work


so thomas,what is yuor opinion on these changes? thanks


MortenMacFly:

--- Quote from: blueshake on December 03, 2009, 10:47:14 am ---
--- Code: ---    NullLoader(const wxString& name, const wxString& str)
    {
         //fileName = name; data = buffer; len = size; Ready();
        data = new char[str.Len()*2 + 1];
        strcpy(data, (const char*)str.mb_str());
        fileName = name; len = strlen(data);Ready();
    };
--- End code ---

--- End quote ---
This is no good, as e.g. the member variable len is no longer assigned., Thus NullLoader will be interface incompatible. Don't change the interface, or the usage of member variables from LoaderBase / AbstractJob. Their meaning and content must be consistent!

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version