Nuitka
The Python compiler
Loading...
Searching...
No Matches
printing.h
1// Copyright 2025, Kay Hayen, mailto:kay.hayen@gmail.com find license text at end of file
2
3#ifndef __NUITKA_PRINTING_H__
4#define __NUITKA_PRINTING_H__
5
6// Helper functions for print. Need to play nice with Python softspace
7// behavior.
8
9extern bool PRINT_NEW_LINE(void);
10extern bool PRINT_ITEM(PyObject *object);
11extern bool PRINT_ITEM_LINE(PyObject *object);
12extern bool PRINT_STRING(char const *str);
13extern bool PRINT_STRING_W(wchar_t const *str);
14extern bool PRINT_FORMAT(char const *fmt, ...);
15extern bool PRINT_ITEM_TO(PyObject *file, PyObject *object);
16extern bool PRINT_NEW_LINE_TO(PyObject *file);
17
18extern PyObject *GET_STDOUT(void);
19extern PyObject *GET_STDERR(void);
20
21// For flushing stdout and stderr.
22extern void FLUSH_STDOUT(void);
23extern void FLUSH_STDERR(void);
24
25// -----------------------------------------------------------------------
26// Helper functions to debug the run time operation of the compiled binary
27// manually or in debug modes.
28
29// Print the reference count of the object.
30extern void PRINT_REFCOUNT(PyObject *object);
31
32// Print the full traceback stack.
33// TODO: Could be ported, the "printf" stuff would need to be split. On Python3
34// the normal C print output gets lost.
35#if PYTHON_VERSION < 0x300
36extern void PRINT_TRACEBACK(PyTracebackObject *traceback);
37#endif
38
39// Print the exception state, including NULL values.
40extern void _PRINT_EXCEPTION3(PyObject *exception_type, PyObject *exception_value, PyTracebackObject *exception_tb);
41extern void _PRINT_EXCEPTION1(PyObject *exception_value);
42
43#if PYTHON_VERSION < 0x3c0
44#define PRINT_EXCEPTION(exception_type, exception_value, exception_tb) \
45 _PRINT_EXCEPTION3(exception_type, exception_value, exception_tb)
46#define PRINT_EXCEPTION_STATE(exception_state) \
47 _PRINT_EXCEPTION3((exception_state)->exception_type, (exception_state)->exception_value, \
48 (exception_state)->exception_tb)
49#else
50#define PRINT_EXCEPTION(exception_type, exception_value, exception_tb) _PRINT_EXCEPTION1(exception_value)
51#define PRINT_EXCEPTION_STATE(exception_state) _PRINT_EXCEPTION1((exception_state)->exception_value)
52#endif
53
54// Print the current exception state, including NULL values.
55extern void PRINT_CURRENT_EXCEPTION(void);
56
57// Print the current exception state, including NULL values.
58extern void PRINT_PUBLISHED_EXCEPTION(void);
59
60// Print the representation of the object, or "<NULL>" if it's not set.
61extern bool PRINT_REPR(PyObject *object);
62
63// Print the word <NULL>, as an alternative to pointers.
64extern bool PRINT_NULL(void);
65
66// Print the type of an object.
67extern bool PRINT_TYPE(PyObject *object);
68
69#endif
70
71// Part of "Nuitka", an optimizing Python compiler that is compatible and
72// integrates with CPython, but also works on its own.
73//
74// Licensed under the Apache License, Version 2.0 (the "License");
75// you may not use this file except in compliance with the License.
76// You may obtain a copy of the License at
77//
78// http://www.apache.org/licenses/LICENSE-2.0
79//
80// Unless required by applicable law or agreed to in writing, software
81// distributed under the License is distributed on an "AS IS" BASIS,
82// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
83// See the License for the specific language governing permissions and
84// limitations under the License.