Exemplo n.º 1
0
void PythonLogSink::logMessage(const tm* pTime, unsigned millis,
        const string& category, unsigned severity, const UTF8String& sMsg)
{
    string sSeverity = boost::to_lower_copy(string(Logger::severityToString(severity)));
    PyObject * extra = PyDict_New();
    PyObject * pyCat = PyString_FromString(category.c_str());

    PyDict_SetItemString(extra, "category", pyCat);

    PyObject * pyMsg = PyString_FromString(sMsg.c_str());
    PyObject * args = PyTuple_New(1);
    PyObject * kwargs = PyDict_New();
    PyDict_SetItemString(kwargs, "extra", extra);
    PyTuple_SetItem(args, 0, pyMsg);

    PyObject_Call(PyObject_GetAttrString(m_pyLogger, sSeverity.c_str()), args, kwargs);

    Py_DECREF(extra);
    Py_DECREF(pyCat);
    Py_DECREF(args);
    Py_DECREF(kwargs);
}
Exemplo n.º 2
0
	void Font::loadGlyph(const UTF8String & str) {
		UCodePoint codePoint;
		for ( auto it = str.getBegin(); str.iterate(&it, &codePoint);) {
			loadGlyph(codePoint);
		}
	}
Exemplo n.º 3
0
const AnsiString & __fastcall AnsiString::operator +=(const UTF8String & rhs)
{
  Data.append(reinterpret_cast<const char *>(rhs.c_str()), rhs.size());
  return *this;
}
Exemplo n.º 4
0
const UTF8String & __fastcall UTF8String::operator +=(const UTF8String & rhs)
{
  Data.append(rhs.Data.c_str(), rhs.size());
  return *this;
}
Exemplo n.º 5
0
   void VTune_RegisterMethod(AvmCore* core, JITCodeInfo* inf) 
   {       
		// assume no method inlining so start/end of JIT code gen = method start/end
       uintptr startAt = inf->startAddr;
       uintptr endAt = inf->endAddr;
		uint32 methodSize = endAt - startAt;

       Stringp name = inf->method->format(core);
       int idx[4];
       bool hasClass = locateNames(core, name, idx);

		// register the method
		iJIT_Method_Load ML;
       Stringp mname = name->substring(idx[2],idx[3]);
		VMPI_memset(&ML, 0, sizeof(iJIT_Method_Load));
       ML.method_id = (inf->vtune) ? inf->vtune->method_id : iJIT_GetNewMethodID();
       ML.method_name = string2char(core, mname);
		ML.method_load_address = (void *)startAt;	// virtual address of that method  - This determines the method range for the iJVM_EVENT_TYPE_ENTER/LEAVE_METHOD_ADDR events
		ML.method_size = methodSize;	// Size in memory - Must be exact

		// md position / line number table
       SortedIntMap<LineNumberRecord*>* tbl = &inf->lineNumTable;
		int size = tbl->size();
		LineNumberInfo* lines = 0;
		if (size)
		{
			int bsz = size*sizeof(LineNumberInfo);
			lines = (LineNumberInfo*) malloc(bsz);
			VMPI_memset(lines, 0, bsz);
		}

       String* fileName = 0;
       int at = 0;
       for(int i=0; i<size; i++) 
		{
			sintptr mdPos = tbl->keyAt(i);
			LineNumberRecord* entry = tbl->at(i);
           if (entry->filename && entry->lineno)
           {
               if (!fileName) fileName = entry->filename;

               // @todo file name should be part of the lines[] record, no?
               lines[at].LineNumber = entry->lineno;
               lines[at].Offset = mdPos - startAt;
               at++;
           }
       }

       // @todo hack for vtune since it can't process multiple records with the same method name 
       if (inf->sid>0 && at>0) {
           mname = core->concatStrings(mname,core->newString("_L"));
           mname = core->concatStrings(mname,core->intToString(lines[0].LineNumber));
           mname = core->concatStrings(mname,core->newString("_"));
           mname = core->concatStrings(mname,core->intToString(inf->sid));
           if (ML.method_name) free(ML.method_name);
           ML.method_name = string2char(core,mname);
       }

       ML.line_number_table = lines;   // Pointer to the begining of the line numbers info array
       ML.line_number_size = at;       // Line Table size in number of entries - Zero if none

       UTF8String* utf = ( fileName ) ? fileName->toUTF8String() : core->kEmptyString->toUTF8String();
		
		ML.class_id = 0;                // uniq class ID
       ML.class_file_name = (hasClass) ? string2char(core,name->substring(idx[0],idx[1])) : 0;     // class file name 
		ML.source_file_name = (char *)(malloc((utf->length()+3)*sizeof(char)));   // +1 for \0 and +2 for wtoc's ()
		wtoc(ML.source_file_name, utf->c_str(), 0);	// source file name 

		ML.user_data = NULL;            // bits supplied by the user for saving in the JIT file...
		ML.user_data_size = 0;          // the size of the user data buffer
		ML.env = iJDE_JittingAPI;

		// DumpVTuneMethodInfo(core, &ML); // Uncommented to debug VTune
		iJIT_NotifyEvent(iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED, &ML);

       if (inf->vtune && core->VTuneStatus == iJIT_CALLGRAPH_ON) 
		{
			MMgc::GCHeap* heap = core->GetGC()->GetGCHeap();
           heap->SetPageProtection(inf->vtune, sizeof (iJIT_Method_NIDS), false, true);   
       }

		// free everything we alloc'd  ( @todo did vtune really copy all the strings?!? )
		if (ML.line_number_table) free(ML.line_number_table);
       if (ML.class_file_name && hasClass) free(ML.class_file_name);
		if (ML.method_name) free(ML.method_name);
		if (ML.source_file_name) free(ML.source_file_name);
	}	
Exemplo n.º 6
0
void TActionLog::Add(UnicodeString Line)
{
  DebugAssert(FConfiguration);
  if (FLogging)
  {
    TGuard Guard(FCriticalSection);
    if (FLogger == nullptr)
    {
      OpenLogFile();
    }

    if (FLogger != nullptr)
    {
      try
      {
        UTF8String UtfLine = UTF8String(Line);
        size_t Written =
          FLogger->Write(UtfLine.c_str(), UtfLine.Length());
        if (Written != static_cast<size_t>(UtfLine.Length()))
        {
          throw ECRTExtException(L"");
        }
        Written =
          FLogger->Write("\n", 1);
        if (Written != 1)
        {
          throw ECRTExtException(L"");
        }
      }
      catch (Exception &E)
      {
//        FCriticalSection.Release();

        // avoid endless loop when trying to close tags when closing log, when logging has failed
        if (!FFailed)
        {
          FFailed = true;
          // We failed logging, turn it off and notify user.
          FConfiguration->SetLogActions(false);
          if (FConfiguration->GetLogActionsRequired())
          {
            throw EFatal(&E, LoadStr(LOG_FATAL_ERROR));
          }
          else
          {
            try
            {
              throw ExtException(&E, LoadStr(LOG_GEN_ERROR));
            }
            catch (Exception &E2)
            {
              if (FUI != nullptr)
              {
                FUI->HandleExtendedException(&E2);
              }
            }
          }
        }
      }
    }
  }
}
Exemplo n.º 7
0
 bool operator==(const UTF8String& s1, const UTF8String& s2)
 {
     return s1.getSrc() == s2.getSrc();
 }
Exemplo n.º 8
0
Anything Anything::decodeJSON(const UTF8String& jsonstring, bool errorhandling) throw (IOException) 
{
	char* buffer = 0;
	struct JSON_parser_struct* jc = 0;

	try
	{
		char errbuf[512];

		JSON_config config;
		init_JSON_config(&config);

		Anything stack = new ListAnythingI(); 
		UTF8StringBuffer trace;
		if (errorhandling) trace->ensureCapacity(jsonstring->length());

		config.depth = -1;
		config.callback = &createAnythingCallback;
		config.callback_ctx = (void*) stack.get();
		config.allow_comments = 0;
		config.handle_floats_manually = 1;

		jc = new_JSON_parser(&config);

		int len = jsonstring->length() + 1;
		buffer = new char[len];
		strcpy(buffer, constcharptr(jsonstring));

		for (int i = 0; i < len; ++i) 
		{
			int nextchar = buffer[i];
			if (nextchar <= 0) break;
			if (!JSON_parser_char(jc, nextchar)) 
			{
				if (errorhandling) trace->append(" <-- syntax error\n");
				sprintf(errbuf, "JSON_parser_char: syntax error at position : %d", i);
				trace->append(errbuf);
				throw IOException(WITHDETAILS(String(trace->toString())));
			}
			if (errorhandling) trace->append((char) nextchar);
		}

		if (!JSON_parser_done(jc)) 
		{
			if (errorhandling) trace->append(" <-- syntax error\n");
			sprintf(errbuf, "JSON_parser_end: syntax error, not yet done.");
			trace->append(errbuf);
			throw IOException(WITHDETAILS(String(trace->toString())));
		}

		// cleanup
		delete_JSON_parser(jc);
		delete [] buffer;

		return pop(stack);
	}
	catch (const IOException&)
	{
		delete_JSON_parser(jc);
		delete [] buffer;
		throw;
	}
	catch (const Exception& e)
	{
		delete_JSON_parser(jc);
		delete [] buffer;
		throw IOException(e->toString());
	}
}
String AbstractContextI::loadValueFromURL(const String& urlstring) const throw (Exception)
{
	String result;
	StringBuffer buf;
	buf->append(urlstring);
	if (0 == buf->indexOf(L"http://"))
	{
		URL url = new URLI(urlstring);
		HttpURLConnection httpurlconnection;
		url->openConnection()->downcast(httpurlconnection);
		if (verboseOutput()) cout << "JNDI context : Get response from url : " << urlstring << endl;
		int rc = httpurlconnection->getResponseCode();
		UTF8StringBuffer cbuf;
#if defined (_WINDOWS_SOURCE)
		cbuf->append(getenv("TEMP"));
		cbuf->append("\\");
		cbuf->append(getenv("USERNAME"));
		cbuf->append(".");
#else
		cbuf->append(getenv("USER_HOME"));
		cbuf->append("/.");
#endif
		cbuf->append(urlstring->toMD5());
		cbuf->append(".properties");
		String cachefilepath = cbuf->toString()->toLowerCase();
		if (200 != rc) 
		{
			if (verboseOutput()) cout << "JNDI context : HTTP status = " << rc << endl;
			if (verboseOutput()) cout << "JNDI context : Trying to load from cached file : " << cachefilepath << endl;
			InputStream file = new FileInputStreamI(cachefilepath);
			UTF8String content;
			file->read(content, 0);
			file->close();
			result = content->toString();
		}
		else
		{
			String response = httpurlconnection->getResponseMessage();
			Writer file = new FileWriterI(cachefilepath);
			file->write(response);
			file->close();
			if (verboseOutput()) cout << "JNDI context : Caching to file : " << cachefilepath << endl;
			result = response;
		}
	}
	else if (0 == buf->indexOf(L"file://"))
	{
		result = loadValueFromFile(urlstring);
	}
	else
	{
		throw NamingException(WITHDETAILS(L"Unsupported URI format: " + urlstring));
	}
	StringBuffer b = result;
	while (-1 < b->indexOf(L"${"))
	{
		InitialContext initialcontext = InitialContext::newInstance();
		int bpos = 0;
		int epos = 0;
		while (bpos < b->length())
		{
			bpos = b->indexOf(L"${", bpos);
			if (-1 == bpos) break;
			epos = b->indexOf(L"}", bpos);
			String variablename = b->substring(bpos + 2, epos);
			StringAnything variablevalue ;
			initialcontext->lookup(L"/" + variablename, variablevalue);
			StringBuffer value = variablevalue->toString(); 
			if (-1 < value->indexOf(L"${" + variablename + L"}") )
				throw Exception(WITHDETAILS(L"Recursive reference found : ${" + variablename + L"}"));
			b->replace(bpos, epos + 1, value->toString());
			bpos = epos + 1;
		}
	}
	return b->toString();
}
Exemplo n.º 10
0
/**
 * Retrieves the value of this node.
 */
void NCDElementImpl::getNodeValue(
	UTF8String& output			///< [out] the value of this node is returned.
) const
{
	output.Empty();
}