Home modules.gotpike.org
Username: Password: [Create Account]
[Forgot Password?]

Modules

ADT
Database
GTK2
GUI
IP
PiJAX
Public
Sql
Stdio
Subversion
System
Tools
Xosd
lua
v4l2
wx

Recent Changes

Public.Parser.XML2 1.50
Public.ZeroMQ 1.1
Public.Template.Mustache 1.0
Public.Protocols.XMPP 1.4
Sql.Provider.jdbc 1.0

Popular Downloads

Public.Parser.JSON2 1.0
Public.Parser.JSON 0.2
GTK2 2.23
Public.Web.FCGI 1.8
Public.Parser.XML2 1.48


Module Information
Public.Image.Cairo
Viewing contents of Public_Image_Cairo-0.93/cairoerror.c

/* -*- Mode: c; indent-tabs-mode: nil; c-basic-offset: 2; c-file-style: "gnu" -*-
 *
 * pike bindings for Cairo (http://www.cairographics.org)
 *
 * Started 2006-02-03
 * Copyright (C) 2006, David Vest 
 *
 * This library is free software; you can redistribute it and/or
 * modify it either under the terms of the GNU Lesser General Public
 * License version 2.1 as published by the Free Software Foundation
 * (the "LGPL") or, at your option, under the terms of the Mozilla
 * Public License Version 1.1 (the "MPL"). If you do not alter this
 * notice, a recipient may use your version of this file under either
 * the MPL or the LGPL.
 *
 * You should have received a copy of the LGPL along with this library
 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 * You should have received a copy of the MPL along with this library
 * in the file COPYING-MPL-1.1
 *
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
 * the specific language governing rights and limitations.
 */

#include "cairomod.h"

/* Combability defines pulled from the Subversion module. */
#if PIKE_MAJOR_VERSION==7 && PIKE_MINOR_VERSION<6
#define error_message desc
#define error_backtrace backtrace
#endif

#ifdef HAVE_CAIRO

/* Error internal object structure */

/*! @module Cairo
 */

/*! @class Error
 *!
 *!  An error generated by Cairo.
 */
struct error_obj {
  /*! @decl int code
   *!
   *! The error status code.
   */
  cairo_status_t cairo_status;

  /*! @decl string status_string
   *!
   *!   String representation of the error
   */
  struct pike_string *cairo_message;
};
static ptrdiff_t error_obj_off;
static struct program *error_program;

/* Prepare a cairo_status_t to be thrown as a pike error */

void cairo_pike_set_error (cairo_status_t err)
{
  struct object* o;
  struct svalue sv;
  push_int (err);
  push_object(clone_object(error_program, 1));
  if(Pike_sp[-1].type != PIKE_T_OBJECT || Pike_sp[-1].u.object == NULL) {
    pop_stack();
    push_error("Failed to clone Cairo.Error object\n");
    return;
  }

  assign_svalue (&throw_value, Pike_sp-1);
  throw_severity = THROW_ERROR;
}

/*! @decl void create( int code )
 *!
 *!  Create an error object with a specific error code.
 *!
 *! @param code
 *!   The status code, one of CAIRO_STATUS_*
 */
static void f_error_create (INT32 args)
{
  struct pike_string *msg;
  const char* msg_data;
  INT_TYPE status;
  struct error_obj *eo =
    (struct error_obj *)(Pike_fp->current_storage + error_obj_off);
  struct generic_error_struct *go =
    (struct generic_error_struct *)
    (get_storage (Pike_fp->current_object, generic_error_program) +
     generic_error_offset);

  get_all_args ("Error", args, "%d", &status);

  f_backtrace (0);
  push_int (0);
  push_int (Pike_sp[-2].u.array->size-2);
  o_range ();
  assign_to_short_svalue ((union anything *)&go->error_backtrace,
			  PIKE_T_ARRAY, Pike_sp-1);
  pop_stack ();

  /* set status */
  eo->cairo_status = status;

  /* set human-readable string */
  msg_data = cairo_status_to_string(status);
  if (!msg_data)
    Pike_error("Unknown status code: %d\n", status);

  push_text(msg_data);
  assign_to_short_svalue ((union anything *)&eo->cairo_message, PIKE_T_STRING,
			  Pike_sp-1);
  push_text ("\n");
  f_add (2);
  assign_to_short_svalue ((union anything *)&go->error_message, PIKE_T_STRING,
			  Pike_sp-1);
  pop_n_elems (args+1);
}

/*! @endclass */

void cairo_mod_init_error()
{
  ptrdiff_t off;
  struct svalue prog;
  prog.type = PIKE_T_PROGRAM;
  prog.subtype = 0;

  ADD_INT_CONSTANT("STATUS_SUCCESS", (INT_TYPE)CAIRO_STATUS_SUCCESS, 0);
  ADD_INT_CONSTANT("STATUS_NO_MEMORY", (INT_TYPE)CAIRO_STATUS_NO_MEMORY, 0);
  ADD_INT_CONSTANT("STATUS_INVALID_RESTORE", (INT_TYPE)CAIRO_STATUS_INVALID_RESTORE, 0);
  ADD_INT_CONSTANT("STATUS_INVALID_POP_GROUP", (INT_TYPE)CAIRO_STATUS_INVALID_POP_GROUP, 0);
  ADD_INT_CONSTANT("STATUS_NO_CURRENT_POINT", (INT_TYPE)CAIRO_STATUS_NO_CURRENT_POINT, 0);
  ADD_INT_CONSTANT("STATUS_INVALID_MATRIX", (INT_TYPE)CAIRO_STATUS_INVALID_MATRIX, 0);
  ADD_INT_CONSTANT("STATUS_INVALID_STATUS", (INT_TYPE)CAIRO_STATUS_INVALID_STATUS, 0);
  ADD_INT_CONSTANT("STATUS_NULL_POINTER", (INT_TYPE)CAIRO_STATUS_NULL_POINTER, 0);
  ADD_INT_CONSTANT("STATUS_INVALID_STRING", (INT_TYPE)CAIRO_STATUS_INVALID_STRING, 0);
  ADD_INT_CONSTANT("STATUS_INVALID_PATH_DATA", (INT_TYPE)CAIRO_STATUS_INVALID_PATH_DATA, 0);
  ADD_INT_CONSTANT("STATUS_READ_ERROR", (INT_TYPE)CAIRO_STATUS_READ_ERROR, 0);
  ADD_INT_CONSTANT("STATUS_WRITE_ERROR", (INT_TYPE)CAIRO_STATUS_WRITE_ERROR, 0);
  ADD_INT_CONSTANT("STATUS_SURFACE_FINISHED", (INT_TYPE)CAIRO_STATUS_SURFACE_FINISHED, 0);
  ADD_INT_CONSTANT("STATUS_SURFACE_TYPE_MISMATCH", (INT_TYPE)CAIRO_STATUS_SURFACE_TYPE_MISMATCH, 0);
  ADD_INT_CONSTANT("STATUS_PATTERN_TYPE_MISMATCH", (INT_TYPE)CAIRO_STATUS_PATTERN_TYPE_MISMATCH, 0);
  ADD_INT_CONSTANT("STATUS_INVALID_CONTENT", (INT_TYPE)CAIRO_STATUS_INVALID_CONTENT, 0);
  ADD_INT_CONSTANT("STATUS_INVALID_FORMAT", (INT_TYPE)CAIRO_STATUS_INVALID_FORMAT, 0);
  ADD_INT_CONSTANT("STATUS_INVALID_VISUAL", (INT_TYPE)CAIRO_STATUS_INVALID_VISUAL, 0);
  ADD_INT_CONSTANT("STATUS_FILE_NOT_FOUND", (INT_TYPE)CAIRO_STATUS_FILE_NOT_FOUND, 0);
  ADD_INT_CONSTANT("STATUS_INVALID_DASH", (INT_TYPE)CAIRO_STATUS_INVALID_DASH, 0);

  start_new_program();
  {
    low_inherit (generic_error_program, 0, -1, 0, 0, NULL);
    error_obj_off = off = ADD_STORAGE (struct error_obj);

    map_variable ("cairo_status", "int", 0, off + OFFSETOF (error_obj, cairo_status),
                  PIKE_T_INT);
    map_variable ("cairo_message", "string", 0, off + OFFSETOF (error_obj, cairo_message),
                  PIKE_T_STRING);

    add_string_constant("error_type", "Cairo.Error", 0);
    add_integer_constant("is_cairo_error", 1, 0);

    ADD_FUNCTION ("create", f_error_create, tFunc (tInt, tVoid), ID_STATIC);
  }
  add_program_constant ("Error", error_program = end_program(), 0);
}

/*! @endmodule */

#endif /* HAVE_CAIRO */

#ifdef error_message
#undef error_message
#endif
#ifdef error_backtrace
#undef error_backtrace
#endif



gotpike.org | Copyright © 2004 - 2019 | Pike is a trademark of Department of Computer and Information Science, Linköping University