summaryrefslogtreecommitdiff
path: root/gi
diff options
context:
space:
mode:
Diffstat (limited to 'gi')
-rw-r--r--gi/Makefile.am3
-rw-r--r--gi/Makefile.in340
-rw-r--r--gi/__init__.py19
-rw-r--r--gi/_glib/Makefile.in256
-rw-r--r--gi/_glib/pyglib-python-compat.h5
-rw-r--r--gi/_gobject/Makefile.in241
-rw-r--r--gi/_gobject/gobjectmodule.c43
-rw-r--r--gi/_gobject/propertyhelper.py14
-rw-r--r--gi/_gobject/pygobject-private.h1
-rw-r--r--gi/_gobject/pygobject.c3
-rw-r--r--gi/_gobject/pygobject.h2
-rw-r--r--gi/_gobject/pygtype.c791
-rw-r--r--gi/docstring.py106
-rw-r--r--gi/gimodule.c18
-rw-r--r--gi/module.py14
-rw-r--r--gi/overrides/GLib.py2
-rw-r--r--gi/overrides/GObject.py17
-rw-r--r--gi/overrides/Gtk.py53
-rw-r--r--gi/overrides/Makefile.in136
-rw-r--r--gi/overrides/__init__.py10
-rw-r--r--gi/pygi-argument.c276
-rw-r--r--gi/pygi-cache.c339
-rw-r--r--gi/pygi-closure.c33
-rw-r--r--gi/pygi-info.c290
-rw-r--r--gi/pygi-invoke.c44
-rw-r--r--gi/pygi-marshal-from-py.c863
-rw-r--r--gi/pygi-marshal-from-py.h131
-rw-r--r--gi/pygi-marshal-to-py.c298
-rw-r--r--gi/pygi-marshal-to-py.h101
-rw-r--r--gi/pygi.h15
-rw-r--r--gi/repository/Makefile.in136
-rw-r--r--gi/types.py159
32 files changed, 2309 insertions, 2450 deletions
diff --git a/gi/Makefile.am b/gi/Makefile.am
index c687d31..fc11ff8 100644
--- a/gi/Makefile.am
+++ b/gi/Makefile.am
@@ -31,7 +31,8 @@ pygi_PYTHON = \
types.py \
module.py \
importer.py \
- pygtkcompat.py
+ pygtkcompat.py \
+ docstring.py
pygi_LTLIBRARIES = _gi.la
diff --git a/gi/Makefile.in b/gi/Makefile.in
index dd02a4c..317ef0c 100644
--- a/gi/Makefile.in
+++ b/gi/Makefile.in
@@ -1,9 +1,8 @@
-# Makefile.in generated by automake 1.11.6 from Makefile.am.
+# Makefile.in generated by automake 1.13.2 from Makefile.am.
# @configure_input@
-# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
-# Foundation, Inc.
+# Copyright (C) 1994-2013 Free Software Foundation, Inc.
+
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
@@ -16,23 +15,51 @@
@SET_MAKE@
VPATH = @srcdir@
-am__make_dryrun = \
- { \
- am__dry=no; \
+am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'
+am__make_running_with_option = \
+ case $${target_option-} in \
+ ?) ;; \
+ *) echo "am__make_running_with_option: internal error: invalid" \
+ "target option '$${target_option-}' specified" >&2; \
+ exit 1;; \
+ esac; \
+ has_opt=no; \
+ sane_makeflags=$$MAKEFLAGS; \
+ if $(am__is_gnu_make); then \
+ sane_makeflags=$$MFLAGS; \
+ else \
case $$MAKEFLAGS in \
*\\[\ \ ]*) \
- echo 'am--echo: ; @echo "AM" OK' | $(MAKE) -f - 2>/dev/null \
- | grep '^AM OK$$' >/dev/null || am__dry=yes;; \
- *) \
- for am__flg in $$MAKEFLAGS; do \
- case $$am__flg in \
- *=*|--*) ;; \
- *n*) am__dry=yes; break;; \
- esac; \
- done;; \
+ bs=\\; \
+ sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
+ | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \
esac; \
- test $$am__dry = yes; \
- }
+ fi; \
+ skip_next=no; \
+ strip_trailopt () \
+ { \
+ flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
+ }; \
+ for flg in $$sane_makeflags; do \
+ test $$skip_next = yes && { skip_next=no; continue; }; \
+ case $$flg in \
+ *=*|--*) continue;; \
+ -*I) strip_trailopt 'I'; skip_next=yes;; \
+ -*I?*) strip_trailopt 'I';; \
+ -*O) strip_trailopt 'O'; skip_next=yes;; \
+ -*O?*) strip_trailopt 'O';; \
+ -*l) strip_trailopt 'l'; skip_next=yes;; \
+ -*l?*) strip_trailopt 'l';; \
+ -[dEDm]) skip_next=yes;; \
+ -[JT]) skip_next=yes;; \
+ esac; \
+ case $$flg in \
+ *$$target_option*) has_opt=yes; break;; \
+ esac; \
+ done; \
+ test $$has_opt = yes
+am__make_dryrun = (target_option=n; $(am__make_running_with_option))
+am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
pkgdatadir = $(datadir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
@@ -56,8 +83,8 @@ host_triplet = @host@
@ENABLE_CAIRO_TRUE@am__append_2 = _gi_cairo.la
subdir = gi
-DIST_COMMON = $(pygi_PYTHON) $(srcdir)/Makefile.am \
- $(srcdir)/Makefile.in
+DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
+ $(top_srcdir)/depcomp $(pygi_PYTHON) $(top_srcdir)/py-compile
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/as-ac-expand.m4 \
$(top_srcdir)/m4/jhflags.m4 $(top_srcdir)/m4/libtool.m4 \
@@ -116,6 +143,7 @@ _gi_la_OBJECTS = $(am__gi_la_OBJECTS)
AM_V_lt = $(am__v_lt_@AM_V@)
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
am__v_lt_0 = --silent
+am__v_lt_1 =
_gi_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(_gi_la_CFLAGS) $(CFLAGS) \
$(_gi_la_LDFLAGS) $(LDFLAGS) -o $@
@@ -127,6 +155,18 @@ _gi_cairo_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(_gi_cairo_la_CFLAGS) \
$(CFLAGS) $(_gi_cairo_la_LDFLAGS) $(LDFLAGS) -o $@
@ENABLE_CAIRO_TRUE@am__gi_cairo_la_rpath = -rpath $(pygidir)
+AM_V_P = $(am__v_P_@AM_V@)
+am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
+am__v_P_0 = false
+am__v_P_1 = :
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
+am__v_GEN_0 = @echo " GEN " $@;
+am__v_GEN_1 =
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
+am__v_at_0 = @
+am__v_at_1 =
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
depcomp = $(SHELL) $(top_srcdir)/depcomp
am__depfiles_maybe = depfiles
@@ -139,41 +179,60 @@ LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(AM_CFLAGS) $(CFLAGS)
AM_V_CC = $(am__v_CC_@AM_V@)
am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
-am__v_CC_0 = @echo " CC " $@;
-AM_V_at = $(am__v_at_@AM_V@)
-am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
-am__v_at_0 = @
+am__v_CC_0 = @echo " CC " $@;
+am__v_CC_1 =
CCLD = $(CC)
LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(AM_LDFLAGS) $(LDFLAGS) -o $@
AM_V_CCLD = $(am__v_CCLD_@AM_V@)
am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
-am__v_CCLD_0 = @echo " CCLD " $@;
-AM_V_GEN = $(am__v_GEN_@AM_V@)
-am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
-am__v_GEN_0 = @echo " GEN " $@;
+am__v_CCLD_0 = @echo " CCLD " $@;
+am__v_CCLD_1 =
SOURCES = $(_gi_la_SOURCES) $(_gi_cairo_la_SOURCES)
DIST_SOURCES = $(_gi_la_SOURCES) $(_gi_cairo_la_SOURCES)
-RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
- html-recursive info-recursive install-data-recursive \
- install-dvi-recursive install-exec-recursive \
- install-html-recursive install-info-recursive \
- install-pdf-recursive install-ps-recursive install-recursive \
- installcheck-recursive installdirs-recursive pdf-recursive \
- ps-recursive uninstall-recursive
+RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \
+ ctags-recursive dvi-recursive html-recursive info-recursive \
+ install-data-recursive install-dvi-recursive \
+ install-exec-recursive install-html-recursive \
+ install-info-recursive install-pdf-recursive \
+ install-ps-recursive install-recursive installcheck-recursive \
+ installdirs-recursive pdf-recursive ps-recursive \
+ tags-recursive uninstall-recursive
am__can_run_installinfo = \
case $$AM_UPDATE_INFO_DIR in \
n|no|NO) false;; \
*) (install-info --version) >/dev/null 2>&1;; \
esac
am__py_compile = PYTHON=$(PYTHON) $(SHELL) $(py_compile)
+am__pep3147_tweak = \
+ sed -e 's|\.py$$||' -e 's|[^/]*$$|__pycache__/&.*.py|'
py_compile = $(top_srcdir)/py-compile
RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \
distclean-recursive maintainer-clean-recursive
-AM_RECURSIVE_TARGETS = $(RECURSIVE_TARGETS:-recursive=) \
- $(RECURSIVE_CLEAN_TARGETS:-recursive=) tags TAGS ctags CTAGS \
+am__recursive_targets = \
+ $(RECURSIVE_TARGETS) \
+ $(RECURSIVE_CLEAN_TARGETS) \
+ $(am__extra_recursive_targets)
+AM_RECURSIVE_TARGETS = $(am__recursive_targets:-recursive=) TAGS CTAGS \
distdir
+am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
+# Read a list of newline-separated strings from the standard input,
+# and print each of them once, without duplicates. Input order is
+# *not* preserved.
+am__uniquify_input = $(AWK) '\
+ BEGIN { nonempty = 0; } \
+ { items[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in items) print i; }; } \
+'
+# Make sure the list of sources is unique. This is necessary because,
+# e.g., the same source file might be shared among _SOURCES variables
+# for different programs/libraries.
+am__define_uniq_tagged_files = \
+ list='$(am__tagged_files)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | $(am__uniquify_input)`
ETAGS = etags
CTAGS = ctags
DIST_SUBDIRS = $(SUBDIRS)
@@ -393,7 +452,8 @@ pygi_PYTHON = \
types.py \
module.py \
importer.py \
- pygtkcompat.py
+ pygtkcompat.py \
+ docstring.py
pygi_LTLIBRARIES = _gi.la $(am__append_2)
_gi_la_SOURCES = \
@@ -509,6 +569,7 @@ $(top_srcdir)/configure: $(am__configure_deps)
$(ACLOCAL_M4): $(am__aclocal_m4_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(am__aclocal_m4_deps):
+
install-pygiLTLIBRARIES: $(pygi_LTLIBRARIES)
@$(NORMAL_INSTALL)
@list='$(pygi_LTLIBRARIES)'; test -n "$(pygidir)" || list=; \
@@ -535,14 +596,18 @@ uninstall-pygiLTLIBRARIES:
clean-pygiLTLIBRARIES:
-test -z "$(pygi_LTLIBRARIES)" || rm -f $(pygi_LTLIBRARIES)
- @list='$(pygi_LTLIBRARIES)'; for p in $$list; do \
- dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
- test "$$dir" != "$$p" || dir=.; \
- echo "rm -f \"$${dir}/so_locations\""; \
- rm -f "$${dir}/so_locations"; \
- done
+ @list='$(pygi_LTLIBRARIES)'; \
+ locs=`for p in $$list; do echo $$p; done | \
+ sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \
+ sort -u`; \
+ test -z "$$locs" || { \
+ echo rm -f $${locs}; \
+ rm -f $${locs}; \
+ }
+
_gi.la: $(_gi_la_OBJECTS) $(_gi_la_DEPENDENCIES) $(EXTRA__gi_la_DEPENDENCIES)
$(AM_V_CCLD)$(_gi_la_LINK) -rpath $(pygidir) $(_gi_la_OBJECTS) $(_gi_la_LIBADD) $(LIBS)
+
_gi_cairo.la: $(_gi_cairo_la_OBJECTS) $(_gi_cairo_la_DEPENDENCIES) $(EXTRA__gi_cairo_la_DEPENDENCIES)
$(AM_V_CCLD)$(_gi_cairo_la_LINK) $(am__gi_cairo_la_rpath) $(_gi_cairo_la_OBJECTS) $(_gi_cairo_la_LIBADD) $(LIBS)
@@ -752,45 +817,54 @@ install-pygiPYTHON: $(pygi_PYTHON)
$(INSTALL_DATA) $$files "$(DESTDIR)$(pygidir)" || exit $$?; \
done || exit $$?; \
if test -n "$$dlist"; then \
- if test -z "$(DESTDIR)"; then \
- $(am__py_compile) --basedir "$(pygidir)" $$dlist; \
- else \
- $(am__py_compile) --destdir "$(DESTDIR)" \
- --basedir "$(pygidir)" $$dlist; \
- fi; \
+ $(am__py_compile) --destdir "$(DESTDIR)" \
+ --basedir "$(pygidir)" $$dlist; \
else :; fi
uninstall-pygiPYTHON:
@$(NORMAL_UNINSTALL)
@list='$(pygi_PYTHON)'; test -n "$(pygidir)" || list=; \
- files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
- test -n "$$files" || exit 0; \
+ py_files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+ test -n "$$py_files" || exit 0; \
dir='$(DESTDIR)$(pygidir)'; \
- filesc=`echo "$$files" | sed 's|$$|c|'`; \
- fileso=`echo "$$files" | sed 's|$$|o|'`; \
+ pyc_files=`echo "$$py_files" | sed 's|$$|c|'`; \
+ pyo_files=`echo "$$py_files" | sed 's|$$|o|'`; \
+ py_files_pep3147=`echo "$$py_files" | $(am__pep3147_tweak)`; \
+ echo "$$py_files_pep3147";\
+ pyc_files_pep3147=`echo "$$py_files_pep3147" | sed 's|$$|c|'`; \
+ pyo_files_pep3147=`echo "$$py_files_pep3147" | sed 's|$$|o|'`; \
st=0; \
- for files in "$$files" "$$filesc" "$$fileso"; do \
+ for files in \
+ "$$py_files" \
+ "$$pyc_files" \
+ "$$pyo_files" \
+ "$$pyc_files_pep3147" \
+ "$$pyo_files_pep3147" \
+ ; do \
$(am__uninstall_files_from_dir) || st=$$?; \
done; \
exit $$st
# This directory's subdirectories are mostly independent; you can cd
-# into them and run `make' without going through this Makefile.
-# To change the values of `make' variables: instead of editing Makefiles,
-# (1) if the variable is set in `config.status', edit `config.status'
-# (which will cause the Makefiles to be regenerated when you run `make');
-# (2) otherwise, pass the desired values on the `make' command line.
-$(RECURSIVE_TARGETS):
- @fail= failcom='exit 1'; \
- for f in x $$MAKEFLAGS; do \
- case $$f in \
- *=* | --[!k]*);; \
- *k*) failcom='fail=yes';; \
- esac; \
- done; \
+# into them and run 'make' without going through this Makefile.
+# To change the values of 'make' variables: instead of editing Makefiles,
+# (1) if the variable is set in 'config.status', edit 'config.status'
+# (which will cause the Makefiles to be regenerated when you run 'make');
+# (2) otherwise, pass the desired values on the 'make' command line.
+$(am__recursive_targets):
+ @fail=; \
+ if $(am__make_keepgoing); then \
+ failcom='fail=yes'; \
+ else \
+ failcom='exit 1'; \
+ fi; \
dot_seen=no; \
target=`echo $@ | sed s/-recursive//`; \
- list='$(SUBDIRS)'; for subdir in $$list; do \
+ case "$@" in \
+ distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \
+ *) list='$(SUBDIRS)' ;; \
+ esac; \
+ for subdir in $$list; do \
echo "Making $$target in $$subdir"; \
if test "$$subdir" = "."; then \
dot_seen=yes; \
@@ -805,57 +879,12 @@ $(RECURSIVE_TARGETS):
$(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
fi; test -z "$$fail"
-$(RECURSIVE_CLEAN_TARGETS):
- @fail= failcom='exit 1'; \
- for f in x $$MAKEFLAGS; do \
- case $$f in \
- *=* | --[!k]*);; \
- *k*) failcom='fail=yes';; \
- esac; \
- done; \
- dot_seen=no; \
- case "$@" in \
- distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \
- *) list='$(SUBDIRS)' ;; \
- esac; \
- rev=''; for subdir in $$list; do \
- if test "$$subdir" = "."; then :; else \
- rev="$$subdir $$rev"; \
- fi; \
- done; \
- rev="$$rev ."; \
- target=`echo $@ | sed s/-recursive//`; \
- for subdir in $$rev; do \
- echo "Making $$target in $$subdir"; \
- if test "$$subdir" = "."; then \
- local_target="$$target-am"; \
- else \
- local_target="$$target"; \
- fi; \
- ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
- || eval $$failcom; \
- done && test -z "$$fail"
-tags-recursive:
- list='$(SUBDIRS)'; for subdir in $$list; do \
- test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \
- done
-ctags-recursive:
- list='$(SUBDIRS)'; for subdir in $$list; do \
- test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \
- done
+ID: $(am__tagged_files)
+ $(am__define_uniq_tagged_files); mkid -fID $$unique
+tags: tags-recursive
+TAGS: tags
-ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
- list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
- unique=`for i in $$list; do \
- if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
- done | \
- $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
- END { if (nonempty) { for (i in files) print i; }; }'`; \
- mkid -fID $$unique
-tags: TAGS
-
-TAGS: tags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
- $(TAGS_FILES) $(LISP)
+tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
set x; \
here=`pwd`; \
if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \
@@ -871,12 +900,7 @@ TAGS: tags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
set "$$@" "$$include_option=$$here/$$subdir/TAGS"; \
fi; \
done; \
- list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
- unique=`for i in $$list; do \
- if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
- done | \
- $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
- END { if (nonempty) { for (i in files) print i; }; }'`; \
+ $(am__define_uniq_tagged_files); \
shift; \
if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
test -n "$$unique" || unique=$$empty_fix; \
@@ -888,15 +912,11 @@ TAGS: tags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$$unique; \
fi; \
fi
-ctags: CTAGS
-CTAGS: ctags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
- $(TAGS_FILES) $(LISP)
- list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
- unique=`for i in $$list; do \
- if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
- done | \
- $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
- END { if (nonempty) { for (i in files) print i; }; }'`; \
+ctags: ctags-recursive
+
+CTAGS: ctags
+ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
+ $(am__define_uniq_tagged_files); \
test -z "$(CTAGS_ARGS)$$unique" \
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
$$unique
@@ -905,6 +925,21 @@ GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& $(am__cd) $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) "$$here"
+cscopelist: cscopelist-recursive
+
+cscopelist-am: $(am__tagged_files)
+ list='$(am__tagged_files)'; \
+ case "$(srcdir)" in \
+ [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \
+ *) sdir=$(subdir)/$(srcdir) ;; \
+ esac; \
+ for i in $$list; do \
+ if test -f "$$i"; then \
+ echo "$(subdir)/$$i"; \
+ else \
+ echo "$$sdir/$$i"; \
+ fi; \
+ done >> $(top_builddir)/cscope.files
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
@@ -1074,25 +1109,24 @@ ps-am:
uninstall-am: uninstall-pygiLTLIBRARIES uninstall-pygiPYTHON
-.MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) check-am \
- ctags-recursive install-am install-strip tags-recursive
-
-.PHONY: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) CTAGS GTAGS \
- all all-am all-local check check-am check-local clean \
- clean-generic clean-libtool clean-local clean-pygiLTLIBRARIES \
- ctags ctags-recursive distclean distclean-compile \
- distclean-generic distclean-libtool distclean-tags distdir dvi \
- dvi-am html html-am info info-am install install-am \
- install-data install-data-am install-dvi install-dvi-am \
- install-exec install-exec-am install-html install-html-am \
- install-info install-info-am install-man install-pdf \
- install-pdf-am install-ps install-ps-am \
- install-pygiLTLIBRARIES install-pygiPYTHON install-strip \
- installcheck installcheck-am installdirs installdirs-am \
- maintainer-clean maintainer-clean-generic mostlyclean \
- mostlyclean-compile mostlyclean-generic mostlyclean-libtool \
- pdf pdf-am ps ps-am tags tags-recursive uninstall uninstall-am \
- uninstall-pygiLTLIBRARIES uninstall-pygiPYTHON
+.MAKE: $(am__recursive_targets) check-am install-am install-strip
+
+.PHONY: $(am__recursive_targets) CTAGS GTAGS TAGS all all-am all-local \
+ check check-am check-local clean clean-generic clean-libtool \
+ clean-local clean-pygiLTLIBRARIES cscopelist-am ctags ctags-am \
+ distclean distclean-compile distclean-generic \
+ distclean-libtool distclean-tags distdir dvi dvi-am html \
+ html-am info info-am install install-am install-data \
+ install-data-am install-dvi install-dvi-am install-exec \
+ install-exec-am install-html install-html-am install-info \
+ install-info-am install-man install-pdf install-pdf-am \
+ install-ps install-ps-am install-pygiLTLIBRARIES \
+ install-pygiPYTHON install-strip installcheck installcheck-am \
+ installdirs installdirs-am maintainer-clean \
+ maintainer-clean-generic mostlyclean mostlyclean-compile \
+ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
+ tags tags-am uninstall uninstall-am uninstall-pygiLTLIBRARIES \
+ uninstall-pygiPYTHON
# This is to ensure we have a symlink to the .so in the
diff --git a/gi/__init__.py b/gi/__init__.py
index e8c12db..0645d44 100644
--- a/gi/__init__.py
+++ b/gi/__init__.py
@@ -24,7 +24,9 @@ from __future__ import absolute_import
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
-from ._gi import _API, Repository
+from ._gi import _API
+from ._gi import Repository
+from ._gi import PyGIDeprecationWarning
# Force loading the GObject typelib so we have available the wrappers for
# base classes such as GInitiallyUnowned
@@ -32,6 +34,7 @@ import gi._gobject
gi # pyflakes
_API = _API # pyflakes
+PyGIDeprecationWarning = PyGIDeprecationWarning
import os
@@ -81,17 +84,3 @@ def require_version(namespace, version):
def get_required_version(namespace):
return _versions.get(namespace, None)
-
-
-# Use RuntimeWarning as the base class of PyGIDeprecationWarning
-# for unstable (odd minor version) and use DeprecationWarning for
-# stable (even minor version). This is so PyGObject deprecations
-# behave the same as regular Python deprecations in stable releases.
-if version_info[1] % 2:
- _DeprecationWarningBase = RuntimeWarning
-else:
- _DeprecationWarningBase = DeprecationWarning
-
-
-class PyGIDeprecationWarning(_DeprecationWarningBase):
- pass
diff --git a/gi/_glib/Makefile.in b/gi/_glib/Makefile.in
index 2829376..3b285e9 100644
--- a/gi/_glib/Makefile.in
+++ b/gi/_glib/Makefile.in
@@ -1,9 +1,8 @@
-# Makefile.in generated by automake 1.11.6 from Makefile.am.
+# Makefile.in generated by automake 1.13.2 from Makefile.am.
# @configure_input@
-# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
-# Foundation, Inc.
+# Copyright (C) 1994-2013 Free Software Foundation, Inc.
+
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
@@ -16,23 +15,51 @@
@SET_MAKE@
VPATH = @srcdir@
-am__make_dryrun = \
- { \
- am__dry=no; \
+am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'
+am__make_running_with_option = \
+ case $${target_option-} in \
+ ?) ;; \
+ *) echo "am__make_running_with_option: internal error: invalid" \
+ "target option '$${target_option-}' specified" >&2; \
+ exit 1;; \
+ esac; \
+ has_opt=no; \
+ sane_makeflags=$$MAKEFLAGS; \
+ if $(am__is_gnu_make); then \
+ sane_makeflags=$$MFLAGS; \
+ else \
case $$MAKEFLAGS in \
*\\[\ \ ]*) \
- echo 'am--echo: ; @echo "AM" OK' | $(MAKE) -f - 2>/dev/null \
- | grep '^AM OK$$' >/dev/null || am__dry=yes;; \
- *) \
- for am__flg in $$MAKEFLAGS; do \
- case $$am__flg in \
- *=*|--*) ;; \
- *n*) am__dry=yes; break;; \
- esac; \
- done;; \
+ bs=\\; \
+ sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
+ | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \
esac; \
- test $$am__dry = yes; \
- }
+ fi; \
+ skip_next=no; \
+ strip_trailopt () \
+ { \
+ flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
+ }; \
+ for flg in $$sane_makeflags; do \
+ test $$skip_next = yes && { skip_next=no; continue; }; \
+ case $$flg in \
+ *=*|--*) continue;; \
+ -*I) strip_trailopt 'I'; skip_next=yes;; \
+ -*I?*) strip_trailopt 'I';; \
+ -*O) strip_trailopt 'O'; skip_next=yes;; \
+ -*O?*) strip_trailopt 'O';; \
+ -*l) strip_trailopt 'l'; skip_next=yes;; \
+ -*l?*) strip_trailopt 'l';; \
+ -[dEDm]) skip_next=yes;; \
+ -[JT]) skip_next=yes;; \
+ esac; \
+ case $$flg in \
+ *$$target_option*) has_opt=yes; break;; \
+ esac; \
+ done; \
+ test $$has_opt = yes
+am__make_dryrun = (target_option=n; $(am__make_running_with_option))
+am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
pkgdatadir = $(datadir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
@@ -56,8 +83,9 @@ host_triplet = @host@
@PLATFORM_WIN32_TRUE@am__append_2 = -DPLATFORM_WIN32
subdir = gi/_glib
-DIST_COMMON = $(pyglib_PYTHON) $(srcdir)/Makefile.am \
- $(srcdir)/Makefile.in
+DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
+ $(top_srcdir)/depcomp $(pyglib_PYTHON) \
+ $(top_srcdir)/py-compile
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/as-ac-expand.m4 \
$(top_srcdir)/m4/jhflags.m4 $(top_srcdir)/m4/libtool.m4 \
@@ -111,6 +139,7 @@ _glib_la_OBJECTS = $(am__glib_la_OBJECTS)
AM_V_lt = $(am__v_lt_@AM_V@)
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
am__v_lt_0 = --silent
+am__v_lt_1 =
_glib_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(_glib_la_CFLAGS) \
$(CFLAGS) $(_glib_la_LDFLAGS) $(LDFLAGS) -o $@
@@ -126,6 +155,18 @@ libpyglib_gi_2_0_@PYTHON_BASENAME@_la_LINK = $(LIBTOOL) $(AM_V_lt) \
$(CCLD) $(libpyglib_gi_2_0_@PYTHON_BASENAME@_la_CFLAGS) \
$(CFLAGS) $(libpyglib_gi_2_0_@PYTHON_BASENAME@_la_LDFLAGS) \
$(LDFLAGS) -o $@
+AM_V_P = $(am__v_P_@AM_V@)
+am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
+am__v_P_0 = false
+am__v_P_1 = :
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
+am__v_GEN_0 = @echo " GEN " $@;
+am__v_GEN_1 =
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
+am__v_at_0 = @
+am__v_at_1 =
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
depcomp = $(SHELL) $(top_srcdir)/depcomp
am__depfiles_maybe = depfiles
@@ -138,20 +179,16 @@ LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(AM_CFLAGS) $(CFLAGS)
AM_V_CC = $(am__v_CC_@AM_V@)
am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
-am__v_CC_0 = @echo " CC " $@;
-AM_V_at = $(am__v_at_@AM_V@)
-am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
-am__v_at_0 = @
+am__v_CC_0 = @echo " CC " $@;
+am__v_CC_1 =
CCLD = $(CC)
LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(AM_LDFLAGS) $(LDFLAGS) -o $@
AM_V_CCLD = $(am__v_CCLD_@AM_V@)
am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
-am__v_CCLD_0 = @echo " CCLD " $@;
-AM_V_GEN = $(am__v_GEN_@AM_V@)
-am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
-am__v_GEN_0 = @echo " GEN " $@;
+am__v_CCLD_0 = @echo " CCLD " $@;
+am__v_CCLD_1 =
SOURCES = $(_glib_la_SOURCES) \
$(libpyglib_gi_2_0_@PYTHON_BASENAME@_la_SOURCES)
DIST_SOURCES = $(_glib_la_SOURCES) \
@@ -162,7 +199,26 @@ am__can_run_installinfo = \
*) (install-info --version) >/dev/null 2>&1;; \
esac
am__py_compile = PYTHON=$(PYTHON) $(SHELL) $(py_compile)
+am__pep3147_tweak = \
+ sed -e 's|\.py$$||' -e 's|[^/]*$$|__pycache__/&.*.py|'
py_compile = $(top_srcdir)/py-compile
+am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
+# Read a list of newline-separated strings from the standard input,
+# and print each of them once, without duplicates. Input order is
+# *not* preserved.
+am__uniquify_input = $(AWK) '\
+ BEGIN { nonempty = 0; } \
+ { items[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in items) print i; }; } \
+'
+# Make sure the list of sources is unique. This is necessary because,
+# e.g., the same source file might be shared among _SOURCES variables
+# for different programs/libraries.
+am__define_uniq_tagged_files = \
+ list='$(am__tagged_files)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | $(am__uniquify_input)`
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
@@ -428,6 +484,7 @@ $(top_srcdir)/configure: $(am__configure_deps)
$(ACLOCAL_M4): $(am__aclocal_m4_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(am__aclocal_m4_deps):
+
install-libLTLIBRARIES: $(lib_LTLIBRARIES)
@$(NORMAL_INSTALL)
@list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \
@@ -454,12 +511,15 @@ uninstall-libLTLIBRARIES:
clean-libLTLIBRARIES:
-test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES)
- @list='$(lib_LTLIBRARIES)'; for p in $$list; do \
- dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
- test "$$dir" != "$$p" || dir=.; \
- echo "rm -f \"$${dir}/so_locations\""; \
- rm -f "$${dir}/so_locations"; \
- done
+ @list='$(lib_LTLIBRARIES)'; \
+ locs=`for p in $$list; do echo $$p; done | \
+ sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \
+ sort -u`; \
+ test -z "$$locs" || { \
+ echo rm -f $${locs}; \
+ rm -f $${locs}; \
+ }
+
install-pyglibLTLIBRARIES: $(pyglib_LTLIBRARIES)
@$(NORMAL_INSTALL)
@list='$(pyglib_LTLIBRARIES)'; test -n "$(pyglibdir)" || list=; \
@@ -486,14 +546,18 @@ uninstall-pyglibLTLIBRARIES:
clean-pyglibLTLIBRARIES:
-test -z "$(pyglib_LTLIBRARIES)" || rm -f $(pyglib_LTLIBRARIES)
- @list='$(pyglib_LTLIBRARIES)'; for p in $$list; do \
- dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
- test "$$dir" != "$$p" || dir=.; \
- echo "rm -f \"$${dir}/so_locations\""; \
- rm -f "$${dir}/so_locations"; \
- done
+ @list='$(pyglib_LTLIBRARIES)'; \
+ locs=`for p in $$list; do echo $$p; done | \
+ sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \
+ sort -u`; \
+ test -z "$$locs" || { \
+ echo rm -f $${locs}; \
+ rm -f $${locs}; \
+ }
+
_glib.la: $(_glib_la_OBJECTS) $(_glib_la_DEPENDENCIES) $(EXTRA__glib_la_DEPENDENCIES)
$(AM_V_CCLD)$(_glib_la_LINK) -rpath $(pyglibdir) $(_glib_la_OBJECTS) $(_glib_la_LIBADD) $(LIBS)
+
libpyglib-gi-2.0-@PYTHON_BASENAME@.la: $(libpyglib_gi_2_0_@PYTHON_BASENAME@_la_OBJECTS) $(libpyglib_gi_2_0_@PYTHON_BASENAME@_la_DEPENDENCIES) $(EXTRA_libpyglib_gi_2_0_@PYTHON_BASENAME@_la_DEPENDENCIES)
$(AM_V_CCLD)$(libpyglib_gi_2_0_@PYTHON_BASENAME@_la_LINK) -rpath $(libdir) $(libpyglib_gi_2_0_@PYTHON_BASENAME@_la_OBJECTS) $(libpyglib_gi_2_0_@PYTHON_BASENAME@_la_LIBADD) $(LIBS)
@@ -591,48 +655,43 @@ install-pyglibPYTHON: $(pyglib_PYTHON)
$(INSTALL_DATA) $$files "$(DESTDIR)$(pyglibdir)" || exit $$?; \
done || exit $$?; \
if test -n "$$dlist"; then \
- if test -z "$(DESTDIR)"; then \
- $(am__py_compile) --basedir "$(pyglibdir)" $$dlist; \
- else \
- $(am__py_compile) --destdir "$(DESTDIR)" \
- --basedir "$(pyglibdir)" $$dlist; \
- fi; \
+ $(am__py_compile) --destdir "$(DESTDIR)" \
+ --basedir "$(pyglibdir)" $$dlist; \
else :; fi
uninstall-pyglibPYTHON:
@$(NORMAL_UNINSTALL)
@list='$(pyglib_PYTHON)'; test -n "$(pyglibdir)" || list=; \
- files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
- test -n "$$files" || exit 0; \
+ py_files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+ test -n "$$py_files" || exit 0; \
dir='$(DESTDIR)$(pyglibdir)'; \
- filesc=`echo "$$files" | sed 's|$$|c|'`; \
- fileso=`echo "$$files" | sed 's|$$|o|'`; \
+ pyc_files=`echo "$$py_files" | sed 's|$$|c|'`; \
+ pyo_files=`echo "$$py_files" | sed 's|$$|o|'`; \
+ py_files_pep3147=`echo "$$py_files" | $(am__pep3147_tweak)`; \
+ echo "$$py_files_pep3147";\
+ pyc_files_pep3147=`echo "$$py_files_pep3147" | sed 's|$$|c|'`; \
+ pyo_files_pep3147=`echo "$$py_files_pep3147" | sed 's|$$|o|'`; \
st=0; \
- for files in "$$files" "$$filesc" "$$fileso"; do \
+ for files in \
+ "$$py_files" \
+ "$$pyc_files" \
+ "$$pyo_files" \
+ "$$pyc_files_pep3147" \
+ "$$pyo_files_pep3147" \
+ ; do \
$(am__uninstall_files_from_dir) || st=$$?; \
done; \
exit $$st
-ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
- list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
- unique=`for i in $$list; do \
- if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
- done | \
- $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
- END { if (nonempty) { for (i in files) print i; }; }'`; \
- mkid -fID $$unique
-tags: TAGS
-
-TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
- $(TAGS_FILES) $(LISP)
+ID: $(am__tagged_files)
+ $(am__define_uniq_tagged_files); mkid -fID $$unique
+tags: tags-am
+TAGS: tags
+
+tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
set x; \
here=`pwd`; \
- list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
- unique=`for i in $$list; do \
- if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
- done | \
- $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
- END { if (nonempty) { for (i in files) print i; }; }'`; \
+ $(am__define_uniq_tagged_files); \
shift; \
if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
test -n "$$unique" || unique=$$empty_fix; \
@@ -644,15 +703,11 @@ TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$$unique; \
fi; \
fi
-ctags: CTAGS
-CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
- $(TAGS_FILES) $(LISP)
- list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
- unique=`for i in $$list; do \
- if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
- done | \
- $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
- END { if (nonempty) { for (i in files) print i; }; }'`; \
+ctags: ctags-am
+
+CTAGS: ctags
+ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
+ $(am__define_uniq_tagged_files); \
test -z "$(CTAGS_ARGS)$$unique" \
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
$$unique
@@ -661,6 +716,21 @@ GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& $(am__cd) $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) "$$here"
+cscopelist: cscopelist-am
+
+cscopelist-am: $(am__tagged_files)
+ list='$(am__tagged_files)'; \
+ case "$(srcdir)" in \
+ [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \
+ *) sdir=$(subdir)/$(srcdir) ;; \
+ esac; \
+ for i in $$list; do \
+ if test -f "$$i"; then \
+ echo "$(subdir)/$$i"; \
+ else \
+ echo "$$sdir/$$i"; \
+ fi; \
+ done >> $(top_builddir)/cscope.files
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
@@ -807,22 +877,22 @@ uninstall-am: uninstall-libLTLIBRARIES uninstall-pyglibLTLIBRARIES \
.MAKE: check-am install-am install-strip
-.PHONY: CTAGS GTAGS all all-am check check-am check-local clean \
+.PHONY: CTAGS GTAGS TAGS all all-am check check-am check-local clean \
clean-generic clean-libLTLIBRARIES clean-libtool clean-local \
- clean-pyglibLTLIBRARIES ctags distclean distclean-compile \
- distclean-generic distclean-libtool distclean-tags distdir dvi \
- dvi-am html html-am info info-am install install-am \
- install-data install-data-am install-dvi install-dvi-am \
- install-exec install-exec-am install-html install-html-am \
- install-info install-info-am install-libLTLIBRARIES \
- install-man install-pdf install-pdf-am install-ps \
- install-ps-am install-pyglibLTLIBRARIES install-pyglibPYTHON \
- install-strip installcheck installcheck-am installdirs \
- maintainer-clean maintainer-clean-generic mostlyclean \
- mostlyclean-compile mostlyclean-generic mostlyclean-libtool \
- pdf pdf-am ps ps-am tags uninstall uninstall-am \
- uninstall-libLTLIBRARIES uninstall-pyglibLTLIBRARIES \
- uninstall-pyglibPYTHON
+ clean-pyglibLTLIBRARIES cscopelist-am ctags ctags-am distclean \
+ distclean-compile distclean-generic distclean-libtool \
+ distclean-tags distdir dvi dvi-am html html-am info info-am \
+ install install-am install-data install-data-am install-dvi \
+ install-dvi-am install-exec install-exec-am install-html \
+ install-html-am install-info install-info-am \
+ install-libLTLIBRARIES install-man install-pdf install-pdf-am \
+ install-ps install-ps-am install-pyglibLTLIBRARIES \
+ install-pyglibPYTHON install-strip installcheck \
+ installcheck-am installdirs maintainer-clean \
+ maintainer-clean-generic mostlyclean mostlyclean-compile \
+ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
+ tags tags-am uninstall uninstall-am uninstall-libLTLIBRARIES \
+ uninstall-pyglibLTLIBRARIES uninstall-pyglibPYTHON
# if we build in a separate tree, we need to symlink the *.py files from the
diff --git a/gi/_glib/pyglib-python-compat.h b/gi/_glib/pyglib-python-compat.h
index 96c27ca..7b4c595 100644
--- a/gi/_glib/pyglib-python-compat.h
+++ b/gi/_glib/pyglib-python-compat.h
@@ -87,6 +87,8 @@ static int _pyglib_init_##modname(PyObject *module)
#define PYGLIB_PyUnicode_AS_STRING PyString_AS_STRING
#define PYGLIB_PyUnicode_GET_SIZE PyString_GET_SIZE
#define PYGLIB_PyUnicode_Type PyString_Type
+#define PYGLIB_PyUnicode_InternFromString PyString_InternFromString
+#define PYGLIB_PyUnicode_InternInPlace PyString_InternInPlace
#define PYGLIB_PyBytes_FromString PyString_FromString
#define PYGLIB_PyBytes_FromStringAndSize PyString_FromStringAndSize
@@ -191,6 +193,9 @@ PyTypeObject symbol = { \
#define PYGLIB_PyUnicode_GET_SIZE PyUnicode_GET_SIZE
#define PYGLIB_PyUnicode_Resize PyUnicode_Resize
#define PYGLIB_PyUnicode_Type PyUnicode_Type
+#define PYGLIB_PyUnicode_InternFromString PyUnicode_InternFromString
+#define PYGLIB_PyUnicode_InternInPlace PyUnicode_InternInPlace
+
#define PYGLIB_PyLong_Check PyLong_Check
#define PYGLIB_PyLong_FromLong PyLong_FromLong
#define PYGLIB_PyLong_AsLong PyLong_AsLong
diff --git a/gi/_gobject/Makefile.in b/gi/_gobject/Makefile.in
index ce28f0e..e621540 100644
--- a/gi/_gobject/Makefile.in
+++ b/gi/_gobject/Makefile.in
@@ -1,9 +1,8 @@
-# Makefile.in generated by automake 1.11.6 from Makefile.am.
+# Makefile.in generated by automake 1.13.2 from Makefile.am.
# @configure_input@
-# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
-# Foundation, Inc.
+# Copyright (C) 1994-2013 Free Software Foundation, Inc.
+
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
@@ -17,23 +16,51 @@
VPATH = @srcdir@
-am__make_dryrun = \
- { \
- am__dry=no; \
+am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'
+am__make_running_with_option = \
+ case $${target_option-} in \
+ ?) ;; \
+ *) echo "am__make_running_with_option: internal error: invalid" \
+ "target option '$${target_option-}' specified" >&2; \
+ exit 1;; \
+ esac; \
+ has_opt=no; \
+ sane_makeflags=$$MAKEFLAGS; \
+ if $(am__is_gnu_make); then \
+ sane_makeflags=$$MFLAGS; \
+ else \
case $$MAKEFLAGS in \
*\\[\ \ ]*) \
- echo 'am--echo: ; @echo "AM" OK' | $(MAKE) -f - 2>/dev/null \
- | grep '^AM OK$$' >/dev/null || am__dry=yes;; \
- *) \
- for am__flg in $$MAKEFLAGS; do \
- case $$am__flg in \
- *=*|--*) ;; \
- *n*) am__dry=yes; break;; \
- esac; \
- done;; \
+ bs=\\; \
+ sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
+ | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \
esac; \
- test $$am__dry = yes; \
- }
+ fi; \
+ skip_next=no; \
+ strip_trailopt () \
+ { \
+ flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
+ }; \
+ for flg in $$sane_makeflags; do \
+ test $$skip_next = yes && { skip_next=no; continue; }; \
+ case $$flg in \
+ *=*|--*) continue;; \
+ -*I) strip_trailopt 'I'; skip_next=yes;; \
+ -*I?*) strip_trailopt 'I';; \
+ -*O) strip_trailopt 'O'; skip_next=yes;; \
+ -*O?*) strip_trailopt 'O';; \
+ -*l) strip_trailopt 'l'; skip_next=yes;; \
+ -*l?*) strip_trailopt 'l';; \
+ -[dEDm]) skip_next=yes;; \
+ -[JT]) skip_next=yes;; \
+ esac; \
+ case $$flg in \
+ *$$target_option*) has_opt=yes; break;; \
+ esac; \
+ done; \
+ test $$has_opt = yes
+am__make_dryrun = (target_option=n; $(am__make_running_with_option))
+am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkglibexecdir = $(libexecdir)/@PACKAGE@
@@ -55,8 +82,9 @@ host_triplet = @host@
@OS_WIN32_TRUE@ -no-undefined
subdir = gi/_gobject
-DIST_COMMON = $(pkginclude_HEADERS) $(pygobject_PYTHON) \
- $(srcdir)/Makefile.am $(srcdir)/Makefile.in
+DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
+ $(top_srcdir)/depcomp $(pygobject_PYTHON) \
+ $(top_srcdir)/py-compile $(pkginclude_HEADERS)
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/as-ac-expand.m4 \
$(top_srcdir)/m4/jhflags.m4 $(top_srcdir)/m4/libtool.m4 \
@@ -113,9 +141,22 @@ _gobject_la_OBJECTS = $(am__gobject_la_OBJECTS)
AM_V_lt = $(am__v_lt_@AM_V@)
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
am__v_lt_0 = --silent
+am__v_lt_1 =
_gobject_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(_gobject_la_CFLAGS) \
$(CFLAGS) $(_gobject_la_LDFLAGS) $(LDFLAGS) -o $@
+AM_V_P = $(am__v_P_@AM_V@)
+am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
+am__v_P_0 = false
+am__v_P_1 = :
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
+am__v_GEN_0 = @echo " GEN " $@;
+am__v_GEN_1 =
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
+am__v_at_0 = @
+am__v_at_1 =
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
depcomp = $(SHELL) $(top_srcdir)/depcomp
am__depfiles_maybe = depfiles
@@ -128,20 +169,16 @@ LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(AM_CFLAGS) $(CFLAGS)
AM_V_CC = $(am__v_CC_@AM_V@)
am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
-am__v_CC_0 = @echo " CC " $@;
-AM_V_at = $(am__v_at_@AM_V@)
-am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
-am__v_at_0 = @
+am__v_CC_0 = @echo " CC " $@;
+am__v_CC_1 =
CCLD = $(CC)
LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(AM_LDFLAGS) $(LDFLAGS) -o $@
AM_V_CCLD = $(am__v_CCLD_@AM_V@)
am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
-am__v_CCLD_0 = @echo " CCLD " $@;
-AM_V_GEN = $(am__v_GEN_@AM_V@)
-am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
-am__v_GEN_0 = @echo " GEN " $@;
+am__v_CCLD_0 = @echo " CCLD " $@;
+am__v_CCLD_1 =
SOURCES = $(_gobject_la_SOURCES)
DIST_SOURCES = $(_gobject_la_SOURCES)
am__can_run_installinfo = \
@@ -150,8 +187,27 @@ am__can_run_installinfo = \
*) (install-info --version) >/dev/null 2>&1;; \
esac
am__py_compile = PYTHON=$(PYTHON) $(SHELL) $(py_compile)
+am__pep3147_tweak = \
+ sed -e 's|\.py$$||' -e 's|[^/]*$$|__pycache__/&.*.py|'
py_compile = $(top_srcdir)/py-compile
HEADERS = $(pkginclude_HEADERS)
+am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
+# Read a list of newline-separated strings from the standard input,
+# and print each of them once, without duplicates. Input order is
+# *not* preserved.
+am__uniquify_input = $(AWK) '\
+ BEGIN { nonempty = 0; } \
+ { items[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in items) print i; }; } \
+'
+# Make sure the list of sources is unique. This is necessary because,
+# e.g., the same source file might be shared among _SOURCES variables
+# for different programs/libraries.
+am__define_uniq_tagged_files = \
+ list='$(am__tagged_files)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | $(am__uniquify_input)`
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
@@ -419,6 +475,7 @@ $(top_srcdir)/configure: $(am__configure_deps)
$(ACLOCAL_M4): $(am__aclocal_m4_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(am__aclocal_m4_deps):
+
install-pygobjectLTLIBRARIES: $(pygobject_LTLIBRARIES)
@$(NORMAL_INSTALL)
@list='$(pygobject_LTLIBRARIES)'; test -n "$(pygobjectdir)" || list=; \
@@ -445,12 +502,15 @@ uninstall-pygobjectLTLIBRARIES:
clean-pygobjectLTLIBRARIES:
-test -z "$(pygobject_LTLIBRARIES)" || rm -f $(pygobject_LTLIBRARIES)
- @list='$(pygobject_LTLIBRARIES)'; for p in $$list; do \
- dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
- test "$$dir" != "$$p" || dir=.; \
- echo "rm -f \"$${dir}/so_locations\""; \
- rm -f "$${dir}/so_locations"; \
- done
+ @list='$(pygobject_LTLIBRARIES)'; \
+ locs=`for p in $$list; do echo $$p; done | \
+ sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \
+ sort -u`; \
+ test -z "$$locs" || { \
+ echo rm -f $${locs}; \
+ rm -f $${locs}; \
+ }
+
_gobject.la: $(_gobject_la_OBJECTS) $(_gobject_la_DEPENDENCIES) $(EXTRA__gobject_la_DEPENDENCIES)
$(AM_V_CCLD)$(_gobject_la_LINK) -rpath $(pygobjectdir) $(_gobject_la_OBJECTS) $(_gobject_la_LIBADD) $(LIBS)
@@ -580,24 +640,30 @@ install-pygobjectPYTHON: $(pygobject_PYTHON)
$(INSTALL_DATA) $$files "$(DESTDIR)$(pygobjectdir)" || exit $$?; \
done || exit $$?; \
if test -n "$$dlist"; then \
- if test -z "$(DESTDIR)"; then \
- $(am__py_compile) --basedir "$(pygobjectdir)" $$dlist; \
- else \
- $(am__py_compile) --destdir "$(DESTDIR)" \
- --basedir "$(pygobjectdir)" $$dlist; \
- fi; \
+ $(am__py_compile) --destdir "$(DESTDIR)" \
+ --basedir "$(pygobjectdir)" $$dlist; \
else :; fi
uninstall-pygobjectPYTHON:
@$(NORMAL_UNINSTALL)
@list='$(pygobject_PYTHON)'; test -n "$(pygobjectdir)" || list=; \
- files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
- test -n "$$files" || exit 0; \
+ py_files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+ test -n "$$py_files" || exit 0; \
dir='$(DESTDIR)$(pygobjectdir)'; \
- filesc=`echo "$$files" | sed 's|$$|c|'`; \
- fileso=`echo "$$files" | sed 's|$$|o|'`; \
+ pyc_files=`echo "$$py_files" | sed 's|$$|c|'`; \
+ pyo_files=`echo "$$py_files" | sed 's|$$|o|'`; \
+ py_files_pep3147=`echo "$$py_files" | $(am__pep3147_tweak)`; \
+ echo "$$py_files_pep3147";\
+ pyc_files_pep3147=`echo "$$py_files_pep3147" | sed 's|$$|c|'`; \
+ pyo_files_pep3147=`echo "$$py_files_pep3147" | sed 's|$$|o|'`; \
st=0; \
- for files in "$$files" "$$filesc" "$$fileso"; do \
+ for files in \
+ "$$py_files" \
+ "$$pyc_files" \
+ "$$pyo_files" \
+ "$$pyc_files_pep3147" \
+ "$$pyo_files_pep3147" \
+ ; do \
$(am__uninstall_files_from_dir) || st=$$?; \
done; \
exit $$st
@@ -623,26 +689,15 @@ uninstall-pkgincludeHEADERS:
files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
dir='$(DESTDIR)$(pkgincludedir)'; $(am__uninstall_files_from_dir)
-ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
- list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
- unique=`for i in $$list; do \
- if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
- done | \
- $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
- END { if (nonempty) { for (i in files) print i; }; }'`; \
- mkid -fID $$unique
-tags: TAGS
-
-TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
- $(TAGS_FILES) $(LISP)
+ID: $(am__tagged_files)
+ $(am__define_uniq_tagged_files); mkid -fID $$unique
+tags: tags-am
+TAGS: tags
+
+tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
set x; \
here=`pwd`; \
- list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
- unique=`for i in $$list; do \
- if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
- done | \
- $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
- END { if (nonempty) { for (i in files) print i; }; }'`; \
+ $(am__define_uniq_tagged_files); \
shift; \
if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
test -n "$$unique" || unique=$$empty_fix; \
@@ -654,15 +709,11 @@ TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$$unique; \
fi; \
fi
-ctags: CTAGS
-CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
- $(TAGS_FILES) $(LISP)
- list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
- unique=`for i in $$list; do \
- if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
- done | \
- $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
- END { if (nonempty) { for (i in files) print i; }; }'`; \
+ctags: ctags-am
+
+CTAGS: ctags
+ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
+ $(am__define_uniq_tagged_files); \
test -z "$(CTAGS_ARGS)$$unique" \
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
$$unique
@@ -671,6 +722,21 @@ GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& $(am__cd) $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) "$$here"
+cscopelist: cscopelist-am
+
+cscopelist-am: $(am__tagged_files)
+ list='$(am__tagged_files)'; \
+ case "$(srcdir)" in \
+ [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \
+ *) sdir=$(subdir)/$(srcdir) ;; \
+ esac; \
+ for i in $$list; do \
+ if test -f "$$i"; then \
+ echo "$(subdir)/$$i"; \
+ else \
+ echo "$$sdir/$$i"; \
+ fi; \
+ done >> $(top_builddir)/cscope.files
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
@@ -818,22 +884,23 @@ uninstall-am: uninstall-pkgincludeHEADERS \
.MAKE: check-am install-am install-strip
-.PHONY: CTAGS GTAGS all all-am check check-am check-local clean \
+.PHONY: CTAGS GTAGS TAGS all all-am check check-am check-local clean \
clean-generic clean-libtool clean-local \
- clean-pygobjectLTLIBRARIES ctags distclean distclean-compile \
- distclean-generic distclean-libtool distclean-tags distdir dvi \
- dvi-am html html-am info info-am install install-am \
- install-data install-data-am install-dvi install-dvi-am \
- install-exec install-exec-am install-html install-html-am \
- install-info install-info-am install-man install-pdf \
- install-pdf-am install-pkgincludeHEADERS install-ps \
- install-ps-am install-pygobjectLTLIBRARIES \
- install-pygobjectPYTHON install-strip installcheck \
- installcheck-am installdirs maintainer-clean \
- maintainer-clean-generic mostlyclean mostlyclean-compile \
- mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
- tags uninstall uninstall-am uninstall-pkgincludeHEADERS \
- uninstall-pygobjectLTLIBRARIES uninstall-pygobjectPYTHON
+ clean-pygobjectLTLIBRARIES cscopelist-am ctags ctags-am \
+ distclean distclean-compile distclean-generic \
+ distclean-libtool distclean-tags distdir dvi dvi-am html \
+ html-am info info-am install install-am install-data \
+ install-data-am install-dvi install-dvi-am install-exec \
+ install-exec-am install-html install-html-am install-info \
+ install-info-am install-man install-pdf install-pdf-am \
+ install-pkgincludeHEADERS install-ps install-ps-am \
+ install-pygobjectLTLIBRARIES install-pygobjectPYTHON \
+ install-strip installcheck installcheck-am installdirs \
+ maintainer-clean maintainer-clean-generic mostlyclean \
+ mostlyclean-compile mostlyclean-generic mostlyclean-libtool \
+ pdf pdf-am ps ps-am tags tags-am uninstall uninstall-am \
+ uninstall-pkgincludeHEADERS uninstall-pygobjectLTLIBRARIES \
+ uninstall-pygobjectPYTHON
# if we build in a separate tree, we need to symlink the *.py files from the
diff --git a/gi/_gobject/gobjectmodule.c b/gi/_gobject/gobjectmodule.c
index 1e1cbd8..ac37904 100644
--- a/gi/_gobject/gobjectmodule.c
+++ b/gi/_gobject/gobjectmodule.c
@@ -623,6 +623,7 @@ create_property (const gchar *prop_name,
pspec = g_param_spec_pointer (prop_name, nick, blurb, flags);
break;
case G_TYPE_OBJECT:
+ case G_TYPE_INTERFACE:
if (!PyArg_ParseTuple(args, ""))
return NULL;
pspec = g_param_spec_object (prop_name, nick, blurb, prop_type, flags);
@@ -1657,6 +1658,40 @@ pyg__install_metaclass(PyObject *dummy, PyTypeObject *metaclass)
return Py_None;
}
+static PyObject *
+pyg__gvalue_get(PyObject *module, PyObject *pygvalue)
+{
+ if (!pyg_boxed_check (pygvalue, G_TYPE_VALUE)) {
+ PyErr_SetString (PyExc_TypeError, "Expected GValue argument.");
+ return NULL;
+ }
+
+ return pyg_value_as_pyobject (pyg_boxed_get(pygvalue, GValue),
+ /*copy_boxed=*/ TRUE);
+}
+
+static PyObject *
+pyg__gvalue_set(PyObject *module, PyObject *args)
+{
+ PyObject *pygvalue;
+ PyObject *pyobject;
+
+ if (!PyArg_ParseTuple (args, "OO:_gobject._gvalue_set",
+ &pygvalue, &pyobject))
+ return NULL;
+
+ if (!pyg_boxed_check (pygvalue, G_TYPE_VALUE)) {
+ PyErr_SetString (PyExc_TypeError, "Expected GValue argument.");
+ return NULL;
+ }
+
+ if (pyg_value_from_pyobject_with_error (pyg_boxed_get (pygvalue, GValue),
+ pyobject) == -1)
+ return NULL;
+
+ Py_RETURN_NONE;
+}
+
static PyMethodDef _gobject_functions[] = {
{ "type_name", pyg_type_name, METH_VARARGS },
{ "type_from_name", pyg_type_from_name, METH_VARARGS },
@@ -1675,6 +1710,10 @@ static PyMethodDef _gobject_functions[] = {
(PyCFunction)pyg_add_emission_hook, METH_VARARGS },
{ "_install_metaclass",
(PyCFunction)pyg__install_metaclass, METH_O },
+ { "_gvalue_get",
+ (PyCFunction)pyg__gvalue_get, METH_O },
+ { "_gvalue_set",
+ (PyCFunction)pyg__gvalue_set, METH_VARARGS },
{ NULL, NULL, 0 }
};
@@ -2071,7 +2110,9 @@ struct _PyGObject_Functions pygobject_api_functions = {
pyg_type_from_object_strict,
pygobject_new_full,
- &PyGObject_Type
+ &PyGObject_Type,
+
+ pyg_value_from_pyobject_with_error
};
/* for addon libraries ... */
diff --git a/gi/_gobject/propertyhelper.py b/gi/_gobject/propertyhelper.py
index e8ccb35..162d30a 100644
--- a/gi/_gobject/propertyhelper.py
+++ b/gi/_gobject/propertyhelper.py
@@ -48,14 +48,13 @@ class Property(object):
Creates a new property which in conjunction with GObject subclass will
create a property proxy:
- >>> class MyObject(GObject.GObject):
- >>> ... prop = GObject.Property(type=str)
+ class MyObject(GObject.GObject):
+ ... prop = GObject.Property(type=str)
- >>> obj = MyObject()
- >>> obj.prop = 'value'
+ obj = MyObject()
+ obj.prop = 'value'
- >>> obj.prop
- 'value'
+ obj.prop # now is 'value'
The API is similar to the builtin property:
@@ -261,7 +260,8 @@ class Property(object):
issubclass(type_, (_gobject.GObject,
_gobject.GEnum,
_gobject.GFlags,
- _gobject.GBoxed))):
+ _gobject.GBoxed,
+ _gobject.GInterface))):
return type_.__gtype__
elif type_ in (TYPE_NONE, TYPE_INTERFACE, TYPE_CHAR, TYPE_UCHAR,
TYPE_INT, TYPE_UINT, TYPE_BOOLEAN, TYPE_LONG,
diff --git a/gi/_gobject/pygobject-private.h b/gi/_gobject/pygobject-private.h
index e2a0af7..294b0f6 100644
--- a/gi/_gobject/pygobject-private.h
+++ b/gi/_gobject/pygobject-private.h
@@ -85,6 +85,7 @@ void pyg_register_gtype_custom(GType gtype,
fromvaluefunc from_func,
tovaluefunc to_func);
int pyg_value_from_pyobject(GValue *value, PyObject *obj);
+int pyg_value_from_pyobject_with_error(GValue *value, PyObject *obj);
PyObject *pyg_value_as_pyobject(const GValue *value, gboolean copy_boxed);
int pyg_param_gvalue_from_pyobject(GValue* value,
PyObject* py_obj,
diff --git a/gi/_gobject/pygobject.c b/gi/_gobject/pygobject.c
index 875da17..126c80e 100644
--- a/gi/_gobject/pygobject.c
+++ b/gi/_gobject/pygobject.c
@@ -2386,8 +2386,11 @@ static gpointer
pyobject_copy(gpointer boxed)
{
PyObject *object = boxed;
+ PyGILState_STATE state;
+ state = pyglib_gil_state_ensure();
Py_INCREF(object);
+ pyglib_gil_state_release(state);
return object;
}
diff --git a/gi/_gobject/pygobject.h b/gi/_gobject/pygobject.h
index f6b531d..76b8b11 100644
--- a/gi/_gobject/pygobject.h
+++ b/gi/_gobject/pygobject.h
@@ -195,6 +195,7 @@ struct _PyGObject_Functions {
PyObject *(* newgobj_full)(GObject *obj, gboolean steal, gpointer g_class);
PyTypeObject *object_type;
+ int (* value_from_pyobject_with_error)(GValue *value, PyObject *obj);
};
@@ -244,6 +245,7 @@ struct _PyGObject_Functions *_PyGObject_API;
#define pyg_flags_get_value (_PyGObject_API->flags_get_value)
#define pyg_register_gtype_custom (_PyGObject_API->register_gtype_custom)
#define pyg_value_from_pyobject (_PyGObject_API->value_from_pyobject)
+#define pyg_value_from_pyobject_with_error (_PyGObject_API->value_from_pyobject_with_error)
#define pyg_value_as_pyobject (_PyGObject_API->value_as_pyobject)
#define pyg_register_interface (_PyGObject_API->register_interface)
#define PyGBoxed_Type (*_PyGObject_API->boxed_type)
diff --git a/gi/_gobject/pygtype.c b/gi/_gobject/pygtype.c
index 498c35e..0b920f6 100644
--- a/gi/_gobject/pygtype.c
+++ b/gi/_gobject/pygtype.c
@@ -663,8 +663,8 @@ pyg_register_gtype_custom(GType gtype,
static int
pyg_value_array_from_pyobject(GValue *value,
- PyObject *obj,
- const GParamSpecValueArray *pspec)
+ PyObject *obj,
+ const GParamSpecValueArray *pspec)
{
int len;
GValueArray *value_array;
@@ -672,55 +672,55 @@ pyg_value_array_from_pyobject(GValue *value,
len = PySequence_Length(obj);
if (len == -1) {
- PyErr_Clear();
- return -1;
+ PyErr_Clear();
+ return -1;
}
if (pspec && pspec->fixed_n_elements > 0 && len != pspec->fixed_n_elements)
- return -1;
+ return -1;
value_array = g_value_array_new(len);
for (i = 0; i < len; ++i) {
- PyObject *item = PySequence_GetItem(obj, i);
- GType type;
- GValue item_value = { 0, };
- int status;
-
- if (! item) {
- PyErr_Clear();
- g_value_array_free(value_array);
- return -1;
- }
+ PyObject *item = PySequence_GetItem(obj, i);
+ GType type;
+ GValue item_value = { 0, };
+ int status;
+
+ if (! item) {
+ PyErr_Clear();
+ g_value_array_free(value_array);
+ return -1;
+ }
- if (pspec && pspec->element_spec)
- type = G_PARAM_SPEC_VALUE_TYPE(pspec->element_spec);
- else if (item == Py_None)
- type = G_TYPE_POINTER; /* store None as NULL */
- else {
- type = pyg_type_from_object((PyObject*)Py_TYPE(item));
- if (! type) {
- PyErr_Clear();
- g_value_array_free(value_array);
- Py_DECREF(item);
- return -1;
- }
- }
+ if (pspec && pspec->element_spec)
+ type = G_PARAM_SPEC_VALUE_TYPE(pspec->element_spec);
+ else if (item == Py_None)
+ type = G_TYPE_POINTER; /* store None as NULL */
+ else {
+ type = pyg_type_from_object((PyObject*)Py_TYPE(item));
+ if (! type) {
+ PyErr_Clear();
+ g_value_array_free(value_array);
+ Py_DECREF(item);
+ return -1;
+ }
+ }
- g_value_init(&item_value, type);
- status = (pspec && pspec->element_spec)
- ? pyg_param_gvalue_from_pyobject(&item_value, item, pspec->element_spec)
- : pyg_value_from_pyobject(&item_value, item);
- Py_DECREF(item);
+ g_value_init(&item_value, type);
+ status = (pspec && pspec->element_spec)
+ ? pyg_param_gvalue_from_pyobject(&item_value, item, pspec->element_spec)
+ : pyg_value_from_pyobject(&item_value, item);
+ Py_DECREF(item);
- if (status == -1) {
- g_value_array_free(value_array);
- g_value_unset(&item_value);
- return -1;
- }
+ if (status == -1) {
+ g_value_array_free(value_array);
+ g_value_unset(&item_value);
+ return -1;
+ }
- g_value_array_append(value_array, &item_value);
- g_value_unset(&item_value);
+ g_value_array_append(value_array, &item_value);
+ g_value_unset(&item_value);
}
g_value_take_boxed(value, value_array);
@@ -729,7 +729,7 @@ pyg_value_array_from_pyobject(GValue *value,
static int
pyg_array_from_pyobject(GValue *value,
- PyObject *obj)
+ PyObject *obj)
{
int len;
GArray *array;
@@ -737,47 +737,47 @@ pyg_array_from_pyobject(GValue *value,
len = PySequence_Length(obj);
if (len == -1) {
- PyErr_Clear();
- return -1;
+ PyErr_Clear();
+ return -1;
}
array = g_array_new(FALSE, TRUE, sizeof(GValue));
for (i = 0; i < len; ++i) {
- PyObject *item = PySequence_GetItem(obj, i);
- GType type;
- GValue item_value = { 0, };
- int status;
-
- if (! item) {
- PyErr_Clear();
- g_array_free(array, FALSE);
- return -1;
- }
+ PyObject *item = PySequence_GetItem(obj, i);
+ GType type;
+ GValue item_value = { 0, };
+ int status;
+
+ if (! item) {
+ PyErr_Clear();
+ g_array_free(array, FALSE);
+ return -1;
+ }
- if (item == Py_None)
- type = G_TYPE_POINTER; /* store None as NULL */
- else {
- type = pyg_type_from_object((PyObject*)Py_TYPE(item));
- if (! type) {
- PyErr_Clear();
- g_array_free(array, FALSE);
- Py_DECREF(item);
- return -1;
- }
- }
+ if (item == Py_None)
+ type = G_TYPE_POINTER; /* store None as NULL */
+ else {
+ type = pyg_type_from_object((PyObject*)Py_TYPE(item));
+ if (! type) {
+ PyErr_Clear();
+ g_array_free(array, FALSE);
+ Py_DECREF(item);
+ return -1;
+ }
+ }
- g_value_init(&item_value, type);
- status = pyg_value_from_pyobject(&item_value, item);
- Py_DECREF(item);
+ g_value_init(&item_value, type);
+ status = pyg_value_from_pyobject(&item_value, item);
+ Py_DECREF(item);
- if (status == -1) {
- g_array_free(array, FALSE);
- g_value_unset(&item_value);
- return -1;
- }
+ if (status == -1) {
+ g_array_free(array, FALSE);
+ g_value_unset(&item_value);
+ return -1;
+ }
- g_array_append_val(array, item_value);
+ g_array_append_val(array, item_value);
}
g_value_take_boxed(value, array);
@@ -785,7 +785,7 @@ pyg_array_from_pyobject(GValue *value,
}
/**
- * pyg_value_from_pyobject:
+ * pyg_value_from_pyobject_with_error:
* @value: the GValue object to store the converted value in.
* @obj: the Python object to convert.
*
@@ -797,107 +797,110 @@ pyg_array_from_pyobject(GValue *value,
* Returns: 0 on success, -1 on error.
*/
int
-pyg_value_from_pyobject(GValue *value, PyObject *obj)
+pyg_value_from_pyobject_with_error(GValue *value, PyObject *obj)
{
PyObject *tmp;
GType value_type = G_VALUE_TYPE(value);
switch (G_TYPE_FUNDAMENTAL(value_type)) {
case G_TYPE_INTERFACE:
- /* we only handle interface types that have a GObject prereq */
- if (g_type_is_a(value_type, G_TYPE_OBJECT)) {
- if (obj == Py_None)
- g_value_set_object(value, NULL);
- else {
- if (!PyObject_TypeCheck(obj, &PyGObject_Type)) {
- return -1;
- }
- if (!G_TYPE_CHECK_INSTANCE_TYPE(pygobject_get(obj),
- value_type)) {
- return -1;
- }
- g_value_set_object(value, pygobject_get(obj));
- }
- } else {
- return -1;
- }
- break;
+ /* we only handle interface types that have a GObject prereq */
+ if (g_type_is_a(value_type, G_TYPE_OBJECT)) {
+ if (obj == Py_None)
+ g_value_set_object(value, NULL);
+ else {
+ if (!PyObject_TypeCheck(obj, &PyGObject_Type)) {
+ PyErr_SetString(PyExc_TypeError, "GObject is required");
+ return -1;
+ }
+ if (!G_TYPE_CHECK_INSTANCE_TYPE(pygobject_get(obj),
+ value_type)) {
+ PyErr_SetString(PyExc_TypeError, "Invalid GObject type for assignment");
+ return -1;
+ }
+ g_value_set_object(value, pygobject_get(obj));
+ }
+ } else {
+ PyErr_SetString(PyExc_TypeError, "Unsupported conversion");
+ return -1;
+ }
+ break;
case G_TYPE_CHAR:
- if (PYGLIB_PyLong_Check(obj)) {
- glong val;
- val = PYGLIB_PyLong_AsLong(obj);
- if (val >= -128 && val <= 127)
- g_value_set_schar(value, (gchar) val);
- else
- return -1;
- }
+ if (PYGLIB_PyLong_Check(obj)) {
+ glong val;
+ val = PYGLIB_PyLong_AsLong(obj);
+ if (val >= -128 && val <= 127)
+ g_value_set_schar(value, (gchar) val);
+ else
+ return -1;
+ }
#if PY_VERSION_HEX < 0x03000000
- else if (PyString_Check(obj)) {
- g_value_set_schar(value, PyString_AsString(obj)[0]);
- }
+ else if (PyString_Check(obj)) {
+ g_value_set_schar(value, PyString_AsString(obj)[0]);
+ }
#endif
- else if (PyUnicode_Check(obj)) {
- tmp = PyUnicode_AsUTF8String(obj);
- g_value_set_schar(value, PYGLIB_PyBytes_AsString(tmp)[0]);
- Py_DECREF(tmp);
- } else {
- PyErr_Clear();
- return -1;
- }
+ else if (PyUnicode_Check(obj)) {
+ tmp = PyUnicode_AsUTF8String(obj);
+ g_value_set_schar(value, PYGLIB_PyBytes_AsString(tmp)[0]);
+ Py_DECREF(tmp);
+ } else {
+ PyErr_SetString(PyExc_TypeError, "Cannot convert to TYPE_CHAR");
+ return -1;
+ }
- break;
+ break;
case G_TYPE_UCHAR:
- if (PYGLIB_PyLong_Check(obj)) {
- glong val;
- val = PYGLIB_PyLong_AsLong(obj);
- if (val >= 0 && val <= 255)
- g_value_set_uchar(value, (guchar) val);
- else
- return -1;
+ if (PYGLIB_PyLong_Check(obj)) {
+ glong val;
+ val = PYGLIB_PyLong_AsLong(obj);
+ if (val >= 0 && val <= 255)
+ g_value_set_uchar(value, (guchar) val);
+ else
+ return -1;
#if PY_VERSION_HEX < 0x03000000
- } else if (PyString_Check(obj)) {
- g_value_set_uchar(value, PyString_AsString(obj)[0]);
+ } else if (PyString_Check(obj)) {
+ g_value_set_uchar(value, PyString_AsString(obj)[0]);
#endif
- } else if (PyUnicode_Check(obj)) {
- tmp = PyUnicode_AsUTF8String(obj);
- g_value_set_uchar(value, PYGLIB_PyBytes_AsString(tmp)[0]);
- Py_DECREF(tmp);
- } else {
- PyErr_Clear();
- return -1;
- }
- break;
+ } else if (PyUnicode_Check(obj)) {
+ tmp = PyUnicode_AsUTF8String(obj);
+ g_value_set_uchar(value, PYGLIB_PyBytes_AsString(tmp)[0]);
+ Py_DECREF(tmp);
+ } else {
+ PyErr_Clear();
+ return -1;
+ }
+ break;
case G_TYPE_BOOLEAN:
- g_value_set_boolean(value, PyObject_IsTrue(obj));
- break;
+ g_value_set_boolean(value, PyObject_IsTrue(obj));
+ break;
case G_TYPE_INT:
- g_value_set_int(value, PYGLIB_PyLong_AsLong(obj));
- break;
+ g_value_set_int(value, PYGLIB_PyLong_AsLong(obj));
+ break;
case G_TYPE_UINT:
- {
- if (PYGLIB_PyLong_Check(obj)) {
- guint val;
+ {
+ if (PYGLIB_PyLong_Check(obj)) {
+ guint val;
- /* check that number is not negative */
- if (PyLong_AsLongLong(obj) < 0)
- return -1;
+ /* check that number is not negative */
+ if (PyLong_AsLongLong(obj) < 0)
+ return -1;
- val = PyLong_AsUnsignedLong(obj);
- if (val <= G_MAXUINT)
- g_value_set_uint(value, val);
- else
- return -1;
- } else {
- g_value_set_uint(value, PyLong_AsUnsignedLong(obj));
- }
- }
- break;
+ val = PyLong_AsUnsignedLong(obj);
+ if (val <= G_MAXUINT)
+ g_value_set_uint(value, val);
+ else
+ return -1;
+ } else {
+ g_value_set_uint(value, PyLong_AsUnsignedLong(obj));
+ }
+ }
+ break;
case G_TYPE_LONG:
- g_value_set_long(value, PYGLIB_PyLong_AsLong(obj));
- break;
+ g_value_set_long(value, PYGLIB_PyLong_AsLong(obj));
+ break;
case G_TYPE_ULONG:
#if PY_VERSION_HEX < 0x03000000
- if (PyInt_Check(obj)) {
+ if (PyInt_Check(obj)) {
long val;
val = PYGLIB_PyLong_AsLong(obj);
@@ -908,14 +911,14 @@ pyg_value_from_pyobject(GValue *value, PyObject *obj)
g_value_set_ulong(value, (gulong)val);
} else
#endif
- if (PyLong_Check(obj))
- g_value_set_ulong(value, PyLong_AsUnsignedLong(obj));
- else
- return -1;
+ if (PyLong_Check(obj))
+ g_value_set_ulong(value, PyLong_AsUnsignedLong(obj));
+ else
+ return -1;
break;
case G_TYPE_INT64:
- g_value_set_int64(value, PyLong_AsLongLong(obj));
- break;
+ g_value_set_int64(value, PyLong_AsLongLong(obj));
+ break;
case G_TYPE_UINT64:
#if PY_VERSION_HEX < 0x03000000
if (PyInt_Check(obj)) {
@@ -927,173 +930,209 @@ pyg_value_from_pyobject(GValue *value, PyObject *obj)
g_value_set_uint64(value, v);
} else
#endif
- if (PyLong_Check(obj))
- g_value_set_uint64(value, PyLong_AsUnsignedLongLong(obj));
- else
- return -1;
- break;
+ if (PyLong_Check(obj))
+ g_value_set_uint64(value, PyLong_AsUnsignedLongLong(obj));
+ else
+ return -1;
+ break;
case G_TYPE_ENUM:
- {
- gint val = 0;
- if (pyg_enum_get_value(G_VALUE_TYPE(value), obj, &val) < 0) {
- PyErr_Clear();
- return -1;
- }
- g_value_set_enum(value, val);
- }
- break;
+ {
+ gint val = 0;
+ if (pyg_enum_get_value(G_VALUE_TYPE(value), obj, &val) < 0) {
+ return -1;
+ }
+ g_value_set_enum(value, val);
+ }
+ break;
case G_TYPE_FLAGS:
- {
- guint val = 0;
- if (pyg_flags_get_value(G_VALUE_TYPE(value), obj, &val) < 0) {
- PyErr_Clear();
- return -1;
- }
- g_value_set_flags(value, val);
- }
- break;
+ {
+ guint val = 0;
+ if (pyg_flags_get_value(G_VALUE_TYPE(value), obj, &val) < 0) {
+ return -1;
+ }
+ g_value_set_flags(value, val);
+ }
+ break;
case G_TYPE_FLOAT:
- g_value_set_float(value, PyFloat_AsDouble(obj));
- break;
+ g_value_set_float(value, PyFloat_AsDouble(obj));
+ break;
case G_TYPE_DOUBLE:
- g_value_set_double(value, PyFloat_AsDouble(obj));
- break;
+ g_value_set_double(value, PyFloat_AsDouble(obj));
+ break;
case G_TYPE_STRING:
- if (obj == Py_None) {
- g_value_set_string(value, NULL);
- } else {
- PyObject* tmp_str = PyObject_Str(obj);
- if (tmp_str == NULL) {
- PyErr_Clear();
- if (PyUnicode_Check(obj)) {
- tmp = PyUnicode_AsUTF8String(obj);
- g_value_set_string(value, PYGLIB_PyBytes_AsString(tmp));
- Py_DECREF(tmp);
- } else {
- return -1;
- }
- } else {
+ if (obj == Py_None) {
+ g_value_set_string(value, NULL);
+ } else {
+ PyObject* tmp_str = PyObject_Str(obj);
+ if (tmp_str == NULL) {
+ PyErr_Clear();
+ if (PyUnicode_Check(obj)) {
+ tmp = PyUnicode_AsUTF8String(obj);
+ g_value_set_string(value, PYGLIB_PyBytes_AsString(tmp));
+ Py_DECREF(tmp);
+ } else {
+ PyErr_SetString(PyExc_TypeError, "Expected string");
+ return -1;
+ }
+ } else {
#if PY_VERSION_HEX < 0x03000000
- g_value_set_string(value, PyString_AsString(tmp_str));
+ g_value_set_string(value, PyString_AsString(tmp_str));
#else
- tmp = PyUnicode_AsUTF8String(tmp_str);
- g_value_set_string(value, PyBytes_AsString(tmp));
- Py_DECREF(tmp);
+ tmp = PyUnicode_AsUTF8String(tmp_str);
+ g_value_set_string(value, PyBytes_AsString(tmp));
+ Py_DECREF(tmp);
#endif
- }
- Py_XDECREF(tmp_str);
- }
- break;
+ }
+ Py_XDECREF(tmp_str);
+ }
+ break;
case G_TYPE_POINTER:
- if (obj == Py_None)
- g_value_set_pointer(value, NULL);
- else if (PyObject_TypeCheck(obj, &PyGPointer_Type) &&
- G_VALUE_HOLDS(value, ((PyGPointer *)obj)->gtype))
- g_value_set_pointer(value, pyg_pointer_get(obj, gpointer));
- else if (PYGLIB_CPointer_Check(obj))
- g_value_set_pointer(value, PYGLIB_CPointer_GetPointer(obj, NULL));
- else if (G_VALUE_HOLDS_GTYPE (value))
- g_value_set_gtype (value, pyg_type_from_object (obj));
- else
- return -1;
- break;
+ if (obj == Py_None)
+ g_value_set_pointer(value, NULL);
+ else if (PyObject_TypeCheck(obj, &PyGPointer_Type) &&
+ G_VALUE_HOLDS(value, ((PyGPointer *)obj)->gtype))
+ g_value_set_pointer(value, pyg_pointer_get(obj, gpointer));
+ else if (PYGLIB_CPointer_Check(obj))
+ g_value_set_pointer(value, PYGLIB_CPointer_GetPointer(obj, NULL));
+ else if (G_VALUE_HOLDS_GTYPE (value))
+ g_value_set_gtype (value, pyg_type_from_object (obj));
+ else {
+ PyErr_SetString(PyExc_TypeError, "Expected pointer");
+ return -1;
+ }
+ break;
case G_TYPE_BOXED: {
- PyGTypeMarshal *bm;
-
- if (obj == Py_None)
- g_value_set_boxed(value, NULL);
- else if (G_VALUE_HOLDS(value, PY_TYPE_OBJECT))
- g_value_set_boxed(value, obj);
- else if (PyObject_TypeCheck(obj, &PyGBoxed_Type) &&
- G_VALUE_HOLDS(value, ((PyGBoxed *)obj)->gtype))
- g_value_set_boxed(value, pyg_boxed_get(obj, gpointer));
+ PyGTypeMarshal *bm;
+
+ if (obj == Py_None)
+ g_value_set_boxed(value, NULL);
+ else if (G_VALUE_HOLDS(value, PY_TYPE_OBJECT))
+ g_value_set_boxed(value, obj);
+ else if (PyObject_TypeCheck(obj, &PyGBoxed_Type) &&
+ G_VALUE_HOLDS(value, ((PyGBoxed *)obj)->gtype))
+ g_value_set_boxed(value, pyg_boxed_get(obj, gpointer));
else if (G_VALUE_HOLDS(value, G_TYPE_VALUE)) {
GType type;
GValue *n_value;
type = pyg_type_from_object((PyObject*)Py_TYPE(obj));
if (G_UNLIKELY (! type)) {
- PyErr_Clear();
return -1;
}
n_value = g_new0 (GValue, 1);
g_value_init (n_value, type);
g_value_take_boxed (value, n_value);
- return pyg_value_from_pyobject (n_value, obj);
+ return pyg_value_from_pyobject_with_error (n_value, obj);
}
else if (PySequence_Check(obj) &&
- G_VALUE_HOLDS(value, G_TYPE_VALUE_ARRAY))
- return pyg_value_array_from_pyobject(value, obj, NULL);
+ G_VALUE_HOLDS(value, G_TYPE_VALUE_ARRAY))
+ return pyg_value_array_from_pyobject(value, obj, NULL);
else if (PySequence_Check(obj) &&
- G_VALUE_HOLDS(value, G_TYPE_ARRAY))
- return pyg_array_from_pyobject(value, obj);
- else if (PYGLIB_PyUnicode_Check(obj) &&
- G_VALUE_HOLDS(value, G_TYPE_GSTRING)) {
+ G_VALUE_HOLDS(value, G_TYPE_ARRAY))
+ return pyg_array_from_pyobject(value, obj);
+ else if (PYGLIB_PyUnicode_Check(obj) &&
+ G_VALUE_HOLDS(value, G_TYPE_GSTRING)) {
GString *string;
char *buffer;
Py_ssize_t len;
if (PYGLIB_PyUnicode_AsStringAndSize(obj, &buffer, &len))
return -1;
string = g_string_new_len(buffer, len);
- g_value_set_boxed(value, string);
- g_string_free (string, TRUE);
+ g_value_set_boxed(value, string);
+ g_string_free (string, TRUE);
break;
}
- else if ((bm = pyg_type_lookup(G_VALUE_TYPE(value))) != NULL)
- return bm->tovalue(value, obj);
- else if (PYGLIB_CPointer_Check(obj))
- g_value_set_boxed(value, PYGLIB_CPointer_GetPointer(obj, NULL));
- else
- return -1;
- break;
+ else if ((bm = pyg_type_lookup(G_VALUE_TYPE(value))) != NULL)
+ return bm->tovalue(value, obj);
+ else if (PYGLIB_CPointer_Check(obj))
+ g_value_set_boxed(value, PYGLIB_CPointer_GetPointer(obj, NULL));
+ else {
+ PyErr_SetString(PyExc_TypeError, "Expected Boxed");
+ return -1;
+ }
+ break;
}
case G_TYPE_PARAM:
/* we need to support both the wrapped _gobject.GParamSpec and the GI
* GObject.ParamSpec */
if (G_IS_PARAM_SPEC (pygobject_get (obj)))
- g_value_set_param(value, G_PARAM_SPEC (pygobject_get (obj)));
+ g_value_set_param(value, G_PARAM_SPEC (pygobject_get (obj)));
else if (PyGParamSpec_Check(obj))
- g_value_set_param(value, PYGLIB_CPointer_GetPointer(obj, NULL));
- else
- return -1;
- break;
+ g_value_set_param(value, PYGLIB_CPointer_GetPointer(obj, NULL));
+ else {
+ PyErr_SetString(PyExc_TypeError, "Expected ParamSpec");
+ return -1;
+ }
+ break;
case G_TYPE_OBJECT:
- if (obj == Py_None) {
- g_value_set_object(value, NULL);
- } else if (PyObject_TypeCheck(obj, &PyGObject_Type) &&
- G_TYPE_CHECK_INSTANCE_TYPE(pygobject_get(obj),
- G_VALUE_TYPE(value))) {
- g_value_set_object(value, pygobject_get(obj));
- } else
- return -1;
- break;
+ if (obj == Py_None) {
+ g_value_set_object(value, NULL);
+ } else if (PyObject_TypeCheck(obj, &PyGObject_Type) &&
+ G_TYPE_CHECK_INSTANCE_TYPE(pygobject_get(obj),
+ G_VALUE_TYPE(value))) {
+ g_value_set_object(value, pygobject_get(obj));
+ } else {
+ PyErr_SetString(PyExc_TypeError, "Expected GObject");
+ return -1;
+ }
+ break;
case G_TYPE_VARIANT:
- {
- if (obj == Py_None)
- g_value_set_variant(value, NULL);
- else if (pyg_type_from_object_strict(obj, FALSE) == G_TYPE_VARIANT)
- g_value_set_variant(value, pyg_boxed_get(obj, GVariant));
- else
- return -1;
- break;
+ {
+ if (obj == Py_None)
+ g_value_set_variant(value, NULL);
+ else if (pyg_type_from_object_strict(obj, FALSE) == G_TYPE_VARIANT)
+ g_value_set_variant(value, pyg_boxed_get(obj, GVariant));
+ else {
+ PyErr_SetString(PyExc_TypeError, "Expected Variant");
+ return -1;
}
+ break;
+ }
default:
- {
- PyGTypeMarshal *bm;
- if ((bm = pyg_type_lookup(G_VALUE_TYPE(value))) != NULL)
- return bm->tovalue(value, obj);
- break;
- }
+ {
+ PyGTypeMarshal *bm;
+ if ((bm = pyg_type_lookup(G_VALUE_TYPE(value))) != NULL) {
+ return bm->tovalue(value, obj);
+ } else {
+ PyErr_SetString(PyExc_TypeError, "Unknown value type");
+ return -1;
+ }
+ break;
}
+ }
+
+ /* If an error occurred, unset the GValue but don't clear the Python error. */
if (PyErr_Occurred()) {
g_value_unset(value);
- PyErr_Clear();
return -1;
}
+
return 0;
}
/**
+ * pyg_value_from_pyobject:
+ * @value: the GValue object to store the converted value in.
+ * @obj: the Python object to convert.
+ *
+ * Same basic function as pyg_value_from_pyobject_with_error but clears
+ * any Python errors before returning.
+ *
+ * Returns: 0 on success, -1 on error.
+ */
+int
+pyg_value_from_pyobject(GValue *value, PyObject *obj)
+{
+ int res = pyg_value_from_pyobject_with_error (value, obj);
+
+ if (PyErr_Occurred()) {
+ PyErr_Clear();
+ return -1;
+ }
+ return res;
+}
+
+/**
* pyg_value_as_pyobject:
* @value: the GValue object.
* @copy_boxed: true if boxed values should be copied.
@@ -1110,148 +1149,148 @@ pyg_value_as_pyobject(const GValue *value, gboolean copy_boxed)
switch (G_TYPE_FUNDAMENTAL(G_VALUE_TYPE(value))) {
case G_TYPE_INTERFACE:
- if (g_type_is_a(G_VALUE_TYPE(value), G_TYPE_OBJECT))
- return pygobject_new(g_value_get_object(value));
- else
- break;
+ if (g_type_is_a(G_VALUE_TYPE(value), G_TYPE_OBJECT))
+ return pygobject_new(g_value_get_object(value));
+ else
+ break;
case G_TYPE_CHAR: {
- gint8 val = g_value_get_schar(value);
- return PYGLIB_PyUnicode_FromStringAndSize((char *)&val, 1);
+ gint8 val = g_value_get_schar(value);
+ return PYGLIB_PyUnicode_FromStringAndSize((char *)&val, 1);
}
case G_TYPE_UCHAR: {
- guint8 val = g_value_get_uchar(value);
- return PYGLIB_PyBytes_FromStringAndSize((char *)&val, 1);
+ guint8 val = g_value_get_uchar(value);
+ return PYGLIB_PyBytes_FromStringAndSize((char *)&val, 1);
}
case G_TYPE_BOOLEAN: {
- return PyBool_FromLong(g_value_get_boolean(value));
+ return PyBool_FromLong(g_value_get_boolean(value));
}
case G_TYPE_INT:
- return PYGLIB_PyLong_FromLong(g_value_get_int(value));
+ return PYGLIB_PyLong_FromLong(g_value_get_int(value));
case G_TYPE_UINT:
- {
- /* in Python, the Int object is backed by a long. If a
+ {
+ /* in Python, the Int object is backed by a long. If a
long can hold the whole value of an unsigned int, use
an Int. Otherwise, use a Long object to avoid overflow.
This matches the ULongArg behavior in codegen/argtypes.h */
#if (G_MAXUINT <= G_MAXLONG)
- return PYGLIB_PyLong_FromLong((glong) g_value_get_uint(value));
+ return PYGLIB_PyLong_FromLong((glong) g_value_get_uint(value));
#else
- return PyLong_FromUnsignedLong((gulong) g_value_get_uint(value));
+ return PyLong_FromUnsignedLong((gulong) g_value_get_uint(value));
#endif
- }
+ }
case G_TYPE_LONG:
- return PYGLIB_PyLong_FromLong(g_value_get_long(value));
+ return PYGLIB_PyLong_FromLong(g_value_get_long(value));
case G_TYPE_ULONG:
- {
- gulong val = g_value_get_ulong(value);
+ {
+ gulong val = g_value_get_ulong(value);
- if (val <= G_MAXLONG)
- return PYGLIB_PyLong_FromLong((glong) val);
- else
- return PyLong_FromUnsignedLong(val);
- }
+ if (val <= G_MAXLONG)
+ return PYGLIB_PyLong_FromLong((glong) val);
+ else
+ return PyLong_FromUnsignedLong(val);
+ }
case G_TYPE_INT64:
- {
- gint64 val = g_value_get_int64(value);
+ {
+ gint64 val = g_value_get_int64(value);
- if (G_MINLONG <= val && val <= G_MAXLONG)
- return PYGLIB_PyLong_FromLong((glong) val);
- else
- return PyLong_FromLongLong(val);
- }
+ if (G_MINLONG <= val && val <= G_MAXLONG)
+ return PYGLIB_PyLong_FromLong((glong) val);
+ else
+ return PyLong_FromLongLong(val);
+ }
case G_TYPE_UINT64:
- {
- guint64 val = g_value_get_uint64(value);
+ {
+ guint64 val = g_value_get_uint64(value);
- if (val <= G_MAXLONG)
- return PYGLIB_PyLong_FromLong((glong) val);
- else
- return PyLong_FromUnsignedLongLong(val);
- }
+ if (val <= G_MAXLONG)
+ return PYGLIB_PyLong_FromLong((glong) val);
+ else
+ return PyLong_FromUnsignedLongLong(val);
+ }
case G_TYPE_ENUM:
- return pyg_enum_from_gtype(G_VALUE_TYPE(value), g_value_get_enum(value));
+ return pyg_enum_from_gtype(G_VALUE_TYPE(value), g_value_get_enum(value));
case G_TYPE_FLAGS:
- return pyg_flags_from_gtype(G_VALUE_TYPE(value), g_value_get_flags(value));
+ return pyg_flags_from_gtype(G_VALUE_TYPE(value), g_value_get_flags(value));
case G_TYPE_FLOAT:
- return PyFloat_FromDouble(g_value_get_float(value));
+ return PyFloat_FromDouble(g_value_get_float(value));
case G_TYPE_DOUBLE:
- return PyFloat_FromDouble(g_value_get_double(value));
+ return PyFloat_FromDouble(g_value_get_double(value));
case G_TYPE_STRING:
- {
- const gchar *str = g_value_get_string(value);
+ {
+ const gchar *str = g_value_get_string(value);
- if (str)
- return PYGLIB_PyUnicode_FromString(str);
- Py_INCREF(Py_None);
- return Py_None;
- }
+ if (str)
+ return PYGLIB_PyUnicode_FromString(str);
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
case G_TYPE_POINTER:
- if (G_VALUE_HOLDS_GTYPE (value))
- return pyg_type_wrapper_new (g_value_get_gtype (value));
- else
- return pyg_pointer_new(G_VALUE_TYPE(value),
- g_value_get_pointer(value));
+ if (G_VALUE_HOLDS_GTYPE (value))
+ return pyg_type_wrapper_new (g_value_get_gtype (value));
+ else
+ return pyg_pointer_new(G_VALUE_TYPE(value),
+ g_value_get_pointer(value));
case G_TYPE_BOXED: {
- PyGTypeMarshal *bm;
+ PyGTypeMarshal *bm;
- if (G_VALUE_HOLDS(value, PY_TYPE_OBJECT)) {
- PyObject *ret = (PyObject *)g_value_dup_boxed(value);
- if (ret == NULL) {
- Py_INCREF(Py_None);
- return Py_None;
- }
- return ret;
+ if (G_VALUE_HOLDS(value, PY_TYPE_OBJECT)) {
+ PyObject *ret = (PyObject *)g_value_dup_boxed(value);
+ if (ret == NULL) {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+ return ret;
} else if (G_VALUE_HOLDS(value, G_TYPE_VALUE)) {
GValue *n_value = g_value_get_boxed (value);
return pyg_value_as_pyobject(n_value, copy_boxed);
} else if (G_VALUE_HOLDS(value, G_TYPE_VALUE_ARRAY)) {
- GValueArray *array = (GValueArray *) g_value_get_boxed(value);
- PyObject *ret = PyList_New(array->n_values);
- int i;
- for (i = 0; i < array->n_values; ++i)
- PyList_SET_ITEM(ret, i, pyg_value_as_pyobject
- (array->values + i, copy_boxed));
- return ret;
- } else if (G_VALUE_HOLDS(value, G_TYPE_GSTRING)) {
- GString *string = (GString *) g_value_get_boxed(value);
- PyObject *ret = PYGLIB_PyUnicode_FromStringAndSize(string->str, string->len);
- return ret;
- }
- bm = pyg_type_lookup(G_VALUE_TYPE(value));
- if (bm) {
- return bm->fromvalue(value);
- } else {
- if (copy_boxed)
- return pyg_boxed_new(G_VALUE_TYPE(value),
- g_value_get_boxed(value), TRUE, TRUE);
- else
- return pyg_boxed_new(G_VALUE_TYPE(value),
- g_value_get_boxed(value),FALSE,FALSE);
- }
+ GValueArray *array = (GValueArray *) g_value_get_boxed(value);
+ PyObject *ret = PyList_New(array->n_values);
+ int i;
+ for (i = 0; i < array->n_values; ++i)
+ PyList_SET_ITEM(ret, i, pyg_value_as_pyobject
+ (array->values + i, copy_boxed));
+ return ret;
+ } else if (G_VALUE_HOLDS(value, G_TYPE_GSTRING)) {
+ GString *string = (GString *) g_value_get_boxed(value);
+ PyObject *ret = PYGLIB_PyUnicode_FromStringAndSize(string->str, string->len);
+ return ret;
+ }
+ bm = pyg_type_lookup(G_VALUE_TYPE(value));
+ if (bm) {
+ return bm->fromvalue(value);
+ } else {
+ if (copy_boxed)
+ return pyg_boxed_new(G_VALUE_TYPE(value),
+ g_value_get_boxed(value), TRUE, TRUE);
+ else
+ return pyg_boxed_new(G_VALUE_TYPE(value),
+ g_value_get_boxed(value),FALSE,FALSE);
+ }
}
case G_TYPE_PARAM:
- return pyg_param_spec_new(g_value_get_param(value));
+ return pyg_param_spec_new(g_value_get_param(value));
case G_TYPE_OBJECT:
- return pygobject_new(g_value_get_object(value));
+ return pygobject_new(g_value_get_object(value));
case G_TYPE_VARIANT:
- {
- GVariant *v = g_value_get_variant(value);
- if (v == NULL) {
- Py_INCREF(Py_None);
- return Py_None;
- }
- return pyg_boxed_new(G_TYPE_VARIANT, g_variant_ref(v), FALSE, FALSE);
+ {
+ GVariant *v = g_value_get_variant(value);
+ if (v == NULL) {
+ Py_INCREF(Py_None);
+ return Py_None;
}
+ return pyg_boxed_new(G_TYPE_VARIANT, g_variant_ref(v), FALSE, FALSE);
+ }
default:
- {
- PyGTypeMarshal *bm;
- if ((bm = pyg_type_lookup(G_VALUE_TYPE(value))))
- return bm->fromvalue(value);
- break;
- }
+ {
+ PyGTypeMarshal *bm;
+ if ((bm = pyg_type_lookup(G_VALUE_TYPE(value))))
+ return bm->fromvalue(value);
+ break;
+ }
}
g_snprintf(buf, sizeof(buf), "unknown type %s",
- g_type_name(G_VALUE_TYPE(value)));
+ g_type_name(G_VALUE_TYPE(value)));
PyErr_SetString(PyExc_TypeError, buf);
return NULL;
}
diff --git a/gi/docstring.py b/gi/docstring.py
new file mode 100644
index 0000000..713bb6e
--- /dev/null
+++ b/gi/docstring.py
@@ -0,0 +1,106 @@
+# -*- Mode: Python; py-indent-offset: 4 -*-
+# vim: tabstop=4 shiftwidth=4 expandtab
+#
+# Copyright (C) 2013 Simon Feltman <sfeltman@gnome.org>
+#
+# docstring.py: documentation string generator for gi.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+# USA
+
+from ._gi import \
+ VFuncInfo, \
+ FunctionInfo, \
+ DIRECTION_IN, \
+ DIRECTION_OUT, \
+ DIRECTION_INOUT
+
+
+#: Module storage for currently registered doc string generator function.
+_generate_doc_string_func = None
+
+
+def set_doc_string_generator(func):
+ """Set doc string generator function
+
+ :Parameters:
+ func : callable
+ Function which takes a GIInfoStruct and returns
+ documentation for it.
+ """
+ global _generate_doc_string_func
+ _generate_doc_string_func = func
+
+
+def get_doc_string_generator():
+ return _generate_doc_string_func
+
+
+def generate_doc_string(info):
+ """Generator a doc string given a GIInfoStruct
+
+ This passes the info struct to the currently registered doc string
+ generator and returns the result.
+ """
+ return _generate_doc_string_func(info)
+
+
+def split_function_info_args(info):
+ """Split a functions args into a tuple of two lists.
+
+ Note that args marked as DIRECTION_INOUT will be in both lists.
+
+ :Returns:
+ Tuple of (in_args, out_args)
+ """
+ in_args = []
+ out_args = []
+ for arg in info.get_arguments():
+ direction = arg.get_direction()
+ if direction in (DIRECTION_IN, DIRECTION_INOUT):
+ in_args.append(arg)
+ if direction in (DIRECTION_OUT, DIRECTION_INOUT):
+ out_args.append(arg)
+ return (in_args, out_args)
+
+
+def _generate_callable_info_function_signature(info):
+ """Default doc string generator"""
+ in_args, out_args = split_function_info_args(info)
+ in_args_strs = []
+ if isinstance(info, VFuncInfo):
+ in_args_strs = ['self']
+ elif isinstance(info, FunctionInfo):
+ if info.is_method():
+ in_args_strs = ['self']
+ elif info.is_constructor():
+ in_args_strs = ['cls']
+
+ for arg in in_args:
+ argstr = arg.get_name() + ':' + arg.get_pytype_hint()
+ if arg.is_optional():
+ argstr += '=<optional>'
+ in_args_strs.append(argstr)
+ in_args_str = ', '.join(in_args_strs)
+
+ if out_args:
+ out_args_str = ', '.join(arg.get_name() + ':' + arg.get_pytype_hint()
+ for arg in out_args)
+ return '%s(%s) -> %s' % (info.get_name(), in_args_str, out_args_str)
+ else:
+ return '%s(%s)' % (info.get_name(), in_args_str)
+
+
+set_doc_string_generator(_generate_callable_info_function_signature)
diff --git a/gi/gimodule.c b/gi/gimodule.c
index 5b6bc14..12dfb36 100644
--- a/gi/gimodule.c
+++ b/gi/gimodule.c
@@ -28,6 +28,8 @@
#include <pygobject.h>
#include <pyglib-python-compat.h>
+PyObject *PyGIDeprecationWarning;
+
static PyObject *
_wrap_pyg_enum_add (PyObject *self,
PyObject *args,
@@ -641,6 +643,22 @@ PYGLIB_MODULE_START(_gi, "_gi")
_pygi_ccallback_register_types (module);
_pygi_argument_init();
+ /* Use RuntimeWarning as the base class of PyGIDeprecationWarning
+ * for unstable (odd minor version) and use DeprecationWarning for
+ * stable (even minor version). This is so PyGObject deprecations
+ * behave the same as regular Python deprecations in stable releases.
+ */
+#if PYGOBJECT_MINOR_VERSION % 2
+ PyGIDeprecationWarning = PyErr_NewException("gi.PyGIDeprecationWarning",
+ PyExc_RuntimeWarning, NULL);
+#else
+ PyGIDeprecationWarning = PyErr_NewException("gi.PyGIDeprecationWarning",
+ PyExc_DeprecationWarning, NULL);
+#endif
+
+ Py_INCREF(PyGIDeprecationWarning);
+ PyModule_AddObject(module, "PyGIDeprecationWarning", PyGIDeprecationWarning);
+
api = PYGLIB_CPointer_WrapPointer ( (void *) &CAPI, "gi._API");
if (api == NULL) {
return PYGLIB_MODULE_ERROR_RETURN;
diff --git a/gi/module.py b/gi/module.py
index dd0a90a..71f8ac5 100644
--- a/gi/module.py
+++ b/gi/module.py
@@ -24,6 +24,7 @@ from __future__ import absolute_import
import sys
import types
+import importlib
_have_py3 = (sys.version_info[0] >= 3)
@@ -56,8 +57,7 @@ from ._gi import \
flags_register_new_gtype_and_add
from .types import \
GObjectMeta, \
- StructMeta, \
- Function
+ StructMeta
from ._gobject._gobject import \
GInterface, \
@@ -90,7 +90,7 @@ def get_parent_for_object(object_info):
namespace = parent_object_info.get_namespace()
name = parent_object_info.get_name()
- module = __import__('gi.repository.%s' % namespace, fromlist=[name])
+ module = importlib.import_module('gi.repository.' + namespace)
return getattr(module, name)
@@ -100,7 +100,7 @@ def get_interfaces_for_object(object_info):
namespace = interface_info.get_namespace()
name = interface_info.get_name()
- module = __import__('gi.repository.%s' % namespace, fromlist=[name])
+ module = importlib.import_module('gi.repository.' + namespace)
interfaces.append(getattr(module, name))
return interfaces
@@ -207,7 +207,6 @@ class IntrospectionModule(object):
self.__dict__[name] = type_
return type_
- name = info.get_name()
dict_ = {
'__info__': info,
'__module__': 'gi.repository.' + self._namespace,
@@ -220,7 +219,7 @@ class IntrospectionModule(object):
g_type.pytype = wrapper
elif isinstance(info, FunctionInfo):
- wrapper = Function(info)
+ wrapper = info
elif isinstance(info, ConstantInfo):
wrapper = info.get_value()
else:
@@ -287,8 +286,7 @@ class DynamicModule(types.ModuleType):
def _load(self):
self._introspection_module = get_introspection_module(self._namespace)
try:
- overrides_modules = __import__('gi.overrides', fromlist=[self._namespace])
- self._overrides_module = getattr(overrides_modules, self._namespace, None)
+ self._overrides_module = importlib.import_module('gi.overrides.' + self._namespace)
except ImportError:
self._overrides_module = None
diff --git a/gi/overrides/GLib.py b/gi/overrides/GLib.py
index 7c512ca..0a4cdb6 100644
--- a/gi/overrides/GLib.py
+++ b/gi/overrides/GLib.py
@@ -48,7 +48,7 @@ spawn_async = _glib.spawn_async
def threads_init():
- warnings.warn('threads_init longer needs to be called. '
+ warnings.warn('threads_init no longer needs to be called. '
'See: https://bugzilla.gnome.org/show_bug.cgi?id=686914',
PyGIDeprecationWarning)
diff --git a/gi/overrides/GObject.py b/gi/overrides/GObject.py
index 42c97a2..044c36e 100644
--- a/gi/overrides/GObject.py
+++ b/gi/overrides/GObject.py
@@ -219,6 +219,15 @@ class Value(GObjectModule.Value):
if self._free_on_dealloc and self.g_type != TYPE_INVALID:
self.unset()
+ def set_boxed(self, boxed):
+ # Workaround the introspection marshalers inability to know
+ # these methods should be marshaling boxed types. This is because
+ # the type information is stored on the GValue.
+ _gobject._gvalue_set(self, boxed)
+
+ def get_boxed(self):
+ return _gobject._gvalue_get(self)
+
def set_value(self, py_value):
gtype = self.g_type
@@ -448,8 +457,8 @@ def signal_handler_block(obj, handler_id):
Returns a context manager which optionally can be used to
automatically unblock the handler:
- >>> with GObject.signal_handler_block(obj, id):
- >>> pass
+ with GObject.signal_handler_block(obj, id):
+ pass
"""
GObjectModule.signal_handler_block(_get_instance_for_signal(obj), handler_id)
return _HandlerBlockManager(obj, handler_id)
@@ -616,8 +625,8 @@ class Object(GObjectModule.Object):
Returns a context manager which optionally can be used to
automatically thaw notifications:
- >>> with obj.freeze_notify():
- >>> pass
+ with obj.freeze_notify():
+ pass
"""
super(Object, self).freeze_notify()
return _FreezeNotifyManager(self)
diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py
index 9a6e1a3..5899596 100644
--- a/gi/overrides/Gtk.py
+++ b/gi/overrides/Gtk.py
@@ -19,6 +19,7 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
# USA
+import collections
import sys
from gi.repository import GObject
from ..overrides import override, strip_boolean_result
@@ -357,32 +358,52 @@ __all__.append('MenuItem')
class Builder(Gtk.Builder):
+ @staticmethod
+ def _extract_handler_and_args(obj_or_map, handler_name):
+ handler = None
+ if isinstance(obj_or_map, collections.Mapping):
+ handler = obj_or_map.get(handler_name, None)
+ else:
+ handler = getattr(obj_or_map, handler_name, None)
- def connect_signals(self, obj_or_map):
- def _full_callback(builder, gobj, signal_name, handler_name, connect_obj, flags, obj_or_map):
- handler = None
- if isinstance(obj_or_map, dict):
- handler = obj_or_map.get(handler_name, None)
- else:
- handler = getattr(obj_or_map, handler_name, None)
+ if handler is None:
+ raise AttributeError('Handler %s not found' % handler_name)
+
+ args = ()
+ if isinstance(handler, collections.Sequence):
+ if len(handler) == 0:
+ raise TypeError("Handler %s tuple can not be empty" % handler)
+ args = handler[1:]
+ handler = handler[0]
- if handler is None:
- raise AttributeError('Handler %s not found' % handler_name)
+ elif not _callable(handler):
+ raise TypeError('Handler %s is not a method, function or tuple' % handler)
- if not _callable(handler):
- raise TypeError('Handler %s is not a method or function' % handler_name)
+ return handler, args
+
+ def connect_signals(self, obj_or_map):
+ """Connect signals specified by this builder to a name, handler mapping.
+
+ Connect signal, name, and handler sets specified in the builder with
+ the given mapping "obj_or_map". The handler/value aspect of the mapping
+ can also contain a tuple in the form of (handler [,arg1 [,argN]])
+ allowing for extra arguments to be passed to the handler. For example:
+ builder.connect_signals({'on_clicked': (on_clicked, arg1, arg2)})
+ """
+ def _full_callback(builder, gobj, signal_name, handler_name, connect_obj, flags, obj_or_map):
+ handler, args = self._extract_handler_and_args(obj_or_map, handler_name)
after = flags & GObject.ConnectFlags.AFTER
if connect_obj is not None:
if after:
- gobj.connect_object_after(signal_name, handler, connect_obj)
+ gobj.connect_object_after(signal_name, handler, connect_obj, *args)
else:
- gobj.connect_object(signal_name, handler, connect_obj)
+ gobj.connect_object(signal_name, handler, connect_obj, *args)
else:
if after:
- gobj.connect_after(signal_name, handler)
+ gobj.connect_after(signal_name, handler, *args)
else:
- gobj.connect(signal_name, handler)
+ gobj.connect(signal_name, handler, *args)
self.connect_signals_full(_full_callback, obj_or_map)
@@ -473,7 +494,7 @@ class Dialog(Gtk.Dialog, Container):
pairs - button text (or stock ID) and a response ID integer are passed
individually. For example:
- >>> dialog.add_buttons(Gtk.STOCK_OPEN, 42, "Close", Gtk.ResponseType.CLOSE)
+ dialog.add_buttons(Gtk.STOCK_OPEN, 42, "Close", Gtk.ResponseType.CLOSE)
will add "Open" and "Close" buttons to dialog.
"""
diff --git a/gi/overrides/Makefile.in b/gi/overrides/Makefile.in
index 2d5e808..740b945 100644
--- a/gi/overrides/Makefile.in
+++ b/gi/overrides/Makefile.in
@@ -1,9 +1,8 @@
-# Makefile.in generated by automake 1.11.6 from Makefile.am.
+# Makefile.in generated by automake 1.13.2 from Makefile.am.
# @configure_input@
-# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
-# Foundation, Inc.
+# Copyright (C) 1994-2013 Free Software Foundation, Inc.
+
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
@@ -15,23 +14,51 @@
@SET_MAKE@
VPATH = @srcdir@
-am__make_dryrun = \
- { \
- am__dry=no; \
+am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'
+am__make_running_with_option = \
+ case $${target_option-} in \
+ ?) ;; \
+ *) echo "am__make_running_with_option: internal error: invalid" \
+ "target option '$${target_option-}' specified" >&2; \
+ exit 1;; \
+ esac; \
+ has_opt=no; \
+ sane_makeflags=$$MAKEFLAGS; \
+ if $(am__is_gnu_make); then \
+ sane_makeflags=$$MFLAGS; \
+ else \
case $$MAKEFLAGS in \
*\\[\ \ ]*) \
- echo 'am--echo: ; @echo "AM" OK' | $(MAKE) -f - 2>/dev/null \
- | grep '^AM OK$$' >/dev/null || am__dry=yes;; \
- *) \
- for am__flg in $$MAKEFLAGS; do \
- case $$am__flg in \
- *=*|--*) ;; \
- *n*) am__dry=yes; break;; \
- esac; \
- done;; \
+ bs=\\; \
+ sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
+ | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \
esac; \
- test $$am__dry = yes; \
- }
+ fi; \
+ skip_next=no; \
+ strip_trailopt () \
+ { \
+ flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
+ }; \
+ for flg in $$sane_makeflags; do \
+ test $$skip_next = yes && { skip_next=no; continue; }; \
+ case $$flg in \
+ *=*|--*) continue;; \
+ -*I) strip_trailopt 'I'; skip_next=yes;; \
+ -*I?*) strip_trailopt 'I';; \
+ -*O) strip_trailopt 'O'; skip_next=yes;; \
+ -*O?*) strip_trailopt 'O';; \
+ -*l) strip_trailopt 'l'; skip_next=yes;; \
+ -*l?*) strip_trailopt 'l';; \
+ -[dEDm]) skip_next=yes;; \
+ -[JT]) skip_next=yes;; \
+ esac; \
+ case $$flg in \
+ *$$target_option*) has_opt=yes; break;; \
+ esac; \
+ done; \
+ test $$has_opt = yes
+am__make_dryrun = (target_option=n; $(am__make_running_with_option))
+am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
pkgdatadir = $(datadir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
@@ -51,8 +78,8 @@ POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
subdir = gi/overrides
-DIST_COMMON = $(pygioverrides_PYTHON) $(srcdir)/Makefile.am \
- $(srcdir)/Makefile.in
+DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
+ $(pygioverrides_PYTHON) $(top_srcdir)/py-compile
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/as-ac-expand.m4 \
$(top_srcdir)/m4/jhflags.m4 $(top_srcdir)/m4/libtool.m4 \
@@ -65,12 +92,18 @@ mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =
+AM_V_P = $(am__v_P_@AM_V@)
+am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
+am__v_P_0 = false
+am__v_P_1 = :
AM_V_GEN = $(am__v_GEN_@AM_V@)
am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
-am__v_GEN_0 = @echo " GEN " $@;
+am__v_GEN_0 = @echo " GEN " $@;
+am__v_GEN_1 =
AM_V_at = $(am__v_at_@AM_V@)
am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
am__v_at_0 = @
+am__v_at_1 =
SOURCES =
DIST_SOURCES =
am__can_run_installinfo = \
@@ -107,7 +140,10 @@ am__uninstall_files_from_dir = { \
}
am__py_compile = PYTHON=$(PYTHON) $(SHELL) $(py_compile)
am__installdirs = "$(DESTDIR)$(pygioverridesdir)"
+am__pep3147_tweak = \
+ sed -e 's|\.py$$||' -e 's|[^/]*$$|__pycache__/&.*.py|'
py_compile = $(top_srcdir)/py-compile
+am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
ACLOCAL_AMFLAGS = @ACLOCAL_AMFLAGS@
@@ -346,32 +382,38 @@ install-pygioverridesPYTHON: $(pygioverrides_PYTHON)
$(INSTALL_DATA) $$files "$(DESTDIR)$(pygioverridesdir)" || exit $$?; \
done || exit $$?; \
if test -n "$$dlist"; then \
- if test -z "$(DESTDIR)"; then \
- $(am__py_compile) --basedir "$(pygioverridesdir)" $$dlist; \
- else \
- $(am__py_compile) --destdir "$(DESTDIR)" \
- --basedir "$(pygioverridesdir)" $$dlist; \
- fi; \
+ $(am__py_compile) --destdir "$(DESTDIR)" \
+ --basedir "$(pygioverridesdir)" $$dlist; \
else :; fi
uninstall-pygioverridesPYTHON:
@$(NORMAL_UNINSTALL)
@list='$(pygioverrides_PYTHON)'; test -n "$(pygioverridesdir)" || list=; \
- files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
- test -n "$$files" || exit 0; \
+ py_files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+ test -n "$$py_files" || exit 0; \
dir='$(DESTDIR)$(pygioverridesdir)'; \
- filesc=`echo "$$files" | sed 's|$$|c|'`; \
- fileso=`echo "$$files" | sed 's|$$|o|'`; \
+ pyc_files=`echo "$$py_files" | sed 's|$$|c|'`; \
+ pyo_files=`echo "$$py_files" | sed 's|$$|o|'`; \
+ py_files_pep3147=`echo "$$py_files" | $(am__pep3147_tweak)`; \
+ echo "$$py_files_pep3147";\
+ pyc_files_pep3147=`echo "$$py_files_pep3147" | sed 's|$$|c|'`; \
+ pyo_files_pep3147=`echo "$$py_files_pep3147" | sed 's|$$|o|'`; \
st=0; \
- for files in "$$files" "$$filesc" "$$fileso"; do \
+ for files in \
+ "$$py_files" \
+ "$$pyc_files" \
+ "$$pyo_files" \
+ "$$pyc_files_pep3147" \
+ "$$pyo_files_pep3147" \
+ ; do \
$(am__uninstall_files_from_dir) || st=$$?; \
done; \
exit $$st
-tags: TAGS
-TAGS:
+tags TAGS:
+
+ctags CTAGS:
-ctags: CTAGS
-CTAGS:
+cscope cscopelist:
distdir: $(DISTFILES)
@@ -511,17 +553,17 @@ uninstall-am: uninstall-pygioverridesPYTHON
.MAKE: check-am install-am install-strip
.PHONY: all all-am all-local check check-am check-local clean \
- clean-generic clean-libtool distclean distclean-generic \
- distclean-libtool distdir dvi dvi-am html html-am info info-am \
- install install-am install-data install-data-am install-dvi \
- install-dvi-am install-exec install-exec-am install-html \
- install-html-am install-info install-info-am install-man \
- install-pdf install-pdf-am install-ps install-ps-am \
- install-pygioverridesPYTHON install-strip installcheck \
- installcheck-am installdirs maintainer-clean \
- maintainer-clean-generic mostlyclean mostlyclean-generic \
- mostlyclean-libtool pdf pdf-am ps ps-am uninstall uninstall-am \
- uninstall-pygioverridesPYTHON
+ clean-generic clean-libtool cscopelist-am ctags-am distclean \
+ distclean-generic distclean-libtool distdir dvi dvi-am html \
+ html-am info info-am install install-am install-data \
+ install-data-am install-dvi install-dvi-am install-exec \
+ install-exec-am install-html install-html-am install-info \
+ install-info-am install-man install-pdf install-pdf-am \
+ install-ps install-ps-am install-pygioverridesPYTHON \
+ install-strip installcheck installcheck-am installdirs \
+ maintainer-clean maintainer-clean-generic mostlyclean \
+ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
+ tags-am uninstall uninstall-am uninstall-pygioverridesPYTHON
# if we build in a separate tree, we need to symlink the *.py files from the
diff --git a/gi/overrides/__init__.py b/gi/overrides/__init__.py
index 99cb152..943ea60 100644
--- a/gi/overrides/__init__.py
+++ b/gi/overrides/__init__.py
@@ -3,6 +3,7 @@ import warnings
import functools
from gi import PyGIDeprecationWarning
+from gi._gi import CallableInfo
from gi._gobject.constants import \
TYPE_NONE, \
TYPE_INVALID
@@ -33,7 +34,8 @@ class _Registry(dict):
raise TypeError('Can not override a type %s, which is not in a gobject introspection typelib' % value.__name__)
if not value.__module__.startswith('gi.overrides'):
- raise KeyError('You have tried to modify the registry outside of the overrides module. This is not allowed')
+ raise KeyError('You have tried to modify the registry outside of the overrides module. '
+ 'This is not allowed (%s, %s)' % (value, value.__module__))
g_type = info.get_g_type()
assert g_type != TYPE_NONE
@@ -52,8 +54,8 @@ class _Registry(dict):
class overridefunc(object):
'''decorator for overriding a function'''
def __init__(self, func):
- if not hasattr(func, '__info__'):
- raise TypeError("func must be an gi function")
+ if not isinstance(func, CallableInfo):
+ raise TypeError("func must be a gi function, got %s" % func)
from ..importer import modules
module_name = func.__module__.rsplit('.', 1)[-1]
self.module = modules[module_name]._introspection_module
@@ -70,7 +72,7 @@ registry = _Registry()
def override(type_):
'''Decorator for registering an override'''
- if isinstance(type_, types.FunctionType):
+ if isinstance(type_, (types.FunctionType, CallableInfo)):
return overridefunc(type_)
else:
registry.register(type_)
diff --git a/gi/pygi-argument.c b/gi/pygi-argument.c
index f477fdf..7d8a837 100644
--- a/gi/pygi-argument.c
+++ b/gi/pygi-argument.c
@@ -898,141 +898,12 @@ _pygi_argument_from_object (PyObject *object,
memset(&arg, 0, sizeof(GIArgument));
type_tag = g_type_info_get_tag (type_info);
- switch (type_tag) {
- case GI_TYPE_TAG_VOID:
- g_warn_if_fail (transfer == GI_TRANSFER_NOTHING);
- if (object == Py_None) {
- arg.v_pointer = NULL;
- } else if (!PYGLIB_PyLong_Check(object) && !PyLong_Check(object)) {
- PyErr_SetString(PyExc_TypeError,
- "Pointer assignment is restricted to integer values. "
- "See: https://bugzilla.gnome.org/show_bug.cgi?id=683599");
- } else {
- arg.v_pointer = PyLong_AsVoidPtr (object);
- }
- break;
- case GI_TYPE_TAG_BOOLEAN:
- {
- arg.v_boolean = PyObject_IsTrue (object);
- break;
- }
- case GI_TYPE_TAG_INT8:
- case GI_TYPE_TAG_INT16:
- case GI_TYPE_TAG_INT32:
- {
- PyObject *int_;
-
- int_ = PYGLIB_PyNumber_Long (object);
- if (int_ == NULL) {
- PyErr_SetString (PyExc_TypeError, "expected int argument");
- break;
- }
-
- if (type_tag == GI_TYPE_TAG_INT32)
- arg.v_int32 = PYGLIB_PyLong_AsLong (int_);
- else if (type_tag == GI_TYPE_TAG_INT8)
- arg.v_int8 = PYGLIB_PyLong_AsLong (int_);
- else if (type_tag == GI_TYPE_TAG_INT16)
- arg.v_int16 = PYGLIB_PyLong_AsLong (int_);
-
- Py_DECREF (int_);
-
- break;
- }
- case GI_TYPE_TAG_UINT8:
- case GI_TYPE_TAG_UINT16:
- case GI_TYPE_TAG_UINT32:
- case GI_TYPE_TAG_UINT64:
- {
- PyObject *number;
- guint64 value;
-
- number = PYGLIB_PyNumber_Long (object);
- if (number == NULL) {
- PyErr_SetString (PyExc_TypeError, "expected int argument");
- break;
- }
-
-#if PY_VERSION_HEX < 0x03000000
- if (PyInt_Check (number)) {
- value = PyInt_AS_LONG (number);
- } else
-#endif
- value = PyLong_AsUnsignedLongLong (number);
-
- if (type_tag == GI_TYPE_TAG_UINT32)
- arg.v_uint32 = value;
- else if (type_tag == GI_TYPE_TAG_UINT64)
- arg.v_uint64 = value;
- else if (type_tag == GI_TYPE_TAG_UINT8)
- arg.v_uint8 = value;
- else if (type_tag == GI_TYPE_TAG_UINT16)
- arg.v_uint16 = value;
-
- Py_DECREF (number);
-
- break;
- }
- case GI_TYPE_TAG_INT64:
- {
- PyObject *number;
- gint64 value;
-
- number = PYGLIB_PyNumber_Long (object);
- if (number == NULL) {
- PyErr_SetString (PyExc_TypeError, "expected int argument");
- break;
- }
-
-#if PY_VERSION_HEX < 0x03000000
- if (PyInt_Check (number)) {
- value = PyInt_AS_LONG (number);
- } else
-#endif
- value = PyLong_AsLongLong (number);
-
- arg.v_int64 = value;
-
- Py_DECREF (number);
-
- break;
- }
- case GI_TYPE_TAG_FLOAT:
- {
- _pygi_marshal_from_py_float (NULL, NULL, NULL,
- object, &arg);
- break;
- }
- case GI_TYPE_TAG_DOUBLE:
- {
- _pygi_marshal_from_py_double (NULL, NULL, NULL,
- object, &arg);
- break;
- }
- case GI_TYPE_TAG_GTYPE:
- {
- arg.v_long = pyg_type_from_object (object);
+ if (_pygi_marshal_from_py_basic_type (object, &arg, type_tag, transfer) ||
+ PyErr_Occurred()) {
+ return arg;
+ }
- break;
- }
- case GI_TYPE_TAG_UNICHAR:
- {
- _pygi_marshal_from_py_unichar (NULL, NULL, NULL,
- object, &arg);
- break;
- }
- case GI_TYPE_TAG_UTF8:
- {
- _pygi_marshal_from_py_utf8 (NULL, NULL, NULL,
- object, &arg);
- break;
- }
- case GI_TYPE_TAG_FILENAME:
- {
- _pygi_marshal_from_py_filename (NULL, NULL, NULL,
- object, &arg);
- break;
- }
+ switch (type_tag) {
case GI_TYPE_TAG_ARRAY:
{
Py_ssize_t length;
@@ -1156,16 +1027,16 @@ array_success:
* Further re-factoring is needed to fix this leak.
* See: https://bugzilla.gnome.org/show_bug.cgi?id=693405
*/
- pygi_marshal_from_py_interface_struct (object,
- &arg,
- NULL, /*arg_name*/
- info, /*interface_info*/
- type_info,
- g_type,
- py_type,
- transfer,
- FALSE, /*is_caller_allocates*/
- g_struct_info_is_foreign (info));
+ _pygi_marshal_from_py_interface_struct (object,
+ &arg,
+ NULL, /*arg_name*/
+ info, /*interface_info*/
+ type_info,
+ g_type,
+ py_type,
+ transfer,
+ FALSE, /*copy_reference*/
+ g_struct_info_is_foreign (info));
Py_DECREF (py_type);
break;
@@ -1189,7 +1060,7 @@ array_success:
case GI_INFO_TYPE_INTERFACE:
case GI_INFO_TYPE_OBJECT:
/* An error within this call will result in a NULL arg */
- pygi_marshal_from_py_gobject (object, &arg, transfer);
+ _pygi_marshal_from_py_gobject_out_arg (object, &arg, transfer);
break;
default:
@@ -1373,6 +1244,8 @@ hash_table_release:
PyErr_SetString (PyExc_NotImplementedError, "error marshalling is not supported yet");
/* TODO */
break;
+ default:
+ g_assert_not_reached ();
}
return arg;
@@ -1380,14 +1253,14 @@ hash_table_release:
/**
* _pygi_argument_to_object:
- * @arg: The argument to convert to an object.
+ * @arg: The argument to convert to an object.
* @type_info: Type info for @arg
* @transfer:
*
* If the argument is of type array, it must be encoded in a GArray, by calling
* _pygi_argument_to_array(). This logic can not be folded into this method
* as determining array lengths may require access to method call arguments.
- *
+ *
* Returns: A PyObject representing @arg
*/
PyObject *
@@ -1399,6 +1272,10 @@ _pygi_argument_to_object (GIArgument *arg,
PyObject *object = NULL;
type_tag = g_type_info_get_tag (type_info);
+ object = _pygi_marshal_to_py_basic_type (arg, type_tag, transfer);
+ if (object)
+ return object;
+
switch (type_tag) {
case GI_TYPE_TAG_VOID:
{
@@ -1408,84 +1285,6 @@ _pygi_argument_to_object (GIArgument *arg,
}
break;
}
- case GI_TYPE_TAG_BOOLEAN:
- {
- object = PyBool_FromLong (arg->v_boolean);
- break;
- }
- case GI_TYPE_TAG_INT8:
- {
- object = PYGLIB_PyLong_FromLong (arg->v_int8);
- break;
- }
- case GI_TYPE_TAG_UINT8:
- {
- object = PYGLIB_PyLong_FromLong (arg->v_uint8);
- break;
- }
- case GI_TYPE_TAG_INT16:
- {
- object = PYGLIB_PyLong_FromLong (arg->v_int16);
- break;
- }
- case GI_TYPE_TAG_UINT16:
- {
- object = PYGLIB_PyLong_FromLong (arg->v_uint16);
- break;
- }
- case GI_TYPE_TAG_INT32:
- {
- object = PYGLIB_PyLong_FromLong (arg->v_int32);
- break;
- }
- case GI_TYPE_TAG_UINT32:
- {
- object = PyLong_FromLongLong (arg->v_uint32);
- break;
- }
- case GI_TYPE_TAG_INT64:
- {
- object = PyLong_FromLongLong (arg->v_int64);
- break;
- }
- case GI_TYPE_TAG_UINT64:
- {
- object = PyLong_FromUnsignedLongLong (arg->v_uint64);
- break;
- }
- case GI_TYPE_TAG_FLOAT:
- {
- object = PyFloat_FromDouble (arg->v_float);
- break;
- }
- case GI_TYPE_TAG_DOUBLE:
- {
- object = PyFloat_FromDouble (arg->v_double);
- break;
- }
- case GI_TYPE_TAG_GTYPE:
- {
- object = pyg_type_wrapper_new ( (GType) arg->v_long);
- break;
- }
- case GI_TYPE_TAG_UNICHAR:
- {
- object = _pygi_marshal_to_py_unichar (NULL, NULL, NULL,
- arg);
- break;
- }
- case GI_TYPE_TAG_UTF8:
- {
- object = _pygi_marshal_to_py_utf8 (NULL, NULL, NULL,
- arg);
- break;
- }
- case GI_TYPE_TAG_FILENAME:
- {
- object = _pygi_marshal_to_py_filename (NULL, NULL, NULL,
- arg);
- break;
- }
case GI_TYPE_TAG_ARRAY:
{
/* Arrays are assumed to be packed in a GArray */
@@ -1571,13 +1370,13 @@ _pygi_argument_to_object (GIArgument *arg,
py_type = _pygi_type_get_from_g_type (g_type);
}
- object = pygi_marshal_to_py_interface_struct (arg,
- info, /*interface_info*/
- g_type,
- py_type,
- transfer,
- FALSE, /*is_allocated*/
- g_struct_info_is_foreign (info));
+ object = _pygi_marshal_to_py_interface_struct (arg,
+ info, /*interface_info*/
+ g_type,
+ py_type,
+ transfer,
+ FALSE, /*is_allocated*/
+ g_struct_info_is_foreign (info));
Py_XDECREF (py_type);
break;
@@ -1634,10 +1433,10 @@ _pygi_argument_to_object (GIArgument *arg,
transfer == GI_TRANSFER_NOTHING &&
g_object_is_floating (arg->v_pointer)) {
g_object_ref (arg->v_pointer);
- object = pygi_marshal_to_py_object (arg, GI_TRANSFER_EVERYTHING);
+ object = _pygi_marshal_to_py_object (arg, GI_TRANSFER_EVERYTHING);
g_object_force_floating (arg->v_pointer);
} else {
- object = pygi_marshal_to_py_object (arg, transfer);
+ object = _pygi_marshal_to_py_object (arg, transfer);
}
break;
@@ -1775,6 +1574,11 @@ _pygi_argument_to_object (GIArgument *arg,
Py_INCREF (object);
break;
}
+ break;
+ }
+ default:
+ {
+ g_assert_not_reached();
}
}
@@ -1899,8 +1703,8 @@ _pygi_argument_from_g_value(const GValue *value,
arg.v_pointer = g_value_get_boxed (value);
break;
case GI_TYPE_TAG_VOID:
- g_critical("Converting of type '%s' is not implemented", g_type_tag_to_string(type_tag));
- g_assert_not_reached();
+ arg.v_pointer = g_value_get_pointer (value);
+ break;
}
return arg;
diff --git a/gi/pygi-cache.c b/gi/pygi-cache.c
index d149732..2f807f8 100644
--- a/gi/pygi-cache.c
+++ b/gi/pygi-cache.c
@@ -260,178 +260,34 @@ _arg_cache_alloc (void)
}
static void
-_arg_cache_from_py_void_setup (PyGIArgCache *arg_cache)
-{
- arg_cache->from_py_marshaller = _pygi_marshal_from_py_void;
-}
-
-static void
-_arg_cache_to_py_void_setup (PyGIArgCache *arg_cache)
-{
- arg_cache->to_py_marshaller = _pygi_marshal_to_py_void;
-}
-
-static void
-_arg_cache_from_py_boolean_setup (PyGIArgCache *arg_cache)
-{
- arg_cache->from_py_marshaller = _pygi_marshal_from_py_boolean;
-}
-
-static void
-_arg_cache_to_py_boolean_setup (PyGIArgCache *arg_cache)
-{
- arg_cache->to_py_marshaller = _pygi_marshal_to_py_boolean;
-}
-
-static void
-_arg_cache_from_py_int8_setup (PyGIArgCache *arg_cache)
+_arg_cache_from_py_basic_type_setup (PyGIArgCache *arg_cache)
{
- arg_cache->from_py_marshaller = _pygi_marshal_from_py_int8;
+ arg_cache->from_py_marshaller = _pygi_marshal_from_py_basic_type_cache_adapter;
}
static void
-_arg_cache_to_py_int8_setup (PyGIArgCache *arg_cache)
+_arg_cache_to_py_basic_type_setup (PyGIArgCache *arg_cache)
{
- arg_cache->to_py_marshaller = _pygi_marshal_to_py_int8;
+ arg_cache->to_py_marshaller = _pygi_marshal_to_py_basic_type_cache_adapter;
}
static void
-_arg_cache_from_py_uint8_setup (PyGIArgCache *arg_cache)
-{
- arg_cache->from_py_marshaller = _pygi_marshal_from_py_uint8;
-}
-
-static void
-_arg_cache_to_py_uint8_setup (PyGIArgCache *arg_cache)
-{
- arg_cache->to_py_marshaller = _pygi_marshal_to_py_uint8;
-}
-
-static void
-_arg_cache_from_py_int16_setup (PyGIArgCache *arg_cache)
-{
- arg_cache->from_py_marshaller = _pygi_marshal_from_py_int16;
-}
-
-static void
-_arg_cache_to_py_int16_setup (PyGIArgCache *arg_cache)
-{
- arg_cache->to_py_marshaller = _pygi_marshal_to_py_int16;
-}
-
-static void
-_arg_cache_from_py_uint16_setup (PyGIArgCache *arg_cache)
-{
- arg_cache->from_py_marshaller = _pygi_marshal_from_py_uint16;
-}
-
-static void
-_arg_cache_to_py_uint16_setup (PyGIArgCache *arg_cache)
-{
- arg_cache->to_py_marshaller = _pygi_marshal_to_py_uint16;
-}
-
-static void
-_arg_cache_from_py_int32_setup (PyGIArgCache *arg_cache)
-{
- arg_cache->from_py_marshaller = _pygi_marshal_from_py_int32;
-}
-
-static void
-_arg_cache_to_py_int32_setup (PyGIArgCache *arg_cache)
-{
- arg_cache->to_py_marshaller = _pygi_marshal_to_py_int32;
-}
-
-static void
-_arg_cache_from_py_uint32_setup (PyGIArgCache *arg_cache)
-{
- arg_cache->from_py_marshaller = _pygi_marshal_from_py_uint32;
-}
-
-static void
-_arg_cache_to_py_uint32_setup (PyGIArgCache *arg_cache)
-{
- arg_cache->to_py_marshaller = _pygi_marshal_to_py_uint32;
-}
-
-static void
-_arg_cache_from_py_int64_setup (PyGIArgCache *arg_cache)
-{
- arg_cache->from_py_marshaller = _pygi_marshal_from_py_int64;
-}
-
-static void
-_arg_cache_to_py_int64_setup (PyGIArgCache *arg_cache)
-{
- arg_cache->to_py_marshaller = _pygi_marshal_to_py_int64;
-}
-
-static void
-_arg_cache_from_py_uint64_setup (PyGIArgCache *arg_cache)
-{
- arg_cache->from_py_marshaller = _pygi_marshal_from_py_uint64;
-}
-
-static void
-_arg_cache_to_py_uint64_setup (PyGIArgCache *arg_cache)
-{
- arg_cache->to_py_marshaller = _pygi_marshal_to_py_uint64;
-}
-
-static void
-_arg_cache_from_py_float_setup (PyGIArgCache *arg_cache)
-{
- arg_cache->from_py_marshaller = _pygi_marshal_from_py_float;
-}
-
-static void
-_arg_cache_to_py_float_setup (PyGIArgCache *arg_cache)
-{
- arg_cache->to_py_marshaller = _pygi_marshal_to_py_float;
-}
-
-static void
-_arg_cache_from_py_double_setup (PyGIArgCache *arg_cache)
-{
- arg_cache->from_py_marshaller = _pygi_marshal_from_py_double;
-}
-
-static void
-_arg_cache_to_py_double_setup (PyGIArgCache *arg_cache)
-{
- arg_cache->to_py_marshaller = _pygi_marshal_to_py_double;
-}
-
-static void
-_arg_cache_from_py_unichar_setup (PyGIArgCache *arg_cache)
-{
- arg_cache->from_py_marshaller = _pygi_marshal_from_py_unichar;
-}
-
-static void
-_arg_cache_to_py_unichar_setup (PyGIArgCache *arg_cache)
-{
- arg_cache->to_py_marshaller = _pygi_marshal_to_py_unichar;
-}
-
-static void
-_arg_cache_from_py_gtype_setup (PyGIArgCache *arg_cache)
+_arg_cache_from_py_void_setup (PyGIArgCache *arg_cache)
{
- arg_cache->from_py_marshaller = _pygi_marshal_from_py_gtype;
+ arg_cache->from_py_marshaller = _pygi_marshal_from_py_void;
}
static void
-_arg_cache_to_py_gtype_setup (PyGIArgCache *arg_cache)
+_arg_cache_to_py_void_setup (PyGIArgCache *arg_cache)
{
- arg_cache->to_py_marshaller = _pygi_marshal_to_py_gtype;
+ arg_cache->to_py_marshaller = _pygi_marshal_to_py_void;
}
static void
_arg_cache_from_py_utf8_setup (PyGIArgCache *arg_cache,
GITransfer transfer)
{
- arg_cache->from_py_marshaller = _pygi_marshal_from_py_utf8;
+ arg_cache->from_py_marshaller = _pygi_marshal_from_py_basic_type_cache_adapter;
arg_cache->from_py_cleanup = _pygi_marshal_cleanup_from_py_utf8;
}
@@ -439,23 +295,7 @@ static void
_arg_cache_to_py_utf8_setup (PyGIArgCache *arg_cache,
GITransfer transfer)
{
- arg_cache->to_py_marshaller = _pygi_marshal_to_py_utf8;
- arg_cache->to_py_cleanup = _pygi_marshal_cleanup_to_py_utf8;
-}
-
-static void
-_arg_cache_from_py_filename_setup (PyGIArgCache *arg_cache,
- GITransfer transfer)
-{
- arg_cache->from_py_marshaller = _pygi_marshal_from_py_filename;
- arg_cache->from_py_cleanup = _pygi_marshal_cleanup_from_py_utf8;
-}
-
-static void
-_arg_cache_to_py_filename_setup (PyGIArgCache *arg_cache,
- GITransfer transfer)
-{
- arg_cache->to_py_marshaller = _pygi_marshal_to_py_filename;
+ arg_cache->to_py_marshaller = _pygi_marshal_to_py_basic_type_cache_adapter;
arg_cache->to_py_cleanup = _pygi_marshal_cleanup_to_py_utf8;
}
@@ -606,14 +446,14 @@ static void
_arg_cache_from_py_interface_union_setup (PyGIArgCache *arg_cache,
GITransfer transfer)
{
- arg_cache->from_py_marshaller = _pygi_marshal_from_py_interface_struct;
+ arg_cache->from_py_marshaller = _pygi_marshal_from_py_interface_struct_cache_adapter;
}
static void
_arg_cache_to_py_interface_union_setup (PyGIArgCache *arg_cache,
GITransfer transfer)
{
- arg_cache->to_py_marshaller = _pygi_marshal_to_py_interface_struct;
+ arg_cache->to_py_marshaller = _pygi_marshal_to_py_interface_struct_cache_adapter;
}
static void
@@ -623,7 +463,7 @@ _arg_cache_from_py_interface_struct_setup (PyGIArgCache *arg_cache,
{
PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *)arg_cache;
iface_cache->is_foreign = g_struct_info_is_foreign ( (GIStructInfo*)iface_info);
- arg_cache->from_py_marshaller = _pygi_marshal_from_py_interface_struct;
+ arg_cache->from_py_marshaller = _pygi_marshal_from_py_interface_struct_cache_adapter;
if (iface_cache->g_type == G_TYPE_VALUE)
arg_cache->from_py_cleanup = _pygi_marshal_cleanup_from_py_interface_struct_gvalue;
@@ -638,7 +478,7 @@ _arg_cache_to_py_interface_struct_setup (PyGIArgCache *arg_cache,
{
PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *)arg_cache;
iface_cache->is_foreign = g_struct_info_is_foreign ( (GIStructInfo*)iface_info);
- arg_cache->to_py_marshaller = _pygi_marshal_to_py_interface_struct;
+ arg_cache->to_py_marshaller = _pygi_marshal_to_py_interface_struct_cache_adapter;
if (iface_cache->is_foreign)
arg_cache->to_py_cleanup = _pygi_marshal_cleanup_to_py_interface_struct_foreign;
@@ -656,7 +496,7 @@ static void
_arg_cache_to_py_interface_object_setup (PyGIArgCache *arg_cache,
GITransfer transfer)
{
- arg_cache->to_py_marshaller = _pygi_marshal_to_py_interface_object;
+ arg_cache->to_py_marshaller = _pygi_marshal_to_py_interface_object_cache_adapter;
arg_cache->to_py_cleanup = _pygi_marshal_cleanup_to_py_interface_object;
}
@@ -870,161 +710,31 @@ _arg_cache_new (GITypeInfo *type_info,
break;
case GI_TYPE_TAG_BOOLEAN:
- arg_cache = _arg_cache_alloc ();
- if (arg_cache == NULL)
- break;
-
- if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
- _arg_cache_from_py_boolean_setup (arg_cache);
-
- if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
- _arg_cache_to_py_boolean_setup (arg_cache);
-
- break;
case GI_TYPE_TAG_INT8:
- arg_cache = _arg_cache_alloc ();
- if (arg_cache == NULL)
- break;
-
- if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
- _arg_cache_from_py_int8_setup (arg_cache);
-
- if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
- _arg_cache_to_py_int8_setup (arg_cache);
-
- break;
case GI_TYPE_TAG_UINT8:
- arg_cache = _arg_cache_alloc ();
- if (arg_cache == NULL)
- break;
-
- if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
- _arg_cache_from_py_uint8_setup (arg_cache);
-
- if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
- _arg_cache_to_py_uint8_setup (arg_cache);
-
- break;
case GI_TYPE_TAG_INT16:
- arg_cache = _arg_cache_alloc ();
- if (arg_cache == NULL)
- break;
-
- if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
- _arg_cache_from_py_int16_setup (arg_cache);
-
- if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
- _arg_cache_to_py_int16_setup (arg_cache);
-
- break;
case GI_TYPE_TAG_UINT16:
- arg_cache = _arg_cache_alloc ();
- if (arg_cache == NULL)
- break;
-
- if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
- _arg_cache_from_py_uint16_setup (arg_cache);
-
- if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
- _arg_cache_to_py_uint16_setup (arg_cache);
- break;
case GI_TYPE_TAG_INT32:
- arg_cache = _arg_cache_alloc ();
- if (arg_cache == NULL)
- break;
-
- if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
- _arg_cache_from_py_int32_setup (arg_cache);
-
- if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
- _arg_cache_to_py_int32_setup (arg_cache);
-
- break;
case GI_TYPE_TAG_UINT32:
- arg_cache = _arg_cache_alloc ();
- if (arg_cache == NULL)
- break;
-
- if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
- _arg_cache_from_py_uint32_setup (arg_cache);
-
- if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
- _arg_cache_to_py_uint32_setup (arg_cache);
-
- break;
case GI_TYPE_TAG_INT64:
- arg_cache = _arg_cache_alloc ();
- if (arg_cache == NULL)
- break;
-
- if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
- _arg_cache_from_py_int64_setup (arg_cache);
-
- if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
- _arg_cache_to_py_int64_setup (arg_cache);
-
- break;
case GI_TYPE_TAG_UINT64:
- arg_cache = _arg_cache_alloc ();
- if (arg_cache == NULL)
- break;
-
- if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
- _arg_cache_from_py_uint64_setup (arg_cache);
-
- if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
- _arg_cache_to_py_uint64_setup (arg_cache);
-
- break;
case GI_TYPE_TAG_FLOAT:
- arg_cache = _arg_cache_alloc ();
- if (arg_cache == NULL)
- break;
-
- if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
- _arg_cache_from_py_float_setup (arg_cache);
-
- if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
- _arg_cache_to_py_float_setup (arg_cache);
-
- break;
case GI_TYPE_TAG_DOUBLE:
- arg_cache = _arg_cache_alloc ();
- if (arg_cache == NULL)
- break;
-
- if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
- _arg_cache_from_py_double_setup (arg_cache);
-
- if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
- _arg_cache_to_py_double_setup (arg_cache);
-
- break;
case GI_TYPE_TAG_UNICHAR:
- arg_cache = _arg_cache_alloc ();
- if (arg_cache == NULL)
- break;
-
- if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
- _arg_cache_from_py_unichar_setup (arg_cache);
-
- if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
- _arg_cache_to_py_unichar_setup (arg_cache);
-
- break;
case GI_TYPE_TAG_GTYPE:
arg_cache = _arg_cache_alloc ();
if (arg_cache == NULL)
break;
if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
- _arg_cache_from_py_gtype_setup (arg_cache);
+ _arg_cache_from_py_basic_type_setup (arg_cache);
if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
- _arg_cache_to_py_gtype_setup (arg_cache);
+ _arg_cache_to_py_basic_type_setup (arg_cache);
break;
case GI_TYPE_TAG_UTF8:
+ case GI_TYPE_TAG_FILENAME:
arg_cache = _arg_cache_alloc ();
if (arg_cache == NULL)
break;
@@ -1036,18 +746,6 @@ _arg_cache_new (GITypeInfo *type_info,
_arg_cache_to_py_utf8_setup (arg_cache, transfer);
break;
- case GI_TYPE_TAG_FILENAME:
- arg_cache = _arg_cache_alloc ();
- if (arg_cache == NULL)
- break;
-
- if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
- _arg_cache_from_py_filename_setup (arg_cache, transfer);
-
- if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
- _arg_cache_to_py_filename_setup (arg_cache, transfer);
-
- break;
case GI_TYPE_TAG_ARRAY:
{
PyGISequenceCache *seq_cache =
@@ -1387,6 +1085,7 @@ _args_cache_generate (GICallableInfo *callable_info,
arg_cache->type_tag = g_type_info_get_tag (type_info);
+ g_base_info_unref (type_info);
g_base_info_unref ( (GIBaseInfo *)arg_info);
continue;
}
diff --git a/gi/pygi-closure.c b/gi/pygi-closure.c
index f30fa52..7582069 100644
--- a/gi/pygi-closure.c
+++ b/gi/pygi-closure.c
@@ -33,6 +33,9 @@ _pygi_closure_assign_pyobj_to_retval (gpointer retval, PyObject *object,
GITransfer transfer)
{
GIArgument arg = _pygi_argument_from_object (object, type_info, transfer);
+ if (PyErr_Occurred ())
+ return;
+
GITypeTag type_tag = g_type_info_get_tag (type_info);
if (retval == NULL)
@@ -108,6 +111,19 @@ _pygi_closure_assign_pyobj_to_retval (gpointer retval, PyObject *object,
}
static void
+_pygi_closure_clear_retval (GICallableInfo *callable_info, gpointer retval)
+{
+ GITypeInfo return_type_info;
+ GITypeTag return_type_tag;
+
+ g_callable_info_load_return_type (callable_info, &return_type_info);
+ return_type_tag = g_type_info_get_tag (&return_type_info);
+ if (return_type_tag != GI_TYPE_TAG_VOID) {
+ *((ffi_arg *) retval) = 0;
+ }
+}
+
+static void
_pygi_closure_assign_pyobj_to_out_argument (gpointer out_arg, PyObject *object,
GITypeInfo *type_info,
GITransfer transfer)
@@ -505,15 +521,8 @@ _pygi_invoke_closure_clear_py_data(PyGICClosure *invoke_closure)
{
PyGILState_STATE state = PyGILState_Ensure();
- if (invoke_closure->function != NULL) {
- Py_DECREF (invoke_closure->function);
- invoke_closure->function = NULL;
- }
-
- if (invoke_closure->user_data != NULL) {
- Py_DECREF (invoke_closure->user_data);
- invoke_closure->user_data = NULL;
- }
+ Py_CLEAR (invoke_closure->function);
+ Py_CLEAR (invoke_closure->user_data);
PyGILState_Release (state);
}
@@ -546,11 +555,17 @@ _pygi_closure_handle (ffi_cif *cif,
Py_DECREF (py_args);
if (retval == NULL) {
+ _pygi_closure_clear_retval (closure->info, result);
PyErr_Print();
goto end;
}
_pygi_closure_set_out_arguments (closure->info, retval, out_args, result);
+ if (PyErr_Occurred ()) {
+ _pygi_closure_clear_retval (closure->info, result);
+ PyErr_Print();
+ }
+
Py_DECREF (retval);
end:
diff --git a/gi/pygi-info.c b/gi/pygi-info.c
index 3e8fcb8..7164ff9 100644
--- a/gi/pygi-info.c
+++ b/gi/pygi-info.c
@@ -27,6 +27,33 @@
#include <pygobject.h>
#include <pyglib-python-compat.h>
+
+/* _generate_doc_string
+ *
+ * C wrapper to call Python implemented "gi.docstring.generate_doc_string"
+ */
+static PyObject *
+_generate_doc_string(PyGIBaseInfo *self)
+{
+ static PyObject *_py_generate_doc_string = NULL;
+
+ if (_py_generate_doc_string == NULL) {
+ PyObject *mod = PyImport_ImportModule ("gi.docstring");
+ if (!mod)
+ return NULL;
+
+ _py_generate_doc_string = PyObject_GetAttrString (mod, "generate_doc_string");
+ if (_py_generate_doc_string == NULL) {
+ Py_DECREF (mod);
+ return NULL;
+ }
+ Py_DECREF (mod);
+ }
+
+ return PyObject_CallFunctionObjArgs (_py_generate_doc_string, self, NULL);
+}
+
+
/* BaseInfo */
static void
@@ -170,6 +197,55 @@ static PyMethodDef _PyGIBaseInfo_methods[] = {
{ NULL, NULL, 0 }
};
+/* _base_info_getattro:
+ *
+ * The usage of __getattr__ is needed because the get/set method table
+ * does not work for __doc__.
+ */
+static PyObject *
+_base_info_getattro(PyGIBaseInfo *self, PyObject *name)
+{
+ PyObject *result;
+
+ static PyObject *docstr;
+ if (docstr == NULL) {
+ docstr= PYGLIB_PyUnicode_InternFromString("__doc__");
+ if (docstr == NULL)
+ return NULL;
+ }
+
+ Py_INCREF (name);
+ PYGLIB_PyUnicode_InternInPlace (&name);
+
+ if (name == docstr) {
+ result = _generate_doc_string (self);
+ } else {
+ result = PyObject_GenericGetAttr ((PyObject *)self, name);
+ }
+
+ Py_DECREF (name);
+ return result;
+}
+
+static PyObject *
+_base_info_attr_name(PyGIBaseInfo *self, void *closure)
+{
+ return _wrap_g_base_info_get_name (self);
+}
+
+static PyObject *
+_base_info_attr_module(PyGIBaseInfo *self, void *closure)
+{
+ return PYGLIB_PyUnicode_FromFormat ("gi.repository.%s",
+ g_base_info_get_namespace (self->info));
+}
+
+static PyGetSetDef _base_info_getsets[] = {
+ { "__name__", (getter)_base_info_attr_name, (setter)0, "Name", NULL},
+ { "__module__", (getter)_base_info_attr_module, (setter)0, "Module name", NULL},
+ { NULL, 0, 0 }
+};
+
PyObject *
_pygi_info_new (GIBaseInfo *info)
{
@@ -281,7 +357,7 @@ out:
/* CallableInfo */
-PYGLIB_DEFINE_TYPE ("gi.CallableInfo", PyGICallableInfo_Type, PyGIBaseInfo);
+PYGLIB_DEFINE_TYPE ("gi.CallableInfo", PyGICallableInfo_Type, PyGICallableInfo);
static PyObject *
_wrap_g_callable_info_get_arguments (PyGIBaseInfo *self)
@@ -319,6 +395,183 @@ _wrap_g_callable_info_get_arguments (PyGIBaseInfo *self)
return infos;
}
+
+/* _callable_info_call:
+ *
+ * Shared wrapper for invoke which can be bound (instance method or class constructor)
+ * or unbound (function or static method).
+ */
+static PyObject *
+_callable_info_call (PyGICallableInfo *self, PyObject *args, PyObject *kwargs)
+{
+ /* Insert the bound arg at the beginning of the invoke method args. */
+ if (self->py_bound_arg) {
+ int i;
+ PyObject *result;
+ Py_ssize_t argcount = PyTuple_Size (args);
+ PyObject *newargs = PyTuple_New (argcount + 1);
+ if (newargs == NULL)
+ return NULL;
+
+ Py_INCREF (self->py_bound_arg);
+ PyTuple_SET_ITEM (newargs, 0, self->py_bound_arg);
+
+ for (i = 0; i < argcount; i++) {
+ PyObject *v = PyTuple_GET_ITEM (args, i);
+ Py_XINCREF (v);
+ PyTuple_SET_ITEM (newargs, i+1, v);
+ }
+
+ /* Invoke with the original GI info struct this wrapper was based upon.
+ * This is necessary to maintain the same cache for all bound versions.
+ */
+ result = _wrap_g_callable_info_invoke ((PyGIBaseInfo *)self->py_unbound_info,
+ newargs, kwargs);
+ Py_DECREF (newargs);
+ return result;
+
+ } else {
+ /* We should never have an unbound info when calling when calling invoke
+ * at this point because the descriptor implementation on sub-classes
+ * should return "self" not a copy when there is no bound arg.
+ */
+ g_assert (self->py_unbound_info == NULL);
+ return _wrap_g_callable_info_invoke ((PyGIBaseInfo *)self, args, kwargs);
+ }
+}
+
+
+/* _function_info_call:
+ *
+ * Specialization of _callable_info_call for GIFunctionInfo which
+ * handles constructor error conditions.
+ */
+static PyObject *
+_function_info_call (PyGICallableInfo *self, PyObject *args, PyObject *kwargs)
+{
+ if (self->py_bound_arg) {
+ GIFunctionInfoFlags flags;
+
+ /* Ensure constructors are only called as class methods on the class
+ * implementing the constructor and not on sub-classes.
+ */
+ flags = g_function_info_get_flags ( (GIFunctionInfo*) self->base.info);
+ if (flags & GI_FUNCTION_IS_CONSTRUCTOR) {
+ PyObject *py_str_name;
+ const gchar *str_name;
+ GIBaseInfo *container_info = g_base_info_get_container (self->base.info);
+ g_assert (container_info != NULL);
+
+ py_str_name = PyObject_GetAttrString (self->py_bound_arg, "__name__");
+ if (py_str_name == NULL)
+ return NULL;
+
+ if (PyUnicode_Check (py_str_name) ) {
+ PyObject *tmp = PyUnicode_AsUTF8String (py_str_name);
+ Py_DECREF (py_str_name);
+ py_str_name = tmp;
+ }
+
+#if PY_VERSION_HEX < 0x03000000
+ str_name = PyString_AsString (py_str_name);
+#else
+ str_name = PyBytes_AsString (py_str_name);
+#endif
+
+ if (strcmp (str_name, g_base_info_get_name (container_info))) {
+ PyErr_Format (PyExc_TypeError,
+ "%s constructor cannot be used to create instances of "
+ "a subclass %s",
+ g_base_info_get_name (container_info),
+ str_name);
+ Py_DECREF (py_str_name);
+ return NULL;
+ }
+ Py_DECREF (py_str_name);
+ }
+ }
+
+ return _callable_info_call (self, args, kwargs);
+}
+
+/* _new_bound_callable_info
+ *
+ * Utility function for sub-classes to create a bound version of themself.
+ */
+static PyGICallableInfo *
+_new_bound_callable_info (PyGICallableInfo *self, PyObject *bound_arg)
+{
+ PyGICallableInfo *new_self;
+
+ /* Return self if this is already bound or there is nothing passed to bind. */
+ if (self->py_bound_arg != NULL || bound_arg == NULL || bound_arg == Py_None) {
+ Py_INCREF ((PyObject *)self);
+ return self;
+ }
+
+ new_self = (PyGICallableInfo *)_pygi_info_new (self->base.info);
+ if (new_self == NULL)
+ return NULL;
+
+ Py_INCREF ((PyObject *)self);
+ new_self->py_unbound_info = (struct PyGICallableInfo *)self;
+
+ Py_INCREF (bound_arg);
+ new_self->py_bound_arg = bound_arg;
+
+ return new_self;
+}
+
+/* _function_info_descr_get
+ *
+ * Descriptor protocol implementation for functions, methods, and constructors.
+ */
+static PyObject *
+_function_info_descr_get (PyGICallableInfo *self, PyObject *obj, PyObject *type) {
+ GIFunctionInfoFlags flags;
+ PyObject *bound_arg = NULL;
+
+ flags = g_function_info_get_flags ( (GIFunctionInfo*) self->base.info);
+ if (flags & GI_FUNCTION_IS_CONSTRUCTOR) {
+ if (type == NULL)
+ bound_arg = (PyObject *)(Py_TYPE(obj));
+ else
+ bound_arg = type;
+ } else if (flags & GI_FUNCTION_IS_METHOD) {
+ bound_arg = obj;
+ }
+
+ return (PyObject *)_new_bound_callable_info (self, bound_arg);
+}
+
+/* _vfunc_info_descr_get
+ *
+ * Descriptor protocol implementation for virtual functions.
+ */
+static PyObject *
+_vfunc_info_descr_get (PyGICallableInfo *self, PyObject *obj, PyObject *type) {
+ PyObject *result;
+ PyObject *bound_arg = NULL;
+
+ bound_arg = PyObject_GetAttrString (type, "__gtype__");
+ if (bound_arg == NULL)
+ return NULL;
+
+ /* _new_bound_callable_info adds its own ref so free the one from GetAttrString */
+ result = (PyObject *)_new_bound_callable_info (self, bound_arg);
+ Py_DECREF (bound_arg);
+ return result;
+}
+
+static void
+_callable_info_dealloc (PyGICallableInfo *self)
+{
+ Py_CLEAR (self->py_unbound_info);
+ Py_CLEAR (self->py_bound_arg);
+
+ PyGIBaseInfo_Type.tp_dealloc ((PyObject *) self);
+}
+
static PyMethodDef _PyGICallableInfo_methods[] = {
{ "invoke", (PyCFunction) _wrap_g_callable_info_invoke, METH_VARARGS | METH_KEYWORDS },
{ "get_arguments", (PyCFunction) _wrap_g_callable_info_get_arguments, METH_NOARGS },
@@ -427,6 +680,7 @@ _g_arg_get_pytype_hint (PyGIBaseInfo *self)
const char *info_name;
PyObject *py_string;
GIBaseInfo *iface = g_type_info_get_interface(&type_info);
+ gchar *name;
info_name = g_base_info_get_name (iface);
if (info_name == NULL) {
@@ -434,7 +688,7 @@ _g_arg_get_pytype_hint (PyGIBaseInfo *self)
return PYGLIB_PyUnicode_FromString(g_type_tag_to_string(type_tag));
}
- gchar *name = g_strdup_printf("%s.%s",
+ name = g_strdup_printf("%s.%s",
g_base_info_get_namespace(iface),
info_name);
g_base_info_unref(iface);
@@ -466,7 +720,7 @@ static PyMethodDef _PyGITypeInfo_methods[] = {
/* FunctionInfo */
-PYGLIB_DEFINE_TYPE ("gi.FunctionInfo", PyGIFunctionInfo_Type, PyGIBaseInfo);
+PYGLIB_DEFINE_TYPE ("gi.FunctionInfo", PyGIFunctionInfo_Type, PyGICallableInfo);
static PyObject *
_wrap_g_function_info_is_constructor (PyGIBaseInfo *self)
@@ -652,7 +906,6 @@ static PyMethodDef _PyGIFunctionInfo_methods[] = {
{ NULL, NULL, 0 }
};
-
/* RegisteredTypeInfo */
PYGLIB_DEFINE_TYPE ("gi.RegisteredTypeInfo", PyGIRegisteredTypeInfo_Type, PyGIBaseInfo);
@@ -1590,7 +1843,7 @@ static PyMethodDef _PyGIUnresolvedInfo_methods[] = {
};
/* GIVFuncInfo */
-PYGLIB_DEFINE_TYPE ("gi.VFuncInfo", PyGIVFuncInfo_Type, PyGIBaseInfo);
+PYGLIB_DEFINE_TYPE ("gi.VFuncInfo", PyGIVFuncInfo_Type, PyGICallableInfo);
static PyObject *
_wrap_g_vfunc_info_get_invoker (PyGIBaseInfo *self)
@@ -1741,12 +1994,13 @@ _pygi_info_register_types (PyObject *m)
PyGIBaseInfo_Type.tp_repr = (reprfunc) _base_info_repr;
PyGIBaseInfo_Type.tp_flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE);
PyGIBaseInfo_Type.tp_weaklistoffset = offsetof(PyGIBaseInfo, inst_weakreflist);
- PyGIBaseInfo_Type.tp_methods = _PyGIBaseInfo_methods;
+ PyGIBaseInfo_Type.tp_methods = _PyGIBaseInfo_methods;
PyGIBaseInfo_Type.tp_richcompare = (richcmpfunc)_base_info_richcompare;
+ PyGIBaseInfo_Type.tp_getset = _base_info_getsets;
+ PyGIBaseInfo_Type.tp_getattro = (getattrofunc) _base_info_getattro;
if (PyType_Ready(&PyGIBaseInfo_Type))
- return;
-
+ return;
if (PyModule_AddObject(m, "BaseInfo", (PyObject *)&PyGIBaseInfo_Type))
return;
@@ -1757,14 +2011,24 @@ _pygi_info_register_types (PyObject *m)
if (PyModule_AddObject(m, "DIRECTION_INOUT", PyLong_FromLong(GI_DIRECTION_INOUT)))
return;
- _PyGI_REGISTER_TYPE (m, PyGIUnresolvedInfo_Type, UnresolvedInfo,
- PyGIBaseInfo_Type);
_PyGI_REGISTER_TYPE (m, PyGICallableInfo_Type, CallableInfo,
PyGIBaseInfo_Type);
- _PyGI_REGISTER_TYPE (m, PyGICallbackInfo_Type, CallbackInfo,
- PyGIBaseInfo_Type);
+ PyGICallableInfo_Type.tp_call = (ternaryfunc) _callable_info_call;
+ PyGICallableInfo_Type.tp_dealloc = (destructor) _callable_info_dealloc;
+
_PyGI_REGISTER_TYPE (m, PyGIFunctionInfo_Type, FunctionInfo,
PyGICallableInfo_Type);
+ PyGIFunctionInfo_Type.tp_call = (ternaryfunc) _function_info_call;
+ PyGIFunctionInfo_Type.tp_descr_get = (descrgetfunc) _function_info_descr_get;
+
+ _PyGI_REGISTER_TYPE (m, PyGIVFuncInfo_Type, VFuncInfo,
+ PyGICallableInfo_Type);
+ PyGIVFuncInfo_Type.tp_descr_get = (descrgetfunc) _vfunc_info_descr_get;
+
+ _PyGI_REGISTER_TYPE (m, PyGIUnresolvedInfo_Type, UnresolvedInfo,
+ PyGIBaseInfo_Type);
+ _PyGI_REGISTER_TYPE (m, PyGICallbackInfo_Type, CallbackInfo,
+ PyGIBaseInfo_Type);
_PyGI_REGISTER_TYPE (m, PyGIRegisteredTypeInfo_Type, RegisteredTypeInfo,
PyGIBaseInfo_Type);
_PyGI_REGISTER_TYPE (m, PyGIStructInfo_Type, StructInfo,
@@ -1781,8 +2045,6 @@ _pygi_info_register_types (PyObject *m)
PyGIBaseInfo_Type);
_PyGI_REGISTER_TYPE (m, PyGIFieldInfo_Type, FieldInfo,
PyGIBaseInfo_Type);
- _PyGI_REGISTER_TYPE (m, PyGIVFuncInfo_Type, VFuncInfo,
- PyGICallableInfo_Type);
_PyGI_REGISTER_TYPE (m, PyGIUnionInfo_Type, UnionInfo,
PyGIRegisteredTypeInfo_Type);
_PyGI_REGISTER_TYPE (m, PyGIBoxedInfo_Type, BoxedInfo,
diff --git a/gi/pygi-invoke.c b/gi/pygi-invoke.c
index ec5da91..17cd278 100644
--- a/gi/pygi-invoke.c
+++ b/gi/pygi-invoke.c
@@ -136,22 +136,14 @@ _check_for_unexpected_kwargs (const gchar *function_name,
/**
* _py_args_combine_and_check_length:
- * @function_name: the name of the function being called. Used for error messages.
- * @arg_name_list: a list of the string names for each argument. The length
- * of this list is the number of required arguments for the
- * function. If an argument has no name, NULL is put in its
- * position in the list.
- * @py_args: the tuple of positional arguments. A referece is stolen, and this
- tuple will be either decreffed or returned as is.
+ * @cache: PyGICallableCache
+ * @py_args: the tuple of positional arguments.
* @py_kwargs: the dict of keyword arguments to be merged with py_args.
- * A reference is borrowed.
*
- * Returns: The py_args and py_kwargs combined into one tuple.
+ * Returns: New value reference to the combined py_args and py_kwargs.
*/
static PyObject *
-_py_args_combine_and_check_length (const gchar *function_name,
- GSList *arg_name_list,
- GHashTable *arg_name_hash,
+_py_args_combine_and_check_length (PyGICallableCache *cache,
PyObject *py_args,
PyObject *py_kwargs)
{
@@ -159,6 +151,7 @@ _py_args_combine_and_check_length (const gchar *function_name,
Py_ssize_t n_py_args, n_py_kwargs, i;
guint n_expected_args;
GSList *l;
+ const gchar *function_name = cache->name;
n_py_args = PyTuple_GET_SIZE (py_args);
if (py_kwargs == NULL)
@@ -166,8 +159,10 @@ _py_args_combine_and_check_length (const gchar *function_name,
else
n_py_kwargs = PyDict_Size (py_kwargs);
- n_expected_args = g_slist_length (arg_name_list);
+ /* Fast path, we already have the exact number of args and not kwargs. */
+ n_expected_args = g_slist_length (cache->arg_name_list);
if (n_py_kwargs == 0 && n_py_args == n_expected_args) {
+ Py_INCREF (py_args);
return py_args;
}
@@ -179,15 +174,12 @@ _py_args_combine_and_check_length (const gchar *function_name,
n_py_kwargs > 0 ? "non-keyword " : "",
n_expected_args == 1 ? "" : "s",
n_py_args);
-
- Py_DECREF (py_args);
return NULL;
}
if (n_py_kwargs > 0 && !_check_for_unexpected_kwargs (function_name,
- arg_name_hash,
+ cache->arg_name_hash,
py_kwargs)) {
- Py_DECREF (py_args);
return NULL;
}
@@ -201,9 +193,7 @@ _py_args_combine_and_check_length (const gchar *function_name,
PyTuple_SET_ITEM (combined_py_args, i, item);
}
- Py_CLEAR(py_args);
-
- for (i = 0, l = arg_name_list; i < n_expected_args && l; i++, l = l->next) {
+ for (i = 0, l = cache->arg_name_list; i < n_expected_args && l; i++, l = l->next) {
PyObject *py_arg_item, *kw_arg_item = NULL;
const gchar *arg_name = l->data;
@@ -250,6 +240,7 @@ _invoke_state_init_from_callable_cache (PyGIInvokeState *state,
PyObject *py_args,
PyObject *kwargs)
{
+ PyObject *combined_args = NULL;
state->implementor_gtype = 0;
/* TODO: We don't use the class parameter sent in by the structure
@@ -292,17 +283,16 @@ _invoke_state_init_from_callable_cache (PyGIInvokeState *state,
* code more error prone and confusing so don't do that unless profiling shows
* significant gain
*/
- state->py_in_args = PyTuple_GetSlice (py_args, 1, PyTuple_Size (py_args));
+ combined_args = PyTuple_GetSlice (py_args, 1, PyTuple_Size (py_args));
} else {
- state->py_in_args = py_args;
- Py_INCREF (state->py_in_args);
+ combined_args = py_args;
+ Py_INCREF (combined_args);
}
- state->py_in_args = _py_args_combine_and_check_length (cache->name,
- cache->arg_name_list,
- cache->arg_name_hash,
- state->py_in_args,
+ state->py_in_args = _py_args_combine_and_check_length (cache,
+ combined_args,
kwargs);
+ Py_DECREF (combined_args);
if (state->py_in_args == NULL) {
return FALSE;
diff --git a/gi/pygi-marshal-from-py.c b/gi/pygi-marshal-from-py.c
index 639a226..a48479b 100644
--- a/gi/pygi-marshal-from-py.c
+++ b/gi/pygi-marshal-from-py.c
@@ -251,431 +251,27 @@ _pygi_marshal_from_py_void (PyGIInvokeState *state,
{
g_warn_if_fail (arg_cache->transfer == GI_TRANSFER_NOTHING);
- if (PYGLIB_CPointer_Check(py_arg)) {
+ if (py_arg == Py_None) {
+ arg->v_pointer = NULL;
+ } else if (PYGLIB_CPointer_Check(py_arg)) {
arg->v_pointer = PYGLIB_CPointer_GetPointer (py_arg, NULL);
} else {
- arg->v_pointer = py_arg;
- }
-
- return TRUE;
-}
-
-gboolean
-_pygi_marshal_from_py_boolean (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- PyObject *py_arg,
- GIArgument *arg)
-{
- arg->v_boolean = PyObject_IsTrue (py_arg);
-
- return TRUE;
-}
-
-gboolean
-_pygi_marshal_from_py_int8 (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- PyObject *py_arg,
- GIArgument *arg)
-{
- PyObject *py_long;
- long long_;
-
- if (PYGLIB_PyBytes_Check (py_arg)) {
-
- if (PYGLIB_PyBytes_Size (py_arg) != 1) {
- PyErr_Format (PyExc_TypeError, "Must be a single character");
- return FALSE;
- }
-
- long_ = (char)(PYGLIB_PyBytes_AsString (py_arg)[0]);
- } else if (PyNumber_Check (py_arg)) {
- py_long = PYGLIB_PyNumber_Long (py_arg);
- if (!py_long)
- return FALSE;
-
- long_ = PYGLIB_PyLong_AsLong (py_long);
- Py_DECREF (py_long);
-
- if (PyErr_Occurred ()) {
- PyErr_Clear ();
- PyErr_Format (PyExc_ValueError, "%ld not in range %d to %d", long_, -128, 127);
- return FALSE;
- }
- } else {
- PyErr_Format (PyExc_TypeError, "Must be number or single byte string, not %s",
- py_arg->ob_type->tp_name);
- return FALSE;
- }
-
- if (long_ < -128 || long_ > 127) {
- PyErr_Format (PyExc_ValueError, "%ld not in range %d to %d", long_, -128, 127);
- return FALSE;
- }
-
- arg->v_int8 = long_;
-
- return TRUE;
-}
-
-gboolean
-_pygi_marshal_from_py_uint8 (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- PyObject *py_arg,
- GIArgument *arg)
-{
- unsigned long long_;
-
- if (PYGLIB_PyBytes_Check (py_arg)) {
-
- if (PYGLIB_PyBytes_Size (py_arg) != 1) {
- PyErr_Format (PyExc_TypeError, "Must be a single character");
- return FALSE;
- }
-
- long_ = (unsigned char)(PYGLIB_PyBytes_AsString (py_arg)[0]);
-
- } else if (PyNumber_Check (py_arg)) {
- PyObject *py_long;
- py_long = PYGLIB_PyNumber_Long (py_arg);
- if (!py_long)
- return FALSE;
-
- long_ = PYGLIB_PyLong_AsLong (py_long);
- Py_DECREF (py_long);
-
- if (PyErr_Occurred ()) {
- PyErr_Clear();
-
- PyErr_Format (PyExc_ValueError, "%ld not in range %d to %d", long_, 0, 255);
- return FALSE;
- }
- } else {
- PyErr_Format (PyExc_TypeError, "Must be number or single byte string, not %s",
- py_arg->ob_type->tp_name);
- return FALSE;
- }
-
- if (long_ < 0 || long_ > 255) {
- PyErr_Format (PyExc_ValueError, "%ld not in range %d to %d", long_, 0, 255);
- return FALSE;
- }
-
- arg->v_uint8 = long_;
-
- return TRUE;
-}
-
-gboolean
-_pygi_marshal_from_py_int16 (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- PyObject *py_arg,
- GIArgument *arg)
-{
- PyObject *py_long;
- long long_;
-
- if (!PyNumber_Check (py_arg)) {
- PyErr_Format (PyExc_TypeError, "Must be number, not %s",
- py_arg->ob_type->tp_name);
- return FALSE;
- }
-
- py_long = PYGLIB_PyNumber_Long (py_arg);
- if (!py_long)
- return FALSE;
-
- long_ = PYGLIB_PyLong_AsLong (py_long);
- Py_DECREF (py_long);
-
- if (PyErr_Occurred ()) {
- PyErr_Clear ();
- PyErr_Format (PyExc_ValueError, "%ld not in range %d to %d", long_, -32768, 32767);
- return FALSE;
- }
-
- if (long_ < -32768 || long_ > 32767) {
- PyErr_Format (PyExc_ValueError, "%ld not in range %d to %d", long_, -32768, 32767);
- return FALSE;
- }
-
- arg->v_int16 = long_;
-
- return TRUE;
-}
-
-gboolean
-_pygi_marshal_from_py_uint16 (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- PyObject *py_arg,
- GIArgument *arg)
-{
- PyObject *py_long;
- long long_;
-
- if (!PyNumber_Check (py_arg)) {
- PyErr_Format (PyExc_TypeError, "Must be number, not %s",
- py_arg->ob_type->tp_name);
- return FALSE;
- }
-
- py_long = PYGLIB_PyNumber_Long (py_arg);
- if (!py_long)
- return FALSE;
-
- long_ = PYGLIB_PyLong_AsLong (py_long);
- Py_DECREF (py_long);
-
- if (PyErr_Occurred ()) {
- PyErr_Clear ();
- PyErr_Format (PyExc_ValueError, "%ld not in range %d to %d", long_, 0, 65535);
- return FALSE;
- }
-
- if (long_ < 0 || long_ > 65535) {
- PyErr_Format (PyExc_ValueError, "%ld not in range %d to %d", long_, 0, 65535);
- return FALSE;
- }
-
- arg->v_uint16 = long_;
-
- return TRUE;
-}
-
-gboolean
-_pygi_marshal_from_py_int32 (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- PyObject *py_arg,
- GIArgument *arg)
-{
- PyObject *py_long;
- long long_;
-
- if (!PyNumber_Check (py_arg)) {
- PyErr_Format (PyExc_TypeError, "Must be number, not %s",
- py_arg->ob_type->tp_name);
- return FALSE;
- }
-
- py_long = PYGLIB_PyNumber_Long (py_arg);
- if (!py_long)
- return FALSE;
-
- long_ = PYGLIB_PyLong_AsLong (py_long);
- Py_DECREF (py_long);
-
- if (PyErr_Occurred ()) {
- PyErr_Clear();
- PyErr_Format (PyExc_ValueError, "%ld not in range %d to %d", long_, G_MININT32, G_MAXINT32);
- return FALSE;
- }
-
- if (long_ < G_MININT32 || long_ > G_MAXINT32) {
- PyErr_Format (PyExc_ValueError, "%ld not in range %d to %d", long_, G_MININT32, G_MAXINT32);
- return FALSE;
- }
-
- arg->v_int32 = long_;
-
- return TRUE;
-}
-
-gboolean
-_pygi_marshal_from_py_uint32 (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- PyObject *py_arg,
- GIArgument *arg)
-{
- PyObject *py_long;
- long long long_;
-
- if (!PyNumber_Check (py_arg)) {
- PyErr_Format (PyExc_TypeError, "Must be number, not %s",
- py_arg->ob_type->tp_name);
- return FALSE;
- }
-
- py_long = PYGLIB_PyNumber_Long (py_arg);
- if (!py_long)
- return FALSE;
-
-#if PY_VERSION_HEX < 0x03000000
- if (PyInt_Check (py_long))
- long_ = PyInt_AsLong (py_long);
- else
-#endif
- long_ = PyLong_AsLongLong (py_long);
-
- Py_DECREF (py_long);
-
- if (PyErr_Occurred ()) {
- PyErr_Clear ();
- PyErr_Format (PyExc_ValueError, "%lld not in range %i to %u", long_, 0, G_MAXUINT32);
- return FALSE;
- }
-
- if (long_ < 0 || long_ > G_MAXUINT32) {
- PyErr_Format (PyExc_ValueError, "%lld not in range %i to %u", long_, 0, G_MAXUINT32);
- return FALSE;
- }
-
- arg->v_uint32 = long_;
-
- return TRUE;
-}
-
-gboolean
-_pygi_marshal_from_py_int64 (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- PyObject *py_arg,
- GIArgument *arg)
-{
- PyObject *py_long;
- gint64 long_;
-
- if (!PyNumber_Check (py_arg)) {
- PyErr_Format (PyExc_TypeError, "Must be number, not %s",
- py_arg->ob_type->tp_name);
- return FALSE;
- }
-
- py_long = PYGLIB_PyNumber_Long (py_arg);
- if (!py_long)
- return FALSE;
-
-#if PY_VERSION_HEX < 0x03000000
- if (PyInt_Check (py_long))
- long_ = (gint64) PyInt_AS_LONG (py_long);
- else
-#endif
- long_ = (gint64) PyLong_AsLongLong (py_long);
-
- Py_DECREF (py_long);
-
- if (PyErr_Occurred ()) {
- /* OverflowError occured but range errors should be returned as ValueError */
- char *long_str;
- PyObject *py_str;
-
- PyErr_Clear ();
-
- py_str = PyObject_Str (py_long);
-
- if (PyUnicode_Check (py_str)) {
- PyObject *py_bytes = PyUnicode_AsUTF8String (py_str);
- Py_DECREF (py_str);
-
- if (py_bytes == NULL)
- return FALSE;
-
- long_str = g_strdup (PYGLIB_PyBytes_AsString (py_bytes));
- if (long_str == NULL) {
- PyErr_NoMemory ();
- return FALSE;
- }
-
- Py_DECREF (py_bytes);
- } else {
- long_str = g_strdup (PYGLIB_PyBytes_AsString(py_str));
- Py_DECREF (py_str);
- }
-
- PyErr_Format (PyExc_ValueError, "%s not in range %lld to %lld",
- long_str, (long long) G_MININT64, (long long) G_MAXINT64);
-
- g_free (long_str);
- return FALSE;
- }
-
- arg->v_int64 = long_;
-
- return TRUE;
-}
-
-gboolean
-_pygi_marshal_from_py_uint64 (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- PyObject *py_arg,
- GIArgument *arg)
-{
- PyObject *py_long;
- guint64 ulong_;
-
- if (!PyNumber_Check (py_arg)) {
- PyErr_Format (PyExc_TypeError, "Must be number, not %s",
- py_arg->ob_type->tp_name);
- return FALSE;
- }
-
- py_long = PYGLIB_PyNumber_Long (py_arg);
- if (!py_long)
- return FALSE;
-
-#if PY_VERSION_HEX < 0x03000000
- if (PyInt_Check (py_long)) {
- long long_ = PyInt_AsLong (py_long);
- if (long_ < 0 || long_ > G_MAXUINT64) {
- PyErr_Format (PyExc_ValueError, "%" G_GUINT64_FORMAT " not in range %d to %" G_GUINT64_FORMAT,
- (gint64) long_, 0, G_MAXUINT64);
- return FALSE;
- }
- ulong_ = (guint64) long_;
- } else
-#endif
- ulong_ = PyLong_AsUnsignedLongLong (py_long);
-
- Py_DECREF (py_long);
-
- if (PyErr_Occurred ()) {
- /* OverflowError occured but range errors should be returned as ValueError */
- char *long_str;
- PyObject *py_str;
-
- PyErr_Clear ();
-
- py_str = PyObject_Str (py_long);
-
- if (PyUnicode_Check (py_str)) {
- PyObject *py_bytes = PyUnicode_AsUTF8String (py_str);
- Py_DECREF (py_str);
-
- if (py_bytes == NULL)
- return FALSE;
+ /* NOTE: This will change to only allow integers and the deprecation
+ * warning will become a runtime exception. Using the following:
+ * arg->v_pointer = PyLong_AsVoidPtr (py_arg);
+ * See: https://bugzilla.gnome.org/show_bug.cgi?id=688081
+ */
- long_str = g_strdup (PYGLIB_PyBytes_AsString (py_bytes));
- if (long_str == NULL) {
- PyErr_NoMemory ();
+ if (!PYGLIB_PyLong_Check(py_arg) && !PyLong_Check(py_arg)) {
+ if (PyErr_WarnEx(PyGIDeprecationWarning,
+ "Pointer arguments will be restricted to integers, capsules, and None. "
+ "See: https://bugzilla.gnome.org/show_bug.cgi?id=683599",
+ 1))
return FALSE;
- }
-
- Py_DECREF (py_bytes);
- } else {
- long_str = g_strdup (PYGLIB_PyBytes_AsString (py_str));
- Py_DECREF (py_str);
}
-
- PyErr_Format (PyExc_ValueError, "%s not in range %d to %" G_GUINT64_FORMAT,
- long_str, 0, G_MAXUINT64);
-
- g_free (long_str);
- return FALSE;
- }
-
- if (ulong_ > G_MAXUINT64) {
- PyErr_Format (PyExc_ValueError, "%" G_GUINT64_FORMAT " not in range %d to %" G_GUINT64_FORMAT, ulong_, 0, G_MAXUINT64);
- return FALSE;
+ arg->v_pointer = py_arg;
}
- arg->v_uint64 = ulong_;
-
return TRUE;
}
@@ -690,7 +286,7 @@ check_valid_double (double x, double min, double max)
/* we need this as PyErr_Format() does not support float types */
snprintf (buf, sizeof (buf), "%g not in range %g to %g", x, min, max);
- PyErr_SetString (PyExc_ValueError, buf);
+ PyErr_SetString (PyExc_OverflowError, buf);
return FALSE;
}
return TRUE;
@@ -718,11 +314,8 @@ _pygi_py_arg_to_double (PyObject *py_arg, double *double_)
return TRUE;
}
-gboolean
-_pygi_marshal_from_py_float (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- PyObject *py_arg,
+static gboolean
+_pygi_marshal_from_py_float (PyObject *py_arg,
GIArgument *arg)
{
double double_;
@@ -737,11 +330,8 @@ _pygi_marshal_from_py_float (PyGIInvokeState *state,
return TRUE;
}
-gboolean
-_pygi_marshal_from_py_double (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- PyObject *py_arg,
+static gboolean
+_pygi_marshal_from_py_double (PyObject *py_arg,
GIArgument *arg)
{
double double_;
@@ -756,11 +346,8 @@ _pygi_marshal_from_py_double (PyGIInvokeState *state,
return TRUE;
}
-gboolean
-_pygi_marshal_from_py_unichar (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- PyObject *py_arg,
+static gboolean
+_pygi_marshal_from_py_unichar (PyObject *py_arg,
GIArgument *arg)
{
Py_ssize_t size;
@@ -811,11 +398,8 @@ _pygi_marshal_from_py_unichar (PyGIInvokeState *state,
return TRUE;
}
-gboolean
-_pygi_marshal_from_py_gtype (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- PyObject *py_arg,
+static gboolean
+_pygi_marshal_from_py_gtype (PyObject *py_arg,
GIArgument *arg)
{
long type_ = pyg_type_from_object (py_arg);
@@ -829,11 +413,9 @@ _pygi_marshal_from_py_gtype (PyGIInvokeState *state,
arg->v_long = type_;
return TRUE;
}
-gboolean
-_pygi_marshal_from_py_utf8 (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- PyObject *py_arg,
+
+static gboolean
+_pygi_marshal_from_py_utf8 (PyObject *py_arg,
GIArgument *arg)
{
gchar *string_;
@@ -866,11 +448,8 @@ _pygi_marshal_from_py_utf8 (PyGIInvokeState *state,
return TRUE;
}
-gboolean
-_pygi_marshal_from_py_filename (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- PyObject *py_arg,
+static gboolean
+_pygi_marshal_from_py_filename (PyObject *py_arg,
GIArgument *arg)
{
gchar *string_;
@@ -908,6 +487,237 @@ _pygi_marshal_from_py_filename (PyGIInvokeState *state,
return TRUE;
}
+static gboolean
+_pygi_marshal_from_py_long (PyObject *object, /* in */
+ GIArgument *arg, /* out */
+ GITypeTag type_tag,
+ GITransfer transfer)
+{
+ PyObject *number;
+
+ if (!PyNumber_Check (object)) {
+ PyErr_Format (PyExc_TypeError, "Must be number, not %s",
+ object->ob_type->tp_name);
+ return FALSE;
+ }
+
+#if PY_MAJOR_VERSION < 3
+ {
+ PyObject *tmp = PyNumber_Int (object);
+ if (tmp) {
+ number = PyNumber_Long (tmp);
+ Py_DECREF (tmp);
+ } else {
+ number = PyNumber_Long (object);
+ }
+ }
+#else
+ number = PyNumber_Long (object);
+#endif
+
+ if (number == NULL) {
+ PyErr_SetString (PyExc_TypeError, "expected int argument");
+ return FALSE;
+ }
+
+ switch (type_tag) {
+ case GI_TYPE_TAG_INT8:
+ {
+ long long_value = PyLong_AsLong (number);
+ if (PyErr_Occurred()) {
+ break;
+ } else if (long_value < G_MININT8 || long_value > G_MAXINT8) {
+ PyErr_Format (PyExc_OverflowError, "%ld not in range %ld to %ld",
+ long_value, (long)G_MININT8, (long)G_MAXINT8);
+ } else {
+ arg->v_int8 = long_value;
+ }
+ break;
+ }
+
+ case GI_TYPE_TAG_UINT8:
+ {
+ long long_value = PyLong_AsLong (number);
+ if (PyErr_Occurred()) {
+ break;
+ } else if (long_value < 0 || long_value > G_MAXUINT8) {
+ PyErr_Format (PyExc_OverflowError, "%ld not in range %ld to %ld",
+ long_value, (long)0, (long)G_MAXUINT8);
+ } else {
+ arg->v_uint8 = long_value;
+ }
+ break;
+ }
+
+ case GI_TYPE_TAG_INT16:
+ {
+ long long_value = PyLong_AsLong (number);
+ if (PyErr_Occurred()) {
+ break;
+ } else if (long_value < G_MININT16 || long_value > G_MAXINT16) {
+ PyErr_Format (PyExc_OverflowError, "%ld not in range %ld to %ld",
+ long_value, (long)G_MININT16, (long)G_MAXINT16);
+ } else {
+ arg->v_int16 = long_value;
+ }
+ break;
+ }
+
+ case GI_TYPE_TAG_UINT16:
+ {
+ long long_value = PyLong_AsLong (number);
+ if (PyErr_Occurred()) {
+ break;
+ } else if (long_value < 0 || long_value > G_MAXUINT16) {
+ PyErr_Format (PyExc_OverflowError, "%ld not in range %ld to %ld",
+ long_value, (long)0, (long)G_MAXUINT16);
+ } else {
+ arg->v_uint16 = long_value;
+ }
+ break;
+ }
+
+ case GI_TYPE_TAG_INT32:
+ {
+ long long_value = PyLong_AsLong (number);
+ if (PyErr_Occurred()) {
+ break;
+ } else if (long_value < G_MININT32 || long_value > G_MAXINT32) {
+ PyErr_Format (PyExc_OverflowError, "%ld not in range %ld to %ld",
+ long_value, (long)G_MININT32, (long)G_MAXINT32);
+ } else {
+ arg->v_int32 = long_value;
+ }
+ break;
+ }
+
+ case GI_TYPE_TAG_UINT32:
+ {
+ PY_LONG_LONG long_value = PyLong_AsLongLong (number);
+ if (PyErr_Occurred()) {
+ break;
+ } else if (long_value < 0 || long_value > G_MAXUINT32) {
+ PyErr_Format (PyExc_OverflowError, "%lld not in range %ld to %lu",
+ long_value, (long)0, (unsigned long)G_MAXUINT32);
+ } else {
+ arg->v_uint32 = long_value;
+ }
+ break;
+ }
+
+ case GI_TYPE_TAG_INT64:
+ {
+ /* Rely on Python overflow error and convert to ValueError for 64 bit values */
+ arg->v_int64 = PyLong_AsLongLong (number);
+ break;
+ }
+
+ case GI_TYPE_TAG_UINT64:
+ {
+ /* Rely on Python overflow error and convert to ValueError for 64 bit values */
+ arg->v_uint64 = PyLong_AsUnsignedLongLong (number);
+ break;
+ }
+
+ default:
+ g_assert_not_reached ();
+ }
+
+ Py_DECREF (number);
+
+ if (PyErr_Occurred())
+ return FALSE;
+ return TRUE;
+}
+
+gboolean
+_pygi_marshal_from_py_basic_type (PyObject *object, /* in */
+ GIArgument *arg, /* out */
+ GITypeTag type_tag,
+ GITransfer transfer)
+{
+ switch (type_tag) {
+ case GI_TYPE_TAG_VOID:
+ g_warn_if_fail (transfer == GI_TRANSFER_NOTHING);
+ if (object == Py_None) {
+ arg->v_pointer = NULL;
+ } else if (!PYGLIB_PyLong_Check(object) && !PyLong_Check(object)) {
+ PyErr_SetString(PyExc_TypeError,
+ "Pointer assignment is restricted to integer values. "
+ "See: https://bugzilla.gnome.org/show_bug.cgi?id=683599");
+ } else {
+ arg->v_pointer = PyLong_AsVoidPtr (object);
+ }
+ break;
+ case GI_TYPE_TAG_INT8:
+ case GI_TYPE_TAG_UINT8:
+ if (PYGLIB_PyBytes_Check (object)) {
+ if (PYGLIB_PyBytes_Size (object) != 1) {
+ PyErr_Format (PyExc_TypeError, "Must be a single character");
+ return FALSE;
+ }
+ if (type_tag == GI_TYPE_TAG_INT8) {
+ arg->v_int8 = (gint8)(PYGLIB_PyBytes_AsString (object)[0]);
+ } else {
+ arg->v_uint8 = (guint8)(PYGLIB_PyBytes_AsString (object)[0]);
+ }
+ } else {
+ return _pygi_marshal_from_py_long (object, arg, type_tag, transfer);
+ }
+ break;
+ case GI_TYPE_TAG_INT16:
+ case GI_TYPE_TAG_UINT16:
+ case GI_TYPE_TAG_INT32:
+ case GI_TYPE_TAG_UINT32:
+ case GI_TYPE_TAG_INT64:
+ case GI_TYPE_TAG_UINT64:
+ return _pygi_marshal_from_py_long (object, arg, type_tag, transfer);
+
+ case GI_TYPE_TAG_BOOLEAN:
+ arg->v_boolean = PyObject_IsTrue (object);
+ break;
+
+ case GI_TYPE_TAG_FLOAT:
+ return _pygi_marshal_from_py_float (object, arg);
+
+ case GI_TYPE_TAG_DOUBLE:
+ return _pygi_marshal_from_py_double (object, arg);
+
+ case GI_TYPE_TAG_GTYPE:
+ return _pygi_marshal_from_py_gtype (object, arg);
+
+ case GI_TYPE_TAG_UNICHAR:
+ return _pygi_marshal_from_py_unichar (object, arg);
+
+ case GI_TYPE_TAG_UTF8:
+ return _pygi_marshal_from_py_utf8 (object, arg);
+
+ case GI_TYPE_TAG_FILENAME:
+ return _pygi_marshal_from_py_filename (object, arg);
+
+ default:
+ return FALSE;
+ }
+
+ if (PyErr_Occurred())
+ return FALSE;
+
+ return TRUE;
+}
+
+gboolean
+_pygi_marshal_from_py_basic_type_cache_adapter (PyGIInvokeState *state,
+ PyGICallableCache *callable_cache,
+ PyGIArgCache *arg_cache,
+ PyObject *py_arg,
+ GIArgument *arg)
+{
+ return _pygi_marshal_from_py_basic_type (py_arg,
+ arg,
+ arg_cache->type_tag,
+ arg_cache->transfer);
+}
+
gboolean
_pygi_marshal_from_py_array (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
@@ -1536,7 +1346,7 @@ _pygi_marshal_from_py_interface_enum (PyGIInvokeState *state,
long c_long;
gint is_instance;
PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *)arg_cache;
- GIBaseInfo *interface;
+ GIBaseInfo *interface = NULL;
is_instance = PyObject_IsInstance (py_arg, iface_cache->py_type);
@@ -1556,6 +1366,7 @@ _pygi_marshal_from_py_interface_enum (PyGIInvokeState *state,
c_long,
g_enum_info_get_storage_type ((GIEnumInfo *)interface))) {
g_assert_not_reached();
+ g_base_info_unref (interface);
return FALSE;
}
@@ -1581,9 +1392,12 @@ _pygi_marshal_from_py_interface_enum (PyGIInvokeState *state,
goto err;
}
+ g_base_info_unref (interface);
return TRUE;
err:
+ if (interface)
+ g_base_info_unref (interface);
PyErr_Format (PyExc_TypeError, "Expected a %s, but got %s",
iface_cache->type_name, py_arg->ob_type->tp_name);
return FALSE;
@@ -1622,9 +1436,11 @@ _pygi_marshal_from_py_interface_flags (PyGIInvokeState *state,
g_assert (g_base_info_get_type (interface) == GI_INFO_TYPE_FLAGS);
if (!gi_argument_from_c_long(arg, c_long,
g_enum_info_get_storage_type ((GIEnumInfo *)interface))) {
+ g_base_info_unref (interface);
return FALSE;
}
+ g_base_info_unref (interface);
return TRUE;
err:
@@ -1635,24 +1451,24 @@ err:
}
gboolean
-_pygi_marshal_from_py_interface_struct (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- PyObject *py_arg,
- GIArgument *arg)
+_pygi_marshal_from_py_interface_struct_cache_adapter (PyGIInvokeState *state,
+ PyGICallableCache *callable_cache,
+ PyGIArgCache *arg_cache,
+ PyObject *py_arg,
+ GIArgument *arg)
{
PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *)arg_cache;
- return pygi_marshal_from_py_interface_struct (py_arg,
- arg,
- arg_cache->arg_name,
- iface_cache->interface_info,
- arg_cache->type_info,
- iface_cache->g_type,
- iface_cache->py_type,
- arg_cache->transfer,
- arg_cache->is_caller_allocates,
- iface_cache->is_foreign);
+ return _pygi_marshal_from_py_interface_struct (py_arg,
+ arg,
+ arg_cache->arg_name,
+ iface_cache->interface_info,
+ arg_cache->type_info,
+ iface_cache->g_type,
+ iface_cache->py_type,
+ arg_cache->transfer,
+ TRUE, /*copy_reference*/
+ iface_cache->is_foreign);
}
gboolean
@@ -1693,7 +1509,7 @@ _pygi_marshal_from_py_interface_object (PyGIInvokeState *state,
return FALSE;
}
- return pygi_marshal_from_py_gobject (py_arg, arg, arg_cache->transfer);
+ return _pygi_marshal_from_py_gobject (py_arg, arg, arg_cache->transfer);
}
gboolean
@@ -1785,14 +1601,14 @@ gboolean _pygi_marshal_from_py_interface_instance (PyGIInvokeState *state,
return TRUE;
}
-/* pygi_marshal_from_py_gobject:
+/* _pygi_marshal_from_py_gobject:
* py_arg: (in):
* arg: (out):
*/
gboolean
-pygi_marshal_from_py_gobject (PyObject *py_arg, /*in*/
- GIArgument *arg, /*out*/
- GITransfer transfer) {
+_pygi_marshal_from_py_gobject (PyObject *py_arg, /*in*/
+ GIArgument *arg, /*out*/
+ GITransfer transfer) {
GObject *gobj;
if (py_arg == Py_None) {
@@ -1810,12 +1626,38 @@ pygi_marshal_from_py_gobject (PyObject *py_arg, /*in*/
gobj = pygobject_get (py_arg);
if (transfer == GI_TRANSFER_EVERYTHING) {
- /* An easy case of adding a new ref that the caller will take ownership of.
- * Pythons existing ref to the GObject will be managed normally with the wrapper.
+ /* For transfer everything, add a new ref that the callee will take ownership of.
+ * Pythons existing ref to the GObject will be managed with the PyGObject wrapper.
*/
g_object_ref (gobj);
+ }
+
+ arg->v_pointer = gobj;
+ return TRUE;
+}
+
+/* _pygi_marshal_from_py_gobject_out_arg:
+ * py_arg: (in):
+ * arg: (out):
+ *
+ * A specialization for marshaling Python GObjects used for out/return values
+ * from a Python implemented vfuncs, signals, or an assignment to a GObject property.
+ */
+gboolean
+_pygi_marshal_from_py_gobject_out_arg (PyObject *py_arg, /*in*/
+ GIArgument *arg, /*out*/
+ GITransfer transfer) {
+ GObject *gobj;
+ if (!_pygi_marshal_from_py_gobject (py_arg, arg, transfer)) {
+ return FALSE;
+ }
- } else if (py_arg->ob_refcnt == 1 && gobj->ref_count == 1) {
+ /* HACK: At this point the basic marshaling of the GObject was successful
+ * but we add some special case hacks for vfunc returns due to buggy APIs:
+ * https://bugzilla.gnome.org/show_bug.cgi?id=693393
+ */
+ gobj = arg->v_pointer;
+ if (py_arg->ob_refcnt == 1 && gobj->ref_count == 1) {
/* If both object ref counts are only 1 at this point (the reference held
* in a return tuple), we assume the GObject will be free'd before reaching
* its target and become invalid. So instead of getting invalid object errors
@@ -1824,12 +1666,10 @@ pygi_marshal_from_py_gobject (PyObject *py_arg, /*in*/
g_object_ref (gobj);
if (((PyGObject *)py_arg)->private_flags.flags & PYGOBJECT_GOBJECT_WAS_FLOATING) {
- /* HACK:
+ /*
* We want to re-float instances that were floating and the Python
* wrapper assumed ownership. With the additional caveat that there
* are not any strong references beyond the return tuple.
- * This should be removed once the following ticket is fixed:
- * https://bugzilla.gnome.org/show_bug.cgi?id=693393
*/
g_object_force_floating (gobj);
@@ -1848,21 +1688,21 @@ pygi_marshal_from_py_gobject (PyObject *py_arg, /*in*/
}
}
- arg->v_pointer = gobj;
return TRUE;
}
-/* pygi_marshal_from_py_gvalue:
+/* _pygi_marshal_from_py_gvalue:
* py_arg: (in):
* arg: (out):
* transfer:
- * is_allocated: TRUE if arg->v_pointer is an already allocated GValue
+ * copy_reference: TRUE if arg should use the pointer reference held by py_arg
+ * when it is already holding a GValue vs. copying the value.
*/
gboolean
-pygi_marshal_from_py_gvalue (PyObject *py_arg,
- GIArgument *arg,
- GITransfer transfer,
- gboolean is_allocated) {
+_pygi_marshal_from_py_gvalue (PyObject *py_arg,
+ GIArgument *arg,
+ GITransfer transfer,
+ gboolean copy_reference) {
GValue *value;
GType object_type;
@@ -1872,24 +1712,21 @@ pygi_marshal_from_py_gvalue (PyObject *py_arg,
return FALSE;
}
- if (is_allocated)
- value = (GValue *)arg->v_pointer;
- else
- value = g_slice_new0 (GValue);
-
/* if already a gvalue, use that, else marshal into gvalue */
if (object_type == G_TYPE_VALUE) {
GValue *source_value = pyg_boxed_get (py_arg, GValue);
- if (G_VALUE_TYPE (value) == G_TYPE_INVALID)
+ if (copy_reference) {
+ value = source_value;
+ } else {
+ value = g_slice_new0 (GValue);
g_value_init (value, G_VALUE_TYPE (source_value));
- g_value_copy (source_value, value);
+ g_value_copy (source_value, value);
+ }
} else {
- if (G_VALUE_TYPE (value) == G_TYPE_INVALID)
- g_value_init (value, object_type);
-
+ value = g_slice_new0 (GValue);
+ g_value_init (value, object_type);
if (pyg_value_from_pyobject (value, py_arg) < 0) {
- if (!is_allocated)
- g_slice_free (GValue, value);
+ g_slice_free (GValue, value);
PyErr_SetString (PyExc_RuntimeError, "PyObject conversion to GValue failed");
return FALSE;
}
@@ -1899,13 +1736,13 @@ pygi_marshal_from_py_gvalue (PyObject *py_arg,
return TRUE;
}
-/* pygi_marshal_from_py_gclosure:
+/* _pygi_marshal_from_py_gclosure:
* py_arg: (in):
* arg: (out):
*/
gboolean
-pygi_marshal_from_py_gclosure(PyObject *py_arg,
- GIArgument *arg)
+_pygi_marshal_from_py_gclosure(PyObject *py_arg,
+ GIArgument *arg)
{
GClosure *closure;
GType object_gtype = pyg_type_from_object_strict (py_arg, FALSE);
@@ -1932,16 +1769,16 @@ pygi_marshal_from_py_gclosure(PyObject *py_arg,
}
gboolean
-pygi_marshal_from_py_interface_struct (PyObject *py_arg,
- GIArgument *arg,
- const gchar *arg_name,
- GIBaseInfo *interface_info,
- GITypeInfo *type_info,
- GType g_type,
- PyObject *py_type,
- GITransfer transfer,
- gboolean is_allocated,
- gboolean is_foreign)
+_pygi_marshal_from_py_interface_struct (PyObject *py_arg,
+ GIArgument *arg,
+ const gchar *arg_name,
+ GIBaseInfo *interface_info,
+ GITypeInfo *type_info,
+ GType g_type,
+ PyObject *py_type,
+ GITransfer transfer,
+ gboolean copy_reference,
+ gboolean is_foreign)
{
if (py_arg == Py_None) {
arg->v_pointer = NULL;
@@ -1953,12 +1790,12 @@ pygi_marshal_from_py_interface_struct (PyObject *py_arg,
*/
if (g_type_is_a (g_type, G_TYPE_CLOSURE)) {
- return pygi_marshal_from_py_gclosure (py_arg, arg);
+ return _pygi_marshal_from_py_gclosure (py_arg, arg);
} else if (g_type_is_a (g_type, G_TYPE_VALUE)) {
- return pygi_marshal_from_py_gvalue(py_arg,
- arg,
- transfer,
- is_allocated);
+ return _pygi_marshal_from_py_gvalue(py_arg,
+ arg,
+ transfer,
+ copy_reference);
} else if (is_foreign) {
PyObject *success;
success = pygi_struct_foreign_convert_to_g_argument (py_arg,
diff --git a/gi/pygi-marshal-from-py.h b/gi/pygi-marshal-from-py.h
index 307d716..9f56a6f 100644
--- a/gi/pygi-marshal-from-py.h
+++ b/gi/pygi-marshal-from-py.h
@@ -38,81 +38,6 @@ gboolean _pygi_marshal_from_py_void (PyGIInvokeState *state,
PyGIArgCache *arg_cache,
PyObject *py_arg,
GIArgument *arg);
-gboolean _pygi_marshal_from_py_boolean (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- PyObject *py_arg,
- GIArgument *arg);
-gboolean _pygi_marshal_from_py_int8 (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- PyObject *py_arg,
- GIArgument *arg);
-gboolean _pygi_marshal_from_py_uint8 (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- PyObject *py_arg,
- GIArgument *arg);
-gboolean _pygi_marshal_from_py_int16 (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- PyObject *py_arg,
- GIArgument *arg);
-gboolean _pygi_marshal_from_py_uint16 (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- PyObject *py_arg,
- GIArgument *arg);
-gboolean _pygi_marshal_from_py_int32 (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- PyObject *py_arg,
- GIArgument *arg);
-gboolean _pygi_marshal_from_py_uint32 (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- PyObject *py_arg,
- GIArgument *arg);
-gboolean _pygi_marshal_from_py_int64 (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- PyObject *py_arg,
- GIArgument *arg);
-gboolean _pygi_marshal_from_py_uint64 (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- PyObject *py_arg,
- GIArgument *arg);
-gboolean _pygi_marshal_from_py_float (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- PyObject *py_arg,
- GIArgument *arg);
-gboolean _pygi_marshal_from_py_double (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- PyObject *py_arg,
- GIArgument *arg);
-gboolean _pygi_marshal_from_py_unichar (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- PyObject *py_arg,
- GIArgument *arg);
-gboolean _pygi_marshal_from_py_gtype (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- PyObject *py_arg,
- GIArgument *arg);
-gboolean _pygi_marshal_from_py_utf8 (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- PyObject *py_arg,
- GIArgument *arg);
-gboolean _pygi_marshal_from_py_filename (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- PyObject *py_arg,
- GIArgument *arg);
gboolean _pygi_marshal_from_py_array (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
@@ -153,11 +78,11 @@ gboolean _pygi_marshal_from_py_interface_flags (PyGIInvokeState *state,
PyGIArgCache *arg_cache,
PyObject *py_arg,
GIArgument *arg);
-gboolean _pygi_marshal_from_py_interface_struct (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- PyObject *py_arg,
- GIArgument *arg);
+gboolean _pygi_marshal_from_py_interface_struct_cache_adapter (PyGIInvokeState *state,
+ PyGICallableCache *callable_cache,
+ PyGIArgCache *arg_cache,
+ PyObject *py_arg,
+ GIArgument *arg);
gboolean _pygi_marshal_from_py_interface_interface(PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
@@ -185,27 +110,39 @@ gboolean _pygi_marshal_from_py_interface_instance (PyGIInvokeState *state,
GIArgument *arg);
/* Simplified marshalers shared between vfunc/closure and direct function calls. */
+gboolean _pygi_marshal_from_py_basic_type (PyObject *object, /* in */
+ GIArgument *arg, /* out */
+ GITypeTag type_tag,
+ GITransfer transfer);
+gboolean _pygi_marshal_from_py_basic_type_cache_adapter (PyGIInvokeState *state,
+ PyGICallableCache *callable_cache,
+ PyGIArgCache *arg_cache,
+ PyObject *py_arg,
+ GIArgument *arg);
-gboolean pygi_marshal_from_py_gobject (PyObject *py_arg, /*in*/
- GIArgument *arg, /*out*/
- GITransfer transfer);
+gboolean _pygi_marshal_from_py_gobject (PyObject *py_arg, /*in*/
+ GIArgument *arg, /*out*/
+ GITransfer transfer);
+gboolean _pygi_marshal_from_py_gobject_out_arg (PyObject *py_arg, /*in*/
+ GIArgument *arg, /*out*/
+ GITransfer transfer);
-gboolean pygi_marshal_from_py_gvalue (PyObject *py_arg, /*in*/
- GIArgument *arg, /*out*/
- GITransfer transfer,
- gboolean is_allocated);
+gboolean _pygi_marshal_from_py_gvalue (PyObject *py_arg, /*in*/
+ GIArgument *arg, /*out*/
+ GITransfer transfer,
+ gboolean is_allocated);
-gboolean pygi_marshal_from_py_gclosure(PyObject *py_arg, /*in*/
- GIArgument *arg); /*out*/
+gboolean _pygi_marshal_from_py_gclosure(PyObject *py_arg, /*in*/
+ GIArgument *arg); /*out*/
-gboolean pygi_marshal_from_py_interface_struct (PyObject *py_arg,
- GIArgument *arg,
- const gchar *arg_name,
- GIBaseInfo *interface_info,
- GITypeInfo *type_info,
- GType g_type,
- PyObject *py_type,
- GITransfer transfer,
+gboolean _pygi_marshal_from_py_interface_struct (PyObject *py_arg,
+ GIArgument *arg,
+ const gchar *arg_name,
+ GIBaseInfo *interface_info,
+ GITypeInfo *type_info,
+ GType g_type,
+ PyObject *py_type,
+ GITransfer transfer,
gboolean is_allocated,
gboolean is_foreign);
diff --git a/gi/pygi-marshal-to-py.c b/gi/pygi-marshal-to-py.c
index 6e16b99..7c260f7 100644
--- a/gi/pygi-marshal-to-py.c
+++ b/gi/pygi-marshal-to-py.c
@@ -33,6 +33,7 @@
#include "pygi-cache.h"
#include "pygi-marshal-cleanup.h"
#include "pygi-marshal-to-py.h"
+#include "pygi-argument.h"
static gboolean
gi_argument_to_c_long (GIArgument *arg_in,
@@ -110,7 +111,6 @@ gi_argument_to_gsize (GIArgument *arg_in,
}
}
-
PyObject *
_pygi_marshal_to_py_void (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
@@ -118,139 +118,23 @@ _pygi_marshal_to_py_void (PyGIInvokeState *state,
GIArgument *arg)
{
PyObject *py_obj = NULL;
- if (arg_cache->is_pointer)
+ if (arg_cache->is_pointer) {
+ /* NOTE: This will change to interpret pointers as integer values
+ * by using the following:
+ * py_obj = PyLong_FromVoidPtr (arg->v_pointer);
+ * See: https://bugzilla.gnome.org/show_bug.cgi?id=688081
+ */
py_obj = arg->v_pointer;
- else
+ } else {
py_obj = Py_None;
+ }
Py_XINCREF (py_obj);
return py_obj;
}
-PyObject *
-_pygi_marshal_to_py_boolean (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- GIArgument *arg)
-{
- PyObject *py_obj = PyBool_FromLong (arg->v_boolean);
- return py_obj;
-}
-
-PyObject *
-_pygi_marshal_to_py_int8 (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- GIArgument *arg)
-{
- PyObject *py_obj = PYGLIB_PyLong_FromLong (arg->v_int8);
- return py_obj;
-}
-
-PyObject *
-_pygi_marshal_to_py_uint8 (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- GIArgument *arg)
-{
- PyObject *py_obj = PYGLIB_PyLong_FromLong (arg->v_uint8);
-
- return py_obj;
-}
-
-PyObject *
-_pygi_marshal_to_py_int16 (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- GIArgument *arg)
-{
- PyObject *py_obj = PYGLIB_PyLong_FromLong (arg->v_int16);
-
- return py_obj;
-}
-
-PyObject *
-_pygi_marshal_to_py_uint16 (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- GIArgument *arg)
-{
- PyObject *py_obj = PYGLIB_PyLong_FromLong (arg->v_uint16);
-
- return py_obj;
-}
-
-PyObject *
-_pygi_marshal_to_py_int32 (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- GIArgument *arg)
-{
- PyObject *py_obj = PYGLIB_PyLong_FromLong (arg->v_int32);
-
- return py_obj;
-}
-
-PyObject *
-_pygi_marshal_to_py_uint32 (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- GIArgument *arg)
-{
- PyObject *py_obj = PyLong_FromLongLong (arg->v_uint32);
-
- return py_obj;
-}
-
-PyObject *
-_pygi_marshal_to_py_int64 (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- GIArgument *arg)
-{
- PyObject *py_obj = PyLong_FromLongLong (arg->v_int64);
-
- return py_obj;
-}
-
-PyObject *
-_pygi_marshal_to_py_uint64 (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- GIArgument *arg)
-{
- PyObject *py_obj = PyLong_FromUnsignedLongLong (arg->v_uint64);
-
- return py_obj;
-}
-
-PyObject *
-_pygi_marshal_to_py_float (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- GIArgument *arg)
-{
- PyObject *py_obj = PyFloat_FromDouble (arg->v_float);
-
- return py_obj;
-}
-
-PyObject *
-_pygi_marshal_to_py_double (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- GIArgument *arg)
-{
- PyObject *py_obj = PyFloat_FromDouble (arg->v_double);
-
- return py_obj;
-}
-
-PyObject *
-_pygi_marshal_to_py_unichar (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- GIArgument *arg)
+static PyObject *
+_pygi_marshal_to_py_unichar (GIArgument *arg)
{
PyObject *py_obj = NULL;
@@ -273,23 +157,8 @@ _pygi_marshal_to_py_unichar (PyGIInvokeState *state,
return py_obj;
}
-PyObject *
-_pygi_marshal_to_py_gtype (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- GIArgument *arg)
-{
- PyObject *py_obj = NULL;
-
- py_obj = pyg_type_wrapper_new ( (GType)arg->v_long);
- return py_obj;
-}
-
-PyObject *
-_pygi_marshal_to_py_utf8 (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- GIArgument *arg)
+static PyObject *
+_pygi_marshal_to_py_utf8 (GIArgument *arg)
{
PyObject *py_obj = NULL;
if (arg->v_string == NULL) {
@@ -300,11 +169,8 @@ _pygi_marshal_to_py_utf8 (PyGIInvokeState *state,
return py_obj;
}
-PyObject *
-_pygi_marshal_to_py_filename (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- GIArgument *arg)
+static PyObject *
+_pygi_marshal_to_py_filename (GIArgument *arg)
{
gchar *string = NULL;
PyObject *py_obj = NULL;
@@ -327,6 +193,89 @@ _pygi_marshal_to_py_filename (PyGIInvokeState *state,
return py_obj;
}
+
+/**
+ * _pygi_marshal_to_py_basic_type:
+ * @arg: The argument to convert to an object.
+ * @type_tag: Type tag for @arg
+ * @transfer: Transfer annotation
+ *
+ * Convert the given argument to a Python object. This function
+ * is restricted to simple types that only require the GITypeTag
+ * and GITransfer. For a more complete conversion routine, use:
+ * _pygi_argument_to_object.
+ *
+ * Returns: A PyObject representing @arg or NULL if it cannot convert
+ * the argument.
+ */
+PyObject *
+_pygi_marshal_to_py_basic_type (GIArgument *arg,
+ GITypeTag type_tag,
+ GITransfer transfer)
+{
+ switch (type_tag) {
+ case GI_TYPE_TAG_BOOLEAN:
+ return PyBool_FromLong (arg->v_boolean);
+
+ case GI_TYPE_TAG_INT8:
+ return PYGLIB_PyLong_FromLong (arg->v_int8);
+
+ case GI_TYPE_TAG_UINT8:
+ return PYGLIB_PyLong_FromLong (arg->v_uint8);
+
+ case GI_TYPE_TAG_INT16:
+ return PYGLIB_PyLong_FromLong (arg->v_int16);
+
+ case GI_TYPE_TAG_UINT16:
+ return PYGLIB_PyLong_FromLong (arg->v_uint16);
+
+ case GI_TYPE_TAG_INT32:
+ return PYGLIB_PyLong_FromLong (arg->v_int32);
+
+ case GI_TYPE_TAG_UINT32:
+ return PyLong_FromLongLong (arg->v_uint32);
+
+ case GI_TYPE_TAG_INT64:
+ return PyLong_FromLongLong (arg->v_int64);
+
+ case GI_TYPE_TAG_UINT64:
+ return PyLong_FromUnsignedLongLong (arg->v_uint64);
+
+ case GI_TYPE_TAG_FLOAT:
+ return PyFloat_FromDouble (arg->v_float);
+
+ case GI_TYPE_TAG_DOUBLE:
+ return PyFloat_FromDouble (arg->v_double);
+
+ case GI_TYPE_TAG_GTYPE:
+ return pyg_type_wrapper_new ( (GType) arg->v_long);
+
+ case GI_TYPE_TAG_UNICHAR:
+ return _pygi_marshal_to_py_unichar (arg);
+
+ case GI_TYPE_TAG_UTF8:
+ return _pygi_marshal_to_py_utf8 (arg);
+
+ case GI_TYPE_TAG_FILENAME:
+ return _pygi_marshal_to_py_filename (arg);
+
+ default:
+ return NULL;
+ }
+ return NULL;
+}
+
+PyObject *
+_pygi_marshal_to_py_basic_type_cache_adapter (PyGIInvokeState *state,
+ PyGICallableCache *callable_cache,
+ PyGIArgCache *arg_cache,
+ GIArgument *arg)
+{
+ return _pygi_marshal_to_py_basic_type (arg,
+ arg_cache->type_tag,
+ arg_cache->transfer);
+}
+
PyObject *
_pygi_marshal_to_py_array (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
@@ -740,6 +689,7 @@ _pygi_marshal_to_py_interface_enum (PyGIInvokeState *state,
} else {
py_obj = pyg_enum_from_gtype (iface_cache->g_type, c_long);
}
+ g_base_info_unref (interface);
return py_obj;
}
@@ -759,9 +709,11 @@ _pygi_marshal_to_py_interface_flags (PyGIInvokeState *state,
if (!gi_argument_to_c_long(arg, &c_long,
g_enum_info_get_storage_type ((GIEnumInfo *)interface))) {
+ g_base_info_unref (interface);
return NULL;
}
+ g_base_info_unref (interface);
if (iface_cache->g_type == G_TYPE_NONE) {
/* An enum with a GType of None is an enum without GType */
@@ -790,20 +742,20 @@ _pygi_marshal_to_py_interface_flags (PyGIInvokeState *state,
}
PyObject *
-_pygi_marshal_to_py_interface_struct (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- GIArgument *arg)
+_pygi_marshal_to_py_interface_struct_cache_adapter (PyGIInvokeState *state,
+ PyGICallableCache *callable_cache,
+ PyGIArgCache *arg_cache,
+ GIArgument *arg)
{
PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *)arg_cache;
- return pygi_marshal_to_py_interface_struct (arg,
- iface_cache->interface_info,
- iface_cache->g_type,
- iface_cache->py_type,
- arg_cache->transfer,
- arg_cache->is_caller_allocates,
- iface_cache->is_foreign);
+ return _pygi_marshal_to_py_interface_struct (arg,
+ iface_cache->interface_info,
+ iface_cache->g_type,
+ iface_cache->py_type,
+ arg_cache->transfer,
+ arg_cache->is_caller_allocates,
+ iface_cache->is_foreign);
}
PyObject *
@@ -833,12 +785,12 @@ _pygi_marshal_to_py_interface_boxed (PyGIInvokeState *state,
}
PyObject *
-_pygi_marshal_to_py_interface_object (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- GIArgument *arg)
+_pygi_marshal_to_py_interface_object_cache_adapter (PyGIInvokeState *state,
+ PyGICallableCache *callable_cache,
+ PyGIArgCache *arg_cache,
+ GIArgument *arg)
{
- return pygi_marshal_to_py_object(arg, arg_cache->transfer);
+ return _pygi_marshal_to_py_object(arg, arg_cache->transfer);
}
PyObject *
@@ -855,7 +807,7 @@ _pygi_marshal_to_py_interface_union (PyGIInvokeState *state,
}
PyObject *
-pygi_marshal_to_py_object (GIArgument *arg, GITransfer transfer) {
+_pygi_marshal_to_py_object (GIArgument *arg, GITransfer transfer) {
PyObject *pyobj;
if (arg->v_pointer == NULL) {
@@ -877,13 +829,13 @@ pygi_marshal_to_py_object (GIArgument *arg, GITransfer transfer) {
}
PyObject *
-pygi_marshal_to_py_interface_struct (GIArgument *arg,
- GIInterfaceInfo *interface_info,
- GType g_type,
- PyObject *py_type,
- GITransfer transfer,
- gboolean is_allocated,
- gboolean is_foreign)
+_pygi_marshal_to_py_interface_struct (GIArgument *arg,
+ GIInterfaceInfo *interface_info,
+ GType g_type,
+ PyObject *py_type,
+ GITransfer transfer,
+ gboolean is_allocated,
+ gboolean is_foreign)
{
PyObject *py_obj = NULL;
diff --git a/gi/pygi-marshal-to-py.h b/gi/pygi-marshal-to-py.h
index 359644d..1378630 100644
--- a/gi/pygi-marshal-to-py.h
+++ b/gi/pygi-marshal-to-py.h
@@ -22,70 +22,17 @@
#ifndef __PYGI_MARSHAL_TO_PY_H__
#define __PYGI_MARSHAL_TO_PY_H__
+PyObject *_pygi_marshal_to_py_basic_type (GIArgument *arg,
+ GITypeTag type_tag,
+ GITransfer transfer);
+PyObject *_pygi_marshal_to_py_basic_type_cache_adapter (PyGIInvokeState *state,
+ PyGICallableCache *callable_cache,
+ PyGIArgCache *arg_cache,
+ GIArgument *arg);
PyObject *_pygi_marshal_to_py_void (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
GIArgument *arg);
-PyObject *_pygi_marshal_to_py_boolean (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- GIArgument *arg);
-PyObject *_pygi_marshal_to_py_int8 (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- GIArgument *arg);
-PyObject *_pygi_marshal_to_py_uint8 (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- GIArgument *arg);
-PyObject *_pygi_marshal_to_py_int16 (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- GIArgument *arg);
-PyObject *_pygi_marshal_to_py_uint16 (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- GIArgument *arg);
-PyObject *_pygi_marshal_to_py_int32 (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- GIArgument *arg);
-PyObject *_pygi_marshal_to_py_uint32 (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- GIArgument *arg);
-PyObject *_pygi_marshal_to_py_int64 (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- GIArgument *arg);
-PyObject *_pygi_marshal_to_py_uint64 (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- GIArgument *arg);
-PyObject *_pygi_marshal_to_py_float (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- GIArgument *arg);
-PyObject *_pygi_marshal_to_py_double (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- GIArgument *arg);
-PyObject *_pygi_marshal_to_py_unichar (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- GIArgument *arg);
-PyObject *_pygi_marshal_to_py_gtype (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- GIArgument *arg);
-PyObject *_pygi_marshal_to_py_utf8 (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- GIArgument *arg);
-PyObject *_pygi_marshal_to_py_filename (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- GIArgument *arg);
PyObject *_pygi_marshal_to_py_array (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
@@ -118,10 +65,10 @@ PyObject *_pygi_marshal_to_py_interface_flags (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
GIArgument *arg);
-PyObject *_pygi_marshal_to_py_interface_struct (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- GIArgument *arg);
+PyObject *_pygi_marshal_to_py_interface_struct_cache_adapter (PyGIInvokeState *state,
+ PyGICallableCache *callable_cache,
+ PyGIArgCache *arg_cache,
+ GIArgument *arg);
PyObject *_pygi_marshal_to_py_interface_interface(PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
@@ -130,10 +77,10 @@ PyObject *_pygi_marshal_to_py_interface_boxed (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
GIArgument *arg);
-PyObject *_pygi_marshal_to_py_interface_object (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- GIArgument *arg);
+PyObject *_pygi_marshal_to_py_interface_object_cache_adapter (PyGIInvokeState *state,
+ PyGICallableCache *callable_cache,
+ PyGIArgCache *arg_cache,
+ GIArgument *arg);
PyObject *_pygi_marshal_to_py_interface_union (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
@@ -141,16 +88,16 @@ PyObject *_pygi_marshal_to_py_interface_union (PyGIInvokeState *state,
/* Simplified marshalers shared between vfunc/closure and direct function calls. */
-PyObject *pygi_marshal_to_py_object (GIArgument *arg,
- GITransfer transfer);
+PyObject *_pygi_marshal_to_py_object (GIArgument *arg,
+ GITransfer transfer);
-PyObject *pygi_marshal_to_py_interface_struct (GIArgument *arg,
- GIInterfaceInfo *interface_info,
- GType g_type,
- PyObject *py_type,
- GITransfer transfer,
- gboolean is_allocated,
- gboolean is_foreign);
+PyObject *_pygi_marshal_to_py_interface_struct (GIArgument *arg,
+ GIInterfaceInfo *interface_info,
+ GType g_type,
+ PyObject *py_type,
+ GITransfer transfer,
+ gboolean is_allocated,
+ gboolean is_foreign);
G_END_DECLS
diff --git a/gi/pygi.h b/gi/pygi.h
index f3f0c81..3bf40bb 100644
--- a/gi/pygi.h
+++ b/gi/pygi.h
@@ -32,6 +32,8 @@
#include <girepository.h>
#include "pygi-cache.h"
+extern PyObject *PyGIDeprecationWarning;
+
typedef struct {
PyObject_HEAD
GIRepository *repository;
@@ -45,6 +47,19 @@ typedef struct {
} PyGIBaseInfo;
typedef struct {
+ PyGIBaseInfo base;
+
+ /* Reference the unbound version of this struct.
+ * We use this for the actual call to invoke because it manages the cache.
+ */
+ struct PyGICallableInfo *py_unbound_info;
+
+ /* Holds bound argument for instance, class, and vfunc methods. */
+ PyObject *py_bound_arg;
+
+} PyGICallableInfo;
+
+typedef struct {
PyGPointer base;
gboolean free_on_dealloc;
} PyGIStruct;
diff --git a/gi/repository/Makefile.in b/gi/repository/Makefile.in
index 6134f6b..77db58d 100644
--- a/gi/repository/Makefile.in
+++ b/gi/repository/Makefile.in
@@ -1,9 +1,8 @@
-# Makefile.in generated by automake 1.11.6 from Makefile.am.
+# Makefile.in generated by automake 1.13.2 from Makefile.am.
# @configure_input@
-# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
-# Foundation, Inc.
+# Copyright (C) 1994-2013 Free Software Foundation, Inc.
+
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
@@ -15,23 +14,51 @@
@SET_MAKE@
VPATH = @srcdir@
-am__make_dryrun = \
- { \
- am__dry=no; \
+am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'
+am__make_running_with_option = \
+ case $${target_option-} in \
+ ?) ;; \
+ *) echo "am__make_running_with_option: internal error: invalid" \
+ "target option '$${target_option-}' specified" >&2; \
+ exit 1;; \
+ esac; \
+ has_opt=no; \
+ sane_makeflags=$$MAKEFLAGS; \
+ if $(am__is_gnu_make); then \
+ sane_makeflags=$$MFLAGS; \
+ else \
case $$MAKEFLAGS in \
*\\[\ \ ]*) \
- echo 'am--echo: ; @echo "AM" OK' | $(MAKE) -f - 2>/dev/null \
- | grep '^AM OK$$' >/dev/null || am__dry=yes;; \
- *) \
- for am__flg in $$MAKEFLAGS; do \
- case $$am__flg in \
- *=*|--*) ;; \
- *n*) am__dry=yes; break;; \
- esac; \
- done;; \
+ bs=\\; \
+ sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
+ | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \
esac; \
- test $$am__dry = yes; \
- }
+ fi; \
+ skip_next=no; \
+ strip_trailopt () \
+ { \
+ flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
+ }; \
+ for flg in $$sane_makeflags; do \
+ test $$skip_next = yes && { skip_next=no; continue; }; \
+ case $$flg in \
+ *=*|--*) continue;; \
+ -*I) strip_trailopt 'I'; skip_next=yes;; \
+ -*I?*) strip_trailopt 'I';; \
+ -*O) strip_trailopt 'O'; skip_next=yes;; \
+ -*O?*) strip_trailopt 'O';; \
+ -*l) strip_trailopt 'l'; skip_next=yes;; \
+ -*l?*) strip_trailopt 'l';; \
+ -[dEDm]) skip_next=yes;; \
+ -[JT]) skip_next=yes;; \
+ esac; \
+ case $$flg in \
+ *$$target_option*) has_opt=yes; break;; \
+ esac; \
+ done; \
+ test $$has_opt = yes
+am__make_dryrun = (target_option=n; $(am__make_running_with_option))
+am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
pkgdatadir = $(datadir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
@@ -51,8 +78,8 @@ POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
subdir = gi/repository
-DIST_COMMON = $(pygirepository_PYTHON) $(srcdir)/Makefile.am \
- $(srcdir)/Makefile.in
+DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
+ $(pygirepository_PYTHON) $(top_srcdir)/py-compile
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/as-ac-expand.m4 \
$(top_srcdir)/m4/jhflags.m4 $(top_srcdir)/m4/libtool.m4 \
@@ -65,12 +92,18 @@ mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =
+AM_V_P = $(am__v_P_@AM_V@)
+am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
+am__v_P_0 = false
+am__v_P_1 = :
AM_V_GEN = $(am__v_GEN_@AM_V@)
am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
-am__v_GEN_0 = @echo " GEN " $@;
+am__v_GEN_0 = @echo " GEN " $@;
+am__v_GEN_1 =
AM_V_at = $(am__v_at_@AM_V@)
am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
am__v_at_0 = @
+am__v_at_1 =
SOURCES =
DIST_SOURCES =
am__can_run_installinfo = \
@@ -107,7 +140,10 @@ am__uninstall_files_from_dir = { \
}
am__py_compile = PYTHON=$(PYTHON) $(SHELL) $(py_compile)
am__installdirs = "$(DESTDIR)$(pygirepositorydir)"
+am__pep3147_tweak = \
+ sed -e 's|\.py$$||' -e 's|[^/]*$$|__pycache__/&.*.py|'
py_compile = $(top_srcdir)/py-compile
+am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
ACLOCAL_AMFLAGS = @ACLOCAL_AMFLAGS@
@@ -338,32 +374,38 @@ install-pygirepositoryPYTHON: $(pygirepository_PYTHON)
$(INSTALL_DATA) $$files "$(DESTDIR)$(pygirepositorydir)" || exit $$?; \
done || exit $$?; \
if test -n "$$dlist"; then \
- if test -z "$(DESTDIR)"; then \
- $(am__py_compile) --basedir "$(pygirepositorydir)" $$dlist; \
- else \
- $(am__py_compile) --destdir "$(DESTDIR)" \
- --basedir "$(pygirepositorydir)" $$dlist; \
- fi; \
+ $(am__py_compile) --destdir "$(DESTDIR)" \
+ --basedir "$(pygirepositorydir)" $$dlist; \
else :; fi
uninstall-pygirepositoryPYTHON:
@$(NORMAL_UNINSTALL)
@list='$(pygirepository_PYTHON)'; test -n "$(pygirepositorydir)" || list=; \
- files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
- test -n "$$files" || exit 0; \
+ py_files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+ test -n "$$py_files" || exit 0; \
dir='$(DESTDIR)$(pygirepositorydir)'; \
- filesc=`echo "$$files" | sed 's|$$|c|'`; \
- fileso=`echo "$$files" | sed 's|$$|o|'`; \
+ pyc_files=`echo "$$py_files" | sed 's|$$|c|'`; \
+ pyo_files=`echo "$$py_files" | sed 's|$$|o|'`; \
+ py_files_pep3147=`echo "$$py_files" | $(am__pep3147_tweak)`; \
+ echo "$$py_files_pep3147";\
+ pyc_files_pep3147=`echo "$$py_files_pep3147" | sed 's|$$|c|'`; \
+ pyo_files_pep3147=`echo "$$py_files_pep3147" | sed 's|$$|o|'`; \
st=0; \
- for files in "$$files" "$$filesc" "$$fileso"; do \
+ for files in \
+ "$$py_files" \
+ "$$pyc_files" \
+ "$$pyo_files" \
+ "$$pyc_files_pep3147" \
+ "$$pyo_files_pep3147" \
+ ; do \
$(am__uninstall_files_from_dir) || st=$$?; \
done; \
exit $$st
-tags: TAGS
-TAGS:
+tags TAGS:
+
+ctags CTAGS:
-ctags: CTAGS
-CTAGS:
+cscope cscopelist:
distdir: $(DISTFILES)
@@ -503,17 +545,17 @@ uninstall-am: uninstall-pygirepositoryPYTHON
.MAKE: check-am install-am install-strip
.PHONY: all all-am all-local check check-am check-local clean \
- clean-generic clean-libtool distclean distclean-generic \
- distclean-libtool distdir dvi dvi-am html html-am info info-am \
- install install-am install-data install-data-am install-dvi \
- install-dvi-am install-exec install-exec-am install-html \
- install-html-am install-info install-info-am install-man \
- install-pdf install-pdf-am install-ps install-ps-am \
- install-pygirepositoryPYTHON install-strip installcheck \
- installcheck-am installdirs maintainer-clean \
- maintainer-clean-generic mostlyclean mostlyclean-generic \
- mostlyclean-libtool pdf pdf-am ps ps-am uninstall uninstall-am \
- uninstall-pygirepositoryPYTHON
+ clean-generic clean-libtool cscopelist-am ctags-am distclean \
+ distclean-generic distclean-libtool distdir dvi dvi-am html \
+ html-am info info-am install install-am install-data \
+ install-data-am install-dvi install-dvi-am install-exec \
+ install-exec-am install-html install-html-am install-info \
+ install-info-am install-man install-pdf install-pdf-am \
+ install-ps install-ps-am install-pygirepositoryPYTHON \
+ install-strip installcheck installcheck-am installdirs \
+ maintainer-clean maintainer-clean-generic mostlyclean \
+ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
+ tags-am uninstall uninstall-am uninstall-pygirepositoryPYTHON
# if we build in a separate tree, we need to symlink the *.py files from the
diff --git a/gi/types.py b/gi/types.py
index 47a81d8..7c0f617 100644
--- a/gi/types.py
+++ b/gi/types.py
@@ -23,6 +23,7 @@
from __future__ import absolute_import
import sys
+import warnings
from . import _gobject
from ._gobject._gobject import GInterface
@@ -33,12 +34,8 @@ from ._gi import \
ObjectInfo, \
StructInfo, \
VFuncInfo, \
- FunctionInfo, \
register_interface_info, \
- hook_up_vfunc_implementation, \
- DIRECTION_IN, \
- DIRECTION_OUT, \
- DIRECTION_INOUT
+ hook_up_vfunc_implementation
StructInfo # pyflakes
@@ -49,115 +46,10 @@ if (3, 0) <= sys.version_info < (3, 3):
return hasattr(obj, '__call__')
-def split_function_info_args(info):
- """Split a functions args into a tuple of two lists.
-
- Note that args marked as DIRECTION_INOUT will be in both lists.
-
- :Returns:
- Tuple of (in_args, out_args)
- """
- in_args = []
- out_args = []
- for arg in info.get_arguments():
- direction = arg.get_direction()
- if direction in (DIRECTION_IN, DIRECTION_INOUT):
- in_args.append(arg)
- if direction in (DIRECTION_OUT, DIRECTION_INOUT):
- out_args.append(arg)
- return (in_args, out_args)
-
-
-def get_callable_info_doc_string(info):
- """Build a signature string which can be used for documentation."""
- in_args, out_args = split_function_info_args(info)
- in_args_strs = []
- if isinstance(info, VFuncInfo):
- in_args_strs = ['self']
- elif isinstance(info, FunctionInfo):
- if info.is_method():
- in_args_strs = ['self']
- elif info.is_constructor():
- in_args_strs = ['cls']
-
- for arg in in_args:
- argstr = arg.get_name() + ':' + arg.get_pytype_hint()
- if arg.is_optional():
- argstr += '=<optional>'
- in_args_strs.append(argstr)
- in_args_str = ', '.join(in_args_strs)
-
- if out_args:
- out_args_str = ', '.join(arg.get_name() + ':' + arg.get_pytype_hint()
- for arg in out_args)
- return '%s(%s) -> %s' % (info.get_name(), in_args_str, out_args_str)
- else:
- return '%s(%s)' % (info.get_name(), in_args_str)
-
-
-def wraps_callable_info(info):
- """Similar to functools.wraps but with specific GICallableInfo support."""
- def update_func(func):
- func.__info__ = info
- func.__name__ = info.get_name()
- func.__module__ = 'gi.repository.' + info.get_namespace()
- func.__doc__ = get_callable_info_doc_string(info)
- return func
- return update_func
-
-
-def Function(info):
- """Wraps GIFunctionInfo"""
- @wraps_callable_info(info)
- def function(*args, **kwargs):
- return info.invoke(*args, **kwargs)
-
- return function
-
-
-class NativeVFunc(object):
- """Wraps GINativeVFuncInfo"""
- def __init__(self, info):
- self.__info__ = info
-
- def __get__(self, instance, klass):
- @wraps_callable_info(self.__info__)
- def native_vfunc(*args, **kwargs):
- return self.__info__.invoke(klass.__gtype__, *args, **kwargs)
- return native_vfunc
-
-
-def Constructor(info):
- """Wraps GIFunctionInfo with get_constructor() == True"""
- @wraps_callable_info(info)
- def constructor(cls, *args, **kwargs):
- cls_name = info.get_container().get_name()
- if cls.__name__ != cls_name:
- raise TypeError('%s constructor cannot be used to create instances of a subclass' % cls_name)
- return info.invoke(cls, *args, **kwargs)
- return constructor
-
-
class MetaClassHelper(object):
-
- def _setup_constructors(cls):
- for method_info in cls.__info__.get_methods():
- if method_info.is_constructor():
- name = method_info.get_name()
- constructor = classmethod(Constructor(method_info))
- setattr(cls, name, constructor)
-
def _setup_methods(cls):
for method_info in cls.__info__.get_methods():
- name = method_info.get_name()
- function = Function(method_info)
- if method_info.is_method():
- method = function
- elif method_info.is_constructor():
- continue
- else:
- method = staticmethod(function)
- setattr(cls, name, method)
+ setattr(cls, method_info.__name__, method_info)
def _setup_fields(cls):
for field_info in cls.__info__.get_fields():
@@ -182,9 +74,8 @@ class MetaClassHelper(object):
vfunc_info = None
for base in cls.__mro__:
method = getattr(base, vfunc_name, None)
- if method is not None and hasattr(method, '__info__') and \
- isinstance(method.__info__, VFuncInfo):
- vfunc_info = method.__info__
+ if method is not None and isinstance(method, VFuncInfo):
+ vfunc_info = method
break
# If we did not find a matching method name in the bases, we might
@@ -231,9 +122,8 @@ class MetaClassHelper(object):
return
for vfunc_info in class_info.get_vfuncs():
- name = 'do_%s' % vfunc_info.get_name()
- value = NativeVFunc(vfunc_info)
- setattr(cls, name, value)
+ name = 'do_%s' % vfunc_info.__name__
+ setattr(cls, name, vfunc_info)
def find_vfunc_info_in_interface(bases, vfunc_name):
@@ -300,7 +190,6 @@ class GObjectMeta(_gobject.GObjectMeta, MetaClassHelper):
if isinstance(cls.__info__, ObjectInfo):
cls._setup_fields()
- cls._setup_constructors()
elif isinstance(cls.__info__, InterfaceInfo):
register_interface_info(cls.__info__.get_g_type())
@@ -309,17 +198,40 @@ class GObjectMeta(_gobject.GObjectMeta, MetaClassHelper):
def mro(C):
- """Compute the class precedence list (mro) according to C3
+ """Compute the class precedence list (mro) according to C3, with GObject
+ interface considerations.
+
+ We override Python's MRO calculation to account for the fact that
+ GObject classes are not affected by the diamond problem:
+ http://en.wikipedia.org/wiki/Diamond_problem
Based on http://www.python.org/download/releases/2.3/mro/
- Modified to consider that interfaces don't create the diamond problem
"""
# TODO: If this turns out being too slow, consider using generators
bases = []
bases_of_subclasses = [[C]]
if C.__bases__:
- bases_of_subclasses += list(map(mro, C.__bases__)) + [list(C.__bases__)]
+ for base in C.__bases__:
+ # Python causes MRO's to be calculated starting with the lowest
+ # base class and working towards the descendant, storing the result
+ # in __mro__ at each point. Therefore at this point we know that
+ # we already have our base class MRO's available to us, there is
+ # no need for us to (re)calculate them.
+ if hasattr(base, '__mro__'):
+ bases_of_subclasses += [list(base.__mro__)]
+ else:
+ warnings.warn('Mixin class %s is an old style class, please '
+ 'update this to derive from "object".' % base,
+ RuntimeWarning)
+ # For old-style classes (Python2 only), the MRO is not
+ # easily accessible. As we do need it here, we calculate
+ # it via recursion, according to the C3 algorithm. Using C3
+ # for old style classes deviates from Python's own behaviour,
+ # but visible effects here would be a corner case triggered by
+ # questionable design.
+ bases_of_subclasses += [mro(base)]
+ bases_of_subclasses += [list(C.__bases__)]
while bases_of_subclasses:
for subclass_bases in bases_of_subclasses:
@@ -357,11 +269,10 @@ class StructMeta(type, MetaClassHelper):
cls._setup_fields()
cls._setup_methods()
- cls._setup_constructors()
for method_info in cls.__info__.get_methods():
if method_info.is_constructor() and \
- method_info.get_name() == 'new' and \
+ method_info.__name__ == 'new' and \
not method_info.get_arguments():
- cls.__new__ = staticmethod(Constructor(method_info))
+ cls.__new__ = staticmethod(method_info)
break