File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44#include " binit.h"
55#include " php_bencode.h"
66
7+ #define CALL_AND_HANDLE (expr ) \
8+ try { \
9+ expr; \
10+ } catch (const std::invalid_argument &ia) { \
11+ zend_throw_exception (NULL , (" Invalid argument: " + std::string (ia.what ())).c_str (), BENCODE_ERROR_INVALID_ARGUMENT); \
12+ RETURN_NULL (); \
13+ } catch (const std::out_of_range &oor) { \
14+ zend_throw_exception (NULL , (" Out of Range error: " + std::string (oor.what ())).c_str (), BENCODE_ERROR_OUT_OF_RANGE); \
15+ RETURN_NULL (); \
16+ } catch (const std::exception &e) { \
17+ zend_throw_exception (NULL , (" Undefined error: " + std::string (e.what ())).c_str (), BENCODE_ERROR_UNDEFINED); \
18+ RETURN_NULL (); \
19+ } catch (...) { \
20+ zend_throw_exception (NULL , " Unknown error" , BENCODE_ERROR_UNKNOWN); \
21+ RETURN_NULL (); \
22+ }
23+
724/* *** BITEM *****/
825PHP_METHOD (bitem, __construct)
926{
Original file line number Diff line number Diff line change 88
99zval *bitem::throw_general_exception (const std::string message)
1010{
11- zend_throw_exception (NULL , message.c_str (), 1 );
11+ zend_throw_exception (NULL , message.c_str (), BENCODE_ERROR_BITEM );
1212 return bitem::get_zval_bool (false );
1313}
1414
Original file line number Diff line number Diff line change @@ -20,21 +20,4 @@ PHP_MSHUTDOWN_FUNCTION(bencode);
2020extern zend_module_entry bencode_module_entry ;
2121#define phpext_bencode_ptr &bencode_module_entry
2222
23- #define CALL_AND_HANDLE (expr ) \
24- try { \
25- return (expr); \
26- } catch (const std::invalid_argument &ia) { \
27- zend_throw_exception (NULL , std::string (" Invalid argument: " + std::string (ia.what ())).c_str (), 2 ); \
28- RETURN_NULL (); \
29- } catch (const std::out_of_range &oor) { \
30- zend_throw_exception (NULL , std::string (" Out of Range error: " + std::string (oor.what ())).c_str (), 3 ); \
31- RETURN_NULL (); \
32- } catch (const std::exception &e) { \
33- zend_throw_exception (NULL , std::string (" Undefined error: " + std::string (e.what ())).c_str (), 4 ); \
34- RETURN_NULL (); \
35- } catch (...) { \
36- zend_throw_exception (NULL , " Unkown error" , 5 ); \
37- RETURN_NULL (); \
38- }
39-
4023#endif
Original file line number Diff line number Diff line change @@ -11,6 +11,14 @@ extern "C" {
1111#include " blist.h"
1212#include " bstr.h"
1313
14+ /* clang-format off */
15+ #define BENCODE_ERROR_BITEM 1
16+ #define BENCODE_ERROR_INVALID_ARGUMENT 2
17+ #define BENCODE_ERROR_OUT_OF_RANGE 3
18+ #define BENCODE_ERROR_UNDEFINED 4
19+ #define BENCODE_ERROR_UNKNOWN 5
20+ /* clang-format on */
21+
1422#define ZEND_CONTAINER_PRE (bclass ) \
1523 typedef struct { \
1624 bclass *bnode_data; \
You can’t perform that action at this time.
0 commit comments