| 
									
										
										
										
											2014-10-26 19:21:54 -04:00
										 |  |  | USING: accessors alien alien.c-types alien.data combinators.short-circuit | 
					
						
							|  |  |  | destructors.private kernel namespaces python.ffi sequences vocabs.loader | 
					
						
							|  |  |  | words ;
 | 
					
						
							| 
									
										
										
										
											2014-01-31 09:59:04 -05:00
										 |  |  | IN: python.errors | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <PRIVATE
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-26 14:04:33 -04:00
										 |  |  | : get-error ( -- ptype pvalue ptraceback )
 | 
					
						
							|  |  |  |     { void* void* void* } [ PyErr_Fetch ] with-out-parameters ;
 | 
					
						
							| 
									
										
										
										
											2014-01-31 09:59:04 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-26 14:04:33 -04:00
										 |  |  | ! Breaking out of a circular dependency. | 
					
						
							|  |  |  | : throw-error ( ptype pvalue ptraceback -- )
 | 
					
						
							|  |  |  |     "throw-error" "python.throwing" lookup-word execute( a b c -- ) ;
 | 
					
						
							| 
									
										
										
										
											2014-01-31 09:59:04 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 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-10-26 19:21:54 -04:00
										 |  |  | : unsteal-ref ( ref -- )
 | 
					
						
							|  |  |  |     always-destructors get [ | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             [ nip Py_DecRef-destructor? ] | 
					
						
							|  |  |  |             [ alien>> [ alien-address ] bi@ = ] | 
					
						
							|  |  |  |         } 2&& not
 | 
					
						
							|  |  |  |     ] with filter! drop ;
 |