Esempio n. 1
0
static HGLOBAL
convert_to_handle_as_coded (Lisp_Object coding_system)
{
  HGLOBAL htext;
  unsigned char *dst = NULL;
  struct coding_system coding;

  ONTRACE (fprintf (stderr, "convert_to_handle_as_coded: %s\n",
		    SDATA (SYMBOL_NAME (coding_system))));

  setup_windows_coding_system (coding_system, &coding);
  coding.dst_bytes = SBYTES (current_text) * 2;
  coding.destination = xmalloc (coding.dst_bytes);
  encode_coding_object (&coding, current_text, 0, 0,
			SCHARS (current_text), SBYTES (current_text), Qnil);

  htext = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, coding.produced +2);

  if (htext != NULL)
    dst = (unsigned char *) GlobalLock (htext);

  if (dst != NULL)
    {
      memcpy (dst, coding.destination, coding.produced);
      /* Add the string terminator.  Add two NULs in case we are
	 producing Unicode here.  */
      dst[coding.produced] = dst[coding.produced+1] = '\0';

      GlobalUnlock (htext);
    }

  xfree (coding.destination);

  return htext;
}
Esempio n. 2
0
static Lisp_Object
render_locale (void)
{
  HANDLE hlocale = NULL;
  LCID * lcid_ptr;

  ONTRACE (fprintf (stderr, "render_locale\n"));

  if (current_lcid == LOCALE_NEUTRAL || current_lcid == DEFAULT_LCID)
    return Qt;

  hlocale = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, sizeof (current_lcid));
  if (hlocale == NULL)
    return Qnil;

  if ((lcid_ptr = (LCID *) GlobalLock (hlocale)) == NULL)
    {
      GlobalFree (hlocale);
      return Qnil;
    }

  *lcid_ptr = current_lcid;
  GlobalUnlock (hlocale);

  if (SetClipboardData (CF_LOCALE, hlocale) == NULL)
    {
      GlobalFree (hlocale);
      return Qnil;
    }

  return Qt;
}
Esempio n. 3
0
TCA UniqueStubs::add(const char* name, TCA start) {
  auto const inAStubs = start > mcg->code.stubs().base();
  UNUSED auto const stop = inAStubs ? mcg->code.stubs().frontier()
    : mcg->code.main().frontier();

  FTRACE(1, "unique stub: {} {} -- {:4} bytes: {}\n",
         inAStubs ? "astubs @ "
         : "  ahot @  ",
         static_cast<void*>(start),
         static_cast<size_t>(stop - start),
         name);

  ONTRACE(2,
          [&]{
            Disasm dasm(Disasm::Options().indent(4));
            std::ostringstream os;
            dasm.disasm(os, start, stop);
            FTRACE(2, "{}\n", os.str());
          }()
         );

  mcg->recordGdbStub(
    mcg->code.blockFor(start),
    start,
    strdup(folly::format("HHVM::{}", name).str().c_str())
  );
  return start;
}
Esempio n. 4
0
static Lisp_Object
render (Lisp_Object oformat)
{
  HGLOBAL htext = NULL;
  UINT format = XFASTINT (oformat);

  ONTRACE (fprintf (stderr, "render\n"));

  if (NILP (current_text))
    return Qnil;

  if (current_requires_encoding || format == CF_UNICODETEXT)
    {
      if (format == current_clipboard_type)
	htext = convert_to_handle_as_coded (current_coding_system);
      else
	switch (format)
	  {
	  case CF_UNICODETEXT:
	    htext = convert_to_handle_as_coded (QUNICODE);
	    break;
	  case CF_TEXT:
	  case CF_OEMTEXT:
	    {
	      Lisp_Object cs;
	      cs = coding_from_cp (cp_from_locale (current_lcid, format));
	      htext = convert_to_handle_as_coded (cs);
	      break;
	    }
	  }
    }
  else
    htext = convert_to_handle_as_ascii ();

  ONTRACE (fprintf (stderr, "render: htext = 0x%08X\n", (unsigned) htext));

  if (htext == NULL)
    return Qnil;

  if (SetClipboardData (format, htext) == NULL)
    {
      GlobalFree (htext);
      return Qnil;
    }

  return Qt;
}
Esempio n. 5
0
static Lisp_Object
render_all (Lisp_Object ignore)
{
  ONTRACE (fprintf (stderr, "render_all\n"));

  /* According to the docs we should not call OpenClipboard() here,
     but testing on W2K and working code in other projects shows that
     it is actually necessary.  */

  OpenClipboard (NULL);

  /* There is no useful means to report errors here, there are none
     expected anyway, and even if there were errors, they wouldn't do
     any harm.  So we just go ahead and do what has to be done without
     bothering with error handling.  */

  ++modifying_clipboard;
  EmptyClipboard ();
  --modifying_clipboard;

  /* For text formats that we don't render here, the OS can use its
     own translation rules instead, so we don't really need to offer
     everything.  To minimize memory consumption we cover three
     possible situations based on our primary format as detected from
     selection-coding-system (see setup_config()):

     - Post CF_TEXT only.  Let the OS convert to CF_OEMTEXT and the OS
       (on NT) or the application (on 9x/Me) convert to
       CF_UNICODETEXT.

     - Post CF_OEMTEXT only.  Similar automatic conversions happen as
       for CF_TEXT.

     - Post CF_UNICODETEXT + CF_TEXT.  9x itself ignores
       CF_UNICODETEXT, even though some applications can still handle
       it.

       Note 1: We render the less capable CF_TEXT *before* the more
       capable CF_UNICODETEXT, to prevent clobbering through automatic
       conversions, just in case.

       Note 2: We could check os_subtype here and only render the
       additional CF_TEXT on 9x/Me.  But OTOH with
       current_clipboard_type == CF_UNICODETEXT we don't involve the
       automatic conversions anywhere else, so to get consistent
       results, we probably don't want to rely on it here either.  */

  render_locale ();

  if (current_clipboard_type == CF_UNICODETEXT)
    render (make_number (CF_TEXT));
  render (make_number (current_clipboard_type));

  CloseClipboard ();

  return Qnil;
}
Esempio n. 6
0
static HGLOBAL
convert_to_handle_as_ascii (void)
{
  HGLOBAL htext = NULL;
  int nbytes;
  int truelen;
  unsigned char *src;
  unsigned char *dst;

  ONTRACE (fprintf (stderr, "convert_to_handle_as_ascii\n"));

  nbytes = SBYTES (current_text) + 1;
  src = SDATA (current_text);

  /* We need to add to the size the number of LF chars where we have
     to insert CR chars (the standard CF_TEXT clipboard format uses
     CRLF line endings, while Emacs uses just LF internally).  */

  truelen = nbytes + current_num_nls;

  if ((htext = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, truelen)) == NULL)
    return NULL;

  if ((dst = (unsigned char *) GlobalLock (htext)) == NULL)
    {
      GlobalFree (htext);
      return NULL;
    }

  /* convert to CRLF line endings expected by clipboard */
  while (1)
    {
      unsigned char *next;
      /* copy next line or remaining bytes including '\0' */
      next = _memccpy (dst, src, '\n', nbytes);
      if (next)
	{
	  /* copied one line ending with '\n' */
	  int copied = next - dst;
	  nbytes -= copied;
	  src += copied;
	  /* insert '\r' before '\n' */
	  next[-1] = '\r';
	  next[0] = '\n';
	  dst = next + 1;
	}
      else
	/* copied remaining partial line -> now finished */
	break;
    }

  GlobalUnlock (htext);

  return htext;
}
Esempio n. 7
0
static LRESULT CALLBACK ALIGN_STACK
owner_callback (HWND win, UINT msg, WPARAM wp, LPARAM lp)
{
  switch (msg)
    {
    case WM_RENDERFORMAT:
      ONTRACE (fprintf (stderr, "WM_RENDERFORMAT\n"));
      run_protected (render, make_number (wp));
      return 0;

    case WM_RENDERALLFORMATS:
      ONTRACE (fprintf (stderr, "WM_RENDERALLFORMATS\n"));
      run_protected (render_all, Qnil);
      return 0;

    case WM_DESTROYCLIPBOARD:
      if (!modifying_clipboard)
	{
	  ONTRACE (fprintf (stderr, "WM_DESTROYCLIPBOARD (other)\n"));
	  current_text = Qnil;
	  current_coding_system = Qnil;
	}
      else
	{
	  ONTRACE (fprintf (stderr, "WM_DESTROYCLIPBOARD (self)\n"));
	}
      return 0;

    case WM_DESTROY:
      if (win == clipboard_owner)
	clipboard_owner = NULL;
      break;
    }

  return DefWindowProc (win, msg, wp, lp);
}
Esempio n. 8
0
void recordType(TypeProfileKey key, DataType dt) {
  if (!profiles) return;
  if (!isProfileRequest()) return;
  assert(dt != KindOfUninit);
  // Normalize strings to KindOfString.
  if (dt == KindOfStaticString) dt = KindOfString;
  TRACE(1, "recordType lookup: %s -> %d\n", key.m_name->data(), dt);
  ValueProfile *prof = keyToVP(key, KeyToVPMode::Write);
  if (prof->m_totalSamples != kMaxCounter) {
    prof->m_totalSamples++;
    // NB: we can't quite assert that we have fewer than kMaxCounter samples,
    // because other threads are updating this structure without locks.
    int dtIndex = getDataTypeIndex(dt);
    if (prof->m_samples[dtIndex] < kMaxCounter) {
      prof->m_samples[dtIndex]++;
    }
  }
  ONTRACE(2, prof->dump());
}
Esempio n. 9
0
static HGLOBAL
convert_to_handle_as_coded (Lisp_Object coding_system)
{
  HGLOBAL htext = NULL, htext2;
  int nbytes;
  unsigned char *src;
  unsigned char *dst = NULL;
  int bufsize;
  struct coding_system coding;
  Lisp_Object string = Qnil;

  ONTRACE (fprintf (stderr, "convert_to_handle_as_coded: %s\n",	
		    SDATA (SYMBOL_NAME (coding_system))));

  setup_coding_system (Fcheck_coding_system (coding_system), &coding);
  coding.src_multibyte = 1;
  coding.dst_multibyte = 0;
  /* Need to set COMPOSITION_DISABLED, otherwise Emacs crashes in
     encode_coding_iso2022 trying to dereference a null pointer.  */
  coding.composing = COMPOSITION_DISABLED;
  if (coding.type == coding_type_iso2022)
    coding.flags |= CODING_FLAG_ISO_SAFE;
  coding.mode |= CODING_MODE_LAST_BLOCK;
  /* Force DOS line-ends. */
  coding.eol_type = CODING_EOL_CRLF;

  if (SYMBOLP (coding.pre_write_conversion)
      && !NILP (Ffboundp (coding.pre_write_conversion)))
    string = run_pre_post_conversion_on_str (current_text, &coding, 1);
  else
    string = current_text;

  nbytes = SBYTES (string);
  src = SDATA (string);

  bufsize = encoding_buffer_size (&coding, nbytes) +2;
  htext = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, bufsize);

  if (htext != NULL)
    dst = (unsigned char *) GlobalLock (htext);

  if (dst != NULL)
    {
      encode_coding (&coding, src, dst, nbytes, bufsize-2);
      /* Add the string terminator.  Add two NULs in case we are
	 producing Unicode here.  */
      dst[coding.produced] = dst[coding.produced+1] = '\0';
    }

  if (dst != NULL)
    GlobalUnlock (htext);

  if (htext != NULL)
    {
      /* Shrink data block to actual size.  */
      htext2 = GlobalReAlloc (htext, coding.produced+2,
			      GMEM_MOVEABLE | GMEM_DDESHARE);
      if (htext2 != NULL) htext = htext2;
    }

  return htext;
}