Created
December 19, 2012 19:27
-
-
Save nagisa/4339696 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// C works correctly. | |
// clang giotest.c -o giotest -pthread -I/usr/include/gtk-3.0 -I/usr/include/atk-1.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/pixman-1 -I/usr/include/libpng15 -lgtk-3 -lgdk-3 -latk-1.0 -lgio-2.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo-gobject -lpango-1.0 -lcairo -lgobject-2.0 -lglib-2.0 | |
#include<glib.h> | |
#include<glib-object.h> | |
#include<gio/gio.h> | |
#include<gtk/gtk.h> | |
#include<stdio.h> | |
#include<stdlib.h> | |
void file_replaced(GObject *source, GAsyncResult *res, gpointer user_data){ | |
printf("Done, check id with md5sum or whatever"); | |
exit(0); | |
} | |
int main(void){ | |
g_type_init(); | |
GFile *file; | |
char *contents = "\x00\x00\x01\x00\x01\x00\x10\x10\x10\x00\x01\x00\x04\x00(\x01\x00\x00" | |
"\x16\x00\x00\x00(\x00\x00\x00\x10\x00\x00\x00 \x00\x00\x00\x01\x00\x04" | |
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" | |
"\x00\x00\x00\x00\x00\x00\x00\x00\x93\x9a\x9c\x00\x9a\xa3\xa3\x00\xa4" | |
"\xa8\xa8\x00\xa8\xae\xae\x00\xad\xb8\xba\x00\xbd\xc3\xc4\x00\xc5\xce" | |
"\xcf\x00\xc9\xd3\xd4\x00\xd1\xd8\xd8\x00\xd7\xdd\xdc\x00\xdf\xe3\xe2" | |
"\x00\xe5\xe8\xe8\x00\xec\xee\xef\x00\xf5\xf6\xf6\x00\x00\x00\x00\x00" | |
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" | |
"\x00\x00\x00\x00\x00\x0c\xbb\xcd\x00\x00\x00\x00\x0cR\x11#Z\x00\x00" | |
"\x8b\x87uD10\t\xa9\x88\x97w\x87S@\x0b\xa8i\x89\xa9\x9a\xa7p\r\xa9y" | |
"\xab\xb9\x99\xaa\xb0\x00\xca\x98x\xb9\x89\xaa\x00\x00\x0c\xb9\x87\x8a" | |
"\x99\xad\x00\x00\x00\r\xbb\xbb\xcc\xd0\x00\x00\x00\x00\x00\x00\x00\x00" | |
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x00\x00\xff\xff\x00\x00" | |
"\xf8?\x00\x00\xe0\x0f\x00\x00\xc0\x03\x00\x00\xc0\x01\x00\x00\x80\x01" | |
"\x00\x00\x80\x01\x00\x00\x80\x01\x00\x00\x80\x01\x00\x00\x80\x01\x00" | |
"\x00\xc0\x03\x00\x00\xe0\x03\x00\x00\xf8\x07\x00\x00\xff\xff\x00\x00" | |
"\xff\xff\x00\x00"; | |
file = g_file_new_for_path("gio_sync"); | |
g_file_replace_contents(file, contents, 200, NULL, 0, G_FILE_CREATE_NONE, NULL, NULL, NULL); | |
file = g_file_new_for_path("gio_async"); | |
g_file_replace_contents_async(file, contents, 200, NULL, 0, G_FILE_CREATE_NONE, NULL, file_replaced, NULL); | |
while(1){ | |
gtk_main_iteration_do(0); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from gi.repository import Gio, Gtk | |
import sys | |
icon = b'\x00\x00\x01\x00\x01\x00\x10\x10\x10\x00\x01\x00\x04\x00(\x01\x00\x00'\ | |
b'\x16\x00\x00\x00(\x00\x00\x00\x10\x00\x00\x00 \x00\x00\x00\x01\x00\x04'\ | |
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'\ | |
b'\x00\x00\x00\x00\x00\x00\x00\x00\x93\x9a\x9c\x00\x9a\xa3\xa3\x00\xa4'\ | |
b'\xa8\xa8\x00\xa8\xae\xae\x00\xad\xb8\xba\x00\xbd\xc3\xc4\x00\xc5\xce'\ | |
b'\xcf\x00\xc9\xd3\xd4\x00\xd1\xd8\xd8\x00\xd7\xdd\xdc\x00\xdf\xe3\xe2'\ | |
b'\x00\xe5\xe8\xe8\x00\xec\xee\xef\x00\xf5\xf6\xf6\x00\x00\x00\x00\x00'\ | |
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'\ | |
b'\x00\x00\x00\x00\x00\x0c\xbb\xcd\x00\x00\x00\x00\x0cR\x11#Z\x00\x00'\ | |
b'\x00\xb3\x10\x01"\x01\\\x00\x00R""\x121\x03\xc0\tUVTC3\x10P\x07\x88'\ | |
b'\x8b\x87uD10\t\xa9\x88\x97w\x87S@\x0b\xa8i\x89\xa9\x9a\xa7p\r\xa9y'\ | |
b'\xab\xb9\x99\xaa\xb0\x00\xca\x98x\xb9\x89\xaa\x00\x00\x0c\xb9\x87\x8a'\ | |
b'\x99\xad\x00\x00\x00\r\xbb\xbb\xcc\xd0\x00\x00\x00\x00\x00\x00\x00\x00'\ | |
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x00\x00\xff\xff\x00\x00'\ | |
b'\xf8?\x00\x00\xe0\x0f\x00\x00\xc0\x03\x00\x00\xc0\x01\x00\x00\x80\x01'\ | |
b'\x00\x00\x80\x01\x00\x00\x80\x01\x00\x00\x80\x01\x00\x00\x80\x01\x00'\ | |
b'\x00\xc0\x03\x00\x00\xe0\x03\x00\x00\xf8\x07\x00\x00\xff\xff\x00\x00'\ | |
b'\xff\xff\x00\x00' | |
print('Writing a sync version') | |
f = Gio.File.new_for_path('gio_sync') | |
f.replace_contents(icon, None, False, Gio.FileCreateFlags.NONE, None) | |
def on_icon_written(f, result, data): | |
f.replace_contents_finish(result) | |
print('Done writing') | |
with open('gio_sync', 'rb') as sync, open('gio_async', 'rb') as async: | |
for i in range(318): | |
async_byte, sync_byte = async.read(1), sync.read(1) | |
if sync_byte != async_byte: | |
print('Sync[{0}]= {1}, Async[{0}]= {2}'.format(i, sync_byte, async_byte)) | |
sys.exit(0) | |
print('Writing an async version') | |
f = Gio.File.new_for_path('gio_async') | |
f.replace_contents_async(icon, None, False, Gio.FileCreateFlags.NONE, None, on_icon_written, None) | |
while Gtk.main_iteration_do(False): | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment