| 
									
										
										
										
											2014-01-31 09:59:04 -05:00
										 |  |  | USING: alien.c-types alien.data kernel python.ffi ;
 | 
					
						
							|  |  |  | IN: python.errors | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ERROR: python-error type message ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <PRIVATE
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : get-error ( -- ptype pvalue )
 | 
					
						
							|  |  |  |     { void* void* void* } [ PyErr_Fetch ] with-out-parameters drop ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : throw-error ( ptype pvalue -- )
 | 
					
						
							|  |  |  |     [ "__name__" PyObject_GetAttrString ] [ PyObject_Str ] bi*
 | 
					
						
							|  |  |  |     [ &Py_DecRef PyString_AsString ] bi@ python-error ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PRIVATE>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-04 14:06:55 -05:00
										 |  |  | : (check-ref) ( ref -- ref )
 | 
					
						
							| 
									
										
										
										
											2014-01-31 09:59:04 -05:00
										 |  |  |     [ get-error throw-error f ] unless* ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-04 14:06:55 -05:00
										 |  |  | : check-new-ref ( ref -- ref )
 | 
					
						
							| 
									
										
										
										
											2014-01-31 09:59:04 -05:00
										 |  |  |     &Py_DecRef (check-ref) ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-04 14:06:55 -05:00
										 |  |  | : check-borrowed-ref ( ref -- ref )
 | 
					
						
							| 
									
										
										
										
											2014-01-31 09:59:04 -05:00
										 |  |  |     dup Py_IncRef &Py_DecRef (check-ref) ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : check-zero ( code -- )
 | 
					
						
							|  |  |  |     0 = [ get-error throw-error ] unless ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-04 14:06:55 -05:00
										 |  |  | : unsteal-ref ( ref -- ref )
 | 
					
						
							| 
									
										
										
										
											2014-01-31 09:59:04 -05:00
										 |  |  |     dup Py_IncRef ;
 |