LCOV - code coverage report
Current view: top level - src - path.c (source / functions) Coverage Total Hit
Test: PHP Cairo Extension Coverage Lines: 96.9 % 32 31
Test Date: 2025-09-10 21:28:33 Functions: 100.0 % 6 6

            Line data    Source code
       1              : /*
       2              :   +----------------------------------------------------------------------+
       3              :   | For PHP Version 8                                                    |
       4              :   +----------------------------------------------------------------------+
       5              :   | Copyright (c) 2015 Elizabeth M Smith                                 |
       6              :   +----------------------------------------------------------------------+
       7              :   | http://www.opensource.org/licenses/mit-license.php  MIT License      |
       8              :   | Also available in LICENSE                                            |
       9              :   +----------------------------------------------------------------------+
      10              :   | Authors: Elizabeth M Smith <auroraeosrose@gmail.com>                 |
      11              :   |          Swen Zanon <swen.zanon@geoglis.de>                          |
      12              :   +----------------------------------------------------------------------+
      13              : */
      14              : 
      15              : #ifdef HAVE_CONFIG_H
      16              : #include "config.h"
      17              : #endif
      18              : 
      19              : #include <cairo.h>
      20              : #include <php.h>
      21              : #include <zend_exceptions.h>
      22              : 
      23              : #include "php_cairo.h"
      24              : #include "php_cairo_internal.h"
      25              : #include "path_arginfo.h"
      26              : 
      27              : 
      28              : zend_class_entry *ce_cairo_path;
      29              : zend_class_entry *ce_cairo_path_datatype;
      30              : 
      31              : static zend_object_handlers cairo_path_object_handlers;
      32              : 
      33            9 : cairo_path_object *cairo_path_fetch_object(zend_object *object)
      34              : {
      35            9 :     return (cairo_path_object *) ((char*)(object) - XtOffsetOf(cairo_path_object, std));
      36              : }
      37              : 
      38              : static inline cairo_path_object *cairo_path_object_get(zval *zv)
      39              : {
      40              :     cairo_path_object *object = Z_CAIRO_PATH_P(zv);
      41              :     if (object->path == NULL) {
      42              :         zend_throw_exception_ex(ce_cairo_exception, 0,
      43              :             "Internal path object missing in %s, you must call parent::__construct in extended classes.",
      44              :             ZSTR_VAL(Z_OBJCE_P(zv)->name));
      45              :         return NULL;
      46              :     }
      47              :     return object;
      48              : }
      49              : 
      50              : /* ----------------------------------------------------------------
      51              :     \Cairo\Path Object management
      52              : ------------------------------------------------------------------*/
      53              : 
      54              : /* {{{ */
      55            4 : static void cairo_path_free_obj(zend_object *object)
      56              : {
      57            4 :     cairo_path_object *intern = cairo_path_fetch_object(object);
      58              : 
      59            4 :     if (!intern) {
      60            0 :         return;
      61              :     }
      62              : 
      63            4 :     if (intern->path) {
      64            4 :         cairo_path_destroy(intern->path);
      65            4 :         intern->path = NULL;
      66              :     }
      67              : 
      68            4 :     zend_object_std_dtor(&intern->std);
      69              : }
      70              : 
      71              : /* {{{ */
      72            4 : static zend_object* cairo_path_obj_ctor(zend_class_entry *ce, cairo_path_object **intern)
      73              : {
      74            4 :     cairo_path_object *object = ecalloc(1, sizeof(cairo_path_object) + zend_object_properties_size(ce));
      75              : 
      76            4 :     object->path = NULL;
      77              : 
      78            4 :     zend_object_std_init(&object->std, ce);
      79            4 :     object->std.handlers = &cairo_path_object_handlers;
      80            4 :     *intern = object;
      81              : 
      82            4 :     return &object->std;
      83              : }
      84              : /* }}} */
      85              : 
      86              : /* {{{ */
      87            4 : static zend_object* cairo_path_create_object(zend_class_entry *ce)
      88              : {
      89            4 :     cairo_path_object *path_obj = NULL;
      90            4 :     zend_object *return_value = cairo_path_obj_ctor(ce, &path_obj);
      91              : 
      92            4 :     object_properties_init(&path_obj->std, ce);
      93            4 :     return return_value;
      94              : }
      95              : /* }}} */
      96              : 
      97              : /* ----------------------------------------------------------------
      98              :     \Cairo\Path C API
      99              : ------------------------------------------------------------------*/
     100              : 
     101            4 : zend_class_entry * php_cairo_get_path_ce()
     102              : {
     103            4 :     return ce_cairo_path;
     104              : }
     105              : 
     106              : /* }}} -----------------------------------------------------------*/
     107              : 
     108              : // TODO: add methods to retrieve path data
     109              : 
     110              : /* ----------------------------------------------------------------
     111              :     \Cairo\Path Definition and registration
     112              : ------------------------------------------------------------------*/
     113              : 
     114              : /* {{{ PHP_MINIT_FUNCTION */
     115          424 : PHP_MINIT_FUNCTION(cairo_path)
     116              : {
     117          424 :     memcpy(
     118              :         &cairo_path_object_handlers,
     119              :         zend_get_std_object_handlers(),
     120              :         sizeof(zend_object_handlers)
     121              :     );
     122              : 
     123              :     /* Path */
     124          424 :     cairo_path_object_handlers.offset = XtOffsetOf(cairo_path_object, std);
     125          424 :     cairo_path_object_handlers.free_obj = cairo_path_free_obj;
     126              : 
     127          424 :     ce_cairo_path = register_class_Cairo_Path();
     128          424 :     ce_cairo_path->create_object = cairo_path_create_object;
     129              : 
     130              :     /* Path\DataType */
     131          424 :     ce_cairo_path_datatype = register_class_Cairo_Path_DataType();
     132              : 
     133          424 :     return SUCCESS;
     134              : }
     135              : /* }}} */
        

Generated by: LCOV version 2.0-1