Author Topic: issue on NullLoader class  (Read 14288 times)

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7253
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: issue on NullLoader class
« Reply #15 on: December 04, 2009, 11:02:19 am »
Quote
Nevertheless this code should be changed to something that works correctly (or removed), but I think it can make sense to have it.


Waiting for your good news.

To make it clear: the code to change is not the NullLoader code (in my opinion), but the code that uses it.
But I don't think I find the time to dig into it soon.

Offline blueshake

  • Regular
  • ***
  • Posts: 459
Re: issue on NullLoader class
« Reply #16 on: December 04, 2009, 11:18:35 am »
it is Ok if NullLoader class can load the text from the Editor when I set the args to true.

Anyway thanks your effort.
Keep low and hear the sadness of little dog.
I fall in love with a girl,but I don't dare to tell her.What should I do?

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7253
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: issue on NullLoader class
« Reply #17 on: December 04, 2009, 12:14:15 pm »
This snippet (FileManager::Load) copies the bytes, m_pchData points to, into NullLoader's data, so no crash anymore (I'm not sure if everything is correct, as written before I have no time, to work on it seriously).

Code: [Select]
                if(ed && fileName == ed->GetFilename())
                {
                    wxString s(ed->GetControl()->GetText());
                    int len = s.length() + 1;
                    NullLoader *nl = new NullLoader(file, (char*)wxStrcpy(new wxChar[len], s.c_str()), len * sizeof(wxChar));
                    return nl;
                }

But you get a problem here:

If I see it correctly, FileLoader loads the content of the files into data (byte by byte from disk), but the editors hold a widechar-string (at least in unicode-builds), so loading a file from disk or via fileloader does not lead to the same content automatically and parsing might fail (happens here for example).

Offline blueshake

  • Regular
  • ***
  • Posts: 459
Re: issue on NullLoader class
« Reply #18 on: December 04, 2009, 01:13:36 pm »
hi,jens:

just as what visualFc do ,what about using this way?


NullLoader *nl = new NullLoader(file, strcpy(new char[len* sizeof(wxChar)], (const char*)s.mb_str()), len * sizeof(wxChar));


« Last Edit: December 04, 2009, 02:03:11 pm by blueshake »
Keep low and hear the sadness of little dog.
I fall in love with a girl,but I don't dare to tell her.What should I do?

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: issue on NullLoader class
« Reply #19 on: December 04, 2009, 11:54:01 pm »
it is Ok if NullLoader class can load the text from the Editor when I set the args to true.
No, because then it is not a NullLoader any more. However, if you insist of doing a fix on loader level, you can write a class like this:

class EditorReuser : public LoaderBase
{
  EditorReuser(cbEditor const& e)
    {
      wxString s(e.GetControl()->GetText());
      fileName = e.GetFilename();
      data = new char[s.length() * sizeof(wxChar)];
      len = s.length() * sizeof(wxChar);
      Ready();
    }
    void operator()(){};
};


Then use a EditorReuser instead of a NullLoader.

Note: not checked for typos or correctness.

Edit: also note that you may have to convert the editor's text, since that will be Unicode characters, not UTF-8 or some Windows codepage (which the parser might expect). Or, you will have to tell the parser that the encoding is Unicode.
« Last Edit: December 04, 2009, 11:57:21 pm by thomas »
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline blueshake

  • Regular
  • ***
  • Posts: 459
Re: issue on NullLoader class
« Reply #20 on: December 05, 2009, 11:52:27 am »
Thanks. I will have a try when I get my time.
Keep low and hear the sadness of little dog.
I fall in love with a girl,but I don't dare to tell her.What should I do?

Offline blueshake

  • Regular
  • ***
  • Posts: 459
Re: issue on NullLoader class
« Reply #21 on: December 06, 2009, 11:02:00 am »
hi,devs:

I think we can learn something from file.h of wxWidget.

code snippet:

Code: [Select]
  bool Write(const wxString& s, const wxMBConv& conv = wxConvUTF8)
  {
      const wxWX2MBbuf buf = s.mb_str(conv);
      if (!buf)
          return false;
      size_t size = strlen(buf);
      return Write((const char *) buf, size) == size;
  }
Keep low and hear the sadness of little dog.
I fall in love with a girl,but I don't dare to tell her.What should I do?