Skip to content

Commit

Permalink
SDL_SetError(), SDL_GetError(), SDL_ClearError
Browse files Browse the repository at this point in the history
  • Loading branch information
remicollet committed Dec 6, 2013
1 parent d3e67e0 commit f1ae804
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ Release_TS
Release_TSDbg
Release_TS_inline
Debug_TS
sdl2*.tgz
sdl-*.tgz
tmp-php.ini
run-tests.php
4 changes: 2 additions & 2 deletions CREDITS
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
SDL2
Remi Collet
SDL
Santiago Lizardo, Remi Collet
16 changes: 16 additions & 0 deletions REFLECTION
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,22 @@ Extension [ <persistent> extension #16 SDL version 2.0.0-dev ] {
- Parameters [0] {
}
}
Function [ <internal:SDL> function SDL_SetError ] {

- Parameters [1] {
Parameter #0 [ <required> $error_message ]
}
}
Function [ <internal:SDL> function SDL_GetError ] {

- Parameters [0] {
}
}
Function [ <internal:SDL> function SDL_ClearError ] {

- Parameters [0] {
}
}
Function [ <internal:SDL> function SDL_RectEmpty ] {

- Parameters [1] {
Expand Down
2 changes: 1 addition & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ SDL2 library wrappers:
Done:
SDL.h
SDL_cpuinfo.h
SDL_error.h
SDL_rect.h
SDL_video.h (video)

Expand All @@ -20,7 +21,6 @@ TODO:
SDL_blendmode.h
SDL_clipboard.h
SDL_endian.h
SDL_error.h
SDL_events.h
SDL_filesystem.h
SDL_gamecontroller.h
Expand Down
1 change: 1 addition & 0 deletions config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ if test "$PHP_SDL" != "no"; then

sources="
cpuinfo.c
error.c
rect.c
surface.c
video.c
Expand Down
98 changes: 98 additions & 0 deletions error.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2013 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Santiago Lizardo <santiagolizardo@php.net> |
| Remi Collet <remi@php.net> |
+----------------------------------------------------------------------+
*/

/* $ Id: $ */

#include "php_sdl.h"

ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_SetError, 0, 0, 1)
ZEND_ARG_INFO(0, error_message)
ZEND_END_ARG_INFO()

/* {{{ proto int SDL_SetError(string error)
* SDL_SetError() unconditionally returns -1.
extern DECLSPEC int SDLCALL SDL_SetError(const char *fmt, ...);
*/
PHP_FUNCTION(SDL_SetError) {
char *error;
int *error_len;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &error, &error_len) == FAILURE) {
RETURN_FALSE;
}

RETURN_LONG(SDL_SetError(error));
}
/* }}} */

ZEND_BEGIN_ARG_INFO_EX(arginfo_error_none, 0, 0, 0)
ZEND_END_ARG_INFO()

/* {{{ proto string SDL_GetError(void)
extern DECLSPEC const char *SDLCALL SDL_GetError(void);
*/
PHP_FUNCTION(SDL_GetError) {
const char *error;

if (zend_parse_parameters_none() == FAILURE) {
RETURN_FALSE;
}

error = SDL_GetError();
if (error) {
RETURN_STRING(error, 1);
}
}
/* }}} */


/* {{{ proto string SDL_ClearError(void)
extern DECLSPEC void SDLCALL SDL_ClearError(void);
*/
PHP_FUNCTION(SDL_ClearError) {

if (zend_parse_parameters_none() == FAILURE) {
RETURN_FALSE;
}

SDL_ClearError();
}
/* }}} */


/* {{{ sdl_error_functions[] */
zend_function_entry sdl_error_functions[] = {
ZEND_FE(SDL_SetError, arginfo_SDL_SetError)
ZEND_FE(SDL_GetError, arginfo_error_none)
ZEND_FE(SDL_ClearError, arginfo_error_none)
ZEND_FE_END
};
/* }}} */


/* {{{ MINIT */
PHP_MINIT_FUNCTION(sdl_error)
{
return (zend_register_functions(NULL, sdl_error_functions, NULL, MODULE_PERSISTENT TSRMLS_CC));
}
/* }}} */

36 changes: 36 additions & 0 deletions error.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2013 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Santiago Lizardo <santiagolizardo@php.net> |
| Remi Collet <remi@php.net> |
+----------------------------------------------------------------------+
*/

/* $ Id: $ */

#ifndef PHP_SDL_ERROR_H
#define PHP_SDL_ERROR_H

#ifdef __cplusplus
extern "C" {
#endif

PHP_MINIT_FUNCTION(sdl_error);

#ifdef __cplusplus
} // extern "C"
#endif

#endif /* PHP_SDL_ERROR_H */

5 changes: 5 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ http://pear.php.net/dtd/package-2.0.xsd">
<file role='src' name='cpuinfo.h'/>
<file role='src' name='rect.c'/>
<file role='src' name='rect.h'/>
<file role='src' name='error.c'/>
<file role='src' name='error.h'/>
<file role='src' name='surface.c'/>
<file role='src' name='surface.h'/>
<file role='src' name='video.c'/>
Expand All @@ -65,6 +67,9 @@ http://pear.php.net/dtd/package-2.0.xsd">
<file role='test' name='003-otherinit.phpt'/>
<file role='test' name='004-cpuinfo.phpt'/>
<file role='test' name='005-video.phpt'/>
<file role='test' name='006-rect.phpt'/>
<file role='test' name='007-rect-oo.phpt'/>
<file role='test' name='008-error.phpt'/>
</dir> <!-- //tests -->
</dir>
</contents>
Expand Down
2 changes: 2 additions & 0 deletions sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "php_sdl.h"
#include "cpuinfo.h"
#include "error.h"
#include "rect.h"
#include "video.h"
#include "window.h"
Expand Down Expand Up @@ -50,6 +51,7 @@ PHP_MINIT_FUNCTION(sdl)

if (1
&& SUCCESS == PHP_MINIT_CALL(sdl_cpuinfo)
&& SUCCESS == PHP_MINIT_CALL(sdl_error)
&& SUCCESS == PHP_MINIT_CALL(sdl_rect)
&& SUCCESS == PHP_MINIT_CALL(sdl_surface)
&& SUCCESS == PHP_MINIT_CALL(sdl_video)
Expand Down
29 changes: 29 additions & 0 deletions tests/008-error.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--TEST--
error group test
--SKIPIF--
<?php
if (!extension_loaded("sdl")) die("skip: SDL extension not loaded");
?>
--FILE--
<?php
echo "+ start\n";
var_dump(SDL_GetError());
echo "+ set\n";
var_dump(SDL_SetError("Foo"));
var_dump(SDL_GetError());
echo "+ clear\n";
var_dump(SDL_ClearError());
var_dump(SDL_GetError());
?>
Done
--EXPECTF--
+ start
string(0) ""
+ set
int(-1)
string(3) "Foo"
+ clear
NULL
string(0) ""
Done

0 comments on commit f1ae804

Please sign in to comment.