| 1 | ;; ***** BEGIN LICENSE BLOCK ***** |
|---|
| 2 | ;; Roadsend PHP Compiler Runtime Libraries |
|---|
| 3 | ;; Copyright (C) 2008 Roadsend, Inc. |
|---|
| 4 | ;; |
|---|
| 5 | ;; This program is free software; you can redistribute it and/or |
|---|
| 6 | ;; modify it under the terms of the GNU Lesser General Public License |
|---|
| 7 | ;; as published by the Free Software Foundation; either version 2.1 |
|---|
| 8 | ;; of the License, or (at your option) any later version. |
|---|
| 9 | ;; |
|---|
| 10 | ;; This program is distributed in the hope that it will be useful, |
|---|
| 11 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 13 | ;; GNU Lesser General Public License for more details. |
|---|
| 14 | ;; |
|---|
| 15 | ;; You should have received a copy of the GNU Lesser General Public License |
|---|
| 16 | ;; along with this program; if not, write to the Free Software |
|---|
| 17 | ;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|---|
| 18 | ;; ***** END LICENSE BLOCK ***** |
|---|
| 19 | (module core-builtins |
|---|
| 20 | (library profiler) |
|---|
| 21 | (include "php-runtime.sch") |
|---|
| 22 | (load |
|---|
| 23 | (php-macros "../php-macros.scm")) |
|---|
| 24 | (use |
|---|
| 25 | (signatures "signatures.scm") |
|---|
| 26 | (php-object "php-object.scm") |
|---|
| 27 | (php-runtime "php-runtime.scm") |
|---|
| 28 | (php-hash "php-hash.scm") |
|---|
| 29 | (php-errors "php-errors.scm")) |
|---|
| 30 | (export |
|---|
| 31 | (init-core-builtins) |
|---|
| 32 | (_default_error_handler errno errstr errfile errline vars) |
|---|
| 33 | (_default_exception_handler exception_obj) |
|---|
| 34 | (php-exit status) |
|---|
| 35 | )) |
|---|
| 36 | |
|---|
| 37 | (define (init-core-builtins) |
|---|
| 38 | (register-extension "runtime" "1.0.0" "php-runtime")) |
|---|
| 39 | |
|---|
| 40 | (defbuiltin (_default_exception_handler exception_obj) |
|---|
| 41 | (php-error "Uncaught exception '" (php-object-class exception_obj) "'")) |
|---|
| 42 | |
|---|
| 43 | (defbuiltin (_default_error_handler errno errstr (errfile "unknown file") (errline "unknown line") (vars 'unset)) |
|---|
| 44 | (let ((etype (check-etype (mkfixnum (convert-to-number errno))))) |
|---|
| 45 | ; if etype wasn't a string, we're not showing the message |
|---|
| 46 | ; due to error reporting level |
|---|
| 47 | (when (string? etype) |
|---|
| 48 | (if *commandline?* |
|---|
| 49 | (begin |
|---|
| 50 | (echo (mkstr "\n" etype ": " errstr " in " errfile " on line " errline "\n")) |
|---|
| 51 | (when (or (equalp errno E_USER_ERROR) |
|---|
| 52 | (equalp errno E_RECOVERABLE_ERROR)) ;XXX any others? |
|---|
| 53 | (php-exit 255))) |
|---|
| 54 | (begin |
|---|
| 55 | (when (equalp errno E_USER_ERROR) |
|---|
| 56 | (print-stack-trace-html)) |
|---|
| 57 | (echo (mkstr "<br />\n<b>" etype "</b>: " errstr " in <b>" errfile "</b> on line <b>" errline "</b><br />\n")) |
|---|
| 58 | (when (or (equalp errno E_USER_ERROR) |
|---|
| 59 | (equalp errno E_RECOVERABLE_ERROR)) ;XXX any others? |
|---|
| 60 | (php-exit 255))))))) |
|---|
| 61 | |
|---|
| 62 | (defalias die php-exit) |
|---|
| 63 | (defalias exit php-exit) |
|---|
| 64 | (defbuiltin (php-exit (status 0)) |
|---|
| 65 | (set! status (maybe-unbox status)) |
|---|
| 66 | (if *commandline?* |
|---|
| 67 | (if (string? status) |
|---|
| 68 | (begin |
|---|
| 69 | (echo status) |
|---|
| 70 | (exit 0)) |
|---|
| 71 | (exit (mkfixnum status))) |
|---|
| 72 | (begin |
|---|
| 73 | (when (string? status) |
|---|
| 74 | (echo status)) |
|---|
| 75 | ;special error that'll be filtered out. |
|---|
| 76 | (error 'php-exit "exiting" 'php-exit)))) |
|---|
| 77 | |
|---|
| 78 | ; based on current error level return either #f if we shouldn't |
|---|
| 79 | ; show this error, or a string detailing the error type |
|---|
| 80 | (define (check-etype errno) |
|---|
| 81 | ;(print "errno is " errno " and level is " (mkstr *error-level*)) |
|---|
| 82 | (if (or (php-= *error-level* E_ALL) |
|---|
| 83 | (php-> (bitwise-and *error-level* errno) 0)) |
|---|
| 84 | (begin |
|---|
| 85 | (cond ((or (php-= errno E_USER_WARNING) |
|---|
| 86 | (php-= errno E_WARNING)) "Warning") |
|---|
| 87 | |
|---|
| 88 | ;((or (php-= errno E_USER_ERROR) |
|---|
| 89 | ; (php-= errno E_ERROR)) "Fatal error") |
|---|
| 90 | ((php-= errno E_USER_ERROR) "Fatal error") |
|---|
| 91 | |
|---|
| 92 | ((php-= errno E_RECOVERABLE_ERROR) "Catchable fatal error") |
|---|
| 93 | |
|---|
| 94 | ((or (php-= errno E_USER_NOTICE) |
|---|
| 95 | (php-= errno E_NOTICE)) "Notice") |
|---|
| 96 | |
|---|
| 97 | (else "Unknown error"))) |
|---|
| 98 | ; they don't want to see this error |
|---|
| 99 | ; based on error-level |
|---|
| 100 | #f)) |
|---|