Beispiel #1
0
int calibre_show_python_error(const char *preamble, int code) {
    PyObject *exc, *val, *tb, *str;
    int ret, issysexit = 0; char *i; 

    if (!PyErr_Occurred()) return code;
    issysexit = PyErr_ExceptionMatches(PyExc_SystemExit);

    PyErr_Fetch(&exc, &val, &tb);

    if (exc != NULL) {
        PyErr_NormalizeException(&exc, &val, &tb);

        if (issysexit) {
            return (val) ? handle_sysexit(val) : 0;
        }
        if (val != NULL) {
            str = PyObject_Unicode(val);
            if (str == NULL) {
                PyErr_Clear();
                str = PyObject_Str(val);
            }
            i = PyString_AsString(str);
            ret = report_code(preamble, (i==NULL)?ERR_OOM:i, code);
            if (tb != NULL) {
                PyErr_Restore(exc, val, tb);
                PyErr_Print();
            }
            return ret;
        }
    }
    return report_code(preamble, "", code);
}
Beispiel #2
0
/* escreve os dados no arquivo. */
void AsmGen::assemble ()
{
  context.header.magic = MAGIC_VERSION_NUM;
  context.header.major_version = VM_VERSION_MAJOR;
  context.header.minor_version = VM_VERSION_MINOR;
  context.header.path_version = VM_VERSION_PATH;

  mount_string_table ();
  mount_num_table ();
  mount_code_table ();

  if (context.header.string_table_len > 0)
	 report_string_table ();
  if (context.header.num_table_len > 0)
	 report_num_table ();
  if (label_table.size () > 0)
	 report_label_table ();

  report_code ();

  output = new ofstream (output_file_name.c_str(), ios::binary);

  output->write ( reinterpret_cast<char *>(&context.header), sizeof (Header));

  if (context.header.string_table_len > 0)
	 output->write ( reinterpret_cast<char *>(context.string_table),
						 context.header.string_table_len * sizeof (char));

  if (context.header.num_table_len > 0)
	 output->write ( reinterpret_cast<char *>(context.num_table),
						 context.header.num_table_len * sizeof (NUMBER));

  output->write ( reinterpret_cast<char *>(context.code_section),
						context.header.code_len * sizeof (Instruction));
  output->close ();
}